Loading repository data…
Loading repository data…
mgisellef / repository
This repository comprises Jupyter Notebooks that serve as supplementary material to the journal article titled "Review of Multifidelity Models." The notebooks contain Python-based implementations that demonstrate toy problems in the multifidelity domain.
The repository, titled ReviewOfMultiFidelityModels_ToyProblems, serves as an invaluable supplement to the academic journal article "Review of Multifidelity Models." Designed as a comprehensive collection of Jupyter Notebooks, the repository aims to present a tangible and easily understandable demonstration of multifidelity models. These models are showcased through a series of Python-based toy problems, thus facilitating a deeper understanding of the article's theoretical concepts. The repository contributes to the broader scientific understanding of multifidelity approaches by providing hands-on, executable examples.
This code provides a demonstration of multi-fidelity modeling techniques for refining low-fidelity (LF) models using high-fidelity (HF) data through additive and multiplicative corrections. The example uses one-dimensional analytic functions to illustrate these concepts and includes plotting for visualization.
The code is organized into two main classes: AddMultCorrPlotter and AddMultCorrModels.
AddMultCorrPlotter ClassThis class is responsible for plotting LF, HF, and correction models.
func_HF(x): High-Fidelity function definition.func_LF(x): Low-Fidelity function definition.plot_functions(): Plots LF and HF functions.x: X-axis values for plotting LF and HF functions.AddMultCorrModels ClassThis class handles the modeling and plotting of additive and multiplicative corrections.
polynomial_fit(x, y, deg=2): Fits a polynomial model to data.func_add(x): Computes the additive correction function.func_mult(x): Computes the multiplicative correction function.plot_additive_correction(): Plots the additive correction.plot_multiplicative_correction(): Plots the multiplicative correction.plot_combined_corrections(): Plots combined corrections.AddMultCorrPlotter class to define LF and HF functions and plot them.AddMultCorrModels class, passing the AddMultCorrPlotter instance.AddMultCorrModels class to plot additive and multiplicative corrections as needed.if __name__ == "__main__":
plotter = AddMultCorrPlotter()
plotter.plot_functions()
models = AddMultCorrModels(plotter)
plt.figure(figsize=[5, 3])
models.plot_additive_correction()
plt.figure(figsize=[5, 3])
models.plot_multiplicative_correction()
plt.figure(figsize=[5, 3.5])
models.plot_combined_corrections()
plt.show()
The presented code is a Python implementation designed to visualize High-Fidelity (HF) and Low-Fidelity (LF) functions and to conduct sensitivity analysis. The code leverages the Matplotlib and NumPy libraries for plotting and numerical operations, respectively. It encapsulates functionality into three classes: FunctionVisualizer, ComprehensiveFunctionVisualizer, and SensitivityAnalysis.
FunctionVisualizer.visualizer = FunctionVisualizer(0, 1)
visualizer.visualize()
visualizer = ComprehensiveFunctionVisualizer(0, 1, np.array([0.1, 0.5, 0.9]))
visualizer.visualize_comprehensive()
x = np.linspace(0, 1, 100)
x_sampHF = np.array([0.1, 0.5, 0.9])
sensitivity = SensitivityAnalysis()
sensitivity.plot_sensitivity(x, x_sampHF, 'A', np.linspace(-1.3, 2.7, 10), 'A_Sensitivity')
The MultiFidelityModel class encapsulates the functionality for generating a Multi-Fidelity Surrogate Model (MFSM). It aims to synergize high-fidelity model (HFM) and low-fidelity model (LFM) data to create a more accurate and computationally efficient model.
x: Numpy array consisting of 100 points linearly spaced between 0 and 1.nLF: Integer, number of LFM samples.nHF: Integer, number of HFM samples.svr: Object of class SVR, used for the Support Vector Regression model.rf: Object of class RandomForestRegressor, used for the Random Forest model.__init__(self, x, nLF, nHF)Initializes class instance variables.
nLF: Number of Low-Fidelity Model samples.nHF: Number of High-Fidelity Model samples.func_HF(x)Static method representing the high-fidelity function.
x: Input variable values (Numpy ndarray).func_LF(x)Static method representing the low-fidelity function.
x: Input variable values (Numpy ndarray).generate_data(self)Generates random sampling points for LFM and HFM and calculates corresponding function values.
fit_SVR(self)Fits the SVR model to approximate the discrepancy between HFM and LFM.
fit_RF(self)Fits the Random Forest model to the low-fidelity data, thus building the Low-Fidelity Surrogate Model (LFSM).
y_MFSM_A(self, x)Calculates the integrated surrogate model using Option A.
x: Input variable values (Numpy ndarray).y_MFSM_B(self, x)Calculates the integrated surrogate model using Option B.
x: Input variable values (Numpy ndarray).plot(self)Generates a plot to visualize the actual LFM, HFM, and MFSM estimates. The plot also displays the discrepancy between the models.
if __name__ == "__main__":
model = MultiFidelityModel(x=1000, nLF=200, nHF=20)
model.generate_data()
model.fit_SVR()
model.fit_RF()
model.plot()
The MultiFidelityAnalysis class is an encapsulation for performing multi-fidelity analysis via Co-Kriging (CoKG). The class provides methods to fit a CoKG model, make predictions, and visualize the Low-Fidelity (LF) and High-Fidelity (HF) models alongside CoKG predictions.
pip install numpy matplotlib openmdao
__init__(self, lb=0, ub=1)Initializes the MultiFidelityAnalysis object.
Parameters:
lb: Lower bound of the variable space (default is 0).ub: Upper bound of the variable space (default is 1).func_HF(x)High-Fidelity (HF) model as a function of x.
Returns:
func_LF(x)Low-Fidelity (LF) model as a function of x.
Returns:
fit_coKG(self, Xe, Xc)Fits the CoKG model with HF and LF data.
Parameters:
Xe: Points where the HF model is evaluated.Xc: Points where the LF model is evaluated.predict_coKG()Predicts the CoKG model response over the generated points.
Returns:
plot_models(self, fHF, fLF, Xe, Xc, f_pred)Plots the LF, HF, and CoKG models with their sampling points.
Parameters:
fHF, fLF: Responses from HF and LF models.Xe, Xc: Sampling points for HF and LF models.f_pred: CoKG predictions.MFA = MultiFidelityAnalysis()
Xe = np.array([[0.2], [0.4], [0.85]])
Xc = np.vstack((np.array([[0.1], [0.25], [0.3], [0.5], [0.6], [0.7], [0.8], [0.9]]), Xe))
MFA.fit_coKG(Xe, Xc)
f_pred = MFA.predict_coKG()
MFA.plot_models(fHF, fLF, Xe, Xc, f_pred)
For further inquiries or contributions, feel free to reach out.
M. Giselle Fernández-Giselle, fernandez48@llnl.gov
This project is licensed under the MIT License.
This example initializes a MultiFidelityModel with 200 LFM samples and 20 HFM samples. Subsequently, it generates data, fits the SVR and RF models, and plots the outcomes.
This Python class encapsulates the functionalities related to the multi-fidelity Forrester function. It provides methods for function evaluation, plotting, and model training.
MultiFidelityForresterA class for encapsulating the functionalities related to the multi-fidelity Forrester function.
__init__(self, lb=0, ub=1, num_points=100)Initializes the class with default lower and upper bounds and the number of points.
lb (float): Lower bound for function evaluationub (float): Upper bound for function evaluationnum_points (int): Number of linearly spaced pointsfunc_HF(self, x)Calculates the high-fidelity function ( f_{\text{HF}}(x) ).
x (float): Input valuefunc_LF(self, x)Calculates the low-fidelity function ( f_{\text{LF}}(x) ).
x (float): Input valueplot_functions(self)Plots both the high-fidelity and low-fidelity functions. Saves the plot as a high-resolution PNG file.
# Instantiate the class and plot the functions
if __name__ == '__main__':
mf_forrester = MultiFidelityForrester()
mf_forrester.plot_functions()
This documentation is intended to provide a clear and concise understanding of the MultiFidelityForrester class, its at