Search in sources :

Example 6 with IntIntVectorStorage

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

the class IntIntVector method max.

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

Example 7 with IntIntVectorStorage

use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage 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 8 with IntIntVectorStorage

use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage 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 9 with IntIntVectorStorage

use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage 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)

Example 10 with IntIntVectorStorage

use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage 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)

Aggregations

IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)34 Int2IntMap (it.unimi.dsi.fastutil.ints.Int2IntMap)24 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)22 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)17 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)14 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)14 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)14 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)12 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)12 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)12 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)12 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)12 Storage (com.tencent.angel.ml.math2.storage.Storage)12 CompIntIntVector (com.tencent.angel.ml.math2.vector.CompIntIntVector)12 AngelException (com.tencent.angel.exception.AngelException)11 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)11 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)8 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)8 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)8 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)8