#################################################################################
# WaterTAP Copyright (c) 2020-2025, The Regents of the University of California,
# through Lawrence Berkeley National Laboratory, Oak Ridge National Laboratory,
# National Renewable Energy Laboratory, and National Energy Technology
# Laboratory (subject to receipt of any required approvals from the U.S. Dept.
# of Energy). All rights reserved.
#
# Please see the files COPYRIGHT.md and LICENSE.md for full copyright and license
# information, respectively. These files are also available online at the URL
# "https://github.com/watertap-org/watertap/"
#################################################################################
import os
import pandas as pd
from idaes.core.surrogate.metrics import compute_fit_metrics
from idaes.core.surrogate.plotting.sm_plotter import surrogate_parity
local_path = os.path.dirname(os.path.abspath(__file__))
__author__ = "Marcus Holly"
def display_performance(surrogate=None, dataframe=None):
metrics = performance_estimation(
surrogate=surrogate,
dataframe=dataframe,
)
"""
Return a formatted DataFrame of surrogate performance metrics for display.
Args:
surrogate: IDAES surrogate object
dataframe: DataFrame containing input and output columns
Returns:
pd.DataFrame: One row per output variable, 1-based index, with columns:
- ``Predicted Variables`` : output variable name
- ``R^2`` : coefficient of determination
- ``MAE`` : mean absolute error
- ``MSE`` : mean squared error
- ``RMSE`` : root mean squared error
- ``Max AE`` : maximum absolute error
"""
display_metrics = pd.DataFrame(
{
"Predicted Variables": metrics["Comp"],
"R^2": metrics["R2"],
"MAE": metrics["MAE"],
"MSE": metrics["MSE"],
"RMSE": metrics["RMSE"],
"Max AE": metrics["maxAE"],
}
)
display_metrics.index = range(1, len(display_metrics) + 1)
return display_metrics
[docs]def display_plot(surrogate, dataframe, method="poly", path=None, show=True):
"""
Produces one parity plot per output variable and consolidates into a PDF
Args:
surrogate: IDAES surrogate object
dataframe: DataFrame containing input and output
columns corresponding to the surrogate's labels
method (str, optional): Surrogate method identifier used to name the
output PDF file (e.g. ``"poly"``, ``"kri"``, ``"rbf"``)
path (str, optional): Directory in which to save the PDF
show (bool, optional): Whether to display each figure interactively
via matplotlib
Returns:
list[matplotlib.figure.Figure]: One figure per output variable
"""
if path is None:
path = os.path.join(local_path, "results")
filename = os.path.join(path, f"{method}_parity.pdf")
return surrogate_parity(surrogate, dataframe, filename=filename, show=show)