use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.
the class Vectors method concatenate.
public static Vector concatenate(Vector vector, Vector vector2) {
Vector con = null;
if (vector instanceof DenseVector) {
con = new DenseVector(vector.size() + vector2.size());
}
if (vector instanceof RandomAccessSparseVector) {
con = new RandomAccessSparseVector(vector.size() + vector2.size());
}
if (vector instanceof SequentialAccessSparseVector) {
con = new SequentialAccessSparseVector(vector.size() + vector2.size());
}
for (Vector.Element nonZeros : vector.nonZeroes()) {
int index = nonZeros.index();
double value = nonZeros.get();
con.set(index, value);
}
for (Vector.Element nonZeros : vector2.nonZeroes()) {
int index = nonZeros.index();
double value = nonZeros.get();
con.set(index + vector.size(), value);
}
return con;
}
use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.
the class Vectors method concatenate.
public static Vector concatenate(Vector vector, double[] numbers) {
Vector con = null;
if (vector instanceof DenseVector) {
con = new DenseVector(vector.size() + numbers.length);
}
if (vector instanceof RandomAccessSparseVector) {
con = new RandomAccessSparseVector(vector.size() + numbers.length);
}
if (vector instanceof SequentialAccessSparseVector) {
con = new SequentialAccessSparseVector(vector.size() + numbers.length);
}
for (Vector.Element nonZeros : vector.nonZeroes()) {
int index = nonZeros.index();
double value = nonZeros.get();
con.set(index, value);
}
for (int i = 0; i < numbers.length; i++) {
con.set(i + vector.size(), numbers[i]);
}
return con;
}
use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.
the class FusedKolmogorovFilter method generateInputsEachClass.
public List<List<Double>> generateInputsEachClass(Vector vector, int[] labels, int numClasses) {
Vector input;
if (vector.isDense()) {
input = vector;
} else {
input = new DenseVector(vector);
}
List<List<Double>> inputsEachClass = new ArrayList<>();
for (int k = 0; k < numClasses; k++) {
inputsEachClass.add(new ArrayList<>());
}
for (int i = 0; i < labels.length; i++) {
int label = labels[i];
inputsEachClass.get(label).add(input.get(i));
}
return inputsEachClass;
}
use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.
the class MLACPlattScaling method predictClassProbs.
@Override
public double[] predictClassProbs(Vector vector) {
double[] scores = scoreEstimator.predictClassScores(vector);
Vector scoreVector = new DenseVector(scores.length);
for (int i = 0; i < scores.length; i++) {
scoreVector.set(i, scores[i]);
}
return this.logisticRegression.predictClassProbs(scoreVector);
}
use of org.apache.mahout.math.DenseVector in project pyramid by cheng-li.
the class MLPlattScaling method predictClassProb.
@Override
public double predictClassProb(Vector vector, int classIndex) {
double score = scoreEstimator.predictClassScore(vector, classIndex);
Vector scoreVector = new DenseVector(1);
scoreVector.set(0, score);
return logisticRegressions.get(classIndex).predictClassProb(scoreVector, 1);
}
Aggregations