You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
Copyright (c) 2020, Matgenix SRL, All rights reserved.
Distributed open source for academic and non-profit users.
Contact Matgenix for commercial usage.
See LICENSE file for details.
"""Example usage of pysisso for a regression using sklearn interface."""
import matplotlib.pyplot as plt
import numpy as np
from pysisso.sklearn import SISSORegressor
Define general parameters
TITLE = "f(x) = 0.5x^3 + 0.5x^2 - 4.0*x - 4.0"
NPOINTS = 100 # Number of data points
SIGMA = 0.5 # Randomness in the data points
PLOT_FIGURES = True # whether to interactively plot the figures with matplotlib
SAVE_FIGURES = False # whether to save the matplotlib figures to a file
CLEAN_RUN_DIR = True # whether to remove the SISSO_dir after the fit
Set the random seed to always keep the same figure
def fun(xx, const=1.0):
return 0.5 * xx ** 3 + 0.5 * xx ** 2 - 4.0 * 0.5 * xx - 4.0 * const
Define the data set
X = np.random.uniform(-2.5, 2.5, NPOINTS)
y = fun(X) + np.random.normal(0.0, scale=SIGMA, size=NPOINTS)
Plot true function and data
xlin = np.linspace(-3, 3, 1000)
ylin = fun(xlin)
fig, subplot = plt.subplots()
subplot.plot(xlin, ylin, "-", color="C0", label="True function")
subplot.plot(X, y, "o", color="C1", label="Data")
subplot.set_xlabel("x")
subplot.set_ylabel("f(x)")
subplot.set_title(TITLE)
subplot.legend()
if SAVE_FIGURES:
fig.savefig("true_data.pdf")
if PLOT_FIGURES:
plt.show()
Define the regressor, fit the data and predict
sisso_regressor = SISSORegressor(
rung=1,
opset="(+)(*)(^2)(^3)(^-1)(cos)(sin)",
desc_dim=3,
clean_run_dir=CLEAN_RUN_DIR,
)
X = X.reshape(-1, 1) # only one feature, X is initially defined as 1D, sklearn needs 2D
sisso_regressor.fit(X, y)
ylin_pred = sisso_regressor.predict(xlin)
Plot the true and predicted functions, together with the data
I run your example and get that: ValueError: Should get exactly one excerpt for input parameters in the string. May I get some help for that? Thanks!
Inside the "Previous_Versions" directory, extract "SISSO.3.0.2" to your /home directory and follow the installation per the "README". I found that the output format is different for each version; and pysisso only works with V3.0.2. Also, you may run into a "forrtl: severe (174): SIGSEGV, segmentation fault" error. Try executing "ulimit -s unlimited" before rerunning cubic_function.py.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I run your example and get that:
ValueError: Should get exactly one excerpt for input parameters in the string.
May I get some help for that? Thanks!
The text was updated successfully, but these errors were encountered: