Skip to content

Commit

Permalink
updating some matplotlib apis in tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
gbomarito committed Sep 18, 2024
1 parent dd7d0fe commit ddb9dcc
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 173 deletions.
26 changes: 16 additions & 10 deletions examples/SMCExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def get_training_data(equ, minx, maxx, numx, noise_ratio):


def make_fitness_function(
training_data, mcmc_steps, num_particles, num_multistarts,
training_data,
mcmc_steps,
num_particles,
num_multistarts,
):
fitness = ExplicitRegression(training_data=training_data, metric="mse")

Expand Down Expand Up @@ -81,7 +84,9 @@ def make_island(
for comp in operators:
component_generator.add_operator(comp)
generator = AGraphGenerator(
stack_size, component_generator, use_simplification=True,
stack_size,
component_generator,
use_simplification=True,
)

# variation
Expand Down Expand Up @@ -111,9 +116,7 @@ def make_island(
x.command_array, y.command_array
),
)
island = Island(
ea, generator, population_size=population_size, hall_of_fame=hof
)
island = Island(ea, generator, population_size=population_size, hall_of_fame=hof)
return island


Expand All @@ -134,24 +137,27 @@ def make_island(
NUM_MULTISTARTS = 8

# ISLAND PARAMS
POPULATION_SIZE = 100
POPULATION_SIZE = 20

# AGRAPH PARAMS
OPERATORS = ["+", "-", "*"]
STACK_SIZE = 64
STACK_SIZE = 16
USE_SIMPLIFICATION = True

# VARIATION PARAMS
CROSSOVER_PROB = 0.4
MUTATION_PROB = 0.4

# EVOLUTION PARAMS
NUM_GENERATIONS = 10
NUM_GENERATIONS = 1

np.random.seed(0)
TRAINING_DATA = get_training_data(TRU_EQU, MINX, MAXX, NUMX, NOISE_RATIO)
NML = make_fitness_function(
TRAINING_DATA, NUM_MCMC_STEPS, NUM_PARTICLES, NUM_MULTISTARTS,
TRAINING_DATA,
NUM_MCMC_STEPS,
NUM_PARTICLES,
NUM_MULTISTARTS,
)
ISLAND = make_island(
NML,
Expand All @@ -162,7 +168,7 @@ def make_island(
MUTATION_PROB,
)

for _ in range(2):
for _ in range(NUM_GENERATIONS):
ISLAND.evolve(1)

print("HOF")
Expand Down
2 changes: 1 addition & 1 deletion examples/Tutorial_1_One_Max.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.12.2"
}
},
"nbformat": 4,
Expand Down
198 changes: 42 additions & 156 deletions examples/Tutorial_2_Zero_Min.ipynb

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions examples/Tutorial_3_Archipelagos_and_Logging.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@
"\n",
"\n",
" def animate(i):\n",
" ax.collections.clear()\n",
" for artist in ax.collections:\n",
" artist.remove()\n",
" polygon = ax.fill_between(x, zero, y[i], color='b', alpha=0.3)\n",
" points.set_ydata(y[i]) # update the data\n",
" points.set_label('Generation :' + str(i))\n",
Expand Down Expand Up @@ -513,13 +514,13 @@
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"source": [],
"metadata": {
"collapsed": false
}
},
"source": []
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
}
5 changes: 3 additions & 2 deletions examples/Tutorial_4_Symbolic_Regression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@
"\n",
"\n",
" def animate(i):\n",
" ax.collections.clear()\n",
" for artist in ax.collections:\n",
" artist.remove()\n",
" points.set_ydata(y[i].evaluate_equation_at(x)) # update the data\n",
" points.set_label('Generation :' + str(g[i]))\n",
" legend = ax.legend(loc='upper right')\n",
Expand Down Expand Up @@ -408,4 +409,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}

0 comments on commit ddb9dcc

Please sign in to comment.