Search in sources :

Example 1 with COVOperator

use of org.apache.sysml.runtime.matrix.operators.COVOperator in project incubator-systemml by apache.

the class CM_N_COVInstruction method parseInstruction.

public static CM_N_COVInstruction parseInstruction(String str) throws DMLRuntimeException {
    String[] parts = InstructionUtils.getInstructionParts(str);
    byte in, out;
    int cst;
    String opcode = parts[0];
    if (opcode.equalsIgnoreCase("cm")) {
        in = Byte.parseByte(parts[1]);
        cst = Integer.parseInt(parts[2]);
        out = Byte.parseByte(parts[3]);
        if (cst > 4 || cst < 0 || cst == 1)
            throw new DMLRuntimeException("constant for central moment has to be 0, 2, 3, or 4");
        AggregateOperationTypes opType = CMOperator.getCMAggOpType(cst);
        CMOperator cm = new CMOperator(CM.getCMFnObject(opType), opType);
        return new CM_N_COVInstruction(cm, in, out, str);
    } else if (opcode.equalsIgnoreCase("cov")) {
        in = Byte.parseByte(parts[1]);
        out = Byte.parseByte(parts[2]);
        COVOperator cov = new COVOperator(COV.getCOMFnObject());
        return new CM_N_COVInstruction(cov, in, out, str);
    } else
        throw new DMLRuntimeException("unknown opcode " + opcode);
}
Also used : COVOperator(org.apache.sysml.runtime.matrix.operators.COVOperator) AggregateOperationTypes(org.apache.sysml.runtime.matrix.operators.CMOperator.AggregateOperationTypes) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 2 with COVOperator

use of org.apache.sysml.runtime.matrix.operators.COVOperator in project incubator-systemml by apache.

the class CovarianceCPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    MatrixBlock matBlock1 = ec.getMatrixInput(input1.getName());
    MatrixBlock matBlock2 = ec.getMatrixInput(input2.getName());
    String output_name = output.getName();
    COVOperator cov_op = (COVOperator) _optr;
    CM_COV_Object covobj = new CM_COV_Object();
    if (input3 == null) {
        // Unweighted: cov.mvar0.mvar1.out
        covobj = matBlock1.covOperations(cov_op, matBlock2);
        ec.releaseMatrixInput(input1.getName());
        ec.releaseMatrixInput(input2.getName());
    } else {
        // Weighted: cov.mvar0.mvar1.weights.out
        MatrixBlock wtBlock = ec.getMatrixInput(input3.getName());
        covobj = matBlock1.covOperations(cov_op, matBlock2, wtBlock);
        ec.releaseMatrixInput(input1.getName());
        ec.releaseMatrixInput(input2.getName());
        ec.releaseMatrixInput(input3.getName());
    }
    double val = covobj.getRequiredResult(_optr);
    DoubleObject ret = new DoubleObject(output_name, val);
    ec.setScalarOutput(output_name, ret);
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) COVOperator(org.apache.sysml.runtime.matrix.operators.COVOperator)

Example 3 with COVOperator

use of org.apache.sysml.runtime.matrix.operators.COVOperator in project incubator-systemml by apache.

the class CovarianceSPInstruction method processInstruction.

@Override
public void processInstruction(ExecutionContext ec) throws DMLRuntimeException {
    SparkExecutionContext sec = (SparkExecutionContext) ec;
    COVOperator cop = ((COVOperator) _optr);
    //get input
    JavaPairRDD<MatrixIndexes, MatrixBlock> in1 = sec.getBinaryBlockRDDHandleForVariable(input1.getName());
    JavaPairRDD<MatrixIndexes, MatrixBlock> in2 = sec.getBinaryBlockRDDHandleForVariable(input2.getName());
    //process central moment instruction
    CM_COV_Object cmobj = null;
    if (//w/o weights
    input3 == null) {
        cmobj = in1.join(in2).values().map(new RDDCOVFunction(cop)).fold(new CM_COV_Object(), new RDDCOVReduceFunction(cop));
    } else //with weights
    {
        JavaPairRDD<MatrixIndexes, MatrixBlock> in3 = sec.getBinaryBlockRDDHandleForVariable(input3.getName());
        cmobj = in1.join(in2).join(in3).values().map(new RDDCOVWeightsFunction(cop)).fold(new CM_COV_Object(), new RDDCOVReduceFunction(cop));
    }
    //create scalar output (no lineage information required)
    double val = cmobj.getRequiredResult(_optr);
    DoubleObject ret = new DoubleObject(output.getName(), val);
    ec.setScalarOutput(output.getName(), ret);
}
Also used : CM_COV_Object(org.apache.sysml.runtime.instructions.cp.CM_COV_Object) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) DoubleObject(org.apache.sysml.runtime.instructions.cp.DoubleObject) COVOperator(org.apache.sysml.runtime.matrix.operators.COVOperator) SparkExecutionContext(org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)

Example 4 with COVOperator

use of org.apache.sysml.runtime.matrix.operators.COVOperator in project incubator-systemml by apache.

the class CovarianceSPInstruction method parseInstruction.

public static CovarianceSPInstruction parseInstruction(String str) throws DMLRuntimeException {
    CPOperand in1 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in2 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    CPOperand in3 = null;
    CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
    String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
    String opcode = parts[0];
    if (!opcode.equalsIgnoreCase("cov")) {
        throw new DMLRuntimeException("CovarianceCPInstruction.parseInstruction():: Unknown opcode " + opcode);
    }
    COVOperator cov = new COVOperator(COV.getCOMFnObject());
    if (parts.length == 4) {
        // CP.cov.mVar0.mVar1.mVar2
        parseBinaryInstruction(str, in1, in2, out);
        return new CovarianceSPInstruction(cov, in1, in2, out, opcode, str);
    } else if (parts.length == 5) {
        // CP.cov.mVar0.mVar1.mVar2.mVar3
        in3 = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
        parseBinaryInstruction(str, in1, in2, in3, out);
        return new CovarianceSPInstruction(cov, in1, in2, in3, out, opcode, str);
    } else {
        throw new DMLRuntimeException("Invalid number of arguments in Instruction: " + str);
    }
}
Also used : COVOperator(org.apache.sysml.runtime.matrix.operators.COVOperator) CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 5 with COVOperator

use of org.apache.sysml.runtime.matrix.operators.COVOperator in project incubator-systemml by apache.

the class CMCOVMRReducer method configure.

public void configure(JobConf job) {
    super.configure(job);
    try {
        cmNcovInstructions = MRJobConfiguration.getCM_N_COVInstructions(job);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    rlens = new HashMap<Byte, Long>();
    clens = new HashMap<Byte, Long>();
    for (CM_N_COVInstruction ins : cmNcovInstructions) {
        if (ins.getOperator() instanceof COVOperator)
            covTags.add(ins.input);
        else
            //CMOperator
            cmFn.put(ins.input, CM.getCMFnObject(((CMOperator) ins.getOperator()).getAggOpType()));
        outputIndexesMapping.put(ins.output, getOutputIndexes(ins.output));
        rlens.put(ins.input, MRJobConfiguration.getNumRows(job, ins.input));
        clens.put(ins.input, MRJobConfiguration.getNumColumns(job, ins.input));
    }
    zeroObj = new CM_COV_Object();
    zeroObj.w = 1;
}
Also used : CM_N_COVInstruction(org.apache.sysml.runtime.instructions.mr.CM_N_COVInstruction) CM_COV_Object(org.apache.sysml.runtime.instructions.cp.CM_COV_Object) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) COVOperator(org.apache.sysml.runtime.matrix.operators.COVOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) IOException(java.io.IOException)

Aggregations

COVOperator (org.apache.sysml.runtime.matrix.operators.COVOperator)7 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)5 IOException (java.io.IOException)2 CM_COV_Object (org.apache.sysml.runtime.instructions.cp.CM_COV_Object)2 CM_N_COVInstruction (org.apache.sysml.runtime.instructions.mr.CM_N_COVInstruction)2 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)2 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)2 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)1 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)1 DoubleObject (org.apache.sysml.runtime.instructions.cp.DoubleObject)1 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)1 AggregateOperationTypes (org.apache.sysml.runtime.matrix.operators.CMOperator.AggregateOperationTypes)1