Search in sources :

Example 56 with IntFloatVector

use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.

the class NodeUtils method deserialize.

public static IntFloatVector deserialize(DataInputStream input) throws IOException {
    IntFloatVector feats;
    int dim = input.readInt();
    int len = input.readInt();
    StorageMethod storageMethod = StorageMethod.valuesOf(input.readInt());
    switch(storageMethod) {
        case DENSE:
            {
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    values[i] = input.readFloat();
                }
                feats = VFactory.denseFloatVector(values);
                break;
            }
        case SPARSE:
            {
                feats = VFactory.sparseFloatVector(dim, len);
                for (int i = 0; i < len; i++) {
                    feats.set(input.readInt(), input.readFloat());
                }
                break;
            }
        case SORTED:
            {
                int[] keys = new int[len];
                float[] values = new float[len];
                for (int i = 0; i < len; i++) {
                    keys[i] = input.readInt();
                    values[i] = input.readFloat();
                }
                feats = VFactory.sortedFloatVector(dim, keys, values);
                break;
            }
        default:
            throw new UnsupportedOperationException("Unsupport storage type " + storageMethod);
    }
    return feats;
}
Also used : StorageMethod(com.tencent.angel.ps.storage.vector.storage.StorageMethod) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 57 with IntFloatVector

use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.

the class MergeUtils method combineIntFloatIndexRowSplits.

// //////////////////////////////////////////////////////////////////////////////
// Combine Int key Float value vector
// //////////////////////////////////////////////////////////////////////////////
public static Vector combineIntFloatIndexRowSplits(int matrixId, int rowId, int resultSize, KeyPart[] keyParts, ValuePart[] valueParts, MatrixMeta matrixMeta) {
    IntFloatVector vector = VFactory.sparseFloatVector((int) matrixMeta.getColNum(), resultSize);
    for (int i = 0; i < keyParts.length; i++) {
        mergeTo(vector, keyParts[i], (FloatValuesPart) valueParts[i]);
    }
    vector.setRowId(rowId);
    vector.setMatrixId(matrixId);
    return vector;
}
Also used : IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 58 with IntFloatVector

use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.

the class CompIntFloatVectorSplitter method split.

@Override
public Map<PartitionKey, RowUpdateSplit> split(Vector vector, List<PartitionKey> parts) {
    IntFloatVector[] vecParts = ((CompIntFloatVector) vector).getPartitions();
    assert vecParts.length == parts.size();
    Map<PartitionKey, RowUpdateSplit> updateSplitMap = new HashMap<>(parts.size());
    for (int i = 0; i < vecParts.length; i++) {
        updateSplitMap.put(parts.get(i), new CompIntFloatRowUpdateSplit(vector.getRowId(), vecParts[i], (int) (parts.get(i).getEndCol() - parts.get(i).getStartCol())));
    }
    return updateSplitMap;
}
Also used : CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) HashMap(java.util.HashMap) PartitionKey(com.tencent.angel.PartitionKey) RowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.RowUpdateSplit) CompIntFloatRowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.CompIntFloatRowUpdateSplit) CompIntFloatRowUpdateSplit(com.tencent.angel.psagent.matrix.oplog.cache.CompIntFloatRowUpdateSplit) CompIntFloatVector(com.tencent.angel.ml.math2.vector.CompIntFloatVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 59 with IntFloatVector

use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.

the class UpdatePSFTest method testSparseFloatUDF.

public void testSparseFloatUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(SPARSE_FLOAT_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    int[] index = genIndexs(feaNum, nnz);
    IntFloatVector deltaVec = new IntFloatVector(feaNum, new IntFloatSparseVectorStorage(feaNum, nnz));
    for (int i = 0; i < index.length; i++) {
        deltaVec.set(index[i], index[i]);
    }
    // for (int i = 0; i < feaNum; i++) {
    // deltaVec.set(i, i);
    // }
    deltaVec.setRowId(0);
    Vector[] updates = new Vector[1];
    updates[0] = deltaVec;
    client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
    IntFloatVector row = (IntFloatVector) client1.getRow(0);
    for (int id : index) {
        // System.out.println("id=" + id + ", value=" + row.get(id));
        assertEquals(row.get(id), deltaVec.get(id), 0.000001);
    }
    Assert.assertTrue(index.length == row.size());
}
Also used : IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) IntFloatSparseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 60 with IntFloatVector

use of com.tencent.angel.ml.math2.vector.IntFloatVector in project angel by Tencent.

the class UpdatePSFTest method testDenseFloatUDF.

public void testDenseFloatUDF() throws Exception {
    Worker worker = LocalClusterContext.get().getWorker(workerAttempt0Id).getWorker();
    MatrixClient client1 = worker.getPSAgent().getMatrixClient(DENSE_FLOAT_MAT, 0);
    int matrixW1Id = client1.getMatrixId();
    int[] index = genIndexs(feaNum, nnz);
    IntFloatVector deltaVec = new IntFloatVector(feaNum, new IntFloatDenseVectorStorage(feaNum));
    for (int i = 0; i < feaNum; i++) {
        deltaVec.set(i, i);
    }
    deltaVec.setRowId(0);
    Vector[] updates = new Vector[1];
    updates[0] = deltaVec;
    client1.asyncUpdate(new IncrementRows(new IncrementRowsParam(matrixW1Id, updates))).get();
    IntFloatVector row = (IntFloatVector) client1.getRow(0);
    for (int id : index) {
        Assert.assertTrue(row.get(id) == deltaVec.get(id));
    }
    Assert.assertTrue(feaNum == row.size());
}
Also used : IncrementRowsParam(com.tencent.angel.ml.matrix.psf.update.update.IncrementRowsParam) IncrementRows(com.tencent.angel.ml.matrix.psf.update.update.IncrementRows) IntFloatDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntFloatDenseVectorStorage) Worker(com.tencent.angel.worker.Worker) MatrixClient(com.tencent.angel.psagent.matrix.MatrixClient) IntLongVector(com.tencent.angel.ml.math2.vector.IntLongVector) LongIntVector(com.tencent.angel.ml.math2.vector.LongIntVector) Vector(com.tencent.angel.ml.math2.vector.Vector) LongFloatVector(com.tencent.angel.ml.math2.vector.LongFloatVector) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector) LongDoubleVector(com.tencent.angel.ml.math2.vector.LongDoubleVector) LongLongVector(com.tencent.angel.ml.math2.vector.LongLongVector) IntIntVector(com.tencent.angel.ml.math2.vector.IntIntVector) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Aggregations

IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)104 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)60 Int2FloatMap (it.unimi.dsi.fastutil.ints.Int2FloatMap)57 IntFloatVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatVectorStorage)50 CompIntFloatVector (com.tencent.angel.ml.math2.vector.CompIntFloatVector)34 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)33 IntIntVectorStorage (com.tencent.angel.ml.math2.storage.IntIntVectorStorage)32 IntLongVectorStorage (com.tencent.angel.ml.math2.storage.IntLongVectorStorage)32 IntFloatSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSparseVectorStorage)31 LongDoubleVectorStorage (com.tencent.angel.ml.math2.storage.LongDoubleVectorStorage)30 LongFloatVectorStorage (com.tencent.angel.ml.math2.storage.LongFloatVectorStorage)30 LongIntVectorStorage (com.tencent.angel.ml.math2.storage.LongIntVectorStorage)30 LongLongVectorStorage (com.tencent.angel.ml.math2.storage.LongLongVectorStorage)30 Storage (com.tencent.angel.ml.math2.storage.Storage)30 IntFloatSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntFloatSortedVectorStorage)25 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)21 AngelException (com.tencent.angel.exception.AngelException)20 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)20 IntIntSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSortedVectorStorage)20 IntIntSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntIntSparseVectorStorage)20