Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit35dc87d

Browse files
committed
post integration debug update
1 parent4c36bea commit35dc87d

File tree

4 files changed

+33
-89
lines changed

4 files changed

+33
-89
lines changed

‎src/chicken_swarm.py‎

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,33 @@
33
##--------------------------------------------------------------------\
44
# chicken_swarm_python
55
# './chicken_swarm_python/src/chicken_swarm.py'
6-
# A basic chicken swarm optimization class. This class follows the same
7-
# format as pso_python and pso_basic to make them interchangeable
8-
# in function calls.
9-
#
6+
# A basic chicken swarm optimization class.
107
#
118
# Author(s): Lauren Linkous, Jonathan Lundquist
12-
# Last update:June 14, 2024
9+
# Last update:August 18, 2024
1310
##--------------------------------------------------------------------\
1411

1512

1613
importnumpyasnp
1714
fromnumpy.randomimportGenerator,MT19937
1815
importsys
19-
importtime
2016
np.seterr(all='raise')
2117

2218

2319
classswarm:
2420
# arguments should take form:
25-
# swarm(int,
26-
# [[float, float, ...]], [[float, float, ...]], [[float, ...]],
21+
# swarm(int, [[float, float, ...]], [[float, float, ...]],
2722
# int, [[float, ...]],
28-
# float, int, int, func, func,
23+
# float, int, int,
24+
# func, func,
2925
# int, int, int, int, int,
30-
# obj, bool)
26+
#classobj, bool)
3127
# int boundary 1 = random, 2 = reflecting
3228
# 3 = absorbing, 4 = invisible
33-
def__init__(self,NO_OF_PARTICLES,
34-
lbound,ubound,
29+
def__init__(self,NO_OF_PARTICLES,lbound,ubound,
3530
output_size,targets,
36-
E_TOL,maxit,boundary,obj_func,constr_func,
31+
E_TOL,maxit,boundary,
32+
obj_func,constr_func,
3733
RN=3,HN=12,MN=8,CN=15,G=150,
3834
parent=None,detailedWarnings=False):
3935

@@ -219,8 +215,6 @@ def __init__(self, NO_OF_PARTICLES,
219215
self.Flist : List to store fitness values.
220216
self.Fvals : List to store fitness values.
221217
self.Mlast : Last location of particle
222-
self.InitDeviation : Initial deviation of particles.
223-
self.delta_t : static time modulation. retained for comparison to original repo. and swarm export
224218
'''
225219

226220
self.output_size=output_size
@@ -242,7 +236,6 @@ def __init__(self, NO_OF_PARTICLES,
242236
self.Flist= []
243237
self.Fvals= []
244238
self.Mlast=1*self.ubound
245-
self.InitDeviation=self.absolute_mean_deviation_of_particles()
246239

247240

248241
self.error_message_generator("swarm successfully initialized")
@@ -462,25 +455,14 @@ def check_bounds(self, particle):
462455
returnupdate
463456

464457

465-
defvalidate_obj_function(self,particle):
466-
# checks the the objective function resolves with the current particle.
467-
# It is possible (and likely) that obj funcs without proper error handling
468-
# will throw over/underflow errors.
469-
# e.g.: numpy does not support float128()
470-
newFVals,noError=self.obj_func(particle,self.output_size)
471-
ifnoError==False:
472-
#print("!!!!")
473-
pass
474-
returnnoError
475-
476458
defrandom_bound(self,particle):
477459
# If particle is out of bounds, bring the particle back in bounds
478460
# The first condition checks if constraints are met,
479461
# and the second determins if the values are to large (positive or negitive)
480462
# and may cause a buffer overflow with large exponents (a bug that was found experimentally)
481-
update=self.check_bounds(particle)ornotself.constr_func(self.M[particle])ornotself.validate_obj_function(np.hstack(self.M[self.current_particle]))
463+
update=self.check_bounds(particle)ornotself.constr_func(self.M[particle])
482464
ifupdate>0:
483-
while(self.check_bounds(particle)>0)or (self.constr_func(self.M[particle])==False)or (self.validate_obj_function(self.M[particle])==False):
465+
while(self.check_bounds(particle)>0)or (self.constr_func(self.M[particle])==False):
484466
variation=self.ubound-self.lbound
485467
self.M[particle]= \
486468
np.squeeze(self.rng.random()*
@@ -507,7 +489,7 @@ def absorbing_bound(self, particle):
507489
self.random_bound(particle)
508490

509491
definvisible_bound(self,particle):
510-
update=self.check_bounds(particle)ornotself.constr_func(self.M[particle])ornotself.validate_obj_function(self.M[particle])
492+
update=self.check_bounds(particle)ornotself.constr_func(self.M[particle])
511493
ifupdate>0:
512494
self.Active[particle]=0
513495
else:
@@ -618,7 +600,6 @@ def export_swarm(self):
618600
'maxit':self.maxit,
619601
'E_TOL':self.E_TOL,
620602
'iter':self.iter,
621-
'delta_t':self.delta_t,
622603
'current_particle':self.current_particle,
623604
'number_of_particles':self.number_of_particles,
624605
'allow_update':self.allow_update,

‎src/main_test.py‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# for integration in the AntennaCAT GUI.
1111
#
1212
# Author(s): Lauren Linkous, Jonathan Lundquist
13-
# Last update:June 14, 2024
13+
# Last update:August 18, 2024
1414
##--------------------------------------------------------------------\
1515

1616

@@ -31,7 +31,6 @@
3131
# 3 = absorbing, 4 = invisible
3232

3333

34-
3534
# Objective function dependent variables
3635
LB=func_configs.LB# Lower boundaries, [[0.21, 0, 0.1]]
3736
UB=func_configs.UB# Upper boundaries, [[1, 1, 0.5]]
@@ -43,8 +42,7 @@
4342
func_F=func_configs.OBJECTIVE_FUNC# objective function
4443
constr_F=func_configs.CONSTR_FUNC# constraint function
4544

46-
47-
45+
4846
# chicken swarm specific
4947
RN=10# Total number of roosters
5048
HN=20# Total number of hens
@@ -81,11 +79,6 @@
8179
# when it is allowed to update and return
8280
# control to optimizer
8381

84-
# for some objective functions, the function
85-
# might not evaluate correctly (e.g., under/overflow)
86-
# so when that happens, the function is not evaluated
87-
# and the 'step' fucntion will re-gen values and try again
88-
8982
mySwarm.call_objective(allow_update)
9083
iter,eval=mySwarm.get_convergence_data()
9184
if (eval<best_eval)and (eval!=0):

‎src/main_test_details.py‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# for integration in the AntennaCAT GUI.
1111
#
1212
# Author(s): Lauren Linkous, Jonathan Lundquist
13-
# Last update:June 14, 2024
13+
# Last update:August 18, 2024
1414
##--------------------------------------------------------------------\
1515

1616

@@ -55,15 +55,6 @@ def __init__(self):
5555
G=70# Reorganize groups every G steps
5656
NO_OF_PARTICLES=RN+HN+MN+CN# Number of particles in swarm
5757

58-
# swarm setup
59-
parent=self# Optional parent class for swarm
60-
# (Used for passing debug messages or
61-
# other information that will appear
62-
# in GUI panels)
63-
64-
detailedWarnings=False# Optional boolean for detailed feedback
65-
66-
6758
# Swarm vars
6859
self.best_eval=1# Starting eval value
6960

@@ -99,12 +90,6 @@ def debug_message_printout(self, txt):
9990
print(msg)
10091

10192

102-
defrecord_params(self):
103-
# this function is called from particle_swarm.py to trigger a write to a log file
104-
# running in the AntennaCAT GUI to record the parameter iteration that caused an error
105-
pass
106-
107-
10893
defrun(self):
10994

11095
# instantiation of particle swarm optimizer

‎src/main_test_graph.py‎

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# matplotlib plot of particle location
1313
#
1414
# Author(s): Lauren Linkous, Jonathan Lundquist
15-
# Last update:June 14, 2024
15+
# Last update:August 18, 2024
1616
##--------------------------------------------------------------------\
1717

1818

@@ -27,7 +27,6 @@
2727
#import lundquist_3_var.configs_F as func_configs # multi objective function
2828

2929

30-
3130
classTestGraph():
3231
def__init__(self):
3332

@@ -40,7 +39,6 @@ def __init__(self):
4039
# 3 = absorbing, 4 = invisible
4140

4241

43-
4442
# Objective function dependent variables
4543
LB=func_configs.LB# Lower boundaries, [[0.21, 0, 0.1]]
4644
UB=func_configs.UB# Upper boundaries, [[1, 1, 0.5]]
@@ -52,8 +50,7 @@ def __init__(self):
5250
func_F=func_configs.OBJECTIVE_FUNC# objective function
5351
constr_F=func_configs.CONSTR_FUNC# constraint function
5452

55-
56-
53+
5754
# chicken swarm specific
5855
RN=10# Total number of roosters
5956
HN=20# Total number of hens
@@ -62,15 +59,6 @@ def __init__(self):
6259
G=70# Reorganize groups every G steps
6360
NO_OF_PARTICLES=RN+HN+MN+CN# Number of particles in swarm
6461

65-
# swarm setup
66-
parent=self# Optional parent class for swarm
67-
# (Used for passing debug messages or
68-
# other information that will appear
69-
# in GUI panels)
70-
71-
detailedWarnings=False# Optional boolean for detailed feedback
72-
73-
7462
# Swarm vars
7563
self.best_eval=1# Starting eval value
7664

@@ -89,7 +77,6 @@ def __init__(self):
8977

9078

9179

92-
9380
self.mySwarm=swarm(NO_OF_PARTICLES,LB,UB,
9481
OUT_VARS,TARGETS,
9582
E_TOL,MAXIT,BOUNDARY,func_F,constr_F,
@@ -103,16 +90,16 @@ def __init__(self):
10390
# position
10491
self.ax1=self.fig.add_subplot(121,projection='3d')
10592
self.ax1.set_title("Particle Location, Iteration: "+str(self.ctr))
106-
self.ax1.set_xlabel('X')
107-
self.ax1.set_ylabel('Y')
108-
self.ax1.set_zlabel('Z')
93+
self.ax1.set_xlabel('x_1')
94+
self.ax1.set_ylabel('x_2')
95+
self.ax1.set_zlabel('x_3')
10996
self.scatter1=None
11097
# fitness
11198
self.ax2=self.fig.add_subplot(122,projection='3d')
11299
self.ax2.set_title("Fitness Relation to Target")
113-
self.ax2.set_xlabel('X')
114-
self.ax2.set_ylabel('Y')
115-
self.ax2.set_zlabel('Z')
100+
self.ax2.set_xlabel('x_1')
101+
self.ax2.set_ylabel('x_2')
102+
self.ax2.set_zlabel('x_3')
116103
self.scatter2=None
117104

118105
defdebug_message_printout(self,txt):
@@ -124,12 +111,6 @@ def debug_message_printout(self, txt):
124111
print(msg)
125112

126113

127-
defrecord_params(self):
128-
# this function is called from particle_swarm.py to trigger a write to a log file
129-
# running in the AntennaCAT GUI to record the parameter iteration that caused an error
130-
pass
131-
132-
133114
defupdate_plot(self,x_coords,y_coords,targets,showTarget=True,clearAx=True):
134115

135116
# check if any points. first call might not have anythign set yet.
@@ -147,12 +128,14 @@ def update_plot(self, x_coords, y_coords, targets, showTarget=True, clearAx=True
147128
self.ax1.set_title("Search Locations, Iteration: "+str(self.ctr))
148129
self.ax1.set_xlabel("$x_1$")
149130
self.ax1.set_ylabel("filler coords")
131+
self.ax1.set_zlabel("filler coords")
150132
self.scatter=self.ax1.scatter(x_coords,x_plot_coords,edgecolors='b')
151133

152134
elifnp.shape(x_coords)[1]==2:#2-dim func
153135
self.ax1.set_title("Search Locations, Iteration: "+str(self.ctr))
154136
self.ax1.set_xlabel("$x_1$")
155137
self.ax1.set_ylabel("$x_2$")
138+
self.ax1.set_zlabel("filler coords")
156139
self.scatter=self.ax1.scatter(x_coords[:,0],x_coords[:,1],edgecolors='b')
157140

158141
elifnp.shape(x_coords)[1]==3:#3-dim func
@@ -167,21 +150,23 @@ def update_plot(self, x_coords, y_coords, targets, showTarget=True, clearAx=True
167150
ifnp.shape(y_coords)[1]==1:#1-dim obj func
168151
y_plot_filler=np.array(y_coords[:,0])*0.0
169152
self.ax2.set_title("Global Best Fitness Relation to Target")
170-
self.ax2.set_xlabel("$F_{1}(x,y)$")
153+
self.ax2.set_xlabel("$F_{1}(x_1,x_2)$")
171154
self.ax2.set_ylabel("filler coords")
155+
self.ax2.set_zlabel("filler coords")
172156
self.scatter=self.ax2.scatter(y_coords,y_plot_filler,marker='o',s=40,facecolor="none",edgecolors="k")
173157

174158
elifnp.shape(y_coords)[1]==2:#2-dim obj func
175159
self.ax2.set_title("Global Best Fitness Relation to Target")
176-
self.ax2.set_xlabel("$F_{1}(x,y)$")
177-
self.ax2.set_ylabel("$F_{2}(x,y)$")
160+
self.ax2.set_xlabel("$F_{1}(x_1,x_2)$")
161+
self.ax2.set_ylabel("$F_{2}(x_1,x_2)$")
162+
self.ax2.set_zlabel("filler coords")
178163
self.scatter=self.ax2.scatter(y_coords[:,0],y_coords[:,1],marker='o',s=40,facecolor="none",edgecolors="k")
179164

180165
elifnp.shape(y_coords)[1]==3:#3-dim obj fun
181166
self.ax2.set_title("Global Best Fitness Relation to Target")
182-
self.ax2.set_xlabel("$F_{1}(x,y)$")
183-
self.ax2.set_ylabel("$F_{2}(x,y)$")
184-
self.ax2.set_zlabel("$F_{3}(x,y)$")
167+
self.ax2.set_xlabel("$F_{1}(x_1,x_2)$")
168+
self.ax2.set_ylabel("$F_{2}(x_1,x_2)$")
169+
self.ax2.set_zlabel("$F_{3}(x_1,x_2)$")
185170
self.scatter=self.ax2.scatter(y_coords[:,0],y_coords[:,1],y_coords[:,2],marker='o',s=40,facecolor="none",edgecolors="k")
186171

187172

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp