Search in sources :

Example 61 with Storage

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

the class LongIntVector method average.

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

Example 62 with Storage

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

the class LongVector method norm.

@Override
public double norm() {
    LongVectorStorage lstorage = (LongVectorStorage) storage;
    double sumval2 = 0.0;
    if (lstorage.isSparse()) {
        LongIterator iter = lstorage.valueIterator();
        while (iter.hasNext()) {
            double val = iter.nextLong();
            sumval2 += val * val;
        }
    } else {
        for (double val : lstorage.getValues()) {
            sumval2 += val * val;
        }
    }
    return Math.sqrt(sumval2);
}
Also used : LongVectorStorage(com.tencent.angel.ml.math2.storage.LongVectorStorage) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator)

Example 63 with Storage

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

the class IntIntVector method argmax.

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

Example 64 with Storage

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

the class IntIntVector method min.

public int min() {
    IntIntVectorStorage idstorage = (IntIntVectorStorage) 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 : IntIntVectorStorage(com.tencent.angel.ml.math2.storage.IntIntVectorStorage) IntIterator(it.unimi.dsi.fastutil.ints.IntIterator)

Example 65 with Storage

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

the class IntIntVector method argmin.

public int argmin() {
    IntIntVectorStorage idstorage = (IntIntVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    int minval = Integer.MAX_VALUE;
    int minidx = -1;
    if (idstorage.isDense()) {
        int[] 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<Int2IntMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Int2IntMap.Entry entry = iter.next();
            int idx = entry.getIntKey();
            int val = entry.getIntValue();
            if (val < minval) {
                minval = val;
                minidx = idx;
            }
        }
    } else {
        int[] indices = idstorage.getIndices();
        int[] 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 : IntIntVectorStorage(com.tencent.angel.ml.math2.storage.IntIntVectorStorage) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

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