use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.
the class ExpectedRecallFeatureExtractor method extractFeatures.
@Override
public Vector extractFeatures(PredictionCandidate predictionCandidate) {
MultiLabel prediction = predictionCandidate.multiLabel;
double expectation = 0;
List<Pair<MultiLabel, Double>> sparseJoint = predictionCandidate.sparseJoint;
for (Pair<MultiLabel, Double> pair : sparseJoint) {
MultiLabel multiLabel = pair.getFirst();
double prob = pair.getSecond();
expectation += Recall.recall(multiLabel, prediction) * prob;
}
Vector vector = new DenseVector(1);
vector.set(0, expectation);
return vector;
}
use of org.apache.mahout.math.DenseVector in project elephant-bird by twitter.
the class VectorWritableConverter method convertDenseVectorDataToVector.
private Vector convertDenseVectorDataToVector(Tuple value) throws IOException {
Vector v;
// determine output vector size
int size = value.size();
int minSize = size;
if (cardinality != null && cardinality != size) {
// cardinality specified on construction overrides instance cardinality
size = cardinality;
if (minSize > size) {
minSize = size;
}
}
// allow conversion of dense vector data to sparse vector
if (sparse) {
// this ctor used to pre-alloc space for entries
v = new RandomAccessSparseVector(size, size);
for (int i = 0; i < minSize; ++i) {
v.setQuick(i, ((Number) value.get(i)).doubleValue());
}
} else {
double[] values = new double[size];
for (int i = 0; i < minSize; ++i) {
values[i] = ((Number) value.get(i)).doubleValue();
}
// this ctor uses values directly, no copying performed
v = new DenseVector(values, true);
}
return v;
}
use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.
the class InstanceFeatureExtractor method extractFeatures.
@Override
public Vector extractFeatures(PredictionCandidate predictionCandidate) {
int size = featureIndices.size();
Vector vector = new DenseVector(size);
for (int j = 0; j < size; j++) {
int index = featureIndices.get(j);
vector.set(j, predictionCandidate.x.get(index));
}
return vector;
}
use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.
the class PriorFeatureExtractor method extractFeatures.
@Override
public Vector extractFeatures(PredictionCandidate prediction) {
Vector vector = new DenseVector(1);
double prior = priors.getOrDefault(prediction.multiLabel, 0.0);
vector.set(0, prior);
return vector;
}
use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.
the class ExpectedF1FeatureExtractor method extractFeatures.
@Override
public Vector extractFeatures(PredictionCandidate predictionCandidate) {
MultiLabel prediction = predictionCandidate.multiLabel;
double expectation = 0;
List<Pair<MultiLabel, Double>> sparseJoint = predictionCandidate.sparseJoint;
for (Pair<MultiLabel, Double> pair : sparseJoint) {
MultiLabel multiLabel = pair.getFirst();
double prob = pair.getSecond();
expectation += FMeasure.f1(prediction, multiLabel) * prob;
}
Vector vector = new DenseVector(1);
vector.set(0, expectation);
return vector;
}
Aggregations