Search in sources :

Example 41 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class VectorSplitTest method sparseHashMapVectorSplit.

@Test
public void sparseHashMapVectorSplit() {
    int[] offsets = { 0, 2, 4, 6, 8 };
    double[] values = { 0.0, 2.0, 4.0, 6.0, 8.0 };
    SparseDoubleVector vector = new SparseDoubleVector(10, offsets, values);
    vector.setRowId(0);
    PartitionKey key1 = new PartitionKey(0, 0, 0, 0, 1, 5);
    PartitionKey key2 = new PartitionKey(1, 0, 0, 5, 1, 10);
    List<PartitionKey> keys = new ArrayList<>();
    keys.add(key1);
    keys.add(key2);
    HashMap<PartitionKey, RowUpdateSplit> splits = RowUpdateSplitUtils.split(vector, keys);
    Assert.assertEquals(keys.size(), splits.size());
    int[] offset1 = { 0, 2, 4 };
    double[] values1 = { 0.0, 2.0, 4.0 };
    SparseDoubleRowUpdateSplit split1 = (SparseDoubleRowUpdateSplit) splits.get(key1);
    Assert.assertNotNull(split1);
    Assert.assertEquals(2, splits.get(key2).size());
    Assert.assertEquals(offset1.length, split1.size());
    Assert.assertEquals(0, split1.getStart());
    Assert.assertEquals(3, split1.getEnd());
    Assert.assertArrayEquals(offset1, Arrays.copyOfRange(split1.getOffsets(), (int) split1.getStart(), (int) split1.getEnd()));
    for (int i = 0; i < split1.size(); i++) {
        Assert.assertEquals(values1[i], split1.getValues()[(int) split1.getStart() + i], 0.0);
    }
    int[] offset2 = { 6, 8 };
    double[] values2 = { 6.0, 8.0 };
    SparseDoubleRowUpdateSplit split2 = (SparseDoubleRowUpdateSplit) splits.get(key2);
    Assert.assertNotNull(split2);
    Assert.assertEquals(offset2.length, split2.size());
    Assert.assertEquals(3, split2.getStart());
    Assert.assertEquals(5, split2.getEnd());
    Assert.assertArrayEquals(offset2, Arrays.copyOfRange(split2.getOffsets(), (int) split2.getStart(), (int) split2.getEnd()));
    for (int i = 0; i < split2.size(); i++) {
        Assert.assertEquals(values2[i], split2.getValues()[(int) split2.getStart() + i], 0.0);
    }
    LOG.info("Pass sparseHashMapVector split Test");
}
Also used : PartitionKey(com.tencent.angel.PartitionKey) Test(org.junit.Test)

Example 42 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class HistAggrParam method split.

@Override
public List<PartitionGetParam> split() {
    List<PartitionKey> parts = PSAgentContext.get().getMatrixMetaManager().getPartitions(matrixId);
    int size = parts.size();
    List<PartitionGetParam> partParams = new ArrayList<PartitionGetParam>(size);
    for (PartitionKey part : parts) {
        partParams.add(new HistPartitionAggrParam(matrixId, part, rowId, splitNum, minChildWeight, regAlpha, regLambda));
    }
    return partParams;
}
Also used : ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)

Example 43 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class GetPartFunc method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartitionGetRowsParam param = (PartitionGetRowsParam) partParam;
    PartitionKey pkey = param.getPartKey();
    pkey = psContext.getMatrixMetaManager().getMatrixMeta(pkey.getMatrixId()).getPartitionMeta(pkey.getPartitionId()).getPartitionKey();
    int ws = pkey.getStartRow();
    int es = pkey.getEndRow();
    List<Integer> reqRows = param.getRowIndexes();
    MatrixStorageManager manager = psContext.getMatrixStorageManager();
    List<ServerRow> rows = new ArrayList<>();
    for (int w : reqRows) rows.add(manager.getRow(pkey, w));
    PartCSRResult csr = new PartCSRResult(rows);
    return csr;
}
Also used : PartitionGetRowsParam(com.tencent.angel.ml.matrix.psf.get.multi.PartitionGetRowsParam) MatrixStorageManager(com.tencent.angel.ps.impl.MatrixStorageManager) ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) ServerRow(com.tencent.angel.ps.impl.matrix.ServerRow)

Example 44 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class LikelihoodFunc method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartitionKey pkey = partParam.getPartKey();
    pkey = psContext.getMatrixMetaManager().getMatrixMeta(pkey.getMatrixId()).getPartitionMeta(pkey.getPartitionId()).getPartitionKey();
    int ws = pkey.getStartRow();
    int es = pkey.getEndRow();
    LikelihoodParam.LikelihoodPartParam param = (LikelihoodParam.LikelihoodPartParam) partParam;
    float beta = param.getBeta();
    double lgammaBeta = Gamma.logGamma(beta);
    double ll = 0;
    for (int w = ws; w < es; w++) {
        ServerRow row = psContext.getMatrixStorageManager().getRow(pkey, w);
        ll += likelihood(row, beta, lgammaBeta);
    }
    return new ScalarPartitionAggrResult(ll);
}
Also used : ScalarPartitionAggrResult(com.tencent.angel.ml.matrix.psf.aggr.enhance.ScalarPartitionAggrResult) PartitionKey(com.tencent.angel.PartitionKey) ServerRow(com.tencent.angel.ps.impl.matrix.ServerRow)

Example 45 with PartitionKey

use of com.tencent.angel.PartitionKey in project angel by Tencent.

the class LikelihoodParam method split.

@Override
public List<PartitionGetParam> split() {
    List<PartitionGetParam> params = new ArrayList<>();
    List<PartitionKey> pkeys = PSAgentContext.get().getMatrixMetaManager().getPartitions(matrixId);
    for (PartitionKey pkey : pkeys) {
        params.add(new LikelihoodPartParam(matrixId, pkey, beta));
    }
    return params;
}
Also used : ArrayList(java.util.ArrayList) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam) PartitionKey(com.tencent.angel.PartitionKey)

Aggregations

PartitionKey (com.tencent.angel.PartitionKey)80 ArrayList (java.util.ArrayList)17 ByteBuf (io.netty.buffer.ByteBuf)12 Test (org.junit.Test)9 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)8 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)7 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)7 PartitionLocation (com.tencent.angel.ml.matrix.PartitionLocation)4 ServerRow (com.tencent.angel.ps.impl.matrix.ServerRow)4 ParameterServerId (com.tencent.angel.ps.ParameterServerId)3 RecoverPartKey (com.tencent.angel.ps.recovery.ha.RecoverPartKey)3 FutureResult (com.tencent.angel.psagent.matrix.transport.FutureResult)3 Map (java.util.Map)3 Location (com.tencent.angel.common.location.Location)2 TVector (com.tencent.angel.ml.math.TVector)2 RowType (com.tencent.angel.ml.matrix.RowType)2 PSLocation (com.tencent.angel.ml.matrix.transport.PSLocation)2 MatrixStorageManager (com.tencent.angel.ps.impl.MatrixStorageManager)2 ClockCache (com.tencent.angel.psagent.clock.ClockCache)2 Worker (com.tencent.angel.worker.Worker)2