Java 类org.apache.commons.math3.linear.OpenMapRealVector 实例源码

项目:Indra    文件:BinaryCodecs.java   
/**
 * Vector deserialization.
 */
public static RealVector unmarshall(byte[] bytes, boolean sparse, int dimensions) throws IOException {
    RealVector realVector = !sparse ? new ArrayRealVector(dimensions) : new OpenMapRealVector(dimensions);

    if (!sparse) {
        try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes))) {
            for (int i = 0; i < dimensions; i++) {
                realVector.setEntry(i, dis.readDouble());
            }
        }
    }
    else {
        try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes))) {
            while (true) {
                try {
                    realVector.setEntry(dis.readInt(), dis.readDouble());
                }
                catch (EOFException e) {
                    break;
                }
            }
        }
    }

    return realVector;
}
项目:eswc-2015-semantic-typing    文件:DocumentSimilarity.java   
public void getTopK(int testIndex, int numPred, ArrayList<String> predictions, ArrayList<Double> confidenceScores)
{
 int size = docs[0].vector.getDimension();
 SparseRealVector onesVector = new OpenMapRealVector(size);
 for(int i=0; i<size; i++)
 {
     onesVector.setEntry(i, 1); 
 }

 List<Prediction> sortedPredictions = new ArrayList<Prediction>();  // descending order of jaccard similarity

 for(int i=0; i<info.noTrainingDocs; i++)
 {
     double jacSim = getJaccardSimilarity(docs[i], docs[info.noTrainingDocs + testIndex], onesVector);
     Prediction pred = new Prediction(new Integer(i).toString(), jacSim);
     if(jacSim > 0.0)
     {
         sortedPredictions.add(pred);
     }
     //System.out.println(i+" "+jacSim);
 }

 Collections.sort(sortedPredictions, new PredictionComparator());

 //System.out.println("no of predictions = "+sortedPredictions.size());

    for(int j=0; j<numPred && j<sortedPredictions.size(); j++)
    {
        predictions.add(sortedPredictions.get(j).predictionIndex);
        confidenceScores.add(sortedPredictions.get(j).confidenceScore);
    }   

}
项目:WikiKreator    文件:DocVector.java   
public DocVector(Map<String,Integer> terms) {
    this.terms = terms;
    this.vector = new OpenMapRealVector(terms.size());
}
项目:WikiKreator    文件:DocVector.java   
public DocVector(Map<String,Integer> terms) {
    this.terms = terms;
    this.vector = new OpenMapRealVector(terms.size());
}
项目:eswc-2015-semantic-typing    文件:DocumentSimilarity.java   
public DocVector(Map<String,Integer> terms) {
  this.terms = terms;
  this.vector = new OpenMapRealVector(terms.size());
}
项目:eventspotter    文件:CosineSimilarity.java   
@SuppressWarnings("deprecation")
public DocVector(Map<String,Integer> terms) {
        this.terms = terms;
        this.vector = new OpenMapRealVector(terms.size());
      }