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);
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations