Search in sources :

Example 31 with LongLongVectorStorage

use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.

the class LongLongVector method argmax.

public long argmax() {
    LongLongVectorStorage idstorage = (LongLongVectorStorage) storage;
    if (idstorage.size() == 0)
        return -1;
    long maxval = Long.MIN_VALUE;
    long maxidx = -1;
    if (idstorage.isSparse()) {
        ObjectIterator<Long2LongMap.Entry> iter = idstorage.entryIterator();
        while (iter.hasNext()) {
            Long2LongMap.Entry entry = iter.next();
            long idx = entry.getLongKey();
            long val = entry.getLongValue();
            if (val > maxval) {
                maxval = val;
                maxidx = idx;
            }
        }
    } else {
        long[] indices = idstorage.getIndices();
        long[] val = idstorage.getValues();
        long size = idstorage.size();
        for (int i = 0; i < size; i++) {
            long idx = indices[i];
            if (val[i] > maxval) {
                maxval = val[i];
                maxidx = idx;
            }
        }
    }
    return maxidx;
}
Also used : Long2LongMap(it.unimi.dsi.fastutil.longs.Long2LongMap) LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage)

Example 32 with LongLongVectorStorage

use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.

the class LongLongVector method numZeros.

public long numZeros() {
    LongLongVectorStorage dstorage = (LongLongVectorStorage) storage;
    if (dstorage.size() == 0)
        return (long) dim;
    long numZero = 0;
    if (dstorage.isSparse()) {
        LongIterator iter = dstorage.valueIterator();
        while (iter.hasNext()) {
            if (iter.nextLong() != 0) {
                numZero += 1;
            }
        }
    } else {
        for (long val : dstorage.getValues()) {
            if (val != 0) {
                numZero += 1;
            }
        }
    }
    return (long) getDim() - numZero;
}
Also used : LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator)

Example 33 with LongLongVectorStorage

use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.

the class LongLongVector method std.

public double std() {
    LongLongVectorStorage dstorage = (LongLongVectorStorage) 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);
}
Also used : LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator)

Example 34 with LongLongVectorStorage

use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.

the class CompLongLongRowUpdateSplit method serialize.

@Override
public void serialize(ByteBuf buf) {
    super.serialize(buf);
    LongLongVectorStorage storage = split.getStorage();
    buf.writeInt(storage.size());
    if (storage instanceof LongLongSparseVectorStorage) {
        ObjectIterator<Long2LongMap.Entry> iter = storage.entryIterator();
        Long2LongMap.Entry entry;
        while (iter.hasNext()) {
            entry = iter.next();
            buf.writeLong(entry.getLongKey());
            buf.writeLong(entry.getLongValue());
        }
    } else if (storage instanceof LongLongSortedVectorStorage) {
        long[] indices = storage.getIndices();
        long[] values = storage.getValues();
        for (int i = 0; i < indices.length; i++) {
            buf.writeLong(indices[i]);
            buf.writeLong(values[i]);
        }
    } else {
        throw new UnsupportedOperationException("unsupport split for storage " + storage.getClass().getName());
    }
}
Also used : Long2LongMap(it.unimi.dsi.fastutil.longs.Long2LongMap) LongLongSortedVectorStorage(com.tencent.angel.ml.math2.storage.LongLongSortedVectorStorage) LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) LongLongSparseVectorStorage(com.tencent.angel.ml.math2.storage.LongLongSparseVectorStorage)

Example 35 with LongLongVectorStorage

use of com.tencent.angel.ml.math2.storage.LongLongVectorStorage in project angel by Tencent.

the class MixedBinaryOutZAExecutor method apply.

private static Vector apply(CompLongLongVector v1, LongDummyVector v2, Binary op) {
    LongLongVector[] parts = v1.getPartitions();
    Storage[] resParts = StorageSwitch.applyComp(v1, v2, op);
    if (v1.size() > v2.size()) {
        long subDim = (v1.getDim() + v1.getNumPartitions() - 1) / v1.getNumPartitions();
        long[] v2Indices = v2.getIndices();
        for (int i = 0; i < v2Indices.length; i++) {
            long idx = v2Indices[i];
            int pidx = (int) (idx / subDim);
            long subidx = idx % subDim;
            if (parts[pidx].hasKey(subidx)) {
                ((LongLongVectorStorage) resParts[pidx]).set(subidx, op.apply(parts[pidx].get(subidx), 1));
            }
        }
    } else {
        long base = 0;
        for (int i = 0; i < parts.length; i++) {
            LongLongVector part = parts[i];
            LongLongVectorStorage resPart = (LongLongVectorStorage) resParts[i];
            if (part.isDense()) {
                long[] partValues = part.getStorage().getValues();
                long[] resPartValues = resPart.getValues();
                for (int j = 0; j < partValues.length; j++) {
                    if (v2.hasKey(j + base)) {
                        resPartValues[j] = op.apply(partValues[j], v2.get(j + base));
                    }
                }
            } else if (part.isSparse()) {
                ObjectIterator<Long2LongMap.Entry> piter = part.getStorage().entryIterator();
                while (piter.hasNext()) {
                    Long2LongMap.Entry entry = piter.next();
                    long idx = entry.getLongKey();
                    if (v2.hasKey(idx + base)) {
                        resPart.set(idx, op.apply(entry.getLongValue(), v2.get(idx + base)));
                    }
                }
            } else {
                // sorted
                if (op.isKeepStorage()) {
                    long[] partIndices = part.getStorage().getIndices();
                    long[] partValues = part.getStorage().getValues();
                    long[] resPartIndices = resPart.getIndices();
                    long[] resPartValues = resPart.getValues();
                    for (int j = 0; j < partIndices.length; j++) {
                        long idx = partIndices[j];
                        if (v2.hasKey(idx + base)) {
                            resPartIndices[j] = idx;
                            resPartValues[j] = op.apply(partValues[j], v2.get(idx + base));
                        }
                    }
                } else {
                    long[] partIndices = part.getStorage().getIndices();
                    long[] partValues = part.getStorage().getValues();
                    for (int j = 0; j < partIndices.length; j++) {
                        long idx = partIndices[j];
                        if (v2.hasKey(idx + base)) {
                            resPart.set(idx, op.apply(partValues[j], v2.get(idx + base)));
                        }
                    }
                }
            }
            base += part.getDim();
        }
    }
    LongLongVector[] res = new LongLongVector[parts.length];
    int i = 0;
    for (LongLongVector part : parts) {
        res[i] = new LongLongVector(part.getMatrixId(), part.getRowId(), part.getClock(), part.getDim(), (LongLongVectorStorage) resParts[i]);
        i++;
    }
    return new CompLongLongVector(v1.getMatrixId(), v1.getRowId(), v1.getClock(), v1.getDim(), res, v1.getSubDim());
}
Also used : Long2LongMap(it.unimi.dsi.fastutil.longs.Long2LongMap) CompLongLongVector(com.tencent.angel.ml.math2.vector.CompLongLongVector) IntIntVectorStorage(com.tencent.angel.ml.math2.storage.IntIntVectorStorage) Storage(com.tencent.angel.ml.math2.storage.Storage) LongIntVectorStorage(com.tencent.angel.ml.math2.storage.LongIntVectorStorage) IntFloatVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatVectorStorage) LongDoubleVectorStorage(com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage) IntDoubleVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage) LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) LongFloatVectorStorage(com.tencent.angel.ml.math2.storage.LongFloatVectorStorage) IntLongVectorStorage(com.tencent.angel.ml.math2.storage.IntLongVectorStorage) CompLongLongVector(com.tencent.angel.ml.math2.vector.CompLongLongVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) LongLongVectorStorage(com.tencent.angel.ml.math2.storage.LongLongVectorStorage) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator)

Aggregations

LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)41 LongLongVector (com.tencent.angel.ml.math2.vector.LongLongVector)24 LongLongSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongLongSparseVectorStorage)21 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)20 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)20 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)20 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)18 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)18 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)18 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)18 Storage (com.tencent.angel.ml.math2.storage.Storage)18 CompLongLongVector (com.tencent.angel.ml.math2.vector.CompLongLongVector)18 LongLongSortedVectorStorage (com.tencent.angel.ml.math2.storage.LongLongSortedVectorStorage)17 Long2LongMap (it.unimi.dsi.fastutil.longs.Long2LongMap)15 LongDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleSparseVectorStorage)14 LongFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatSparseVectorStorage)14 AngelException (com.tencent.angel.exception.AngelException)12 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)12 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)12 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)12