use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.
the class CMLCRF method calClassProbs.
/**
* marginal probabilities
* @param assignmentProbs
* @return
*/
public double[] calClassProbs(double[] assignmentProbs) {
double[] classProbs = new double[numClasses];
for (int a = 0; a < numSupports; a++) {
MultiLabel assignment = supportCombinations.get(a);
double prob = assignmentProbs[a];
for (Integer label : assignment.getMatchedLabels()) {
classProbs[label] += prob;
}
}
return classProbs;
}
use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.
the class CMLCRF method predictCombinationScore.
// todo fix: handle separately
private double predictCombinationScore(int labelComIndex, double[] classScores) {
MultiLabel label = supportCombinations.get(labelComIndex);
double score = 0.0;
for (Integer l : label.getMatchedLabels()) {
score += classScores[l];
}
if (considerPair) {
score += combinationLabelPartScores[labelComIndex];
}
return score;
}
use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.
the class SparseCBMOptimzer method updateGamma.
private void updateGamma(int n) {
Vector x = dataSet.getRow(n);
MultiLabel y = dataSet.getMultiLabels()[n];
double[] posterior = cbm.posteriorMembership(x, y);
for (int k = 0; k < cbm.numComponents; k++) {
gammas[n][k] = posterior[k];
}
}
use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.
the class BlockwiseCD method calEmpiricalCountForFeature.
private double calEmpiricalCountForFeature(int parameterIndex) {
double empiricalCount = 0.0;
int classIndex = parameterToClass[parameterIndex];
int featureIndex = parameterToFeature[parameterIndex];
if (featureIndex == -1) {
for (int i = 0; i < dataSet.getNumDataPoints(); i++) {
if (dataSet.getMultiLabels()[i].matchClass(classIndex)) {
empiricalCount += 1;
}
}
} else {
Vector column = dataSet.getColumn(featureIndex);
MultiLabel[] multiLabels = dataSet.getMultiLabels();
for (Vector.Element element : column.nonZeroes()) {
int dataIndex = element.index();
double featureValue = element.get();
if (multiLabels[dataIndex].matchClass(classIndex)) {
empiricalCount += featureValue;
}
}
}
return empiricalCount;
}
use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.
the class CRFF1Loss method calEmpiricalCountForLabelPair.
private double calEmpiricalCountForLabelPair(int parameterIndex) {
double empiricalCount = 0.0;
int start = parameterIndex - numWeightsForFeatures;
int l1 = parameterToL1[start];
int l2 = parameterToL2[start];
int featureCase = start % 4;
for (int i = 0; i < dataSet.getNumDataPoints(); i++) {
MultiLabel label = dataSet.getMultiLabels()[i];
switch(featureCase) {
// both l1, l2 equal 0;
case 0:
if (!label.matchClass(l1) && !label.matchClass(l2))
empiricalCount += 1.0;
break;
// l1 = 1; l2 = 0;
case 1:
if (label.matchClass(l1) && !label.matchClass(l2))
empiricalCount += 1.0;
break;
// l1 = 0; l2 = 1;
case 2:
if (!label.matchClass(l1) && label.matchClass(l2))
empiricalCount += 1.0;
break;
// l1 = 1; l2 = 1;
case 3:
if (label.matchClass(l1) && label.matchClass(l2))
empiricalCount += 1.0;
break;
default:
throw new RuntimeException("feature case :" + featureCase + " failed.");
}
}
return empiricalCount;
}
Aggregations