Class SurrogateModelRegistry

java.lang.Object
neqsim.process.ml.surrogate.SurrogateModelRegistry
All Implemented Interfaces:
Serializable

public class SurrogateModelRegistry extends Object implements Serializable
Registry for managing trained surrogate (machine learning) models.

Surrogate models are fast approximations of computationally expensive physics models. This registry provides:

  • Model Caching: Keep frequently-used models in memory
  • Persistence: Save/load models to disk for reuse
  • Version Management: Track model versions and validity
  • Fallback: Automatic fallback to physics model if surrogate fails

Usage Example:

// Register a surrogate model for flash calculations
SurrogateModelRegistry registry = SurrogateModelRegistry.getInstance();

registry.register("flash-separator-1", new SurrogateModel() {
  @Override
  public double[] predict(double[] input) {
    // Neural network inference
    return neuralNet.forward(input);
  }
});

// Use with automatic fallback to physics
double[] result =
    registry.predictWithFallback("flash-separator-1", input, physicsModel::calculate);
Version:
1.0
Author:
ESOL
See Also:
  • Field Details

  • Constructor Details

    • SurrogateModelRegistry

      private SurrogateModelRegistry()
      Private constructor for singleton pattern.
  • Method Details

    • getInstance

      public static SurrogateModelRegistry getInstance()
      Gets the singleton instance of the registry.
      Returns:
      the global registry instance
    • register

      public void register(String modelId, SurrogateModelRegistry.SurrogateModel model)
      Registers a surrogate model.
      Parameters:
      modelId - unique identifier for the model
      model - the surrogate model implementation
    • register

      Registers a surrogate model with metadata.
      Parameters:
      modelId - unique identifier for the model
      model - the surrogate model implementation
      metadata - model metadata (training info, validity, etc.)
    • get

      Gets a registered surrogate model.
      Parameters:
      modelId - the model identifier
      Returns:
      the model, or empty if not found
    • hasModel

      public boolean hasModel(String modelId)
      Checks if a model is registered.
      Parameters:
      modelId - the model identifier
      Returns:
      true if registered
    • unregister

      public boolean unregister(String modelId)
      Removes a model from the registry.
      Parameters:
      modelId - the model identifier
      Returns:
      true if removed
    • predictWithFallback

      public double[] predictWithFallback(String modelId, double[] input, Function<double[],double[]> physicsFallback)
      Predicts using a surrogate model with automatic fallback.

      If the surrogate model fails or is outside its validity range, the physics model will be used as a fallback.

      Parameters:
      modelId - the surrogate model identifier
      input - input vector
      physicsFallback - fallback physics calculation
      Returns:
      prediction result
    • saveModel

      public void saveModel(String modelId, String filePath) throws IOException
      Saves a model to disk.
      Parameters:
      modelId - the model identifier
      filePath - output file path
      Throws:
      IOException - if save fails
    • loadModel

      public void loadModel(String modelId, String filePath) throws IOException, ClassNotFoundException
      Loads a model from disk.
      Parameters:
      modelId - identifier to register the model under
      filePath - input file path
      Throws:
      IOException - if load fails
      ClassNotFoundException - if model class not found
    • getMetadata

      Gets statistics for a registered model.
      Parameters:
      modelId - the model identifier
      Returns:
      metadata with usage statistics
    • getAllModels

      Gets all registered model IDs.
      Returns:
      map of model IDs to their metadata
    • clear

      public void clear()
      Clears all registered models.
    • isEnableFallback

      public boolean isEnableFallback()
    • setEnableFallback

      public void setEnableFallback(boolean enableFallback)
    • getPersistenceDirectory

      public String getPersistenceDirectory()
    • setPersistenceDirectory

      public void setPersistenceDirectory(String directory)