use of com.tencent.angel.ml.math2.storage.Storage 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);
}
use of com.tencent.angel.ml.math2.storage.Storage 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;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class LongLongVector method max.
public long max() {
LongLongVectorStorage idstorage = (LongLongVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
long maxval = Long.MIN_VALUE;
if (idstorage.isSparse()) {
LongIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
long val = iter.nextLong();
if (val > maxval) {
maxval = val;
}
}
} else {
for (long val : idstorage.getValues()) {
if (val > maxval) {
maxval = val;
}
}
}
return maxval;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class LongLongVector method average.
public double average() {
LongLongVectorStorage dstorage = (LongLongVectorStorage) storage;
if (dstorage.size() == 0)
return 0;
double sumval = 0.0;
if (dstorage.isSparse()) {
LongIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
sumval += iter.nextLong();
}
} else {
for (double val : dstorage.getValues()) {
sumval += val;
}
}
sumval /= getDim();
return sumval;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class LongLongVector method argmin.
public long argmin() {
LongLongVectorStorage idstorage = (LongLongVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
long minval = Long.MAX_VALUE;
long minidx = -1;
if (idstorage.isSparse()) {
ObjectIterator<Long2LongMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Long2LongMap.Entry entry = iter.next();
long idx = entry.getLongKey();
long val = entry.getLongValue();
if (val < minval) {
minval = val;
minidx = idx;
}
}
} else {
long[] indices = idstorage.getIndices();
long[] val = idstorage.getValues();
long size = idstorage.size();
for (int i = 0; i < size; i++) {
long idx = indices[i];
if (val[i] < minval) {
minval = val[i];
minidx = idx;
}
}
}
return minidx;
}
Aggregations