use of com.tencent.angel.ml.math2.storage.Storage 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;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class IntFloatVector method argmin.
public int argmin() {
IntFloatVectorStorage idstorage = (IntFloatVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
float minval = Float.MAX_VALUE;
int minidx = -1;
if (idstorage.isDense()) {
float[] val = idstorage.getValues();
int length = val.length;
for (int idx = 0; idx < length; idx++) {
if (val[idx] < minval) {
minval = val[idx];
minidx = idx;
}
}
} else if (idstorage.isSparse()) {
ObjectIterator<Int2FloatMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int idx = entry.getIntKey();
float val = entry.getFloatValue();
if (val < minval) {
minval = val;
minidx = idx;
}
}
} else {
int[] indices = idstorage.getIndices();
float[] val = idstorage.getValues();
int size = idstorage.size();
for (int i = 0; i < size; i++) {
int idx = indices[i];
if (val[i] < minval) {
minval = val[i];
minidx = idx;
}
}
}
return minidx;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class LongIntVector method std.
public double std() {
LongIntVectorStorage dstorage = (LongIntVectorStorage) storage;
if (dstorage.size() == 0)
return 0;
double sumval = 0.0;
double sumval2 = 0.0;
if (dstorage.isSparse()) {
IntIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
double val = iter.nextInt();
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 LongIntVector method numZeros.
public long numZeros() {
LongIntVectorStorage dstorage = (LongIntVectorStorage) storage;
if (dstorage.size() == 0)
return (long) dim;
long numZero = 0;
if (dstorage.isSparse()) {
IntIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
if (iter.nextInt() != 0) {
numZero += 1;
}
}
} else {
for (int val : dstorage.getValues()) {
if (val != 0) {
numZero += 1;
}
}
}
return (long) getDim() - numZero;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class LongIntVector method min.
public int min() {
LongIntVectorStorage idstorage = (LongIntVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
int minval = Integer.MAX_VALUE;
if (idstorage.isSparse()) {
IntIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
int val = iter.nextInt();
if (val < minval) {
minval = val;
}
}
} else {
for (int val : idstorage.getValues()) {
if (val < minval) {
minval = val;
}
}
}
return minval;
}
Aggregations