Class VectorExample
- java.lang.Object
-
- com.tibco.patterns.learn.training.VectorExample
-
- Direct Known Subclasses:
RecPairExample
public class VectorExample extends java.lang.ObjectStores a feature vector and a label that are used for training the model. Also stores the current and previous predictions from the model.
-
-
Constructor Summary
Constructors Constructor Description VectorExample(double[] featureValues, boolean label)Creates example with given parameters and no prediction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancorrectPrediction()Checks if the RLink prediction is correct.double[]getFeatureValues()booleangetLabel()intgetNFeatures()RLinkOutgetPrediction()RLinkOutgetPrevPrediction()Used from TrainingObservers that need to compare previous and current iterations.voidpredict(int modelId)Calculates prediction using default options.voidpredict(int modelId, PredictOptions predictOpts)Calculates prediction using the given model and options, stores it in this example.java.lang.StringtoString()
-
-
-
Constructor Detail
-
VectorExample
public VectorExample(double[] featureValues, boolean label)Creates example with given parameters and no prediction.- Parameters:
featureValues- - the feature vector.label- - actual label of this example.- Throws:
java.lang.IllegalArgumentException- if featureValues is null, empty, or contains an invalid value. All values must be between 0 and 1, or -1 for an empty feature.
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getFeatureValues
public double[] getFeatureValues()
- Returns:
- a copy of the feature values array.
-
getNFeatures
public int getNFeatures()
- Returns:
- the number of features in the feature vector.
-
getLabel
public boolean getLabel()
- Returns:
- actual label of this example.
-
correctPrediction
public boolean correctPrediction()
Checks if the RLink prediction is correct.- Returns:
- true if the model prediction for this example is correct.
- Throws:
java.lang.IllegalStateException- if this example does not contain an RLink prediction.
-
predict
public void predict(int modelId, PredictOptions predictOpts)Calculates prediction using the given model and options, stores it in this example. Saves the previously calculated prediction, if any.- Parameters:
modelId- - ID of an existing RLink model.predictOpts- - the options to use for this prediction. If null, uses default uptions.
-
predict
public void predict(int modelId)
Calculates prediction using default options. Seepredict(int, PredictOptions).
-
getPrediction
public RLinkOut getPrediction()
- Returns:
- internal reference to the model prediction for this example. Null if any predict() method was never called, or predictions have been cleared.
-
getPrevPrediction
public RLinkOut getPrevPrediction()
Used from TrainingObservers that need to compare previous and current iterations.- Returns:
- internal reference to the previous model prediction. Null if any predict() method was called less than 2 times, or predictions have been cleared.
-
-