Search in sources :

Example 1 with FloatIterator

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

the class IntFloatVector method numZeros.

public int numZeros() {
    IntFloatVectorStorage dstorage = (IntFloatVectorStorage) storage;
    if (dstorage.size() == 0)
        return (int) dim;
    int 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 (int) getDim() - numZero;
}
Also used : FloatIterator(it.unimi.dsi.fastutil.floats.FloatIterator) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)

Example 2 with FloatIterator

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

the class IntFloatVector method max.

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

Example 3 with FloatIterator

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

the class IntFloatVector method average.

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

Example 4 with FloatIterator

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

the class LongFloatVector method max.

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

Example 5 with FloatIterator

use of it.unimi.dsi.fastutil.floats.FloatIterator 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)

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