Example usage for org.apache.commons.math3.linear RealVector setEntry

List of usage examples for org.apache.commons.math3.linear RealVector setEntry

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear RealVector setEntry.

Prototype

public abstract void setEntry(int index, double value) throws OutOfRangeException;

Source Link

Document

Set a single element.

Usage

From source file:trustframework.utils.Similarity.java

/**
 * Build a real vector from frequencies//from  w  w  w  .  j av  a2s.  c o m
 * @param <T> Type of hask keys
 * @param freq hash with frequencies
 * @param keys set of all keys available
 * @return 
 */
private static <T> RealVector buildRealVector(Map<T, Integer> freq, Set<T> keys) {
    RealVector vector = new ArrayRealVector(keys.size());
    int i = 0;
    for (T term : keys) {
        int value = freq.containsKey(term) ? freq.get(term) : 0;
        vector.setEntry(i++, value);
    }
    vector = vector.mapDivide(vector.getL1Norm());
    return vector;
}