Skip to content

Commit

Permalink
'v2.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
smasky committed Jun 4, 2024
1 parent 3a9b1a5 commit 4f4c086
Show file tree
Hide file tree
Showing 11 changed files with 1,011 additions and 21 deletions.
2 changes: 1 addition & 1 deletion UQPyL/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from . import problems, surrogates, optimization, sensibility, DoE, utility

__version__ = "2.0.4"
__version__ = "2.0.5"
__author__ = "wmtSky"

__all__=[
Expand Down
2 changes: 1 addition & 1 deletion UQPyL/optimization/asmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def run(self, oneStep=False):
history_best_decs[FE]=BestX
history_best_objs[FE]=BestY

Result={'best_dec':BestX, 'best_obj':BestY, 'history_best_decs': history_best_decs, 'history_best_objs':history_best_objs ,'FE':FE}
Result={'best_dec':BestX, 'best_obj':BestY, 'history_best_decs': history_best_decs, 'history_best_objs':history_best_objs ,'FEs':FE}

return Result

Expand Down
2 changes: 1 addition & 1 deletion UQPyL/sensibility/morris.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def analyze(self, X: Optional[np.ndarray]=None, Y: Optional[np.ndarray]=None, ve

N=int(X.shape[0]/self.num_levels)

for i in range(N):
for i in range(num_trajectory):
X_sub=X[i*(n_input+1):(i+1)*(n_input+1), :]
Y_sub=Y[i*(n_input+1):(i+1)*(n_input+1), :]

Expand Down
33 changes: 33 additions & 0 deletions examples/draw_p.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
os.chdir('./examples')

import numpy as np
import matplotlib.pyplot as plt

values=np.loadtxt('./sensibility.txt', dtype=np.float32)
with open('./si_names.txt', 'r') as f:
name=f.readlines()
name=[n.strip() for n in name]
colors=['#03AED2', '#FFC55A', '#75A47F', '#D2649A']
labels=['Sobol\'', 'FAST', 'Morris', 'MARS']
x=np.arange(len(name))
bar_width=0.2
for i in range(4):
plt.bar(x + i * bar_width, values[:, i], bar_width, label=labels[i], color=colors[i])
for i in range(len(name) - 1):
plt.axvline(x=i+1-bar_width, color='black', linestyle='--', linewidth=0.75)


plt.xlim(-0.5, 25.8)
plt.xticks(x+0.3, [f'P{i+1}' for i in range(len(name))], fontsize=14)
plt.yticks(fontsize=14)
plt.tick_params(axis='both', which='both', length=0)
plt.xlabel('Parameters', fontsize=14)
plt.ylabel('Sensibility', fontsize=14)
plt.legend(loc='upper right', fancybox=True, shadow=True, ncol=4, fontsize=14)
ax = plt.gca()
ax.spines['top'].set_linewidth(2)
ax.spines['bottom'].set_linewidth(2)
ax.spines['left'].set_linewidth(2)
ax.spines['right'].set_linewidth(2)
plt.show()
29 changes: 13 additions & 16 deletions examples/example_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,32 @@
- 6. MOEAD/D - Multi-objective
- 7. MO_ASMO - Multi-objective - Surrogate
'''
#tmp
#--------------tmp-------------------#
import sys
sys.path.append(".")
from scipy.io import loadmat
print(sys.path)
import os
os.chdir('./examples')
#
#-----------tmp--------------------#
import numpy as np

################1. Genetic Algorithm (GA) - Single objective################
# print('################1. Genetic Algorithm (GA) - Single objective################')
# from UQPyL.optimization import GA
# from UQPyL.problems import Sphere
print('################1. Genetic Algorithm (GA) - Single objective################')
from UQPyL.optimization import GA
from UQPyL.problems import Sphere

problem=Sphere(n_input=30, ub=100, lb=-100)
ga=GA(problem, n_samples=50)
res=ga.run()
print('Best objective:', res['best_obj'])
print('Best decisions:', res['best_dec'])
print('FE:', res['FEs'])

# problem=Sphere(n_input=30, ub=100, lb=-100)
# ga=GA(problem, n_samples=50)
# res=ga.run()
# print('Best objective:', res['best_obj'])
# print('Best decisions:', res['best_dec'])
# print('FE:', res['FEs'])

# import matplotlib.pyplot as plt
# FEs_objs=res['history_best_objs']
# FEs=list(FEs_objs.keys())
# objs=list(FEs_objs.values())
# plt.plot(FEs, np.log10(objs))


################2. SCE-UA - Single objective################
# print('################2. SCE-UA - Single objective################')
# from UQPyL.optimization import SCE_UA
Expand Down Expand Up @@ -83,7 +80,7 @@
problem=Sphere(n_input=30, ub=100, lb=-100)
rbf=RBF(kernel=Cubic())
asmo=ASMO(problem, rbf, n_init=50)
res=asmo.run(maxFE=1000)
res=asmo.run()
print('Best objective:', res['best_obj'])
print('Best decisions:', res['best_dec'])
print('FE:', res['FEs'])
Expand Down
Loading

0 comments on commit 4f4c086

Please sign in to comment.