Search in sources :

Example 76 with Storage

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

the class LongLongVector method min.

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

Example 77 with Storage

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

the class LongFloatVector method std.

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

Example 78 with Storage

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

the class DoubleVector method sum.

@Override
public double sum() {
    DoubleVectorStorage dstorage = (DoubleVectorStorage) storage;
    double sumval = 0.0;
    if (dstorage.isSparse()) {
        DoubleIterator iter = dstorage.valueIterator();
        while (iter.hasNext()) {
            sumval += iter.nextDouble();
        }
    } else {
        for (double val : dstorage.getValues()) {
            sumval += val;
        }
    }
    return sumval;
}
Also used : DoubleIterator(it.unimi.dsi.fastutil.doubles.DoubleIterator) DoubleVectorStorage(com.tencent.angel.ml.math2.storage.DoubleVectorStorage)

Example 79 with Storage

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

the class DoubleVector method norm.

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

Example 80 with Storage

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

the class IntDoubleVector method std.

public double std() {
    IntDoubleVectorStorage dstorage = (IntDoubleVectorStorage) 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 : IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) DoubleIterator(it.unimi.dsi.fastutil.doubles.DoubleIterator)

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