Search in sources :

Example 21 with RowBasedPartition

use of com.tencent.angel.ps.storage.partition.RowBasedPartition 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());
        }
    }
}
Also used : QuantifyFloatPartParam(com.tencent.angel.ml.psf.compress.QuantifyFloatParam.QuantifyFloatPartParam) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition)

Example 22 with RowBasedPartition

use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.

the class InitAliasTable method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    InitAliasTablePartParam param = (InitAliasTablePartParam) partParam;
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    RowBasedPartition part = (RowBasedPartition) matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongAnyRow row = (ServerLongAnyRow) part.getRow(0);
    ObjectIterator<Long2ObjectMap.Entry<AliasElement>> iter = param.getNodeId2Neighbors().long2ObjectEntrySet().iterator();
    row.startWrite();
    try {
        while (iter.hasNext()) {
            Long2ObjectMap.Entry<AliasElement> entry = iter.next();
            AliasElement element = entry.getValue();
            if (element == null) {
                row.set(entry.getLongKey(), null);
            } else {
                row.set(entry.getLongKey(), new AliasElement(element.getNeighborIds(), element.getAccept(), element.getAlias()));
            }
        }
    } finally {
        row.endWrite();
    }
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 23 with RowBasedPartition

use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.

the class ComputeW method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    if (partParam instanceof MultiRowPartitionUpdateParam) {
        MultiRowPartitionUpdateParam param = (MultiRowPartitionUpdateParam) partParam;
        int[] rowIds = param.getRowIds();
        double[][] values = param.getValues();
        double alpha = values[0][0];
        double beta = values[0][1];
        double lambda1 = values[0][2];
        double lambda2 = values[0][3];
        int offset = (int) values[1][0];
        RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(param.getPartKey());
        for (int i = 0; i < offset; i++) {
            Vector z = ServerRowUtils.getVector(part.getRow(rowIds[0] * offset + i));
            Vector n = ServerRowUtils.getVector(part.getRow(rowIds[1] * offset + i));
            Vector w = Ufuncs.ftrlthreshold(z, n, alpha, beta, lambda1, lambda2);
            ServerRowUtils.setVector(part.getRow(rowIds[2] * offset + i), w.ifilter(1e-11));
        }
    // // calculate bias
    // if (param.getPartKey().getStartCol() <= 0 && param.getPartKey().getEndCol() > 0) {
    // double zVal = VectorUtils.getDouble(z, 0);
    // double nVal = VectorUtils.getDouble(n, 0);
    // VectorUtils.setFloat(w, 0, (float) (-1.0 * alpha * zVal / (beta + Math.sqrt(nVal))));
    // }
    }
}
Also used : MultiRowPartitionUpdateParam(com.tencent.angel.ml.matrix.psf.update.enhance.MultiRowUpdateParam.MultiRowPartitionUpdateParam) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) Vector(com.tencent.angel.ml.math2.vector.Vector)

Example 24 with RowBasedPartition

use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.

the class IndexGet method partitionGet.

/**
 * Each server partition execute this function and return values of specified index.
 *
 * @param partParam the partition parameter
 * @return values of specified index
 */
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    long startTs = System.currentTimeMillis();
    RowBasedPartition part = (RowBasedPartition) psContext.getMatrixStorageManager().getPart(partParam.getMatrixId(), partParam.getPartKey().getPartitionId());
    PartitionGetResult result = null;
    if (part != null) {
        int rowId = ((IndexPartGetParam) partParam).getRowId();
        int[] indexes = ((IndexPartGetParam) partParam).getIndexes();
        ServerRow row = part.getRow(rowId);
        RowType rowType = row.getRowType();
        switch(rowType) {
            case T_DOUBLE_DENSE:
            case T_DOUBLE_SPARSE:
            case T_DOUBLE_DENSE_COMPONENT:
            case T_DOUBLE_SPARSE_COMPONENT:
                {
                    result = new IndexPartGetDoubleResult(partParam.getPartKey(), ((ServerIntDoubleRow) row).get(indexes));
                    break;
                }
            case T_FLOAT_DENSE:
            case T_FLOAT_SPARSE:
            case T_FLOAT_DENSE_COMPONENT:
            case T_FLOAT_SPARSE_COMPONENT:
                {
                    result = new IndexPartGetFloatResult(partParam.getPartKey(), ((ServerIntFloatRow) row).get(indexes));
                    break;
                }
            case T_INT_DENSE:
            case T_INT_SPARSE:
            case T_INT_DENSE_COMPONENT:
            case T_INT_SPARSE_COMPONENT:
                {
                    result = new IndexPartGetIntResult(partParam.getPartKey(), ((ServerIntIntRow) row).get(indexes));
                    break;
                }
            case T_LONG_DENSE:
            case T_LONG_SPARSE:
            case T_LONG_DENSE_COMPONENT:
            case T_LONG_SPARSE_COMPONENT:
                {
                    result = new IndexPartGetLongResult(partParam.getPartKey(), ((ServerIntLongRow) row).get(indexes));
                    break;
                }
            default:
                throw new UnsupportedOperationException("Unsupport operation: update " + rowType + " to " + this.getClass().getName());
        }
    }
    LOG.debug("Partition get use time=" + (System.currentTimeMillis() - startTs) + " ms");
    return result;
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 25 with RowBasedPartition

use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.

the class IncrementRows method getVector.

/**
 * Get inner vector from server matrix, it is can be only use in RowBasedPartition and basic row
 * type
 *
 * @param matrixId matrix id
 * @param rowId row id
 * @param part partition key
 * @return inner vector
 */
protected Vector getVector(int matrixId, int rowId, PartitionKey part) {
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(matrixId);
    ServerRow psRow = ((RowBasedPartition) matrix.getPartition(part.getPartitionId())).getRow(rowId);
    return ServerRowUtils.getVector(psRow);
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition)

Aggregations

RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)38 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)28 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)20 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)15 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)6 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)5 ServerIntAnyRow (com.tencent.angel.ps.storage.vector.ServerIntAnyRow)4 Random (java.util.Random)4 ServerLongIntRow (com.tencent.angel.ps.storage.vector.ServerLongIntRow)3 Vector (com.tencent.angel.ml.math2.vector.Vector)2 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)2 ServerAnyAnyRow (com.tencent.angel.ps.storage.vector.ServerAnyAnyRow)2 ServerLongLongRow (com.tencent.angel.ps.storage.vector.ServerLongLongRow)2 LongArrayElement (com.tencent.angel.ps.storage.vector.element.LongArrayElement)2 AngelException (com.tencent.angel.exception.AngelException)1 Node (com.tencent.angel.graph.data.Node)1 DynamicNeighborElement (com.tencent.angel.graph.model.neighbor.dynamic.DynamicNeighborElement)1 NeighborsAliasTableElement (com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement)1 CompIntDoubleVector (com.tencent.angel.ml.math2.vector.CompIntDoubleVector)1 CompIntFloatVector (com.tencent.angel.ml.math2.vector.CompIntFloatVector)1