THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
The following code block shows the abstract class of AlgoOperator.
Code Block | ||
---|---|---|
| ||
public abstract class AlgoOperator<T extends AlgoOperator> implements WithParams <T> {
// the first output table
protected Table output = null;
// the side output tables
private Table[] sideOutputs = null;
// the params
private Params params = null;
/**
* get the output table
*
* @return
*/
public final Table getOutputTable() {
if (null == this.output) {
throw new RuntimeException(
"There is no output. Please call current AlgoOperator's 'link' or related method firstly, or this "
+ "AlgoOperator has no output.");
} else {
return this.output;
}
}
/**
* get Params for this algorithm.
*
* @return
*/
public final Params getParams() {
return params;
}
/**
* get side outputs of this operator
*
* @return
*/
public final AlgoOperator<?>[] getSideOutputs() {
if (null == sideOutputs) {
return null;
}
TableSourceOp[] sideOutputOps = new TableSourceOp[sideOutputs.length];
for (int i = 0; i < sideOutputs.length; i++) {
sideOutputOps[i] = new TableSourceOp(sideOutputs[i]);
}
return sideOutputOps;
}
/**
* Link from other AlgoOperators. This function encapsulates the computation logic of this AlgoOperator.
* Note that: Only the first output table of each input will be used in the computation logic.
*
* @param inputs the input AlgoOperators
* @return return this AlgoOperator
*/
public final T linkFrom(AlgoOperator <?>... inputs) {
Table[] inputTables = new Table[inputs.length];
for (int i = 0; i < inputs.length; i++) {
inputTables[i] = inputs[i].getOutputTable();
}
Table[] outputTables = compute(inputTables);
if (null != outputTables && outputTables.length > 0) {
this.output = outputTables[0];
}
if (null != outputTables && outputTables.length > 1) {
this.sideOutputs = Arrays.copyOfRange(outputTables, 1, outputTables.length);
}
return (T) this;
}
/**
* Link to another operator.
*
* @param next the AlgoOperator to link to.
* @return return the “next operator”
*/
public final <S extends AlgoOperator<?>> AlgoOperator<?> link(S next) {
next.linkFrom(this);
return next;
}
/**
* Applies the computation logic on the input tables.
* tables.
*
* @param inputs the input tables
* @return the output tables
*/
@Internal
public abstract Table[] compute(Table... inputs);
}
|
...
Code Block | ||
---|---|---|
| ||
// User code TableSourceOp edges, nodeLabels; // used for training, can be constructed from Table TableSourceOp nodeIds; // used for prediction, can be constructed from Table AlgoOperator modelOp = new MetaPath2vecTrainOp() .linkFrom(edges, nodeLabels); AlgoOperator result = new MetaPath2vecPredictOp() .linkFrom(modelOp, nodeIds); // Developer code public class MetaPath2vecTrainOp extends AlgoOperator<MetaPath2vecTrainOp> { @Internal @Override public abstract Table[] compute(Table… inputs) { // do the computation logic } } public class MetaPath2VecPredictOp extends AlgoOperator<MetaPath2VecPredictOp> { @Internal @Override public abstract Table[] compute(Table… inputs) { // do the computation logic } } |
...
Code Block | ||
---|---|---|
| ||
// User code:
TableSourceOp input;
AlgoOperator auc = new EvaluationAUCOp().linkFrom(input);
// Developer Code:
public class EvaluationAUCOp extends AlgoOperator<EvaluationAUCOp> {
@Internal
@Override
public abstract Table[] compute(Table… inputs) {
// do the computation logic
}
}
|
...