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

Commit3758d13

Browse files
committed
chicken swarm import updates for new objective funcs
1 parentd189559 commit3758d13

File tree

9 files changed

+138
-298
lines changed

9 files changed

+138
-298
lines changed

‎src/chicken_swarm.py‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,37 @@ def move_hen(self, particle):
333333
clipped_val=np.clip(((fitness_this_chicken-fitness_rooster)/(np.abs(fitness_this_chicken)+epsilon)),-709.00,709.00)
334334
S1=np.exp(clipped_val)
335335
# S1*RANDOM(0-to-1)*(LocationRoosterGroupmate-thisChickenLocation)
336-
term_1=S1*self.rng.uniform(0,1)*(rooster_loc-self.M[particle])
336+
# these terms can overflow because of the exp()
337+
# some S2 results are evaluating on the scale of 8.218407461554972e+307
338+
# these clipped bounds are effectively are zero and inf
339+
# term_1 = S1*self.rng.uniform(0,1)*(rooster_loc-self.M[particle])
340+
# still dealing with overflow issues. apply cap to S1
341+
ifS1>10e50:
342+
S1=10e50
343+
elifS1<-10e50:
344+
S1=-10e50
345+
clipped_term1=np.clip((S1*self.rng.uniform(0,1)*(rooster_loc-self.M[particle])),-10e50,10e10)
346+
term_1=clipped_term1
337347

338348
#S2 = np.exp(float(fitness_random_chicken-fitness_this_chicken))
339349
#np.exp(...) throws overflow errors. Using clip as a generic catch
340350
clipped_val=np.clip((fitness_random_chicken-fitness_this_chicken),-709.00,709.00)
341351
S2=np.exp(clipped_val)
342352
#S2*RANDOM(0-to-1)*(LoctionRandomChickenInSwarm-thisChickenLocation)
343-
term_2=S2*self.rng.uniform(0,1)*(random_chicken_loc-self.M[particle])
353+
354+
# these terms can overflow because of the exp()
355+
# some S2 results are evaluating on the scale of 8.218407461554972e+307
356+
# these clipped bounds are effectively are zero and inf
357+
#term_2 = S2*self.rng.uniform(0,1)*(random_chicken_loc-self.M[particle])
358+
# This still causes overflow:
359+
# clipped_term2 = np.clip((S2*self.rng.uniform(0,1)*(random_chicken_loc-self.M[particle])), -10e50, 10e10)
360+
ifS2>10e50:
361+
S2=10e50
362+
elifS2<-10e50:
363+
S2=-10e50
364+
365+
clipped_term2=np.clip((S2*self.rng.uniform(0,1)*(random_chicken_loc-self.M[particle])),-10e50,10e10)
366+
term_2=clipped_term2
344367

345368
# new_loc = old_loc + term_1 + term_2
346369
self.M[particle]=self.M[particle]+term_1+term_2
@@ -404,23 +427,21 @@ def reorganize_swarm(self):
404427
group_nums=np.arange(self.RN)
405428

406429
# first rooster, to reset the array
407-
self.chicken_info=np.vstack([0,0,-1])
430+
self.chicken_info=np.array([0,0,-1])
408431

409432
foriinrange(1,int(self.number_of_particles)):
410433
ifclassList[i]==0:#rooster
411434
# assign to the next group (i-1), and done.
412435
# CLASSIFICATION(0-4), GROUP(0-m), MOTHER-CHILD ID
413436
self.chicken_info= \
414-
np.hstack([self.chicken_info,
415-
np.vstack([classList[i],i,-1])])
437+
np.vstack([self.chicken_info, [classList[i],i,-1]])
416438

417439
elif (classList[i]==1)or (classList[i]==2):#hen, mother hen
418440
# assign to a random group.
419441
# CLASSIFICATION(0-4), GROUP(0-m), MOTHER-CHILD ID
420442
hen_group=self.rng.choice(group_nums)
421443
self.chicken_info= \
422-
np.hstack([self.chicken_info,
423-
np.vstack([classList[i],hen_group,-1])])
444+
np.vstack([self.chicken_info,[classList[i],hen_group,-1]])
424445

425446
elifclassList[i]==3:#chick
426447
# select a random hen to be the 'mother' and assign to group
@@ -433,8 +454,7 @@ def reorganize_swarm(self):
433454
mother_group=self.chicken_info[chicken_idx][1]
434455
# assign chick to group, and to that mother hen
435456
self.chicken_info= \
436-
np.hstack([self.chicken_info,
437-
np.vstack([classList[i],mother_group,chicken_idx])])
457+
np.vstack([self.chicken_info,[classList[i],mother_group,chicken_idx]])
438458

439459
groupAssigned=True
440460

‎src/configs_F.py‎

Lines changed: 0 additions & 28 deletions
This file was deleted.

‎src/constr_F.py‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎src/constr_default.py‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎src/func_F.py‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎src/main_function_graph.py‎

Lines changed: 0 additions & 125 deletions
This file was deleted.

‎src/main_test.py‎

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,44 @@
1616

1717
importnumpyasnp
1818
fromchicken_swarmimportswarm
19-
fromfunc_Fimportfunc_F
20-
fromconstr_Fimportconstr_F
19+
# OBJECTIVE FUNCTION SELECTION
20+
#import one_dim_x_test.configs_F as func_configs # single objective, 1D input
21+
importhimmelblau.configs_Fasfunc_configs# single objective, 2D input
22+
#import lundquist_3_var.configs_F as func_configs # multi objective function
2123

2224

23-
if__name__=="__main__":
24-
# objective function boundaries
25-
LB= [[0.21,0,0.1]]# Lower boundaries
26-
UB= [[1,1,0.5]]# Upper boundaries
27-
OUT_VARS=2# Number of output variables (y-values)
28-
TARGETS= [0,0]# Target values for output
29-
30-
31-
# chicken swarm specific
32-
RN=10# Total number of roosters
33-
HN=20# Total number of hens
34-
MN=15# Number of mother hens in total hens
35-
CN=20# Total number of chicks
36-
G=200# Reorganize groups every G steps
3725

26+
if__name__=="__main__":
3827
# swarm variables
39-
NO_OF_PARTICLES=RN+HN+CN# Number of particles in swarm
4028
WEIGHTS= [[2,2.2,2]]# Update vector weights. Used as C1 constant in tracing mode.
4129
E_TOL=10**-6# Convergence Tolerance
4230
MAXIT=10000# Maximum allowed iterations
4331
BOUNDARY=1# int boundary 1 = random, 2 = reflecting
4432
# 3 = absorbing, 4 = invisible
4533

4634

35+
36+
# Objective function dependent variables
37+
LB=func_configs.LB# Lower boundaries, [[0.21, 0, 0.1]]
38+
UB=func_configs.UB# Upper boundaries, [[1, 1, 0.5]]
39+
IN_VARS=func_configs.IN_VARS# Number of input variables (x-values)
40+
OUT_VARS=func_configs.OUT_VARS# Number of output variables (y-values)
41+
TARGETS=func_configs.TARGETS# Target values for output
42+
43+
# Objective function dependent variables
44+
func_F=func_configs.OBJECTIVE_FUNC# objective function
45+
constr_F=func_configs.CONSTR_FUNC# constraint function
46+
47+
48+
49+
# chicken swarm specific
50+
RN=10# Total number of roosters
51+
HN=20# Total number of hens
52+
MN=15# Number of mother hens in total hens
53+
CN=20# Total number of chicks
54+
G=70# Reorganize groups every G steps
55+
NO_OF_PARTICLES=RN+HN+CN# Number of particles in swarm
56+
4757
# swarm setup
4858
best_eval=1
4959

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp