use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class IntIntVector method average.
public double average() {
IntIntVectorStorage dstorage = (IntIntVectorStorage) storage;
if (dstorage.size() == 0)
return 0;
double sumval = 0.0;
if (dstorage.isSparse()) {
IntIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
sumval += iter.nextInt();
}
} 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 IntLongVector method average.
public double average() {
IntLongVectorStorage dstorage = (IntLongVectorStorage) 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 IntLongVector method argmax.
public int argmax() {
IntLongVectorStorage idstorage = (IntLongVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
long maxval = Long.MIN_VALUE;
int maxidx = -1;
if (idstorage.isDense()) {
long[] val = idstorage.getValues();
int length = val.length;
for (int idx = 0; idx < length; idx++) {
if (val[idx] > maxval) {
maxval = val[idx];
maxidx = idx;
}
}
} else if (idstorage.isSparse()) {
ObjectIterator<Int2LongMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Int2LongMap.Entry entry = iter.next();
int idx = entry.getIntKey();
long val = entry.getLongValue();
if (val > maxval) {
maxval = val;
maxidx = idx;
}
}
} else {
int[] indices = idstorage.getIndices();
long[] val = idstorage.getValues();
int size = idstorage.size();
for (int i = 0; i < size; i++) {
int idx = indices[i];
if (val[i] > maxval) {
maxval = val[i];
maxidx = idx;
}
}
}
return maxidx;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class IntLongVector method std.
public double std() {
IntLongVectorStorage dstorage = (IntLongVectorStorage) storage;
if (dstorage.size() == 0)
return 0;
double sumval = 0.0;
double sumval2 = 0.0;
if (dstorage.isSparse()) {
LongIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
double val = iter.nextLong();
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 LongDoubleVector method argmin.
public long argmin() {
LongDoubleVectorStorage idstorage = (LongDoubleVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
double minval = Double.MAX_VALUE;
long minidx = -1;
if (idstorage.isSparse()) {
ObjectIterator<Long2DoubleMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Long2DoubleMap.Entry entry = iter.next();
long idx = entry.getLongKey();
double val = entry.getDoubleValue();
if (val < minval) {
minval = val;
minidx = idx;
}
}
} else {
long[] indices = idstorage.getIndices();
double[] 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