def run(settings, Iterations): size = settings['size'] nSensors = settings['nSensors'] nMotors = settings['nMotors'] # LOAD ISING CORRELATIONS # filename = 'correlations-ising2D-size400.npy' filename2 = 'correlations-ising-generalized-size83.npy' settings['Cdist'] = np.load(filename2) # --- POPULATE THE ENVIRONMENT WITH FOOD ---------------+ foods = [] for i in range(0, settings['food_num']): foods.append(food(settings)) # Food is only created uniformly distributed at the very beginning. # For a new iteration the placement of the food is kept. # --- POPULATE THE ENVIRONMENT WITH ORGANISMS ----------+ startstr = 'Starting simulation: (' + str(settings['TimeSteps']) + \ ' timesteps) x (' + str(Iterations) + ' iterations)' print(startstr) isings = [] for i in range(0, settings['pop_size']): isings.append( ising(settings, size, nSensors, nMotors, name='gen[0]-org[' + str(i) + ']')) # ------- Reinitialize isings -------- for i, I in enumerate(isings): if i < 25: I.species = 0 I.Beta = 1 if settings['isolated_populations']: I.isolated_population = 0 else: I.species = 1 I.Beta = 10 if settings['isolated_populations']: I.isolated_population = 1 #No critical learning: # CriticalLearning(isings, foods, settings, Iterations) sim_name, not_used_isings = EvolutionLearning(isings, foods, settings, Iterations) return sim_name
N = 64 Nsensors = 4 Nmotors = 2 size = N + Nsensors + Nmotors ind = 9 beta = 1 Iterations = 1000 T = 3600 visualize = True visualize = False I = ising(size, Nsensors, Nmotors) I.Beta = beta filename = 'files/network-size_' + str(size) + '-sensors_' + str( Nsensors) + '-motors_' + str(Nmotors) + '-T_' + str( T) + '-Iterations_' + str(Iterations) + '-ind_' + str(ind) + '.npz' directorio = '_' + str(size) + '_' + str(Nsensors) + '_' + str( Nmotors) + '_' + str(T) + '_' + str(Iterations) + '_' + str(ind) data = np.load(filename) I.h = data['h'] I.J = data['J'] p = np.zeros(T) s = np.zeros(T) m = np.zeros(T)
def run(settings, Iterations): size = settings['size'] nSensors = settings['nSensors'] nMotors = settings['nMotors'] # LOAD ISING CORRELATIONS # filename = 'correlations-ising2D-size400.npy' filename2 = 'correlations-ising-generalized-size83.npy' # This adds 13 MB to settings.pickle and we don't need it # settings['Cdist'] = np.load(filename2) # --- POPULATE THE ENVIRONMENT WITH FOOD ---------------+ foods = [] for i in range(0, settings['food_num']): foods.append(food(settings)) # Food is only created uniformly distributed at the very beginning. # For a new iteration the placement of the food is kept. if settings['beta_linspace'] is not None: settings['init_beta'] = beta_linspace(settings) # --- POPULATE THE ENVIRONMENT WITH ORGANISMS ----------+ try: set_isings = settings['set_isings'] except KeyError: set_isings = None try: change_beta_loaded_simulation = settings[ 'change_beta_loaded_simulation'] except KeyError: change_beta_loaded_simulation = None if set_isings is not None: isings = settings['set_isings'] elif settings['LoadIsings']: if not settings['switch_seasons_repeat_pipeline']: loadfile = 'save/' + settings['loadfile'] + '/isings/gen[' + str( settings['iter']) + ']-isings.pickle' else: loadfile = 'save/' + settings['loadfile'] + '/isings/gen[' + str( settings['iter']) + ']-isings.pickle' startstr = 'Loading simulation:' + loadfile + ' (' + str(settings['TimeSteps']) + \ ' timesteps) x (' + str(Iterations) + ' iterations)' if not settings['switch_seasons_repeat_pipeline']: prev_settings = load_settings(settings['loadfile']) #pop size of current simulation is taken from loaded simulation settings['pop_size'] = prev_settings['pop_size'] print(startstr) try: file = open(loadfile, 'rb') isings = pickle.load(file) file.close() except FileNotFoundError: # Looking for compressed ising file in case normal pickle file is not found isings = decompress_pickle(loadfile) if settings['speciation']: for I in isings: I.species = 0 I.shared_fitness = 0 if change_beta_loaded_simulation is not None: for I in isings: I.Beta = change_beta_loaded_simulation else: startstr = 'Starting simulation: (' + str(settings['TimeSteps']) + \ ' timesteps) x (' + str(Iterations) + ' iterations)' print(startstr) isings = [] for i in range(0, settings['pop_size']): isings.append( ising(settings, size, nSensors, nMotors, name='gen[0]-org[' + str(i) + ']')) if settings['beta_linspace_within_sim']: beta_linspace_within_sim(isings, settings) # --- CYCLE THROUGH EACH GENERATION --------------------+ # Choose between CriticalLearning (which has both inverse-ising and GA with toggle) # or EvolutionLearning which is only GA. The functions are fairly similar, should find a # better way to call them than this. # ------------------------------------------------------+ #No critical learning: # CriticalLearning(isings, foods, settings, Iterations) sim_name, not_used_isings = EvolutionLearning(isings, foods, settings, Iterations) return sim_name