Search in sources :

Example 6 with FloatIterator

use of it.unimi.dsi.fastutil.floats.FloatIterator in project angel by Tencent.

the class LongFloatVector method numZeros.

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

Example 7 with FloatIterator

use of it.unimi.dsi.fastutil.floats.FloatIterator in project angel by Tencent.

the class LongFloatVector method min.

public float min() {
    LongFloatVectorStorage idstorage = (LongFloatVectorStorage) storage;
    if (idstorage.size() == 0)
        return 0;
    float minval = Float.MAX_VALUE;
    if (idstorage.isSparse()) {
        FloatIterator iter = idstorage.valueIterator();
        while (iter.hasNext()) {
            float val = iter.nextFloat();
            if (val < minval) {
                minval = val;
            }
        }
    } else {
        for (float val : idstorage.getValues()) {
            if (val < minval) {
                minval = val;
            }
        }
    }
    return minval;
}
Also used : FloatIterator(it.unimi.dsi.fastutil.floats.FloatIterator) LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)

Example 8 with FloatIterator

use of it.unimi.dsi.fastutil.floats.FloatIterator in project angel by Tencent.

the class LongFloatVector method average.

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

Example 9 with FloatIterator

use of it.unimi.dsi.fastutil.floats.FloatIterator in project angel by Tencent.

the class IntFloatVector method min.

public float min() {
    IntFloatVectorStorage idstorage = (IntFloatVectorStorage) storage;
    if (idstorage.size() == 0)
        return 0;
    float minval = Float.MAX_VALUE;
    if (idstorage.isSparse()) {
        FloatIterator iter = idstorage.valueIterator();
        while (iter.hasNext()) {
            float val = iter.nextFloat();
            if (val < minval) {
                minval = val;
            }
        }
    } else {
        for (float val : idstorage.getValues()) {
            if (val < minval) {
                minval = val;
            }
        }
    }
    return minval;
}
Also used : FloatIterator(it.unimi.dsi.fastutil.floats.FloatIterator) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)

Example 10 with FloatIterator

use of it.unimi.dsi.fastutil.floats.FloatIterator in project angel by Tencent.

the class IntFloatVector method std.

public double std() {
    IntFloatVectorStorage dstorage = (IntFloatVectorStorage) 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) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)

Aggregations

FloatIterator (it.unimi.dsi.fastutil.floats.FloatIterator)12 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)5 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)5 FloatVectorStorage (com.tencent.angel.ml.math2.storage.FloatVectorStorage)2