java.lang.Object
com.pervasive.datarush.ports.LogicalPort
com.pervasive.datarush.ports.model.AbstractModelPort<T>
- Type Parameters:
T- the type of model.
- Direct Known Subclasses:
DoneSignalPort,PMMLPort,SimpleModelPort
Common base class for all types of model ports. Client's should generally not
need to extend this class; rather they should use one of the predefined subclasses
(either
SimpleModelPort or PMMLPort).
The term "model" originated in the analytics package because model ports are most commonly
used for prediction models (i.e. PMML). Model ports share the following
characteristics:
- Models are assumed to be "small". By "small" we mean small enough to fit into memory.
- The framework provides built-in support for building partial models and then
reducing to a single model. This happens automatically when a parallel
operator outputs a model which feeds into a non-parallel operator; the non-parallel operator
must specify a
merge-handler. Note thatMergeModelis a convenient, re-usable model reducer, parameterized with a merge-handler. - The framework provides built-in support for replicating a final model to a parallelized operator, a common scenario for parallelized predictors. This happens automatically anytime a model from a non-parallel operator is fed into a parallel operator. In this case, a duplicate copy of the model is replicated to all partitions. Note that in this scenario, parallel partitions within the same JVM will share a copy of the model. (This is an optimization to reduce memory consumption). Thus, care must be taken to ensure that predictors not mutate the model.
RecordPort's
where gather and scatter operators are symmetric).-
Nested Class Summary
Nested classes/interfaces inherited from class com.pervasive.datarush.ports.LogicalPort
LogicalPort.Direction -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractModelPort(LogicalOperator owner, String name, LogicalPort.Direction direction, boolean optional, ModelStorageHandler<T> storageHandler) Subclasses must invoke this constructor -
Method Summary
Modifier and TypeMethodDescriptionabstract LogicalPortFactory<? extends AbstractModelPort<?>>Returns the factory that knows how to create ports of this typeabstract AbstractModelPortMetadatagetMetadata(T model) Returns the metadata associate with the model.final TgetModel(ExecutionContext ctx) Reads the model from this model input port.Returns the java class of the modelprotected final ModelStorageHandler<T>Returns the storage handler responsible for persisting the modelfinal voidsetMergeHandler(MetadataCalculationContext ctx, ModelMergeHandler<T> mergeHandler) Sets the merge handler for the input portfinal voidsetModel(ExecutionContext ctx, T model) Outputs the model on this model output port.Methods inherited from class com.pervasive.datarush.ports.LogicalPort
getDirection, getMetadataType, getName, getOwner, isOptional, toString
-
Constructor Details
-
AbstractModelPort
protected AbstractModelPort(LogicalOperator owner, String name, LogicalPort.Direction direction, boolean optional, ModelStorageHandler<T> storageHandler) Subclasses must invoke this constructor- Parameters:
owner- the operator that owns this portname- the name of the portdirection- the direction, input vs. outputoptional- whether the port is optionalstorageHandler- a storage handler responsible for persisting the model
-
-
Method Details
-
getModelClass
Returns the java class of the model- Returns:
- the java class of the model
-
getStorageHandler
Returns the storage handler responsible for persisting the model- Returns:
- the storage handler responsible for persisting the model
-
getMetadata
Returns the metadata associate with the model. (Given a model, we should always be able to get its metadata.- Parameters:
model- the model object- Returns:
- the metadata
-
getFactory
Description copied from class:LogicalPortReturns the factory that knows how to create ports of this type- Specified by:
getFactoryin classLogicalPort- Returns:
- the factory that knows how to create ports of this type
-
setMergeHandler
public final void setMergeHandler(MetadataCalculationContext ctx, ModelMergeHandler<T> mergeHandler) Sets the merge handler for the input port- Parameters:
ctx- the metadata contextmergeHandler- the merge handler to use
-
getModel
Reads the model from this model input port. This method must be invoked at least once for each model input port (additional invocations will return the same model reference as the first)- Parameters:
ctx- the execution context- Returns:
- the model from with this model input port.
-
setModel
Outputs the model on this model output port. This method must be invoked exactly once for each model output port.- Parameters:
ctx- the execution contextmodel- the model
-