ecclesia
Version:
Framework for political and electoral simulations
31 lines • 889 B
JavaScript
// src/actors/disagreement.ts
import { sum } from "@gouvernathor/python";
function symmetricDiff({ nOpinions, opinMax }) {
return (a, b) => sum(a.map((oa, i) => Math.abs(oa - b[i]))) / (nOpinions * 2 * opinMax);
}
function ponderedDiff({ nOpinions, opinMax }) {
return (a, b) => 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);
};
}
export {
fromMaxDiff,
ponderedDiff,
symmetricDiff
};
//# sourceMappingURL=disagreement.js.map