Class HybridModelAdapter
java.lang.Object
neqsim.process.integration.ml.HybridModelAdapter
- All Implemented Interfaces:
Serializable, MLCorrectionInterface
Adapter for integrating external ML models with NeqSim hybrid physics simulations.
This class provides a bridge between NeqSim's physics-based models and external ML frameworks. It supports various correction strategies and can be extended for specific ML platforms.
- Version:
- 1.0
- Author:
- ESOL
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumStrategy for combining physics and ML predictions. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHybridModelAdapter(String[] featureNames, HybridModelAdapter.CombinationStrategy strategy) Creates a new hybrid model adapter. -
Method Summary
Modifier and TypeMethodDescriptionstatic HybridModelAdapterCreates an additive correction adapter.private doublecalculateMLOutput(double[] features) Calculates the ML model output using the configured linear surrogate.doublecorrect(double physicsPrediction, double[] features) Applies ML correction to a physics-based prediction.doublegetBias()Gets the current bias term.doublegetConfidence(double[] features) Gets the confidence level for a prediction.intGets the number of features expected by this model.String[]Gets the expected feature names for this ML model.Gets the model version or identifier.Gets the combination strategy.doublegetUncertainty(double physicsPrediction, double[] features) Gets the uncertainty (standard deviation) for a prediction.double[]Gets the current model weights.booleanisReady()Checks if the model is ready for inference.static HybridModelAdaptermultiplicative(String[] featureNames) Creates a multiplicative correction adapter.voidonModelUpdate(byte[] modelPayload) Updates the ML model with new weights/parameters.voidsetConfidenceThreshold(double threshold) Sets the confidence threshold for REPLACEMENT strategy.voidsetLinearModel(double[] weights, double bias) Sets the model weights directly (for testing or simple models).voidSets the combination strategy.voidtrainLinear(double[][] featureMatrix, double[] targets) Trains the linear model on provided data.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MLCorrectionInterface
correctBatch
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
featureNames
-
modelVersion
-
strategy
-
ready
private boolean ready -
weights
private double[] weights -
bias
private double bias -
confidenceThreshold
private double confidenceThreshold
-
-
Constructor Details
-
HybridModelAdapter
Creates a new hybrid model adapter.- Parameters:
featureNames- names of input featuresstrategy- combination strategy
-
-
Method Details
-
additive
Creates an additive correction adapter.- Parameters:
featureNames- names of input features- Returns:
- configured adapter
-
multiplicative
Creates a multiplicative correction adapter.- Parameters:
featureNames- names of input features- Returns:
- configured adapter
-
correct
public double correct(double physicsPrediction, double[] features) Description copied from interface:MLCorrectionInterfaceApplies ML correction to a physics-based prediction.- Specified by:
correctin interfaceMLCorrectionInterface- Parameters:
physicsPrediction- the prediction from the physics modelfeatures- input features for the ML model- Returns:
- corrected prediction
-
calculateMLOutput
private double calculateMLOutput(double[] features) Calculates the ML model output using the configured linear surrogate.- Parameters:
features- feature vector provided by the process context- Returns:
- ML prediction corresponding to the supplied features
-
getFeatureNames
Description copied from interface:MLCorrectionInterfaceGets the expected feature names for this ML model.- Specified by:
getFeatureNamesin interfaceMLCorrectionInterface- Returns:
- array of feature names in expected order
-
getFeatureCount
public int getFeatureCount()Description copied from interface:MLCorrectionInterfaceGets the number of features expected by this model.- Specified by:
getFeatureCountin interfaceMLCorrectionInterface- Returns:
- number of features
-
isReady
public boolean isReady()Description copied from interface:MLCorrectionInterfaceChecks if the model is ready for inference.- Specified by:
isReadyin interfaceMLCorrectionInterface- Returns:
- true if the model can make predictions
-
onModelUpdate
public void onModelUpdate(byte[] modelPayload) Description copied from interface:MLCorrectionInterfaceUpdates the ML model with new weights/parameters.This method is called when an external AI platform pushes updated model parameters after retraining.
- Specified by:
onModelUpdatein interfaceMLCorrectionInterface- Parameters:
modelPayload- serialized model parameters
-
getModelVersion
Description copied from interface:MLCorrectionInterfaceGets the model version or identifier.- Specified by:
getModelVersionin interfaceMLCorrectionInterface- Returns:
- model version string
-
getConfidence
public double getConfidence(double[] features) Description copied from interface:MLCorrectionInterfaceGets the confidence level for a prediction.- Specified by:
getConfidencein interfaceMLCorrectionInterface- Parameters:
features- input features- Returns:
- confidence score between 0 and 1
-
getUncertainty
public double getUncertainty(double physicsPrediction, double[] features) Description copied from interface:MLCorrectionInterfaceGets the uncertainty (standard deviation) for a prediction.- Specified by:
getUncertaintyin interfaceMLCorrectionInterface- Parameters:
physicsPrediction- the physics predictionfeatures- input features- Returns:
- predicted standard deviation
-
setLinearModel
public void setLinearModel(double[] weights, double bias) Sets the model weights directly (for testing or simple models).- Parameters:
weights- array of weightsbias- bias term
-
getStrategy
Gets the combination strategy.- Returns:
- the strategy
-
setStrategy
Sets the combination strategy.- Parameters:
strategy- the strategy
-
setConfidenceThreshold
public void setConfidenceThreshold(double threshold) Sets the confidence threshold for REPLACEMENT strategy.- Parameters:
threshold- confidence threshold (0-1)
-
trainLinear
public void trainLinear(double[][] featureMatrix, double[] targets) Trains the linear model on provided data.This is a simple least-squares regression for demonstration. Production implementations should use proper ML libraries.
- Parameters:
featureMatrix- training features (samples x features)targets- target correction values
-
getWeights
public double[] getWeights()Gets the current model weights.- Returns:
- array of weights
-
getBias
public double getBias()Gets the current bias term.- Returns:
- bias value
-