use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class LongIntVector method average.
public double average() {
LongIntVectorStorage dstorage = (LongIntVectorStorage) 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 LongVector method norm.
@Override
public double norm() {
LongVectorStorage lstorage = (LongVectorStorage) storage;
double sumval2 = 0.0;
if (lstorage.isSparse()) {
LongIterator iter = lstorage.valueIterator();
while (iter.hasNext()) {
double val = iter.nextLong();
sumval2 += val * val;
}
} else {
for (double val : lstorage.getValues()) {
sumval2 += val * val;
}
}
return Math.sqrt(sumval2);
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class IntIntVector method argmax.
public int argmax() {
IntIntVectorStorage idstorage = (IntIntVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
int maxval = Integer.MIN_VALUE;
int maxidx = -1;
if (idstorage.isDense()) {
int[] 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<Int2IntMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
int val = entry.getIntValue();
if (val > maxval) {
maxval = val;
maxidx = idx;
}
}
} else {
int[] indices = idstorage.getIndices();
int[] 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 IntIntVector method min.
public int min() {
IntIntVectorStorage idstorage = (IntIntVectorStorage) 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;
}
use of com.tencent.angel.ml.math2.storage.Storage in project angel by Tencent.
the class IntIntVector method argmin.
public int argmin() {
IntIntVectorStorage idstorage = (IntIntVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
int minval = Integer.MAX_VALUE;
int minidx = -1;
if (idstorage.isDense()) {
int[] 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<Int2IntMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Int2IntMap.Entry entry = iter.next();
int idx = entry.getIntKey();
int val = entry.getIntValue();
if (val < minval) {
minval = val;
minidx = idx;
}
}
} else {
int[] indices = idstorage.getIndices();
int[] 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;
}
Aggregations