use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.
the class IMLLogisticLoss method calEmpricalCount.
private double calEmpricalCount(int parameterIndex) {
int classIndex = logisticRegression.getWeights().getClassIndex(parameterIndex);
MultiLabel[] labels = dataSet.getMultiLabels();
int featureIndex = logisticRegression.getWeights().getFeatureIndex(parameterIndex);
double count = 0;
//bias
if (featureIndex == -1) {
for (int i = 0; i < dataSet.getNumDataPoints(); i++) {
if (labels[i].matchClass(classIndex)) {
count += 1;
}
}
} else {
Vector featureColumn = dataSet.getColumn(featureIndex);
for (Vector.Element element : featureColumn.nonZeroes()) {
int dataPointIndex = element.index();
double featureValue = element.get();
MultiLabel label = labels[dataPointIndex];
if (label.matchClass(classIndex)) {
count += featureValue;
}
}
}
return count;
}
use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.
the class IMLLogisticRegression method predictWithConstraints.
/**
* only consider these assignments
* @param vector
* @return
*/
private MultiLabel predictWithConstraints(Vector vector) {
double maxScore = Double.NEGATIVE_INFINITY;
MultiLabel prediction = null;
double[] classScores = predictClassScores(vector);
for (MultiLabel assignment : this.assignments) {
double score = this.calAssignmentScore(assignment, classScores);
if (score > maxScore) {
maxScore = score;
prediction = assignment;
}
}
return prediction;
}
use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.
the class GeneralF1Predictor method exhaustiveSearch.
public static MultiLabel exhaustiveSearch(int numClasses, Matrix lossMatrix, List<Double> probabilities) {
double bestScore = Double.POSITIVE_INFINITY;
Vector vector = new DenseVector(probabilities.size());
for (int i = 0; i < vector.size(); i++) {
vector.set(i, probabilities.get(i));
}
List<MultiLabel> multiLabels = Enumerator.enumerate(numClasses);
MultiLabel multiLabel = null;
for (int j = 0; j < lossMatrix.numCols(); j++) {
Vector column = lossMatrix.viewColumn(j);
double score = column.dot(vector);
System.out.println("column " + j + ", expected loss = " + score);
if (score < bestScore) {
bestScore = score;
multiLabel = multiLabels.get(j);
}
}
return multiLabel;
}
use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.
the class InstanceF1Predictor method predict.
@Override
public MultiLabel predict(Vector vector) {
double[] probs = imlGradientBoosting.predictAllAssignmentProbsWithConstraint(vector);
List<Double> probList = Arrays.stream(probs).mapToObj(a -> a).collect(Collectors.toList());
GeneralF1Predictor generalF1Predictor = new GeneralF1Predictor();
return generalF1Predictor.predict(imlGradientBoosting.getNumClasses(), imlGradientBoosting.getAssignments(), probList);
}
use of edu.neu.ccs.pyramid.dataset.MultiLabel in project pyramid by cheng-li.
the class MLLogisticLoss method calEmpricalCount.
private double calEmpricalCount(int parameterIndex) {
int classIndex = mlLogisticRegression.getWeights().getClassIndex(parameterIndex);
MultiLabel[] labels = dataSet.getMultiLabels();
int featureIndex = mlLogisticRegression.getWeights().getFeatureIndex(parameterIndex);
double count = 0;
//bias
if (featureIndex == -1) {
for (int i = 0; i < dataSet.getNumDataPoints(); i++) {
if (labels[i].matchClass(classIndex)) {
count += 1;
}
}
} else {
Vector featureColumn = dataSet.getColumn(featureIndex);
for (Vector.Element element : featureColumn.nonZeroes()) {
int dataPointIndex = element.index();
double featureValue = element.get();
MultiLabel label = labels[dataPointIndex];
if (label.matchClass(classIndex)) {
count += featureValue;
}
}
}
return count;
}
Aggregations