MilesCranmer commited on
Commit
2e104cc
1 Parent(s): c4d7c3f

New arg for insert node weight

Browse files
Files changed (3) hide show
  1. eureqa.jl +6 -9
  2. eureqa.py +12 -0
  3. hyperparamopt.py +1 -0
eureqa.jl CHANGED
@@ -420,18 +420,15 @@ function iterate(
420
  elseif mutationChoice < cweights[2]
421
  tree = mutateOperator(tree)
422
  elseif mutationChoice < cweights[3] && n < maxsize
423
- toInsert = rand() < 0.1
424
- if toInsert
425
- tree = insertRandomOp(tree)
426
- else
427
- tree = appendRandomOp(tree)
428
- end
429
- elseif mutationChoice < cweights[4]
430
- tree = deleteRandomOp(tree)
431
  elseif mutationChoice < cweights[5]
 
 
432
  tree = simplifyTree(tree) # Sometimes we simplify tree
433
  return tree
434
- elseif mutationChoice < cweights[6]
435
  tree = genRandomTree(5) # Sometimes we simplify tree
436
  else
437
  return tree
 
420
  elseif mutationChoice < cweights[2]
421
  tree = mutateOperator(tree)
422
  elseif mutationChoice < cweights[3] && n < maxsize
423
+ tree = appendRandomOp(tree)
424
+ elseif mutationChoice < cweights[4] && n < maxsize
425
+ tree = insertRandomOp(tree)
 
 
 
 
 
426
  elseif mutationChoice < cweights[5]
427
+ tree = deleteRandomOp(tree)
428
+ elseif mutationChoice < cweights[6]
429
  tree = simplifyTree(tree) # Sometimes we simplify tree
430
  return tree
431
+ elseif mutationChoice < cweights[7]
432
  tree = genRandomTree(5) # Sometimes we simplify tree
433
  else
434
  return tree
eureqa.py CHANGED
@@ -11,6 +11,7 @@ default_fractionReplaced = 0.057940
11
  default_fractionReplacedHof = 0.206182
12
  default_npop = 124.000000
13
  default_weightAddNode = 1.599672
 
14
  default_weightDeleteNode = 0.049554
15
  default_weightMutateConstant = 5.295328
16
  default_weightMutateOperator = 0.465999
@@ -38,6 +39,7 @@ def eureqa(X=None, y=None, threads=4,
38
  shouldOptimizeConstants=True,
39
  topn=int(default_topn),
40
  weightAddNode=default_weightAddNode,
 
41
  weightDeleteNode=default_weightDeleteNode,
42
  weightDoNothing=default_weightDoNothing,
43
  weightMutateConstant=default_weightMutateConstant,
@@ -82,6 +84,7 @@ def eureqa(X=None, y=None, threads=4,
82
  constants (Nelder-Mead/Newton) at the end of each iteration.
83
  :param topn: int, How many top individuals migrate from each population.
84
  :param weightAddNode: float, Relative likelihood for mutation to add a node
 
85
  :param weightDeleteNode: float, Relative likelihood for mutation to delete a node
86
  :param weightDoNothing: float, Relative likelihood for mutation to leave the individual
87
  :param weightMutateConstant: float, Relative likelihood for mutation to change
@@ -139,6 +142,7 @@ const mutationWeights = [
139
  {weightMutateConstant:f},
140
  {weightMutateOperator:f},
141
  {weightAddNode:f},
 
142
  {weightDeleteNode:f},
143
  {weightSimplify:f},
144
  {weightRandomize:f},
@@ -201,6 +205,14 @@ if __name__ == "__main__":
201
  parser.add_argument("--topn", type=int, default=int(default_topn), help="How many best species to distribute from each population")
202
  parser.add_argument("--fractionReplacedHof", type=float, default=default_fractionReplacedHof, help="Fraction of population to replace with hall of fame")
203
  parser.add_argument("--fractionReplaced", type=float, default=default_fractionReplaced, help="Fraction of population to replace with best from other populations")
 
 
 
 
 
 
 
 
204
  parser.add_argument("--migration", type=bool, default=True, help="Whether to migrate")
205
  parser.add_argument("--hofMigration", type=bool, default=True, help="Whether to have hall of fame migration")
206
  parser.add_argument("--shouldOptimizeConstants", type=bool, default=True, help="Whether to use classical optimization on constants before every migration (doesn't impact performance that much)")
 
11
  default_fractionReplacedHof = 0.206182
12
  default_npop = 124.000000
13
  default_weightAddNode = 1.599672
14
+ default_weightInsertNode = 1.599672
15
  default_weightDeleteNode = 0.049554
16
  default_weightMutateConstant = 5.295328
17
  default_weightMutateOperator = 0.465999
 
39
  shouldOptimizeConstants=True,
40
  topn=int(default_topn),
41
  weightAddNode=default_weightAddNode,
42
+ weightInsertNode=default_weightInsertNode,
43
  weightDeleteNode=default_weightDeleteNode,
44
  weightDoNothing=default_weightDoNothing,
45
  weightMutateConstant=default_weightMutateConstant,
 
84
  constants (Nelder-Mead/Newton) at the end of each iteration.
85
  :param topn: int, How many top individuals migrate from each population.
86
  :param weightAddNode: float, Relative likelihood for mutation to add a node
87
+ :param weightInsertNode: float, Relative likelihood for mutation to insert a node
88
  :param weightDeleteNode: float, Relative likelihood for mutation to delete a node
89
  :param weightDoNothing: float, Relative likelihood for mutation to leave the individual
90
  :param weightMutateConstant: float, Relative likelihood for mutation to change
 
142
  {weightMutateConstant:f},
143
  {weightMutateOperator:f},
144
  {weightAddNode:f},
145
+ {weightInsertNode:f},
146
  {weightDeleteNode:f},
147
  {weightSimplify:f},
148
  {weightRandomize:f},
 
205
  parser.add_argument("--topn", type=int, default=int(default_topn), help="How many best species to distribute from each population")
206
  parser.add_argument("--fractionReplacedHof", type=float, default=default_fractionReplacedHof, help="Fraction of population to replace with hall of fame")
207
  parser.add_argument("--fractionReplaced", type=float, default=default_fractionReplaced, help="Fraction of population to replace with best from other populations")
208
+ parser.add_argument("--weightAddNode", type=float, default=default_weightAddNode)
209
+ parser.add_argument("--weightInsertNode", type=float, default=default_weightInsertNode)
210
+ parser.add_argument("--weightDeleteNode", type=float, default=default_weightDeleteNode)
211
+ parser.add_argument("--weightMutateConstant", type=float, default=default_weightMutateConstant)
212
+ parser.add_argument("--weightMutateOperator", type=float, default=default_weightMutateOperator)
213
+ parser.add_argument("--weightRandomize", type=float, default=default_weightRandomize)
214
+ parser.add_argument("--weightSimplify", type=float, default=default_weightSimplify)
215
+ parser.add_argument("--weightDoNothing", type=float, default=default_weightDoNothing)
216
  parser.add_argument("--migration", type=bool, default=True, help="Whether to migrate")
217
  parser.add_argument("--hofMigration", type=bool, default=True, help="Whether to have hall of fame migration")
218
  parser.add_argument("--shouldOptimizeConstants", type=bool, default=True, help="Whether to use classical optimization on constants before every migration (doesn't impact performance that much)")
hyperparamopt.py CHANGED
@@ -117,6 +117,7 @@ space = {
117
  'weightMutateConstant': hp.lognormal('weightMutateConstant', np.log(4.0), 1.0),
118
  'weightMutateOperator': hp.lognormal('weightMutateOperator', np.log(0.5), 1.0),
119
  'weightAddNode': hp.lognormal('weightAddNode', np.log(0.5), 1.0),
 
120
  'weightDeleteNode': hp.lognormal('weightDeleteNode', np.log(0.5), 1.0),
121
  'weightSimplify': hp.lognormal('weightSimplify', np.log(0.05), 1.0),
122
  'weightRandomize': hp.lognormal('weightRandomize', np.log(0.25), 1.0),
 
117
  'weightMutateConstant': hp.lognormal('weightMutateConstant', np.log(4.0), 1.0),
118
  'weightMutateOperator': hp.lognormal('weightMutateOperator', np.log(0.5), 1.0),
119
  'weightAddNode': hp.lognormal('weightAddNode', np.log(0.5), 1.0),
120
+ 'weightInsertNode': hp.lognormal('weightInsertNode', np.log(0.5), 1.0),
121
  'weightDeleteNode': hp.lognormal('weightDeleteNode', np.log(0.5), 1.0),
122
  'weightSimplify': hp.lognormal('weightSimplify', np.log(0.05), 1.0),
123
  'weightRandomize': hp.lognormal('weightRandomize', np.log(0.25), 1.0),