22
22
import math
23
23
import numpy as np
24
24
import math
25
- import warnings
26
- from optimizer import Optimizer , FileManager , Randomizer
25
+ from optimizer import Optimizer , FileManager , Randomizer , logger
27
26
from numba import njit , jit
28
27
import scipy .stats as stats
29
28
@@ -202,7 +201,7 @@ def __init__(self,
202
201
self .num_particles = num_particles
203
202
204
203
if len (lower_bounds ) != len (upper_bounds ):
205
- warnings . warn (f"Warning: lower_bounds and upper_bounds have different lengths."
204
+ logger . warning (f"Warning: lower_bounds and upper_bounds have different lengths."
206
205
f"The lowest length ({ min (len (lower_bounds ), len (upper_bounds ))} ) is taken." )
207
206
self .num_params = min (len (lower_bounds ), len (upper_bounds ))
208
207
self .lower_bounds = lower_bounds
@@ -219,7 +218,7 @@ def __init__(self,
219
218
'spread' , 'lower_bounds' , 'upper_bounds' , 'random' , 'gaussian' }
220
219
221
220
if initial_particles_position == 'spread' :
222
- warnings . warn (f"Initial distribution set to 'random'." )
221
+ logger . warning (f"Initial distribution set to 'random'." )
223
222
initial_particles_position = 'random'
224
223
# self.spread_particles()
225
224
@@ -297,9 +296,9 @@ def check_types(self):
297
296
f"Upper bound { i } is not acceptable" )
298
297
299
298
if lb_types != ub_types :
300
- warnings . warn (
299
+ logger . warning (
301
300
"Warning: lower_bounds and upper_bounds are of different types" )
302
- warnings . warn ("Keeping the least restrictive type" )
301
+ logger . warning ("Keeping the least restrictive type" )
303
302
for i in range (self .num_params ):
304
303
if lb_types [i ] == float or ub_types [i ] == float :
305
304
self .lower_bounds [i ] = float (self .lower_bounds [i ])
@@ -329,16 +328,21 @@ def insert_nodes(self, param_list, is_bool=False):
329
328
return param_list
330
329
331
330
def get_nodes (self ):
332
- all_nodes = [[self .lower_bounds [idx ], self .upper_bounds [idx ]]
333
- for idx in range (self .num_params )]
331
+
332
+ def ndcube (* args ):
333
+ return list (itertools .product (* map (lambda x : [x [0 ], x [1 ]], args )))
334
+
335
+ bounds = list (zip (self .lower_bounds , self .upper_bounds ))
336
+ all_nodes = ndcube (* bounds )
337
+ print (len (all_nodes ))
338
+ exit ()
334
339
indices_with_bool = [idx for idx , node in enumerate (
335
340
all_nodes ) if any (isinstance (val , bool ) for val in node )]
336
341
all_nodes = [[2 if isinstance (val , bool ) and val else 0 if isinstance (
337
342
val , bool ) and not val else val for val in node ] for node in all_nodes ]
338
343
339
344
if self .num_particles < self .num_params :
340
- warnings .warn (f"Warning: not enough particles, now you are running with {
341
- len (all_nodes [0 ])} particles" )
345
+ logger .warning (f"Warning: not enough particles, now you are running with { len (all_nodes [0 ])} particles" )
342
346
343
347
particle_count = len (all_nodes [0 ])
344
348
while particle_count < self .num_particles :
0 commit comments