Search in sources :

Example 11 with RowType

use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.

the class ModelMergeAndConvert method convertModel.

private static void convertModel(Configuration conf, String modelInputDir, String convertedModelDir, MatrixFilesMeta meta, ModelLineConvert lineConvert) throws IOException {
    Path outputFile = new Path(convertedModelDir, dataFile);
    FileSystem fs = outputFile.getFileSystem(conf);
    FSDataOutputStream output = fs.create(outputFile);
    convertHeader(meta, output);
    RowType rowType = RowType.valueOf(meta.getRowType());
    switch(rowType) {
        case T_DOUBLE_DENSE:
        case T_DOUBLE_DENSE_COMPONENT:
            {
                convertDenseDoubleModel(conf, output, modelInputDir, lineConvert);
                break;
            }
        case T_DOUBLE_SPARSE:
        case T_DOUBLE_SPARSE_COMPONENT:
            {
                convertSparseDoubleModel(conf, output, modelInputDir, lineConvert);
                break;
            }
        case T_DOUBLE_SPARSE_LONGKEY:
        case T_DOUBLE_SPARSE_LONGKEY_COMPONENT:
            {
                convertSparseDoubleLongKeyModel(conf, output, modelInputDir, lineConvert);
                break;
            }
        case T_FLOAT_DENSE:
        case T_FLOAT_DENSE_COMPONENT:
            {
                convertDenseFloatModel(conf, output, modelInputDir, lineConvert);
                break;
            }
        case T_FLOAT_SPARSE:
        case T_FLOAT_SPARSE_COMPONENT:
            {
                convertSparseFloatModel(conf, output, modelInputDir, lineConvert);
                break;
            }
        case T_INT_DENSE:
        case T_INT_DENSE_COMPONENT:
            {
                convertDenseIntModel(conf, output, modelInputDir, lineConvert);
                break;
            }
        case T_INT_SPARSE:
        case T_INT_SPARSE_COMPONENT:
            {
                convertSparseIntModel(conf, output, modelInputDir, lineConvert);
                break;
            }
    }
    output.close();
}
Also used : RowType(com.tencent.angel.ml.matrix.RowType)

Example 12 with RowType

use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.

the class ModelLoader method loadToIntMaps.

/**
 * Load dense double model to int->int maps
 *
 * @param modelDir model save directory path
 * @return model data
 */
public static Int2IntOpenHashMap[] loadToIntMaps(String modelDir, Configuration conf) throws IOException {
    // Load model meta
    MatrixFilesMeta meta = getMeta(modelDir, conf);
    RowType rowType = RowType.valueOf(meta.getRowType());
    // Check row type
    if (rowType != RowType.T_INT_SPARSE && rowType != RowType.T_INT_SPARSE_COMPONENT) {
        throw new IOException("model row type is not sparse int, you should check it");
    }
    // Load model
    SparseIntModel model = new SparseIntModel(meta.getRow(), meta.getCol());
    loadModel(modelDir, model, meta, conf);
    return model.getModel();
}
Also used : MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) RowType(com.tencent.angel.ml.matrix.RowType) IOException(java.io.IOException)

Example 13 with RowType

use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.

the class ModelLoader method loadToDoubleArrays.

/**
 * Load dense double model to a 2-dimension double array
 *
 * @param modelDir model save directory path
 * @return model data
 */
public static double[][] loadToDoubleArrays(String modelDir, Configuration conf) throws IOException {
    // Load model meta
    MatrixFilesMeta meta = getMeta(modelDir, conf);
    RowType rowType = RowType.valueOf(meta.getRowType());
    // Check row type
    if (rowType != RowType.T_DOUBLE_DENSE && rowType != RowType.T_DOUBLE_DENSE_COMPONENT) {
        throw new IOException("model row type is not dense double, you should check it");
    }
    // Load model
    DenseDoubleModel model = new DenseDoubleModel(meta.getRow(), meta.getCol());
    loadModel(modelDir, model, meta, conf);
    return model.getModel();
}
Also used : MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) RowType(com.tencent.angel.ml.matrix.RowType) IOException(java.io.IOException)

Example 14 with RowType

use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.

the class ModelLoader method loadToDoubleMaps.

/**
 * Load dense double model to int->double maps
 *
 * @param modelDir model save directory path
 * @return model data
 */
public static Int2DoubleOpenHashMap[] loadToDoubleMaps(String modelDir, Configuration conf) throws IOException {
    // Load model meta
    MatrixFilesMeta meta = getMeta(modelDir, conf);
    RowType rowType = RowType.valueOf(meta.getRowType());
    // Check row type
    if (rowType != RowType.T_DOUBLE_SPARSE && rowType != RowType.T_DOUBLE_SPARSE_COMPONENT) {
        throw new IOException("model row type is not sparse double, you should check it");
    }
    // Load model
    SparseDoubleModel model = new SparseDoubleModel(meta.getRow(), meta.getCol());
    loadModel(modelDir, model, meta, conf);
    return model.getModel();
}
Also used : MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) RowType(com.tencent.angel.ml.matrix.RowType) IOException(java.io.IOException)

Example 15 with RowType

use of com.tencent.angel.ml.matrix.RowType in project angel by Tencent.

the class ModelLoader method loadToIntArrays.

/**
 * Load dense float model to a 2-dimension int array
 *
 * @param modelDir model save directory path
 * @return model data
 */
public static int[][] loadToIntArrays(String modelDir, Configuration conf) throws IOException {
    // Load model meta
    MatrixFilesMeta meta = getMeta(modelDir, conf);
    RowType rowType = RowType.valueOf(meta.getRowType());
    // Check row type
    if (rowType != RowType.T_INT_DENSE && rowType != RowType.T_INT_DENSE_COMPONENT) {
        throw new IOException("model row type is not dense int, you should check it");
    }
    // Load model
    DenseIntModel model = new DenseIntModel(meta.getRow(), meta.getCol());
    loadModel(modelDir, model, meta, conf);
    return model.getModel();
}
Also used : MatrixFilesMeta(com.tencent.angel.model.output.format.MatrixFilesMeta) RowType(com.tencent.angel.ml.matrix.RowType) IOException(java.io.IOException)

Aggregations

RowType (com.tencent.angel.ml.matrix.RowType)38 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)7 MatrixFilesMeta (com.tencent.angel.model.output.format.MatrixFilesMeta)7 IOException (java.io.IOException)7 Vector (com.tencent.angel.ml.math2.vector.Vector)5 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)4 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)4 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)4 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)3 PartitionKey (com.tencent.angel.PartitionKey)2 AngelException (com.tencent.angel.exception.AngelException)2 RowBasedMatrix (com.tencent.angel.ml.math2.matrix.RowBasedMatrix)2 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)2 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)2 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)2 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 BlasDoubleMatrix (com.tencent.angel.ml.math2.matrix.BlasDoubleMatrix)1 BlasFloatMatrix (com.tencent.angel.ml.math2.matrix.BlasFloatMatrix)1 RBIntDoubleMatrix (com.tencent.angel.ml.math2.matrix.RBIntDoubleMatrix)1 RBIntFloatMatrix (com.tencent.angel.ml.math2.matrix.RBIntFloatMatrix)1