From 36208bf6301730e3c72aff3a10f47b0ae7983df0 Mon Sep 17 00:00:00 2001 From: Smasky <492109831@qq.com> Date: Tue, 24 Dec 2024 13:47:13 +0800 Subject: [PATCH] '1224' --- UQPyL/__init__.py | 2 +- UQPyL/optimization/__init__.py | 2 +- .../optimization/single_objective/__init__.py | 3 +- UQPyL/sensibility/delta_test.py | 3 ++ UQPyL/sensibility/mars_sa.py | 2 +- UQPyL/surrogates/gp/gaussian_process.py | 2 +- UQPyL/surrogates/kriging/kriging.py | 2 +- UQPyL/surrogates/util/__init__.py | 9 ----- examples/example_surrogate.py | 36 +++++++++---------- pyproject.toml | 2 +- setup.py | 2 +- 11 files changed, 29 insertions(+), 36 deletions(-) diff --git a/UQPyL/__init__.py b/UQPyL/__init__.py index 3896b904..4904b7b1 100644 --- a/UQPyL/__init__.py +++ b/UQPyL/__init__.py @@ -1,6 +1,6 @@ from . import problems, surrogates, optimization, sensibility, DoE, utility -__version__ = "2.0.10" +__version__ = "2.0.11" __author__ = "wmtSky" __all__=[ diff --git a/UQPyL/optimization/__init__.py b/UQPyL/optimization/__init__.py index c7c5ef3e..b4845b2b 100644 --- a/UQPyL/optimization/__init__.py +++ b/UQPyL/optimization/__init__.py @@ -1,4 +1,4 @@ -from .single_objective import GA, PSO, CSA, DE, SCE_UA, ML_SCE_UA, ASMO, ABC, Binary_GA, EGO +from .single_objective import GA, PSO, CSA, DE, SCE_UA, ML_SCE_UA, ASMO, ABC, EGO from .multi_objective import NSGAII, MOEAD, MOASMO, RVEA # from .mathematics import Boxmin, Adam from .algorithmABC import Algorithm diff --git a/UQPyL/optimization/single_objective/__init__.py b/UQPyL/optimization/single_objective/__init__.py index 59b6e01e..2116b17b 100644 --- a/UQPyL/optimization/single_objective/__init__.py +++ b/UQPyL/optimization/single_objective/__init__.py @@ -7,5 +7,4 @@ from .csa import CSA from .asmo import ASMO from .abc import ABC -from .ego import EGO -from ._binary_ga import Binary_GA \ No newline at end of file +from .ego import EGO \ No newline at end of file diff --git a/UQPyL/sensibility/delta_test.py b/UQPyL/sensibility/delta_test.py index 07750ea8..4011c619 100644 --- a/UQPyL/sensibility/delta_test.py +++ b/UQPyL/sensibility/delta_test.py @@ -85,7 +85,9 @@ def analyze(self, X: np.ndarray=None, Y: np.ndarray=None, verbose: bool=False) - X, Y=self.__check_and_scale_xy__(X, Y) n_input=self.n_input + ##main process + self.X_=X; self.Y_=Y optimizer=Binary_GA(self._cal_delta, self.n_input, population_size=n_input*2) best_paras, self.best_value, history_paras, _=optimizer.run() @@ -95,6 +97,7 @@ def analyze(self, X: np.ndarray=None, Y: np.ndarray=None, verbose: bool=False) - HSP_paras=[self.labels[index] for index, value in enumerate(best_paras) if value==1] Si={'S1': S1_score, 'HSP':HSP_paras} + self.Si=Si if verbose: diff --git a/UQPyL/sensibility/mars_sa.py b/UQPyL/sensibility/mars_sa.py index 89bdb949..04851f0c 100644 --- a/UQPyL/sensibility/mars_sa.py +++ b/UQPyL/sensibility/mars_sa.py @@ -1,7 +1,7 @@ import numpy as np from typing import Optional, Tuple -from ..surrogates import MARS, Surrogate +from ..surrogates import MARS from ..utility import MinMaxScaler, Scaler from ..problems import ProblemABC as Problem from ..DoE import LHS, Sampler diff --git a/UQPyL/surrogates/gp/gaussian_process.py b/UQPyL/surrogates/gp/gaussian_process.py index 3b0c7a91..b8868571 100644 --- a/UQPyL/surrogates/gp/gaussian_process.py +++ b/UQPyL/surrogates/gp/gaussian_process.py @@ -3,7 +3,7 @@ from typing import Tuple, Optional, Literal from .kernel import BaseKernel, RBF -from ..utility.boxmin import Boxmin +from ..util.boxmin import Boxmin from ...problems import PracticalProblem from ..surrogateABC import Surrogate from ...optimization import Algorithm diff --git a/UQPyL/surrogates/kriging/kriging.py b/UQPyL/surrogates/kriging/kriging.py index 31629996..121dd239 100644 --- a/UQPyL/surrogates/kriging/kriging.py +++ b/UQPyL/surrogates/kriging/kriging.py @@ -5,7 +5,7 @@ from .kernel import BaseKernel, Guass -from ..utility.boxmin import Boxmin +from ..util.boxmin import Boxmin from ..surrogateABC import Surrogate from ...optimization.algorithmABC import Algorithm from ...optimization.single_objective import GA diff --git a/UQPyL/surrogates/util/__init__.py b/UQPyL/surrogates/util/__init__.py index 43a6f3d4..e69de29b 100644 --- a/UQPyL/surrogates/util/__init__.py +++ b/UQPyL/surrogates/util/__init__.py @@ -1,9 +0,0 @@ -''' -Author: smasky (Mengtian Wu Hohai Unversity) -Date: 2024-12-24 09:35:39 -LastEditTime: 2024-12-24 09:35:55 -LastEditors: smasky -Description: -FilePath: \UQPyL\UQPyL\surrogates\utility\__init__.py -You will never know unless you try -''' diff --git a/examples/example_surrogate.py b/examples/example_surrogate.py index 2f8bc35d..aa5a7f55 100644 --- a/examples/example_surrogate.py +++ b/examples/example_surrogate.py @@ -22,31 +22,31 @@ # np.savetxt('xTrain.txt', xTrain); np.savetxt('yTrain.txt', yTrain.reshape(-1, 1)) #-------------------Kriging----------------------------# -# from UQPyL.surrogates.kriging import KRG -# from UQPyL.surrogates.kriging.kernel import Guass, Cubic, Exp -# from UQPyL.utility.scalers import MinMaxScaler, StandardScaler -# from UQPyL.optimization import GA -# from time import time +from UQPyL.surrogates.kriging import KRG +from UQPyL.surrogates.kriging.kernel import Guass, Cubic, Exp +from UQPyL.utility.scalers import MinMaxScaler, StandardScaler +from UQPyL.optimization import GA +from time import time -# kernel=Guass(theta=1.0, heterogeneous=True) +kernel=Guass(theta=1.0, heterogeneous=True) # kernel=Cubic(theta=1.0, heterogeneous=True) # kernel=Exp(theta=1.0, heterogeneous=True) -# optimizer = GA(maxFEs=1000, nPop=50, saveFlag=False, logFlag=False, verboseFreq=1) +optimizer = GA(maxFEs=1000, nPop=50, saveFlag=False, logFlag=False, verboseFreq=1) -#use Boxmin -# krg=KRG(scalers=(MinMaxScaler(0,1), MinMaxScaler(0,1)), kernel=kernel, n_restart_optimize=0) -#use optimization -#krg=KRG(scalers=(MinMaxScaler(0,1), MinMaxScaler(0,1)), kernel=kernel, optimizer=optimizer, n_restart_optimize=0, fitMode='likelihood') +# use Boxmin +krg=KRG(scalers=(MinMaxScaler(0,1), MinMaxScaler(0,1)), kernel=kernel, n_restart_optimize=0) +# use optimization +# krg=KRG(scalers=(MinMaxScaler(0,1), MinMaxScaler(0,1)), kernel=kernel, optimizer=optimizer, n_restart_optimize=0, fitMode='likelihood') # krg.fit(xTrain, yTrain) -#use autoTuner -# tuner=autoTuner(optimizer=optimizer, model=krg) -# paraList=tuner.getParaList() -# tuner.tune(xTrain, yTrain, paraList, ratio=10) -# yPred=krg.predict(xTest) -# value=r_square(yTest, yPred) -# print(value) +# use autoTuner +tuner=autoTuner(optimizer=optimizer, model=krg) +paraList=tuner.getParaList() +tuner.opTune(xTrain, yTrain, paraList, ratio=10) +yPred=krg.predict(xTest) +value=r_square(yTest, yPred) +print(value) #-------------------Gaussian Process---------------------# # from UQPyL.surrogates.gp import GPR diff --git a/pyproject.toml b/pyproject.toml index 13b65b26..5d651b56 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ build-backend = "setuptools.build_meta" [project] name = "UQPyL" -version = "2.0.10" +version = "2.0.11" authors = [ {name = "wmtSky", email = "wmtsky@hhu.edu.cn"} ] diff --git a/setup.py b/setup.py index 5e84e382..6b1d9f12 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ setup( name="UQPyL", author="wmtSky", - version="2.0.10", + version="2.0.11", author_email="wmtsky@hhu.edu.cn", ext_modules=extensions, packages=find_packages(),