Search in sources :

Example 1 with DelegatingNamedVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DelegatingNamedVector in project ignite by apache.

the class VectorUtils method of.

/**
 * Creates named vector based on map of keys and values.
 *
 * @param values Values.
 * @return Named vector.
 */
public static NamedVector of(Map<String, Double> values) {
    SparseVector vector = new SparseVector(values.size());
    for (int i = 0; i < values.size(); i++) vector.set(i, Double.NaN);
    Map<String, Integer> dict = new HashMap<>();
    int idx = 0;
    for (Map.Entry<String, Double> e : values.entrySet()) {
        dict.put(e.getKey(), idx);
        vector.set(idx, e.getValue());
        idx++;
    }
    return new DelegatingNamedVector(vector, dict);
}
Also used : HashMap(java.util.HashMap) DelegatingNamedVector(org.apache.ignite.ml.math.primitives.vector.impl.DelegatingNamedVector) SparseVector(org.apache.ignite.ml.math.primitives.vector.impl.SparseVector) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 DelegatingNamedVector (org.apache.ignite.ml.math.primitives.vector.impl.DelegatingNamedVector)1 SparseVector (org.apache.ignite.ml.math.primitives.vector.impl.SparseVector)1