Search in sources :

Example 6 with DoubleIterator

use of it.unimi.dsi.fastutil.doubles.DoubleIterator in project angel by Tencent.

the class IntDoubleVector method numZeros.

public int numZeros() {
    IntDoubleVectorStorage dstorage = (IntDoubleVectorStorage) storage;
    if (dstorage.size() == 0)
        return (int) dim;
    int numZero = 0;
    if (dstorage.isSparse()) {
        DoubleIterator iter = dstorage.valueIterator();
        while (iter.hasNext()) {
            if (iter.nextDouble() != 0) {
                numZero += 1;
            }
        }
    } else {
        for (double val : dstorage.getValues()) {
            if (val != 0) {
                numZero += 1;
            }
        }
    }
    return (int) getDim() - numZero;
}
Also used : IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) DoubleIterator(it.unimi.dsi.fastutil.doubles.DoubleIterator)

Example 7 with DoubleIterator

use of it.unimi.dsi.fastutil.doubles.DoubleIterator in project angel by Tencent.

the class LongDoubleVector method average.

public double average() {
    LongDoubleVectorStorage dstorage = (LongDoubleVectorStorage) storage;
    if (dstorage.size() == 0)
        return 0;
    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;
        }
    }
    sumval /= getDim();
    return sumval;
}
Also used : DoubleIterator(it.unimi.dsi.fastutil.doubles.DoubleIterator) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)

Example 8 with DoubleIterator

use of it.unimi.dsi.fastutil.doubles.DoubleIterator in project angel by Tencent.

the class LongDoubleVector method max.

public double max() {
    LongDoubleVectorStorage idstorage = (LongDoubleVectorStorage) storage;
    if (idstorage.size() == 0)
        return 0;
    double maxval = Double.MIN_VALUE;
    if (idstorage.isSparse()) {
        DoubleIterator iter = idstorage.valueIterator();
        while (iter.hasNext()) {
            double val = iter.nextDouble();
            if (val > maxval) {
                maxval = val;
            }
        }
    } else {
        for (double val : idstorage.getValues()) {
            if (val > maxval) {
                maxval = val;
            }
        }
    }
    return maxval;
}
Also used : DoubleIterator(it.unimi.dsi.fastutil.doubles.DoubleIterator) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)

Example 9 with DoubleIterator

use of it.unimi.dsi.fastutil.doubles.DoubleIterator in project angel by Tencent.

the class LongDoubleVector method numZeros.

public long numZeros() {
    LongDoubleVectorStorage dstorage = (LongDoubleVectorStorage) storage;
    if (dstorage.size() == 0)
        return (long) dim;
    long numZero = 0;
    if (dstorage.isSparse()) {
        DoubleIterator iter = dstorage.valueIterator();
        while (iter.hasNext()) {
            if (iter.nextDouble() != 0) {
                numZero += 1;
            }
        }
    } else {
        for (double val : dstorage.getValues()) {
            if (val != 0) {
                numZero += 1;
            }
        }
    }
    return (long) getDim() - numZero;
}
Also used : DoubleIterator(it.unimi.dsi.fastutil.doubles.DoubleIterator) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)

Example 10 with DoubleIterator

use of it.unimi.dsi.fastutil.doubles.DoubleIterator in project angel by Tencent.

the class LongDoubleVector method min.

public double min() {
    LongDoubleVectorStorage idstorage = (LongDoubleVectorStorage) storage;
    if (idstorage.size() == 0)
        return 0;
    double minval = Double.MAX_VALUE;
    if (idstorage.isSparse()) {
        DoubleIterator iter = idstorage.valueIterator();
        while (iter.hasNext()) {
            double val = iter.nextDouble();
            if (val < minval) {
                minval = val;
            }
        }
    } else {
        for (double val : idstorage.getValues()) {
            if (val < minval) {
                minval = val;
            }
        }
    }
    return minval;
}
Also used : DoubleIterator(it.unimi.dsi.fastutil.doubles.DoubleIterator) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)

Aggregations

DoubleIterator (it.unimi.dsi.fastutil.doubles.DoubleIterator)12 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)5 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)5 DoubleVectorStorage (com.tencent.angel.ml.math2.storage.DoubleVectorStorage)2