Class HybridModelAdapter

java.lang.Object
neqsim.process.integration.ml.HybridModelAdapter
All Implemented Interfaces:
Serializable, MLCorrectionInterface

public class HybridModelAdapter extends Object implements MLCorrectionInterface, Serializable
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:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • featureNames

      private String[] featureNames
    • modelVersion

      private String modelVersion
    • strategy

    • ready

      private boolean ready
    • weights

      private double[] weights
    • bias

      private double bias
    • confidenceThreshold

      private double confidenceThreshold
  • Constructor Details

    • HybridModelAdapter

      public HybridModelAdapter(String[] featureNames, HybridModelAdapter.CombinationStrategy strategy)
      Creates a new hybrid model adapter.
      Parameters:
      featureNames - names of input features
      strategy - combination strategy
  • Method Details

    • additive

      public static HybridModelAdapter additive(String[] featureNames)
      Creates an additive correction adapter.
      Parameters:
      featureNames - names of input features
      Returns:
      configured adapter
    • multiplicative

      public static HybridModelAdapter multiplicative(String[] featureNames)
      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: MLCorrectionInterface
      Applies ML correction to a physics-based prediction.
      Specified by:
      correct in interface MLCorrectionInterface
      Parameters:
      physicsPrediction - the prediction from the physics model
      features - 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

      public String[] getFeatureNames()
      Description copied from interface: MLCorrectionInterface
      Gets the expected feature names for this ML model.
      Specified by:
      getFeatureNames in interface MLCorrectionInterface
      Returns:
      array of feature names in expected order
    • getFeatureCount

      public int getFeatureCount()
      Description copied from interface: MLCorrectionInterface
      Gets the number of features expected by this model.
      Specified by:
      getFeatureCount in interface MLCorrectionInterface
      Returns:
      number of features
    • isReady

      public boolean isReady()
      Description copied from interface: MLCorrectionInterface
      Checks if the model is ready for inference.
      Specified by:
      isReady in interface MLCorrectionInterface
      Returns:
      true if the model can make predictions
    • onModelUpdate

      public void onModelUpdate(byte[] modelPayload)
      Description copied from interface: MLCorrectionInterface
      Updates the ML model with new weights/parameters.

      This method is called when an external AI platform pushes updated model parameters after retraining.

      Specified by:
      onModelUpdate in interface MLCorrectionInterface
      Parameters:
      modelPayload - serialized model parameters
    • getModelVersion

      public String getModelVersion()
      Description copied from interface: MLCorrectionInterface
      Gets the model version or identifier.
      Specified by:
      getModelVersion in interface MLCorrectionInterface
      Returns:
      model version string
    • getConfidence

      public double getConfidence(double[] features)
      Description copied from interface: MLCorrectionInterface
      Gets the confidence level for a prediction.
      Specified by:
      getConfidence in interface MLCorrectionInterface
      Parameters:
      features - input features
      Returns:
      confidence score between 0 and 1
    • getUncertainty

      public double getUncertainty(double physicsPrediction, double[] features)
      Description copied from interface: MLCorrectionInterface
      Gets the uncertainty (standard deviation) for a prediction.
      Specified by:
      getUncertainty in interface MLCorrectionInterface
      Parameters:
      physicsPrediction - the physics prediction
      features - 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 weights
      bias - bias term
    • getStrategy

      Gets the combination strategy.
      Returns:
      the strategy
    • setStrategy

      public void setStrategy(HybridModelAdapter.CombinationStrategy strategy)
      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