ecclesia
Version:
Framework for political and electoral simulations
58 lines (57 loc) • 2.04 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/actors/disagreement.ts
var disagreement_exports = {};
__export(disagreement_exports, {
fromMaxDiff: () => fromMaxDiff,
ponderedDiff: () => ponderedDiff,
symmetricDiff: () => symmetricDiff
});
module.exports = __toCommonJS(disagreement_exports);
var import_python = require("@gouvernathor/python");
function symmetricDiff({ nOpinions, opinMax }) {
return (a, b) => (0, import_python.sum)(a.map((oa, i) => Math.abs(oa - b[i]))) / (nOpinions * 2 * opinMax);
}
function ponderedDiff({ nOpinions, opinMax }) {
return (a, b) => (0, import_python.sum)(a.map((oa, i) => Math.abs(oa - b[i]) * b[i])) / (nOpinions * 2 * opinMax ** 2);
}
function fromMaxDiff({ nOpinions, opinMax }) {
return (a, b) => {
let diffSum = 0;
for (let i = 0; i < nOpinions; i++) {
const ao = a[i];
const bo = b[i];
if (ao * bo < 0) {
diffSum += Math.abs(ao * bo);
} else if (Math.abs(ao) < Math.abs(bo)) {
;
} else {
diffSum += Math.abs(ao - bo);
}
}
return diffSum / (nOpinions * opinMax ** 2);
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
fromMaxDiff,
ponderedDiff,
symmetricDiff
});
//# sourceMappingURL=disagreement.cjs.map