use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.
the class IntFloatVector method min.
public float min() {
IntFloatVectorStorage idstorage = (IntFloatVectorStorage) storage;
if (idstorage.size() == 0)
return 0;
float minval = Float.MAX_VALUE;
if (idstorage.isSparse()) {
FloatIterator iter = idstorage.valueIterator();
while (iter.hasNext()) {
float val = iter.nextFloat();
if (val < minval) {
minval = val;
}
}
} else {
for (float val : idstorage.getValues()) {
if (val < minval) {
minval = val;
}
}
}
return minval;
}
use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.
the class IntFloatVector method std.
public double std() {
IntFloatVectorStorage dstorage = (IntFloatVectorStorage) storage;
if (dstorage.size() == 0)
return 0;
double sumval = 0.0;
double sumval2 = 0.0;
if (dstorage.isSparse()) {
FloatIterator iter = dstorage.valueIterator();
while (iter.hasNext()) {
double val = iter.nextFloat();
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.IntFloatVectorStorage in project angel by Tencent.
the class IntFloatVector method argmax.
public int argmax() {
IntFloatVectorStorage idstorage = (IntFloatVectorStorage) storage;
if (idstorage.size() == 0)
return -1;
float maxval = Float.MIN_VALUE;
int maxidx = -1;
if (idstorage.isDense()) {
float[] 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<Int2FloatMap.Entry> iter = idstorage.entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry entry = iter.next();
int idx = entry.getIntKey();
float val = entry.getFloatValue();
if (val > maxval) {
maxval = val;
maxidx = 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] > maxval) {
maxval = val[i];
maxidx = idx;
}
}
}
return maxidx;
}
use of com.tencent.angel.ml.math2.storage.IntFloatVectorStorage in project angel by Tencent.
the class HashRouterUtils method splitIntFloatVector.
public static void splitIntFloatVector(KeyHash hasher, MatrixMeta matrixMeta, IntFloatVector vector, KeyValuePart[] dataParts) {
int dataPartNum = dataParts.length;
int dataPartNumMinus1 = dataPartNum - 1;
if (isPow2(dataPartNum)) {
IntFloatVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Use iterator
IntFloatSparseVectorStorage sparseStorage = (IntFloatSparseVectorStorage) storage;
ObjectIterator<Int2FloatMap.Entry> iter = sparseStorage.entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry keyValue = iter.next();
int partId = computeHashCode(hasher, keyValue.getIntKey()) & dataPartNumMinus1;
((HashIntKeysFloatValuesPart) dataParts[partId]).add(keyValue.getIntKey(), keyValue.getFloatValue());
}
} else if (storage.isDense()) {
// Get values
IntFloatDenseVectorStorage denseStorage = (IntFloatDenseVectorStorage) storage;
float[] values = denseStorage.getValues();
for (int i = 0; i < values.length; i++) {
int partId = computeHashCode(hasher, i) & dataPartNumMinus1;
((HashIntKeysFloatValuesPart) dataParts[partId]).add(i, values[i]);
}
} else {
// Key and value array pair
IntFloatSortedVectorStorage sortStorage = (IntFloatSortedVectorStorage) storage;
int[] keys = sortStorage.getIndices();
float[] values = sortStorage.getValues();
for (int i = 0; i < keys.length; i++) {
int partId = computeHashCode(hasher, keys[i]) & dataPartNumMinus1;
((HashIntKeysFloatValuesPart) dataParts[partId]).add(keys[i], values[i]);
}
}
} else {
IntFloatVectorStorage storage = vector.getStorage();
if (storage.isSparse()) {
// Use iterator
IntFloatSparseVectorStorage sparseStorage = (IntFloatSparseVectorStorage) storage;
ObjectIterator<Int2FloatMap.Entry> iter = sparseStorage.entryIterator();
while (iter.hasNext()) {
Int2FloatMap.Entry keyValue = iter.next();
int partId = computeHashCode(hasher, keyValue.getIntKey()) % dataPartNum;
((HashIntKeysFloatValuesPart) dataParts[partId]).add(keyValue.getIntKey(), keyValue.getFloatValue());
}
} else if (storage.isDense()) {
// Get values
IntFloatDenseVectorStorage denseStorage = (IntFloatDenseVectorStorage) storage;
float[] values = denseStorage.getValues();
for (int i = 0; i < values.length; i++) {
int partId = computeHashCode(hasher, i) % dataPartNum;
((HashIntKeysFloatValuesPart) dataParts[partId]).add(i, values[i]);
}
} else {
// Key and value array pair
IntFloatSortedVectorStorage sortStorage = (IntFloatSortedVectorStorage) storage;
int[] keys = sortStorage.getIndices();
float[] values = sortStorage.getValues();
for (int i = 0; i < keys.length; i++) {
int partId = computeHashCode(hasher, keys[i]) % dataPartNum;
((HashIntKeysFloatValuesPart) dataParts[partId]).add(keys[i], values[i]);
}
}
}
}
Aggregations