/**
* A GraphBuilder provides APIs to build Estimator/Model/AlgoOperator from a DAG of stages, each of
* which could be an Estimator, Model, Transformer or AlgoOperator.
*/
@PublicEvolving
public final class GraphBuilder {
private int maxOutputLength = 20;
public GraphBuilder() {}
/**
* Specifies the loose upper bound (could be loose) of the number of output tables that can be
returned by the
* returned by the* TransformerModel::getModelData() and AlgoOperator::transform() methods, for any stage
involved in this
* involved in this* Graph.
*
* <p>The default upper bound is 20.
*/
public GraphBuilder setMaxOutputLengthsetMaxOutputTableNum(int maxOutputLength) {...}
/**
* Creates a TableId associated with this GraphBuilder. It can be used to specify the passing of
* tables between stages, as well as the input/output tables of the Graph/GraphModel generated
* by this builder.
*
* @return A TableId.
*/
public TableId createTableId() {...}
/**
* IfAdds thean stageAlgoOperator isin an Estimator, both its fit method and the transform method of its fitted
* Model would be the graph.
*
* <p>When the graph runs as Estimator, the transform() of the given AlgoOperator would be
* invoked with the given inputs. Then when the graphGraphModel runs.
fitted by this graph runs, *the
* <p>Iftransform() thisof stage is a Model, Transformer or AlgoOperator, its transform method the given AlgoOperator would be
* invoked with the given inputs when the graph runs.
*
* <p>Returns<p>When athe listgraph ofruns TableIds,as whichAlgoOperator representsor outputsModel, ofthe AlgoOperator::transform() of the given stage.AlgoOperator
*/
would be invoked publicwith TableId[] getOutputs(Stage<?> stage, TableId... inputs) {...}
the given inputs.
/**
* If<p>NOTE: thisthe stagenumber isof anthe Estimator,returned itsTableIds fitdoes methodnot wouldrepresent bethe invokedactual withnumber estimatorInputs, and theof Tables
* transformoutputted method of its fitted Model wouldby transform(). This number could be invokedconfigured withusing algoInputs.{@link
*
#setMaxOutputTableNum(int)}. Users should make *sure <p>Thisthat methodthis throws Exception ifnumber >= the stageactual isnumber notof
an Estimator.
* Tables *
outputted by transform().
*
<p>This method is useful when* the@param statealgoOp isAn an Estimator AND the Estimator::fit needs to takeAlgoOperator instance.
* a@param inputs differentA list of TableIds which Tablesrepresents frominputs theto Model::transform() of the fitted Model.given
* AlgoOperator.
* <p>Returns@return aA list of TableIds, which represents the outputs of Model::transform() of the fitted Model.given
*/ AlgoOperator.
public */
public TableId[] getOutputsaddAlgoOperator(Stage<AlgoOperator<?> stagealgoOp, TableId[] estimatorInputs, TableId[] algoInputs... inputs) {...}
/**
* The setModelData() of Adds an Estimator in the graph.
*
* <p>When the fittedgraph GraphModelruns shouldas invokeEstimator, the setModelDatafit() of the given Estimator would be invoked with
* stage with the given inputs.
Then when the GraphModel */
fitted by this graph publicruns, voidthe setModelData(Stage<?> stage, TableId... inputs) {...}
/**transform() of the
* TheModel getModelData()fitted ofby the fittedgiven GraphModelEstimator shouldwould invokebe the getModelData() ofinvoked with the given inputs.
* stage.
*
<p>When the graph runs *as <p>ReturnsAlgoOperator a list of TableIdsor Model, which represents the outputs of getModelDatafit() of the given
Estimator would be
* stage.
* invoked with */
the given inputs, then public TableId[] getModelData(Stage<?> stage) {...}
/**the transform() of the Model fitted by the given
* ReturnsEstimator anwould Estimatorbe instanceinvoked with the followinggiven behavior:inputs.
*
* <p>1) Estimator::fit should take<p>NOTE: the number of the givenreturned TableIds inputsdoes andnot returnrepresent athe Modelactual withnumber theof followingTables
* behavior.
*outputted by transform(). This number could be configured using {@link
* <p>2#setMaxOutputTableNum(int) Model::transform}. Users should takemake thesure giventhat inputsthis andnumber return>= the given outputs.actual number of
*
Tables outputted by transform().
* <p>The fit method of*
the returned Estimator and the* transform@param methodestimator ofAn the fitted ModelEstimator instance.
* should@param invokeinputs theA correspondinglist methodsof ofTableIds thewhich internalrepresents stagesinputs asto specifiedfit() byof the
given * GraphBuilder.Estimator as
*/
public Estimator<?, ?> buildEstimator(TableId[] inputs, TableId[] outputs) {...}
/**
* Returns an Estimator instance with the following behavior:
*
* <p>1) Estimator::fit should take the given inputs and returns a Model with the following
* behaviorwell as inputs to transform() of the Model fitted by the given Estimator.
* @return A list of TableIds which represents the outputs of transform() of the Model fitted by
* the given Estimator.
*/
public * <p>2) Model::transform should take the given inputs and return the given outputs.
TableId[] addEstimator(Estimator<?, ?> estimator, TableId... inputs) {...}
/**
* <p>3) Model::setModelData should takeAdds an Estimator in the given inputModelDatagraph.
*
* <p>4) Model::getModelData should return <p>When the graph runs as Estimator, the given outputModelData.
*fit() of the given Estimator would be invoked with
* estimatorInputs. Then <p>Thewhen fitthe methodGraphModel offitted theby returnedthis Estimatorgraph andruns, the transform/setModelData/getModelData() of the
* methodsModel fitted ofby the fittedgiven ModelEstimator shouldwould invokebe theinvoked correspondingwith methodsmodelInputs.
of the internal stages as*
* specified by<p>When the GraphBuilder.
graph runs as AlgoOperator or */
Model, the fit() public Estimator<?, ?> buildEstimator(TableId[] inputs, TableId[] outputs, TableId[] inputModelData, TableId[] outputModelData) {...}
/**of the given Estimator would be
* invoked with estimatorInputs, then the transform() of the Model fitted by the given Estimator
* Returnswould anbe Estimatorinvoked instance with the following behavior:modelInputs.
*
* <p>1) Estimator::fit should take the given estimatorInputs and returns a Model with the<p>NOTE: the number of the returned TableIds does not represent the actual number of Tables
* following behavior.
*outputted by transform(). This number could be configured using {@link
* <p>2#setMaxOutputTableNum(int) Model::transform}. Users should takemake thesure giventhat transformerInputsthis andnumber return>= the given outputs.actual number of
*
Tables outputted * <p>3) Model::setModelData should take the given inputModelDataby transform().
*
* <p>4) Model::getModelData should return the given outputModelData@param estimator An Estimator instance.
*
@param estimatorInputs A list *of <p>TheTableIds fitwhich methodrepresents ofinputs theto returnedfit() Estimatorof and the transform/setModelData/getModelDatagiven
* methods of the fitted ModelEstimator.
should invoke the corresponding methods* of@param themodelInputs internalA stageslist as
of TableIds which represents inputs *to specifiedtransform() byof the GraphBuilder.Model
*/
public Estimator<?, ?> buildEstimator(TableId[] estimatorInputs, TableId[] algoInputs, TableId[] outputs, TableId[] inputModelData, TableId[] outputModelData) {...}
/**
* Returns an AlgoOperator instance with the following behavior:
*fitted by the given Estimator.
* @return A list of TableIds which represents the outputs of transform() of the Model fitted by
* <p>1) AlgoOperator::transform should take the given inputs and returns the given outputsEstimator.
*/
public * <p>The transform method of the returned AlgoOperator should invoke the corresponding methods
* of the internal stages as specified by the GraphBuilder.TableId[] addEstimator(
Estimator<?, ?> estimator, TableId[] estimatorInputs, TableId[] modelInputs) {...}
/**
*/
When the graph public AlgoOperator<?> buildAlgoOperator(TableId[] inputs, TableId[] outputs) {...}
/**runs as Estimator, it first generates a GraphModel that contains the Model
* fitted Returnsby athe Modelgiven instanceEstimator. withThen thewhen following behavior:this GraphModel runs, the setModelData() of the
* fitted Model would be invoked with the given inputs before its transform() is invoked.
*
* <p>When the graph runs as AlgoOperator or Model, the setModelData() of the Model fitted by
* the given Estimator would be invoked with the given inputs before its transform() is invoked.
*
* @param estimator An Estimator instance.
* @param inputs A list of TableIds which represents inputs to setModelData() of the Model
* fitted by the given Estimator.
*/
public void setModelDataOnEstimator(Estimator<?, ?> estimator, TableId... inputs) {...}
/**
* When the graph runs as Estimator, the setModelData() of the given Model would be invoked with
* the given inputs before its transform() is invoked. Then when the GraphModel fitted by this
* graph runs, the setModelData() of the given Model would be invoked with the given inputs.
*
* <p>When the graph runs as AlgoOperator or Model, the setModelData() of the given Model would
* be invoked with the given inputs before its transform() is invoked.
*
* @param model A Model instance.
* @param inputs A list of TableIds which represents inputs to setModelData() of the given
* Model.
*/
public void setModelDataOnModel(Model<?> model, TableId... inputs) {...}
/**
* When the graph runs as Estimator, it first generates a GraphModel that contains the Model
* fitted by the given Estimator. Then when this GraphModel runs, the getModelData() of the
* fitted Model would be invoked.
*
* <p>When the graph runs as AlgoOperator or Model, the getModelData() of the Model fitted by
* the given Estimator would be invoked.
*
* <p>NOTE: the number of the returned TableIds does not represent the actual number of Tables
* outputted by getModelData(). This number could be configured using {@link
* #setMaxOutputTableNum(int)}. Users should make sure that this number >= the actual number of
* Tables outputted by getModelData().
*
* @param estimator An Estimator instance.
* @return A list of TableIds which represents the outputs of getModelData() of the Model fitted
* by the given Estimator.
*/
public TableId[] getModelDataFromEstimator(Estimator<?, ?> estimator) {...}
/**
* When the graph runs as Estimator, the getModelData() of the given Model would be invoked.
* Then when the GraphModel fitted by this graph runs, the getModelData() of the given Model
* would be invoked.
*
* <p>When the graph runs as AlgoOperator or Model, the getModelData() of the given Model would
* be invoked.
*
* <p>NOTE: the number of the returned TableIds does not represent the actual number of Tables
* outputted by getModelData(). This number could be configured using {@link
* #setMaxOutputTableNum(int)}. Users should make sure that this number >= the actual number of
* Tables outputted by getModelData().
*
* @param model A Model instance.
* @return A list of TableIds which represents the outputs of getModelData() of the given Model.
*/
public TableId[] getModelDataFromModel(Model<?> model) {...}
/**
* Wraps nodes of the graph into an Estimator.
*
* <p>When the returned Estimator runs, and when the Model fitted by the returned Estimator
* runs, the sequence of operations recorded by the {@code addAlgoOperator(...)}, {@code
* addEstimator(...)}, {@code setModelData(...)} and {@code getModelData(...)} would be executed
* as specified in the Java doc of the corresponding methods.
*
* @param inputs A list of TableIds which represents inputs to fit() of the returned Estimator
* as well as inputs to transform() of the Model fitted by the returned Estimator.
* @param outputs A list of TableIds which represents outputs of transform() of the Model fitted
* by the returned Estimator.
* @return An Estimator which wraps the nodes of this graph.
*/
public Estimator<?, ?> buildEstimator(TableId[] inputs, TableId[] outputs) {...}
/**
* Wraps nodes of the graph into an Estimator.
*
* <p>When the returned Estimator runs, and when the Model fitted by the returned Estimator
* runs, the sequence of operations recorded by the {@code addAlgoOperator(...)}, {@code
* addEstimator(...)}, {@code setModelData(...)} and {@code getModelData(...)} would be executed
* as specified in the Java doc of the corresponding methods.
*
* @param inputs A list of TableIds which represents inputs to fit() of the returned Estimator
* as well as inputs to transform() of the Model fitted by the returned Estimator.
* @param outputs A list of TableIds which represents outputs of transform() of the Model fitted
* by the returned Estimator.
* @param inputModelData A list of TableIds which represents inputs to setModelData() of the
* Model fitted by the returned Estimator.
* @param outputModelData A list of TableIds which represents outputs of getModelData() of the
* Model fitted by the returned Estimator.
* @return An Estimator which wraps the nodes of this graph.
*/
public Estimator<?, ?> buildEstimator(
TableId[] inputs,
TableId[] outputs,
TableId[] inputModelData,
TableId[] outputModelData) {...}
/**
* Wraps nodes of the graph into an Estimator.
*
* <p>When the returned Estimator runs, and when the Model fitted by the returned Estimator
* runs, the sequence of operations recorded by the {@code addAlgoOperator(...)}, {@code
* addEstimator(...)}, {@code setModelData(...)} and {@code getModelData(...)} would be executed
* as specified in the Java doc of the corresponding methods.
*
* @param estimatorInputs A list of TableIds which represents inputs to fit() of the returned
* Estimator.
* @param modelInputs A list of TableIds which represents inputs to transform() of the Model
* fitted by the returned Estimator.
* @param outputs A list of TableIds which represents outputs of transform() of the Model fitted
* by the returned Estimator.
* @param inputModelData A list of TableIds which represents inputs to setModelData() of the
* Model fitted by the returned Estimator.
* @param outputModelData A list of TableIds which represents outputs of getModelData() of the
* Model fitted by the returned Estimator.
* @return An Estimator which wraps the nodes of this graph.
*/
public Estimator<?, ?> buildEstimator(
TableId[] estimatorInputs,
TableId[] modelInputs,
TableId[] outputs,
TableId[] inputModelData,
TableId[] outputModelData) {...}
/**
* Wraps nodes of the graph into an AlgoOperator.
*
* <p>When the returned AlgoOperator runs, the sequence of operations recorded by the {@code
* addAlgoOperator(...)} and {@code addEstimator(...)} would be executed as specified in the
* Java doc of the corresponding methods.
*
* @param inputs A list of TableIds which represents inputs to transform() of the returned
* AlgoOperator.
* @param outputs A list of TableIds which represents outputs of transform() of the returned
* AlgoOperator.
* @return An AlgoOperator which wraps the nodes of this graph.
*/
public AlgoOperator<?> buildAlgoOperator(TableId[] inputs, TableId[] outputs) {...}
/**
* Wraps nodes of the graph into a Model.
*
* <p>When the returned Model runs, the sequence of operations recorded by the {@code
* addAlgoOperator(...)} and {@code addEstimator(...)} would be executed as specified in the
* Java doc of the corresponding methods.
*
* @param inputs A list of TableIds which represents inputs to transform() of the returned
* Model.
* @param outputs A list of TableIds which represents outputs of transform() of the returned
* Model.
* @return A Model which wraps the nodes of this graph.
*/
public Model<?> buildModel(TableId[] inputs, TableId[] outputs) {...}
/**
* Wraps nodes of the graph into a Model.
*
* <p>When the returned Model runs, the sequence of operations recorded by the {@code
* addAlgoOperator(...)}, {@code addEstimator(...)}, {@code setModelData(...)} and {@code
*
getModelData(...)} would be executed *as <p>1) Model::transform should takespecified in the givenJava inputsdoc and returnsof the given outputs.corresponding
* methods.
*
<p>The transform method of the* returned@param Modelinputs should invoke the corresponding methods of the
* internal stages as specified by the GraphBuilder.
*/A list of TableIds which represents inputs to transform() of the returned
public Model<?> buildModel(TableId[] inputs, TableId[] outputs) {...}
* Model.
/**
* Returns a Model instance with the following behavior:* @param outputs A list of TableIds which represents outputs of transform() of the returned
*
* <p>1) Model::transform should take the given inputs and returns the given outputs.
*Model.
* @param inputModelData A list of TableIds which represents inputs to setModelData() of the
* <p>2) Model::setModelData should take the givenreturned inputModelDataModel.
*
@param outputModelData A list *of <p>3) Model::getModelData should return the given outputModelData.
*TableIds which represents outputs of getModelData() of the
* <p>The transform/setModelData/getModelData methods of the returned Model should invoke the.
* corresponding methods@return ofA theModel internalwhich stageswraps asthe specifiednodes byof thethis GraphBuildergraph.
*/
public Model<?> buildModel(
TableId[] inputs,
TableId[] outputs,
TableId[] inputModelData,
TableId[] outputModelData) {...}
}
|