Class InferenceResult
- java.lang.Object
-
- com.codedstream.otterstream.inference.model.InferenceResult
-
public class InferenceResult extends Object
Container for ML inference results including predictions and metadata.Represents the output from an inference operation, containing the model's predictions, timing information, and success status.
Result Types:
- Success: Contains predictions in outputs map
- Failure: Contains error message and empty outputs
Usage Examples:
Creating Success Result:
Map<String, Object> outputs = Map.of( "probability", 0.92, "class", "fraudulent", "confidence", 0.88 ); InferenceResult result = new InferenceResult(outputs, 45, "fraud-detector");Creating Failure Result:
InferenceResult result = new InferenceResult( "fraud-detector", "Model execution timeout", 5000 );Consuming Results:
if (result.isSuccess()) { double prob = result.getOutput("probability"); String prediction = result.getOutput("class"); System.out.println("Prediction: " + prediction + " (" + prob + ")"); } else { log.error("Inference failed: {}", result.getErrorMessage()); }- Since:
- 1.0.0
- Author:
- Nestor Martourez, Sr Software and Data Streaming Engineer @ CodedStreams
-
-
Constructor Summary
Constructors Constructor Description InferenceResult(String modelId, String errorMessage, long inferenceTimeMs)Creates a failed inference result.InferenceResult(Map<String,Object> outputs, long inferenceTimeMs, String modelId)Creates a successful inference result.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetErrorMessage()Gets error message for failed inferences.longgetInferenceTimeMs()Gets inference duration.StringgetModelId()Gets model identifier.<T> TgetOutput(String key)Gets a specific output value by name.Map<String,Object>getOutputs()Gets all output predictions.booleanisSuccess()Checks if inference was successful.
-
-
-
Constructor Detail
-
InferenceResult
public InferenceResult(Map<String,Object> outputs, long inferenceTimeMs, String modelId)
Creates a successful inference result.- Parameters:
outputs- map of output name to predicted valueinferenceTimeMs- inference duration in millisecondsmodelId- identifier of the model that made the prediction
-
-
Method Detail
-
getOutputs
public Map<String,Object> getOutputs()
Gets all output predictions.- Returns:
- immutable map of output name to value
-
getInferenceTimeMs
public long getInferenceTimeMs()
Gets inference duration.- Returns:
- duration in milliseconds
-
getModelId
public String getModelId()
Gets model identifier.- Returns:
- model ID
-
isSuccess
public boolean isSuccess()
Checks if inference was successful.- Returns:
- true if successful, false if failed
-
getErrorMessage
public String getErrorMessage()
Gets error message for failed inferences.- Returns:
- error message, or null if successful
-
getOutput
public <T> T getOutput(String key)
Gets a specific output value by name.Convenience method with type casting.
- Type Parameters:
T- expected type of the output- Parameters:
key- output name- Returns:
- output value cast to type T, or null if not found
- Throws:
ClassCastException- if type T doesn't match actual type
-
-