use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.
the class IndexGetRowsHandler method handle.
@Override
public ResponseData handle(RequestHeader header, RequestData data) throws Exception {
IndexPartGetRowsRequest request = (IndexPartGetRowsRequest) data;
int[] rowIds = request.getRowIds();
KeyPart keyPart = request.getKeyPart();
ServerRow[] rows = new ServerRow[rowIds.length];
ValuePart[] results = new ValuePart[rowIds.length];
for (int i = 0; i < rowIds.length; i++) {
rows[i] = context.getMatrixStorageManager().getRow(header.matrixId, rowIds[i], header.partId);
rows[i].startRead();
try {
results[i] = ServerRowUtils.getByKeys(rows[i], keyPart);
} finally {
rows[i].endRead();
}
}
IndexPartGetRowsResponse response = new IndexPartGetRowsResponse(results);
return response;
}
use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.
the class ServerRowsStorage method init.
/**
* Init the server rows in the storage
*
* @param partKey partition key
* @param rowType row type
* @param estElemNum estimate element number
* @param valueClass row element type
*/
public void init(PartitionKey partKey, RowType rowType, long estElemNum, Class<? extends IElement> valueClass, RouterType routerType) {
int rowStart = partKey.getStartRow();
int rowEnd = partKey.getEndRow();
long startCol = partKey.getStartCol();
long endCol = partKey.getEndCol();
if (estElemNum < 0) {
estElemNum = 0;
}
for (int rowIndex = rowStart; rowIndex < rowEnd; rowIndex++) {
ServerRow row = ServerRowFactory.createServerRow(rowIndex, rowType, startCol, endCol, (int) estElemNum, valueClass, routerType);
row.init();
putRow(rowIndex, row);
}
}
use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.
the class QuantifyDoubleFunc method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
if (part != null) {
QuantifyDoublePartUParam cp = (QuantifyDoublePartUParam) partParam;
ServerRow row = part.getRow(cp.getRowId());
if (row != null) {
update(row, cp.getArraySlice());
}
}
}
use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.
the class QuantifyFloatFunc method partitionUpdate.
@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
if (part != null) {
QuantifyFloatPartParam cp = (QuantifyFloatPartParam) partParam;
ServerRow row = part.getRow(cp.getRowId());
if (row != null) {
update(row, cp.getArraySlice());
}
}
}
use of com.tencent.angel.ps.storage.vector.ServerRow in project angel by Tencent.
the class AdaDeltaUpdateFunc method update.
@Override
public void update(RowBasedPartition partition, int factor, double[] scalars) {
double epsilon = scalars[0];
double alpha = scalars[1];
double beta = scalars[2];
double lr = scalars[3];
double l1RegParam = scalars[4];
double l2RegParam = scalars[5];
double epoch = (int) scalars[6];
double batchSize = (int) scalars[7];
for (int f = 0; f < factor; f++) {
ServerRow gradientServerRow = partition.getRow(f + 3 * factor);
try {
gradientServerRow.startWrite();
Vector weight = ServerRowUtils.getVector(partition.getRow(f));
Vector square1 = ServerRowUtils.getVector(partition.getRow(f + factor));
Vector square2 = ServerRowUtils.getVector(partition.getRow(f + 2 * factor));
Vector gradient = ServerRowUtils.getVector(gradientServerRow);
if (batchSize > 1) {
gradient.idiv(batchSize);
}
OptFuncs.iexpsmoothing2(square1, gradient, alpha);
Vector hessian = OptFuncs.adadeltahessian(square1, square2);
if (l2RegParam != 0) {
gradient.iaxpy(weight, l2RegParam);
}
OptFuncs.iadadeltadelta(gradient, hessian, l2RegParam);
weight.isub(gradient);
OptFuncs.iexpsmoothing2(square2, gradient, beta);
if (l1RegParam != 0) {
OptFuncs.iadadeltathredshold(weight, hessian, l1RegParam, l2RegParam);
}
gradient.clear();
} finally {
gradientServerRow.endWrite();
}
}
}
Aggregations