66 lines
1.9 KiB
Plaintext
66 lines
1.9 KiB
Plaintext
<snippet>
|
|
<subclass>afryca.ase.Snippet</subclass>
|
|
<file></file>
|
|
<category>Library</category>
|
|
<name>disunification</name>
|
|
<description>Disunite different kinds of information</description>
|
|
<code>
|
|
var disunification = (typeof exports === "undefined")?(function disunification() {}):(exports);
|
|
if(typeof global !== "undefined") { global.disunification = disunification; }
|
|
|
|
disunification.disunite = function disunite(preferences) {
|
|
var structure;
|
|
var structurePreferences;
|
|
var unifiedDomain;
|
|
var twoTuplePreference;
|
|
|
|
var twoTuples = new ArrayList(preferences.size());
|
|
|
|
for(var p = 0; p < preferences.size(); p++) {
|
|
structure = preferences.get(p);
|
|
structurePreferences = structure.getPreferences();
|
|
twoTuplePreference = structure.createDefaultStructure(structurePreferences[0].length | 0, structurePreferences.length | 0);
|
|
for(var row = 0; row < structurePreferences.length; row++) {
|
|
for(var col = 0; col < structurePreferences[row].length; col++) {
|
|
unifiedDomain = structurePreferences[row][col];
|
|
if(unifiedDomain instanceof TwoTuple) {
|
|
twoTuplePreference.getPreferences()[row][col] = structurePreferences[row][col];
|
|
} else {
|
|
twoTuplePreference.getPreferences()[row][col] = disunification.disuniteValuation(unifiedDomain);
|
|
}
|
|
}
|
|
}
|
|
|
|
twoTuples.add(twoTuplePreference);
|
|
}
|
|
|
|
return twoTuples;
|
|
}
|
|
|
|
disunification.disuniteValuation = function disuniteValuation(unifiedDomain) {
|
|
var result = new TwoTuple(unifiedDomain.clone());
|
|
var size = unifiedDomain.getLabelSet().getCardinality();
|
|
var numerator = 0;
|
|
var denominator = 0;
|
|
var measure;
|
|
var beta = 0;
|
|
|
|
for (var i = 0; i < size; i++) {
|
|
result.getDomain().setValue(i | 0, 0 | 0);
|
|
measure = unifiedDomain.getValue(i | 0);
|
|
numerator += measure * i;
|
|
denominator += measure;
|
|
}
|
|
|
|
if (denominator != 0) {
|
|
beta = numerator / denominator;
|
|
}
|
|
|
|
result.calculateDelta(beta);
|
|
|
|
return result;
|
|
}
|
|
|
|
disunification
|
|
</code>
|
|
</snippet> |