Search in sources :

Example 1 with SparseDummyVector

use of com.tencent.angel.ml.math.vector.SparseDummyVector in project angel by Tencent.

the class LabeledUpdateIndexBaseTask method preProcess.

@Override
public void preProcess(TaskContext taskContext) {
    try {
        Reader<KEYIN, VALUEIN> reader = taskContext.getReader();
        while (reader.nextKeyValue()) {
            LabeledData out = parse(reader.getCurrentKey(), reader.getCurrentValue());
            if (out != null) {
                taskDataBlock.put(out);
                if (updateIndexEnable) {
                    TAbstractVector vector = out.getX();
                    if (vector instanceof SparseDummyVector) {
                        int[] indexes = ((SparseDummyVector) vector).getIndices();
                        for (int i = 0; i < indexes.length; i++) {
                            indexSet.add(indexes[i]);
                        }
                    }
                }
            }
        }
        taskDataBlock.flush();
    } catch (Exception e) {
        throw new AngelException("Pre-Process Error.", e);
    }
}
Also used : AngelException(com.tencent.angel.exception.AngelException) LabeledData(com.tencent.angel.ml.feature.LabeledData) TAbstractVector(com.tencent.angel.ml.math.TAbstractVector) SparseDummyVector(com.tencent.angel.ml.math.vector.SparseDummyVector) AngelException(com.tencent.angel.exception.AngelException) IOException(java.io.IOException)

Example 2 with SparseDummyVector

use of com.tencent.angel.ml.math.vector.SparseDummyVector in project angel by Tencent.

the class DoubleVectorTest method densePlusByDummyTest.

@Test
public void densePlusByDummyTest() {
    DenseDoubleVector vector = new DenseDoubleVector(10);
    vector.set(1, 1.0);
    vector.set(3, 3.0);
    vector.set(5, 5.0);
    SparseDummyVector dummyVector = new SparseDummyVector(10);
    dummyVector.set(1, 1.0);
    dummyVector.set(3, 1.0);
    vector.plusBy(dummyVector, 1.0);
    Assert.assertEquals(2.0, vector.get(1), 0.0);
    Assert.assertEquals(4.0, vector.get(3), 0.0);
    Assert.assertEquals(5.0, vector.get(5), 0.0);
    Assert.assertEquals(0.0, vector.get(7), 0.0);
}
Also used : DenseDoubleVector(com.tencent.angel.ml.math.vector.DenseDoubleVector) SparseDummyVector(com.tencent.angel.ml.math.vector.SparseDummyVector) Test(org.junit.Test)

Example 3 with SparseDummyVector

use of com.tencent.angel.ml.math.vector.SparseDummyVector in project angel by Tencent.

the class DoubleVectorTest method plusBySparseTest.

@Test
public void plusBySparseTest() {
    SparseDoubleVector vector = new SparseDoubleVector(10);
    vector.set(1, 1.0);
    vector.set(3, 3.0);
    vector.set(5, 5.0);
    SparseDummyVector dummyVector = new SparseDummyVector(10);
    dummyVector.set(1, 1.0);
    dummyVector.set(3, 1.0);
    vector.plusBy(dummyVector, 1.0);
    Assert.assertEquals(2.0, vector.get(1), 0.0);
    Assert.assertEquals(4.0, vector.get(3), 0.0);
    Assert.assertEquals(5.0, vector.get(5), 0.0);
}
Also used : SparseDummyVector(com.tencent.angel.ml.math.vector.SparseDummyVector) SparseDoubleVector(com.tencent.angel.ml.math.vector.SparseDoubleVector) Test(org.junit.Test)

Aggregations

SparseDummyVector (com.tencent.angel.ml.math.vector.SparseDummyVector)3 Test (org.junit.Test)2 AngelException (com.tencent.angel.exception.AngelException)1 LabeledData (com.tencent.angel.ml.feature.LabeledData)1 TAbstractVector (com.tencent.angel.ml.math.TAbstractVector)1 DenseDoubleVector (com.tencent.angel.ml.math.vector.DenseDoubleVector)1 SparseDoubleVector (com.tencent.angel.ml.math.vector.SparseDoubleVector)1 IOException (java.io.IOException)1