Search in sources :

Example 56 with Storage

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

the class IntFloatVector method average.

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

Example 57 with Storage

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

the class IntFloatVector method argmin.

public int argmin() {
    IntFloatVectorStorage idstorage = (IntFloatVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    float minval = Float.MAX_VALUE;
    int minidx = -1;
    if (idstorage.isDense()) {
        float[] val = idstorage.getValues();
        int length = val.length;
        for (int idx = 0; idx < length; idx++) {
            if (val[idx] < minval) {
                minval = val[idx];
                minidx = 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 < minval) {
                minval = val;
                minidx = 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] < minval) {
                minval = val[i];
                minidx = idx;
            }
        }
    }
    return minidx;
}
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 58 with Storage

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

the class LongIntVector method std.

public double std() {
    LongIntVectorStorage dstorage = (LongIntVectorStorage) storage;
    if (dstorage.size() == 0)
        return 0;
    double sumval = 0.0;
    double sumval2 = 0.0;
    if (dstorage.isSparse()) {
        IntIterator iter = dstorage.valueIterator();
        while (iter.hasNext()) {
            double val = iter.nextInt();
            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 : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage)

Example 59 with Storage

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

the class LongIntVector method numZeros.

public long numZeros() {
    LongIntVectorStorage dstorage = (LongIntVectorStorage) storage;
    if (dstorage.size() == 0)
        return (long) dim;
    long numZero = 0;
    if (dstorage.isSparse()) {
        IntIterator iter = dstorage.valueIterator();
        while (iter.hasNext()) {
            if (iter.nextInt() != 0) {
                numZero += 1;
            }
        }
    } else {
        for (int val : dstorage.getValues()) {
            if (val != 0) {
                numZero += 1;
            }
        }
    }
    return (long) getDim() - numZero;
}
Also used : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage)

Example 60 with Storage

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

the class LongIntVector method min.

public int min() {
    LongIntVectorStorage idstorage = (LongIntVectorStorage) storage;
    if (idstorage.size() == 0)
        return 0;
    int minval = Integer.MAX_VALUE;
    if (idstorage.isSparse()) {
        IntIterator iter = idstorage.valueIterator();
        while (iter.hasNext()) {
            int val = iter.nextInt();
            if (val < minval) {
                minval = val;
            }
        }
    } else {
        for (int val : idstorage.getValues()) {
            if (val < minval) {
                minval = val;
            }
        }
    }
    return minval;
}
Also used : IntIterator(it.unimi.dsi.fastutil.ints.IntIterator) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage)

Aggregations

IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)187 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)186 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)185 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)183 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)182 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)181 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)180 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)180 Storage (com.tencent.angel.ml.math2.storage.Storage)169 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)139 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)123 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)123 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)121 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)119 LongDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSortedVectorStorage)119 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)119 LongIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongIntSparseVectorStorage)119 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)118 LongFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSortedVectorStorage)118 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)117