Java Code Examples for org.apache.mahout.math.Matrix#numCols()

The following examples show how to use org.apache.mahout.math.Matrix#numCols() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneralF1Predictor.java    From pyramid with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: LaserOfflineTrainTask.java    From laser with Apache License 2.0 5 votes vote down vote up
public void writeOrigOfflineModel(Path model, FileSystem fs,
		org.apache.hadoop.conf.Configuration conf, MsgpackClient client)
		throws Exception {
	Vector alpha = readVector(new Path(model, "alpha"), fs, conf);
	Vector beta = readVector(new Path(model, "beta"), fs, conf);
	Matrix A = readMatrix(new Path(model, "A"), fs, conf);

	Object[] req = new Object[3];
	List<Float> alpha1 = new ArrayList<Float>(alpha.size());

	for (int i = 0; i < alpha.size(); i++) {
		alpha1.add((float) (alpha.get(i)));
	}
	req[0] = alpha1;

	List<Float> beta1 = new ArrayList<Float>(beta.size());
	for (int i = 0; i < beta.size(); i++) {
		beta1.add((float) beta.get(i));
	}
	req[1] = beta1;

	List<Float> conjunction = new ArrayList<Float>(A.numRows()
			* A.numCols());
	for (int row = 0; row < A.numRows(); row++) {
		Vector vec = A.viewRow(row);
		for (int col = 0; col < A.numCols(); col++) {
			conjunction.add((float) vec.get(col));
		}
	}
	req[2] = conjunction;
	client.writeIgnoreRetValue(req, "updateLaserOfflineModel");

}