Search in sources :

Example 51 with IntFloatVectorStorage

use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.

the class IntFloatVector method min.

public float min() {
    IntFloatVectorStorage idstorage = (IntFloatVectorStorage) storage;
    if (idstorage.size() == 0)
        return 0;
    float minval = Float.MAX_VALUE;
    if (idstorage.isSparse()) {
        FloatIterator iter = idstorage.valueIterator();
        while (iter.hasNext()) {
            float val = iter.nextFloat();
            if (val < minval) {
                minval = val;
            }
        }
    } else {
        for (float val : idstorage.getValues()) {
            if (val < minval) {
                minval = val;
            }
        }
    }
    return minval;
}
Also used : FloatIterator(it.unimi.dsi.fastutil.floats.FloatIterator) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)

Example 52 with IntFloatVectorStorage

use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.

the class IntFloatVector method std.

public double std() {
    IntFloatVectorStorage dstorage = (IntFloatVectorStorage) storage;
    if (dstorage.size() == 0)
        return 0;
    double sumval = 0.0;
    double sumval2 = 0.0;
    if (dstorage.isSparse()) {
        FloatIterator iter = dstorage.valueIterator();
        while (iter.hasNext()) {
            double val = iter.nextFloat();
            sumval += val;
            sumval2 += val * val;
        }
    } else {
        for (double val : dstorage.getValues()) {
            sumval += val;
            sumval2 += val * val;
        }
    }
    sumval /= getDim();
    sumval2 /= getDim();
    return Math.sqrt(sumval2 - sumval * sumval);
}
Also used : FloatIterator(it.unimi.dsi.fastutil.floats.FloatIterator) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)

Example 53 with IntFloatVectorStorage

use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.

the class IntFloatVector method argmax.

public int argmax() {
    IntFloatVectorStorage idstorage = (IntFloatVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    float maxval = Float.MIN_VALUE;
    int maxidx = -1;
    if (idstorage.isDense()) {
        float[] val = idstorage.getValues();
        int length = val.length;
        for (int idx = 0; idx < length; idx++) {
            if (val[idx] > maxval) {
                maxval = val[idx];
                maxidx = idx;
            }
        }
    } else if (idstorage.isSparse()) {
        ObjectIterator<Int2FloatMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Int2FloatMap.Entry entry = iter.next();
            int idx = entry.getIntKey();
            float val = entry.getFloatValue();
            if (val > maxval) {
                maxval = val;
                maxidx = idx;
            }
        }
    } else {
        int[] indices = idstorage.getIndices();
        float[] val = idstorage.getValues();
        int size = idstorage.size();
        for (int i = 0; i < size; i++) {
            int idx = indices[i];
            if (val[i] > maxval) {
                maxval = val[i];
                maxidx = idx;
            }
        }
    }
    return maxidx;
}
Also used : IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 54 with IntFloatVectorStorage

use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.

the class HashRouterUtils method splitIntFloatVector.

public static void splitIntFloatVector(KeyHash hasher, MatrixMeta matrixMeta, IntFloatVector vector, KeyValuePart[] dataParts) {
    int dataPartNum = dataParts.length;
    int dataPartNumMinus1 = dataPartNum - 1;
    if (isPow2(dataPartNum)) {
        IntFloatVectorStorage storage = vector.getStorage();
        if (storage.isSparse()) {
            // Use iterator
            IntFloatSparseVectorStorage sparseStorage = (IntFloatSparseVectorStorage) storage;
            ObjectIterator<Int2FloatMap.Entry> iter = sparseStorage.entryIterator();
            while (iter.hasNext()) {
                Int2FloatMap.Entry keyValue = iter.next();
                int partId = computeHashCode(hasher, keyValue.getIntKey()) & dataPartNumMinus1;
                ((HashIntKeysFloatValuesPart) dataParts[partId]).add(keyValue.getIntKey(), keyValue.getFloatValue());
            }
        } else if (storage.isDense()) {
            // Get values
            IntFloatDenseVectorStorage denseStorage = (IntFloatDenseVectorStorage) storage;
            float[] values = denseStorage.getValues();
            for (int i = 0; i < values.length; i++) {
                int partId = computeHashCode(hasher, i) & dataPartNumMinus1;
                ((HashIntKeysFloatValuesPart) dataParts[partId]).add(i, values[i]);
            }
        } else {
            // Key and value array pair
            IntFloatSortedVectorStorage sortStorage = (IntFloatSortedVectorStorage) storage;
            int[] keys = sortStorage.getIndices();
            float[] values = sortStorage.getValues();
            for (int i = 0; i < keys.length; i++) {
                int partId = computeHashCode(hasher, keys[i]) & dataPartNumMinus1;
                ((HashIntKeysFloatValuesPart) dataParts[partId]).add(keys[i], values[i]);
            }
        }
    } else {
        IntFloatVectorStorage storage = vector.getStorage();
        if (storage.isSparse()) {
            // Use iterator
            IntFloatSparseVectorStorage sparseStorage = (IntFloatSparseVectorStorage) storage;
            ObjectIterator<Int2FloatMap.Entry> iter = sparseStorage.entryIterator();
            while (iter.hasNext()) {
                Int2FloatMap.Entry keyValue = iter.next();
                int partId = computeHashCode(hasher, keyValue.getIntKey()) % dataPartNum;
                ((HashIntKeysFloatValuesPart) dataParts[partId]).add(keyValue.getIntKey(), keyValue.getFloatValue());
            }
        } else if (storage.isDense()) {
            // Get values
            IntFloatDenseVectorStorage denseStorage = (IntFloatDenseVectorStorage) storage;
            float[] values = denseStorage.getValues();
            for (int i = 0; i < values.length; i++) {
                int partId = computeHashCode(hasher, i) % dataPartNum;
                ((HashIntKeysFloatValuesPart) dataParts[partId]).add(i, values[i]);
            }
        } else {
            // Key and value array pair
            IntFloatSortedVectorStorage sortStorage = (IntFloatSortedVectorStorage) storage;
            int[] keys = sortStorage.getIndices();
            float[] values = sortStorage.getValues();
            for (int i = 0; i < keys.length; i++) {
                int partId = computeHashCode(hasher, keys[i]) % dataPartNum;
                ((HashIntKeysFloatValuesPart) dataParts[partId]).add(keys[i], values[i]);
            }
        }
    }
}
Also used : IntFloatSortedVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) IntFloatDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage) IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap)

Aggregations

IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)52 Int2FloatMap (it.unimi.dsi.fastutil.ints.Int2FloatMap)40 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)38 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)33 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)26 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)26 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)26 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)24 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)24 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)24 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)24 Storage (com.tencent.angel.ml.math2.storage.Storage)24 CompIntFloatVector (com.tencent.angel.ml.math2.vector.CompIntFloatVector)24 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)22 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)19 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)16 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)16 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)16 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)16 IntLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntLongSortedVectorStorage)16