Class SurrogateModelRegistry
java.lang.Object
neqsim.process.ml.surrogate.SurrogateModelRegistry
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMetadata for a surrogate model.static interfaceInterface for surrogate model implementations.private static classInternal entry combining model and metadata. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate static SurrogateModelRegistryprivate final Map<String, SurrogateModelRegistry.SurrogateModelEntry> private Stringprivate static final long -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor for singleton pattern. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all registered models.Gets a registered surrogate model.Gets all registered model IDs.static SurrogateModelRegistryGets the singleton instance of the registry.getMetadata(String modelId) Gets statistics for a registered model.booleanChecks if a model is registered.booleanvoidLoads a model from disk.double[]predictWithFallback(String modelId, double[] input, Function<double[], double[]> physicsFallback) Predicts using a surrogate model with automatic fallback.voidregister(String modelId, SurrogateModelRegistry.SurrogateModel model) Registers a surrogate model.voidregister(String modelId, SurrogateModelRegistry.SurrogateModel model, SurrogateModelRegistry.SurrogateMetadata metadata) Registers a surrogate model with metadata.voidSaves a model to disk.voidsetEnableFallback(boolean enableFallback) voidsetPersistenceDirectory(String directory) booleanunregister(String modelId) Removes a model from the registry.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
instance
-
models
-
enableFallback
private boolean enableFallback -
persistenceDirectory
-
-
Constructor Details
-
SurrogateModelRegistry
private SurrogateModelRegistry()Private constructor for singleton pattern.
-
-
Method Details
-
getInstance
Gets the singleton instance of the registry.- Returns:
- the global registry instance
-
register
Registers a surrogate model.- Parameters:
modelId- unique identifier for the modelmodel- the surrogate model implementation
-
register
public void register(String modelId, SurrogateModelRegistry.SurrogateModel model, SurrogateModelRegistry.SurrogateMetadata metadata) Registers a surrogate model with metadata.- Parameters:
modelId- unique identifier for the modelmodel- the surrogate model implementationmetadata- 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
Checks if a model is registered.- Parameters:
modelId- the model identifier- Returns:
- true if registered
-
unregister
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 identifierinput- input vectorphysicsFallback- fallback physics calculation- Returns:
- prediction result
-
saveModel
Saves a model to disk.- Parameters:
modelId- the model identifierfilePath- output file path- Throws:
IOException- if save fails
-
loadModel
Loads a model from disk.- Parameters:
modelId- identifier to register the model underfilePath- input file path- Throws:
IOException- if load failsClassNotFoundException- 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
-
setPersistenceDirectory
-