Search in sources :

Example 66 with Storage

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

the class IntIntVector method average.

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

Example 67 with Storage

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

the class IntLongVector method average.

public double average() {
    IntLongVectorStorage dstorage = (IntLongVectorStorage) 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 : IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator)

Example 68 with Storage

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

the class IntLongVector method argmax.

public int argmax() {
    IntLongVectorStorage idstorage = (IntLongVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    long maxval = Long.MIN_VALUE;
    int maxidx = -1;
    if (idstorage.isDense()) {
        long[] 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<Int2LongMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Int2LongMap.Entry entry = iter.next();
            int idx = entry.getIntKey();
            long val = entry.getLongValue();
            if (val > maxval) {
                maxval = val;
                maxidx = idx;
            }
        }
    } else {
        int[] indices = idstorage.getIndices();
        long[] 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 : IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Example 69 with Storage

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

the class IntLongVector method std.

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

Example 70 with Storage

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

the class LongDoubleVector method argmin.

public long argmin() {
    LongDoubleVectorStorage idstorage = (LongDoubleVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    double minval = Double.MAX_VALUE;
    long minidx = -1;
    if (idstorage.isSparse()) {
        ObjectIterator<Long2DoubleMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Long2DoubleMap.Entry entry = iter.next();
            long idx = entry.getLongKey();
            double val = entry.getDoubleValue();
            if (val < minval) {
                minval = val;
                minidx = idx;
            }
        }
    } else {
        long[] indices = idstorage.getIndices();
        double[] 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 : Long2DoubleMap(it.unimi.dsi.fastutil.longs.Long2DoubleMap) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)

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