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");
}
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;
}
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;
}
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);
}
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;
}
Aggregations