Search in sources :

Example 71 with Storage

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

the class LongDoubleVector method std.

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

Example 72 with Storage

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

the class LongFloatVector method max.

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

Example 73 with Storage

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

the class LongLongVector method max.

public long max() {
    LongLongVectorStorage idstorage = (LongLongVectorStorage) storage;
    if (idstorage.size() == 0)
        return 0;
    long maxval = Long.MIN_VALUE;
    if (idstorage.isSparse()) {
        LongIterator iter = idstorage.valueIterator();
        while (iter.hasNext()) {
            long val = iter.nextLong();
            if (val > maxval) {
                maxval = val;
            }
        }
    } else {
        for (long val : idstorage.getValues()) {
            if (val > maxval) {
                maxval = val;
            }
        }
    }
    return maxval;
}
Also used : LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator)

Example 74 with Storage

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

the class LongLongVector method average.

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

Example 75 with Storage

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

the class LongLongVector method argmin.

public long argmin() {
    LongLongVectorStorage idstorage = (LongLongVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    long minval = Long.MAX_VALUE;
    long minidx = -1;
    if (idstorage.isSparse()) {
        ObjectIterator<Long2LongMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Long2LongMap.Entry entry = iter.next();
            long idx = entry.getLongKey();
            long val = entry.getLongValue();
            if (val < minval) {
                minval = val;
                minidx = idx;
            }
        }
    } else {
        long[] indices = idstorage.getIndices();
        long[] val = idstorage.getValues();
        long size = idstorage.size();
        for (int i = 0; i < size; i++) {
            long idx = indices[i];
            if (val[i] < minval) {
                minval = val[i];
                minidx = idx;
            }
        }
    }
    return minidx;
}
Also used : Long2LongMap(it.unimi.dsi.fastutil.longs.Long2LongMap) LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage)

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