Skip to content

Commit 20140d9

Browse files
author
Ezequiel Torres
committed
Fix in ExperimentInProgress when closing
1 parent db66f98 commit 20140d9

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed

MLC/GUI/Experiment/ExperimentInProgress.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def __init__(self, parent, parent_signal, chart_params, from_gen, to_gen):
151151

152152
def closeEvent(self, event):
153153
logger.debug('[EXPERIMENT_IN_PROGRESS] [CLOSE_DIALOG] - Executing overriden closeEvent function')
154+
logger.debug('TUVIEJAAA: {0}'.format(self._simulation_has_finished))
154155
if not self._simulation_has_finished:
155156
if not self.on_cancel_button_clicked():
156157
event.ignore()
@@ -202,9 +203,12 @@ def _update_dialog(self, indivs_per_gen_counter, total_indivs_counter, gen_count
202203

203204
def _simulation_finished(self):
204205
logger.debug('{0} [SIM_FINISHED] - Executing _simulation_finished function'.format(self._log_prefix))
206+
self._simulation_has_finished = True
207+
# Set the MainWindow to invisible to not see the it after press 'Yes'
208+
self.setVisible(False)
209+
205210
self._parent_signal.emit(self._experiment_condition.experiment_cancelled(),
206211
self._experiment_condition.experiment_failure())
207-
self._simulation_has_finished = True
208212
self.close()
209213

210214
def _update_current_gen_experiment(self, indiv_index, cost):
@@ -377,7 +381,6 @@ def simulation_started(self):
377381
def simulation_finished(self):
378382
logger.debug('{0} [SIM_FINISHED] - Executing simulation_finished function'.format(self._log_prefix))
379383
self._dialog.simulation_finished.emit()
380-
self._dialog.close()
381384

382385
def _check_if_project_stopped_or_cancelled(self):
383386
self._experiment_condition.wait_if_experiment_stopped()
60.2 KB
Loading

templates/toy_problem.py

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import numpy as np
2525
import MLC.Log.log as lg
2626
import matplotlib.pyplot as plt
27+
import random
2728
import sys
2829
import time
2930

@@ -32,26 +33,13 @@
3233

3334

3435
def individual_data(indiv):
35-
x = np.linspace(-10.0, 10.0, num=201)
36+
SAMPLES = 201
37+
x = np.linspace(-10.0, 10.0, num=SAMPLES)
3638
y = np.tanh(x**3 - x**2 - 1)
3739

38-
# FIXME: Added timeout to visualize
39-
# time.sleep(0.5)
40-
4140
config = Config.get_instance()
42-
# artificial_noise = self._config.getint('EVALUATOR', 'artificialnoise')
43-
44-
# In this test we have no noise by config file. But, if this were the
45-
# case, we would a have problem because the random of MATLAB is not
46-
# the random of Python :(
47-
# WORKAROUND: Generate the noise in matlab and process it in python
48-
49-
# MAKE SOME NOISE!!!
50-
# noise = eng.eval('rand(length(zeros(1, ' + str(len(x)) + ')))-0.5')
51-
# np_noise = np.array([s for s in noise[0]])
52-
# y2 = y + np_noise * 500 * artificial_noise
53-
54-
y2 = y
41+
artificial_noise = config.getint('EVALUATOR', 'artificialnoise')
42+
y_with_noise = y + [random.random() - 0.5 for _ in xrange(SAMPLES)] + artificial_noise * 500
5543

5644
if isinstance(indiv.get_formal(), str):
5745
formal = indiv.get_formal().replace('S0', 'x')
@@ -61,35 +49,33 @@ def individual_data(indiv):
6149

6250
# Calculate J like the sum of the square difference of the
6351
# functions in every point
64-
6552
lg.logger_.debug('[POP][TOY_PROBLEM] Individual Formal: ' + formal)
66-
mlc_y3 = indiv.get_tree().calculate_expression([x])
53+
b = indiv.get_tree().calculate_expression([x])
6754

6855
# If the expression doesn't have the term 'x',
6956
# the eval returns a value (float) instead of an array.
7057
# In that case transform it to an array
71-
if type(mlc_y3) == float:
72-
mlc_y3 = np.repeat(mlc_y3, len(x))
58+
if type(b) == float:
59+
b = np.repeat(b, SAMPLES)
7360

74-
return x, y, y2, mlc_y3
61+
return x, y, y_with_noise, b
7562

7663

7764
def cost(indiv):
78-
x, y, y2, mlc_y3 = individual_data(indiv)
65+
x, y, y_with_noise, b = individual_data(indiv)
7966

80-
# Deactivate the numpy warnings, because this sum raise an overflow
67+
# Deactivate the numpy warnings, because this sum could raise an overflow
8168
# Runtime warning from time to time
8269
np.seterr(all='ignore')
83-
cost_mlc_y3 = float(np.sum((mlc_y3 - y2)**2))
70+
cost_value = float(np.sum((b - y_with_noise)**2))
8471
np.seterr(all='warn')
8572

86-
return cost_mlc_y3
73+
return cost_value
8774

8875

8976
def show_best(index, generation, indiv, cost, block=True):
90-
x, y, y2, mlc_y3 = individual_data(indiv)
91-
# FIXME: Absolute only makes sense if we're working with complex numbers. It's not the case...
92-
y4 = np.sqrt((y - mlc_y3)**2 / (1 + np.absolute(x**2)))
77+
x, y, y_with_noise, b = individual_data(indiv)
78+
cuadratic_error = np.sqrt((y_with_noise - b)**2 / (1 + np.absolute(x**2)))
9379

9480
fig = plt.figure()
9581
# Put figure window on top of all other windows
@@ -101,9 +87,9 @@ def show_best(index, generation, indiv, cost, block=True):
10187
cost,
10288
indiv.get_formal()))
10389
plt.subplot(2, 1, 1)
104-
plt.plot(x, y, x, y2, '*', x, mlc_y3)
90+
plt.plot(x, y, x, y_with_noise, '*', x, b)
10591

10692
plt.subplot(2, 1, 2)
107-
plt.plot(x, y4, '*r')
93+
plt.plot(x, cuadratic_error, '*r')
10894
plt.yscale('log')
10995
plt.show(block=block)

0 commit comments

Comments
 (0)