use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage in project angel by Tencent.
the class IntIntVector method max.
public int max() {
IntIntVectorStorage idstorage = (IntIntVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
int maxval = Integer.MIN_VALUE;
if (idstorage.isSparse()) {
IntIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
int val = iter.nextInt();
if (val > maxval) {
maxval = val;
}
}
} else {
for (int val : idstorage.getValues()) {
if (val > maxval) {
maxval = val;
}
}
}
return maxval;
}
use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage 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.IntIntVectorStorage 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.IntIntVectorStorage 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;
}
use of com.tencent.angel.ml.math2.storage.IntIntVectorStorage 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;
}
Aggregations