Search in sources :

Example 1 with DoubleIterator

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

the class LongDoubleVector method std.

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

Example 2 with DoubleIterator

use of it.unimi.dsi.fastutil.doubles.DoubleIterator 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 3 with DoubleIterator

use of it.unimi.dsi.fastutil.doubles.DoubleIterator 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 4 with DoubleIterator

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

Example 5 with DoubleIterator

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

the class IntDoubleVector method average.

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

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