MilesCranmer commited on
Commit
48d465b
β€’
1 Parent(s): a8b2d62

Make filenaming more consistent

Browse files
julia/{complexityChecks.jl β†’ CheckConstraints.jl} RENAMED
@@ -39,4 +39,4 @@ function flagUnaOperatorComplexity(tree::Node, op::Int)::Bool
39
  else
40
  return (flagUnaOperatorComplexity(tree.l, op) || flagUnaOperatorComplexity(tree.r, op))
41
  end
42
- end
 
39
  else
40
  return (flagUnaOperatorComplexity(tree.l, op) || flagUnaOperatorComplexity(tree.r, op))
41
  end
42
+ end
julia/{optimization.jl β†’ ConstantOptimization.jl} RENAMED
File without changes
julia/{Node.jl β†’ Equation.jl} RENAMED
File without changes
julia/{eval.jl β†’ EvaluateEquation.jl} RENAMED
@@ -45,38 +45,3 @@ function evalTreeArray(tree::Node, cX::Array{Float32, 2})::Union{Array{Float32,
45
  return cumulator
46
  end
47
  end
48
-
49
- # Score an equation
50
- function scoreFunc(tree::Node)::Float32
51
- prediction = evalTreeArray(tree)
52
- if prediction === nothing
53
- return 1f9
54
- end
55
- if weighted
56
- mse = MSE(prediction, y, weights)
57
- else
58
- mse = MSE(prediction, y)
59
- end
60
- return mse / baselineMSE + countNodes(tree)*parsimony
61
- end
62
-
63
- # Score an equation with a small batch
64
- function scoreFuncBatch(tree::Node)::Float32
65
- # batchSize
66
- batch_idx = randperm(len)[1:batchSize]
67
- batch_X = X[batch_idx, :]
68
- prediction = evalTreeArray(tree, batch_X)
69
- if prediction === nothing
70
- return 1f9
71
- end
72
- size_adjustment = 1f0
73
- batch_y = y[batch_idx]
74
- if weighted
75
- batch_w = weights[batch_idx]
76
- mse = MSE(prediction, batch_y, batch_w)
77
- size_adjustment = 1f0 * len / batchSize
78
- else
79
- mse = MSE(prediction, batch_y)
80
- end
81
- return size_adjustment * mse / baselineMSE + countNodes(tree)*parsimony
82
- end
 
45
  return cumulator
46
  end
47
  end
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
julia/{errors.jl β†’ LossFunctions.jl} RENAMED
@@ -34,4 +34,47 @@ end
34
  # Mean of square error between two arrays
35
  function MSE(x::Array{Float32}, y::Array{Float32}, w::Array{Float32})::Float32
36
  return SSE(x, y, w)/sum(w)
37
- end
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  # Mean of square error between two arrays
35
  function MSE(x::Array{Float32}, y::Array{Float32}, w::Array{Float32})::Float32
36
  return SSE(x, y, w)/sum(w)
37
+ end
38
+
39
+ if weighted
40
+ const avgy = sum(y .* weights)/sum(weights)
41
+ const baselineMSE = MSE(y, convert(Array{Float32, 1}, ones(len) .* avgy), weights)
42
+ else
43
+ const avgy = sum(y)/len
44
+ const baselineMSE = MSE(y, convert(Array{Float32, 1}, ones(len) .* avgy))
45
+ end
46
+
47
+ # Score an equation
48
+ function scoreFunc(tree::Node)::Float32
49
+ prediction = evalTreeArray(tree)
50
+ if prediction === nothing
51
+ return 1f9
52
+ end
53
+ if weighted
54
+ mse = MSE(prediction, y, weights)
55
+ else
56
+ mse = MSE(prediction, y)
57
+ end
58
+ return mse / baselineMSE + countNodes(tree)*parsimony
59
+ end
60
+
61
+ # Score an equation with a small batch
62
+ function scoreFuncBatch(tree::Node)::Float32
63
+ # batchSize
64
+ batch_idx = randperm(len)[1:batchSize]
65
+ batch_X = X[batch_idx, :]
66
+ prediction = evalTreeArray(tree, batch_X)
67
+ if prediction === nothing
68
+ return 1f9
69
+ end
70
+ size_adjustment = 1f0
71
+ batch_y = y[batch_idx]
72
+ if weighted
73
+ batch_w = weights[batch_idx]
74
+ mse = MSE(prediction, batch_y, batch_w)
75
+ size_adjustment = 1f0 * len / batchSize
76
+ else
77
+ mse = MSE(prediction, batch_y)
78
+ end
79
+ return size_adjustment * mse / baselineMSE + countNodes(tree)*parsimony
80
+ end
julia/{simulatedAnnealing.jl β†’ Mutate.jl} RENAMED
@@ -1,5 +1,4 @@
1
- # Go through one simulated annealing mutation cycle
2
- # exp(-delta/T) defines probability of accepting a change
3
  function iterate(member::PopMember, T::Float32, curmaxsize::Integer, frequencyComplexity::Array{Float32, 1})::PopMember
4
  prev = member.tree
5
  tree = prev
@@ -122,4 +121,4 @@ function iterate(member::PopMember, T::Float32, curmaxsize::Integer, frequencyCo
122
  end
123
  end
124
  return PopMember(tree, afterLoss)
125
- end
 
1
+ # Go through one mutation cycle
 
2
  function iterate(member::PopMember, T::Float32, curmaxsize::Integer, frequencyComplexity::Array{Float32, 1})::PopMember
3
  prev = member.tree
4
  tree = prev
 
121
  end
122
  end
123
  return PopMember(tree, afterLoss)
124
+ end
julia/{randomMutations.jl β†’ MutationFunctions.jl} RENAMED
File without changes
julia/{constants.jl β†’ ProgramConstants.jl} RENAMED
File without changes
julia/{regEvolCycle.jl β†’ RegularizedEvolution.jl} RENAMED
File without changes
julia/{simplification.jl β†’ SimplifyEquation.jl} RENAMED
File without changes
julia/{run.jl β†’ SingleIteration.jl} RENAMED
File without changes
julia/{utils.jl β†’ Utils.jl} RENAMED
@@ -29,4 +29,4 @@ function testConfiguration()
29
  @printf("\n\nYour configuration is invalid - one of your operators is not well-defined over the real line.\n\n\n")
30
  throw(error)
31
  end
32
- end
 
29
  @printf("\n\nYour configuration is invalid - one of your operators is not well-defined over the real line.\n\n\n")
30
  throw(error)
31
  end
32
+ end
julia/halloffame.jl CHANGED
@@ -5,4 +5,4 @@ mutable struct HallOfFame
5
 
6
  # Arranged by complexity - store one at each.
7
  HallOfFame() = new([PopMember(Node(1f0), 1f9) for i=1:actualMaxsize], [false for i=1:actualMaxsize])
8
- end
 
5
 
6
  # Arranged by complexity - store one at each.
7
  HallOfFame() = new([PopMember(Node(1f0), 1f9) for i=1:actualMaxsize], [false for i=1:actualMaxsize])
8
+ end
julia/sr.jl CHANGED
@@ -2,48 +2,21 @@ import Optim
2
  import Printf: @printf
3
  import Random: shuffle!, randperm
4
 
5
-
6
- include("constants.jl")
7
-
8
- include("errors.jl")
9
-
10
- if weighted
11
- const avgy = sum(y .* weights)/sum(weights)
12
- const baselineMSE = MSE(y, convert(Array{Float32, 1}, ones(len) .* avgy), weights)
13
- else
14
- const avgy = sum(y)/len
15
- const baselineMSE = MSE(y, convert(Array{Float32, 1}, ones(len) .* avgy))
16
- end
17
-
18
- include("utils.jl")
19
-
20
- include("Node.jl")
21
-
22
- include("eval.jl")
23
-
24
- include("randomMutations.jl")
25
-
26
- include("simplification.jl")
27
-
28
  include("PopMember.jl")
29
-
30
-
31
- include("halloffame.jl")
32
-
33
-
34
- include("complexityChecks.jl")
35
-
36
- include("simulatedAnnealing.jl")
37
-
38
  include("Population.jl")
39
-
40
- include("regEvolCycle.jl")
41
-
42
- include("run.jl")
43
-
44
- include("optimization.jl")
45
-
46
-
47
 
48
  function fullRun(niterations::Integer;
49
  npop::Integer=300,
 
2
  import Printf: @printf
3
  import Random: shuffle!, randperm
4
 
5
+ include("Equation.jl")
6
+ include("ProgramConstants.jl")
7
+ include("LossFunctions.jl")
8
+ include("Utils.jl")
9
+ include("EvaluateEquation.jl")
10
+ include("MutationFunctions.jl")
11
+ include("SimplifyEquation.jl")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  include("PopMember.jl")
13
+ include("HallOfFame.jl")
14
+ include("CheckConstraints.jl")
15
+ include("Mutate.jl")
 
 
 
 
 
 
16
  include("Population.jl")
17
+ include("RegularizedEvolution.jl")
18
+ include("SingleIteration.jl")
19
+ include("ConstantOptimization.jl")
 
 
 
 
 
20
 
21
  function fullRun(niterations::Integer;
22
  npop::Integer=300,