//
// CPN is different from Class Mass Normalization (CMN) as CMN is used post
// classification, while CPN is used before the classification process is
// started.
public void ClassPriorNormalization() {
TObjectDoubleHashMap labels = new TObjectDoubleHashMap();
// compute class weight sum
TObjectDoubleHashMap classSeedSum = new TObjectDoubleHashMap();
Iterator<String> viter0 = this._vertices.keySet().iterator();
while (viter0.hasNext()) {
String vName = viter0.next();
Vertex2 v = _vertices.get(vName);
if (v.IsSeedNode()) {
TObjectDoubleIterator injLabIter =
this._labelManager.getLabelScores(v.GetInjectedLabelScores()).iterator();
while (injLabIter.hasNext()) {
injLabIter.advance();
double currVal = classSeedSum.containsKey(injLabIter.key()) ?
classSeedSum.get(injLabIter.key()) : 0;
classSeedSum.put(injLabIter.key(), currVal + injLabIter.value());
// add the label to the list of labels
if (!labels.containsKey(injLabIter.key())) {
labels.put(injLabIter.key(), 1.0);
}
}
}
}
double[] seedWeightSums = classSeedSum.getValues();
double maxSum = -1;
for (int wsi = 0; wsi < seedWeightSums.length; ++wsi) {
if (seedWeightSums[wsi] > maxSum) {
maxSum = seedWeightSums[wsi];
}
}
TObjectDoubleHashMap seedAmpliFactor = new TObjectDoubleHashMap();
TObjectDoubleIterator wIter = classSeedSum.iterator();
while (wIter.hasNext()) {
wIter.advance();
seedAmpliFactor.put(wIter.key(), maxSum / wIter.value());
System.out.println("Label: " + wIter.key() +
" ampli_factor: " + seedAmpliFactor.get(wIter.key()));
}
// now multiply injected scores with amplification factors
Iterator<String> viter = this._vertices.keySet().iterator();
while (viter.hasNext()) {
String vName = viter.next();
Vertex2 v = _vertices.get(vName);
if (v.IsSeedNode()) {
TObjectDoubleIterator injLabIter =
this._labelManager.getLabelScores(v.GetInjectedLabelScores()).iterator();
while (injLabIter.hasNext()) {
injLabIter.advance();
double currVal = injLabIter.value();
injLabIter.setValue(currVal * seedAmpliFactor.get(injLabIter.key()));
}
}
}
}