MilesCranmer commited on
Commit
627c408
1 Parent(s): 44b1333

Calculate length as constant

Browse files
Files changed (2) hide show
  1. README.md +3 -1
  2. eureqa.jl +16 -13
README.md CHANGED
@@ -148,7 +148,7 @@ pd.DataFrame, Results dataframe, giving complexity, MSE, and equations
148
  # TODO
149
 
150
  - [ ] Make scaling of changes to constant a hyperparameter
151
- - [ ] Update hall of fame every iteration
152
  - [ ] Calculate feature importances of future mutations, by looking at correlation between residual of model, and the features.
153
  - Store feature importances of future, and periodically update it.
154
  - [ ] Implement more parts of the original Eureqa algorithms: https://www.creativemachineslab.com/eureqa.html
@@ -162,6 +162,8 @@ pd.DataFrame, Results dataframe, giving complexity, MSE, and equations
162
  - Current most expensive operations:
163
  - [ ] Calculating the loss function - there is duplicate calculations happening.
164
  - [x] Declaration of the weights array every iteration
 
 
165
  - [x] Record very best individual in each population, and return at end.
166
  - [x] Write our own tree copy operation; deepcopy() is the slowest operation by far.
167
  - [x] Hyperparameter tune
 
148
  # TODO
149
 
150
  - [ ] Make scaling of changes to constant a hyperparameter
151
+ - [ ] Update hall of fame every iteration?
152
  - [ ] Calculate feature importances of future mutations, by looking at correlation between residual of model, and the features.
153
  - Store feature importances of future, and periodically update it.
154
  - [ ] Implement more parts of the original Eureqa algorithms: https://www.creativemachineslab.com/eureqa.html
 
162
  - Current most expensive operations:
163
  - [ ] Calculating the loss function - there is duplicate calculations happening.
164
  - [x] Declaration of the weights array every iteration
165
+ - [x] Add a node at the top of a tree
166
+ - [x] Insert a node at the top of a subtree
167
  - [x] Record very best individual in each population, and return at end.
168
  - [x] Write our own tree copy operation; deepcopy() is the slowest operation by far.
169
  - [x] Hyperparameter tune
eureqa.jl CHANGED
@@ -3,6 +3,21 @@ import Optim
3
  const maxdegree = 2
4
  const actualMaxsize = maxsize + maxdegree
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  id = (x,) -> x
7
  const nuna = size(unaops)[1]
8
  const nbin = size(binops)[1]
@@ -211,7 +226,6 @@ end
211
 
212
  # Evaluate an equation over an array of datapoints
213
  function evalTreeArray(tree::Node)::Array{Float32, 1}
214
- len = size(X)[1]
215
  if tree.degree == 0
216
  if tree.constant
217
  return ones(Float32, len) .* tree.val
@@ -225,17 +239,6 @@ function evalTreeArray(tree::Node)::Array{Float32, 1}
225
  end
226
  end
227
 
228
- # Sum of square error between two arrays
229
- function SSE(x::Array{Float32}, y::Array{Float32})::Float32
230
- diff = (x - y)
231
- return sum(diff .* diff)
232
- end
233
-
234
- # Mean of square error between two arrays
235
- function MSE(x::Array{Float32}, y::Array{Float32})::Float32
236
- return SSE(x, y)/size(x)[1]
237
- end
238
-
239
  # Score an equation
240
  function scoreFunc(tree::Node)::Float32
241
  try
@@ -608,7 +611,7 @@ function fullRun(niterations::Integer;
608
  debug(verbosity, "-----------------------------------------")
609
  debug(verbosity, "Complexity \t MSE \t Equation")
610
  println(io,"Complexity|MSE|Equation")
611
- for size=1:maxsize
612
  if hallOfFame.exists[size]
613
  member = hallOfFame.members[size]
614
  numberSmallerAndBetter = sum([member.score > hallOfFame.members[i].score for i=1:(size-1)])
 
3
  const maxdegree = 2
4
  const actualMaxsize = maxsize + maxdegree
5
 
6
+
7
+ # Sum of square error between two arrays
8
+ function SSE(x::Array{Float32}, y::Array{Float32})::Float32
9
+ diff = (x - y)
10
+ return sum(diff .* diff)
11
+ end
12
+
13
+ # Mean of square error between two arrays
14
+ function MSE(x::Array{Float32}, y::Array{Float32})::Float32
15
+ return SSE(x, y)/size(x)[1]
16
+ end
17
+
18
+ const len = size(X)[1]
19
+ const baselineMSE = MSE(y, convert(Array{Float32, 1}, ones(len) .* sum(y)/len))
20
+
21
  id = (x,) -> x
22
  const nuna = size(unaops)[1]
23
  const nbin = size(binops)[1]
 
226
 
227
  # Evaluate an equation over an array of datapoints
228
  function evalTreeArray(tree::Node)::Array{Float32, 1}
 
229
  if tree.degree == 0
230
  if tree.constant
231
  return ones(Float32, len) .* tree.val
 
239
  end
240
  end
241
 
 
 
 
 
 
 
 
 
 
 
 
242
  # Score an equation
243
  function scoreFunc(tree::Node)::Float32
244
  try
 
611
  debug(verbosity, "-----------------------------------------")
612
  debug(verbosity, "Complexity \t MSE \t Equation")
613
  println(io,"Complexity|MSE|Equation")
614
+ for size=1:actualMaxsize
615
  if hallOfFame.exists[size]
616
  member = hallOfFame.members[size]
617
  numberSmallerAndBetter = sum([member.score > hallOfFame.members[i].score for i=1:(size-1)])