Search in sources :

Example 16 with IntDoubleDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.

the class RowBasedMatrix method dot.

@Override
public Vector dot(Vector other) {
    double[] resArr = new double[rows.length];
    for (int i = 0; i < rows.length; i++) {
        resArr[i] = rows[i].dot(other);
    }
    IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(resArr);
    return new IntDoubleVector(matrixId, 0, clock, rows.length, storage);
}
Also used : IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 17 with IntDoubleDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.

the class DotMatrixExecutor method apply.

private static Vector apply(BlasDoubleMatrix mat, boolean trans, IntDoubleVector v) {
    int m = mat.getNumRows(), n = mat.getNumCols();
    double[] resArr;
    if (trans) {
        assert m == v.getDim();
        resArr = new double[n];
    } else {
        assert n == v.getDim();
        resArr = new double[m];
    }
    int r = mat.getNumRows(), c = mat.getNumCols();
    double[] data = mat.getData();
    if (v.isDense()) {
        double[] tempArray = v.getStorage().getValues();
        if (trans) {
            blas.dgemv("N", c, r, 1.0, data, c, tempArray, 1, 0.0, resArr, 1);
        } else {
            blas.dgemv("T", c, r, 1.0, data, c, tempArray, 1, 0.0, resArr, 1);
        }
    } else if (v.isSparse()) {
        if (trans) {
            for (int j = 0; j < c; j++) {
                ObjectIterator<Int2DoubleMap.Entry> iter = v.getStorage().entryIterator();
                while (iter.hasNext()) {
                    Int2DoubleMap.Entry entry = iter.next();
                    int i = entry.getIntKey();
                    resArr[j] += data[i * c + j] * entry.getDoubleValue();
                }
            }
        } else {
            for (int i = 0; i < r; i++) {
                ObjectIterator<Int2DoubleMap.Entry> iter = v.getStorage().entryIterator();
                while (iter.hasNext()) {
                    Int2DoubleMap.Entry entry = iter.next();
                    int j = entry.getIntKey();
                    resArr[i] += data[i * c + j] * entry.getDoubleValue();
                }
            }
        }
    } else {
        // sorted
        if (trans) {
            for (int j = 0; j < r; j++) {
                int[] idxs = v.getStorage().getIndices();
                double[] vals = v.getStorage().getValues();
                for (int k = 0; k < idxs.length; k++) {
                    resArr[j] += data[idxs[k] * c + j] * vals[k];
                }
            }
        } else {
            for (int i = 0; i < r; i++) {
                int[] idxs = v.getStorage().getIndices();
                double[] vals = v.getStorage().getValues();
                for (int k = 0; k < idxs.length; k++) {
                    resArr[i] += data[i * c + idxs[k]] * vals[k];
                }
            }
        }
    }
    IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(resArr);
    return new IntDoubleVector(v.getMatrixId(), v.getClock(), 0, resArr.length, storage);
}
Also used : IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) Int2DoubleMap(it.unimi.dsi.fastutil.ints.Int2DoubleMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 18 with IntDoubleDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.

the class DotMatrixExecutor method apply.

private static Vector apply(BlasDoubleMatrix mat, boolean trans, IntLongVector v) {
    int m = mat.getNumRows(), n = mat.getNumCols();
    double[] resArr;
    if (trans) {
        assert m == v.getDim();
        resArr = new double[n];
    } else {
        assert n == v.getDim();
        resArr = new double[m];
    }
    int r = mat.getNumRows(), c = mat.getNumCols();
    double[] data = mat.getData();
    if (v.isDense()) {
        double[] tempArray = ArrayCopy.copy(v.getStorage().getValues(), new double[v.getDim()]);
        if (trans) {
            blas.dgemv("N", c, r, 1.0, data, c, tempArray, 1, 0.0, resArr, 1);
        } else {
            blas.dgemv("T", c, r, 1.0, data, c, tempArray, 1, 0.0, resArr, 1);
        }
    } else if (v.isSparse()) {
        if (trans) {
            for (int j = 0; j < c; j++) {
                ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
                while (iter.hasNext()) {
                    Int2LongMap.Entry entry = iter.next();
                    int i = entry.getIntKey();
                    resArr[j] += data[i * c + j] * entry.getLongValue();
                }
            }
        } else {
            for (int i = 0; i < r; i++) {
                ObjectIterator<Int2LongMap.Entry> iter = v.getStorage().entryIterator();
                while (iter.hasNext()) {
                    Int2LongMap.Entry entry = iter.next();
                    int j = entry.getIntKey();
                    resArr[i] += data[i * c + j] * entry.getLongValue();
                }
            }
        }
    } else {
        // sorted
        if (trans) {
            for (int j = 0; j < r; j++) {
                int[] idxs = v.getStorage().getIndices();
                long[] vals = v.getStorage().getValues();
                for (int k = 0; k < idxs.length; k++) {
                    resArr[j] += data[idxs[k] * c + j] * vals[k];
                }
            }
        } else {
            for (int i = 0; i < r; i++) {
                int[] idxs = v.getStorage().getIndices();
                long[] vals = v.getStorage().getValues();
                for (int k = 0; k < idxs.length; k++) {
                    resArr[i] += data[i * c + idxs[k]] * vals[k];
                }
            }
        }
    }
    IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(resArr);
    return new IntDoubleVector(v.getMatrixId(), v.getClock(), 0, resArr.length, storage);
}
Also used : IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) Int2LongMap(it.unimi.dsi.fastutil.ints.Int2LongMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 19 with IntDoubleDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.

the class DotMatrixExecutor method apply.

private static Vector apply(BlasDoubleMatrix mat, boolean trans, IntFloatVector v) {
    int m = mat.getNumRows(), n = mat.getNumCols();
    double[] resArr;
    if (trans) {
        assert m == v.getDim();
        resArr = new double[n];
    } else {
        assert n == v.getDim();
        resArr = new double[m];
    }
    int r = mat.getNumRows(), c = mat.getNumCols();
    double[] data = mat.getData();
    if (v.isDense()) {
        double[] tempArray = ArrayCopy.copy(v.getStorage().getValues(), new double[v.getDim()]);
        if (trans) {
            blas.dgemv("N", c, r, 1.0, data, c, tempArray, 1, 0.0, resArr, 1);
        } else {
            blas.dgemv("T", c, r, 1.0, data, c, tempArray, 1, 0.0, resArr, 1);
        }
    } else if (v.isSparse()) {
        if (trans) {
            for (int j = 0; j < c; j++) {
                ObjectIterator<Int2FloatMap.Entry> iter = v.getStorage().entryIterator();
                while (iter.hasNext()) {
                    Int2FloatMap.Entry entry = iter.next();
                    int i = entry.getIntKey();
                    resArr[j] += data[i * c + j] * entry.getFloatValue();
                }
            }
        } else {
            for (int i = 0; i < r; i++) {
                ObjectIterator<Int2FloatMap.Entry> iter = v.getStorage().entryIterator();
                while (iter.hasNext()) {
                    Int2FloatMap.Entry entry = iter.next();
                    int j = entry.getIntKey();
                    resArr[i] += data[i * c + j] * entry.getFloatValue();
                }
            }
        }
    } else {
        // sorted
        if (trans) {
            for (int j = 0; j < r; j++) {
                int[] idxs = v.getStorage().getIndices();
                float[] vals = v.getStorage().getValues();
                for (int k = 0; k < idxs.length; k++) {
                    resArr[j] += data[idxs[k] * c + j] * vals[k];
                }
            }
        } else {
            for (int i = 0; i < r; i++) {
                int[] idxs = v.getStorage().getIndices();
                float[] vals = v.getStorage().getValues();
                for (int k = 0; k < idxs.length; k++) {
                    resArr[i] += data[i * c + idxs[k]] * vals[k];
                }
            }
        }
    }
    IntDoubleDenseVectorStorage storage = new IntDoubleDenseVectorStorage(resArr);
    return new IntDoubleVector(v.getMatrixId(), v.getClock(), 0, resArr.length, storage);
}
Also used : IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) Int2FloatMap(it.unimi.dsi.fastutil.ints.Int2FloatMap) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Example 20 with IntDoubleDenseVectorStorage

use of com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage in project angel by Tencent.

the class GBDTController method updateLeafPreds.

public void updateLeafPreds() throws Exception {
    LOG.info("------Update leaf node predictions------");
    long startTime = System.currentTimeMillis();
    Set<String> needFlushMatrixSet = new HashSet<String>(1);
    if (taskContext.getTaskIndex() == 0) {
        int nodeNum = this.forest[currentTree].nodes.size();
        IntDoubleVector vec = new IntDoubleVector(this.maxNodeNum, new IntDoubleDenseVectorStorage(this.maxNodeNum));
        for (int nid = 0; nid < nodeNum; nid++) {
            if (null != this.forest[currentTree].nodes.get(nid) && this.forest[currentTree].nodes.get(nid).isLeaf()) {
                float weight = this.forest[currentTree].nodes.get(nid).getLeafValue();
                LOG.debug(String.format("Leaf weight of node[%d]: %f", nid, weight));
                vec.set(nid, weight);
            }
        }
        PSModel nodePreds = this.model.getPSModel(this.param.nodePredsName);
        nodePreds.increment(this.currentTree, vec);
        // the leader task adds node prediction to flush list
        needFlushMatrixSet.add(this.param.nodePredsName);
    }
    clockAllMatrix(needFlushMatrixSet, true);
    LOG.info(String.format("Update leaf node predictions cost: %d ms", System.currentTimeMillis() - startTime));
}
Also used : IntDoubleDenseVectorStorage(com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage) PSModel(com.tencent.angel.ml.model.PSModel) IntDoubleVector(com.tencent.angel.ml.math2.vector.IntDoubleVector)

Aggregations

IntDoubleDenseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleDenseVectorStorage)24 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)21 PSModel (com.tencent.angel.ml.model.PSModel)4 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)4 IntDoubleSortedVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSortedVectorStorage)3 IntDoubleSparseVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleSparseVectorStorage)3 IntDoubleVectorStorage (com.tencent.angel.ml.math2.storage.IntDoubleVectorStorage)3 Int2DoubleMap (it.unimi.dsi.fastutil.ints.Int2DoubleMap)3 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)2 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)2 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)2 Worker (com.tencent.angel.worker.Worker)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AngelException (com.tencent.angel.exception.AngelException)1 AMMatrixMetaManager (com.tencent.angel.master.matrixmeta.AMMatrixMetaManager)1 AMTask (com.tencent.angel.master.task.AMTask)1 AMTaskManager (com.tencent.angel.master.task.AMTaskManager)1 SplitEntry (com.tencent.angel.ml.GBDT.algo.tree.SplitEntry)1 GBDTGradHistGetRowFunc (com.tencent.angel.ml.GBDT.psf.GBDTGradHistGetRowFunc)1 HistAggrParam (com.tencent.angel.ml.GBDT.psf.HistAggrParam)1