- Timestamp:
- 08/03/21 14:00:12 (3 years ago)
- Location:
- framspy
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/evolalg/base/union_step.py
r1139 r1146 12 12 self.steps = [steps] 13 13 14 def init(self): 15 for s in self.steps: 16 if isinstance(s, Step): 17 s.init() 18 14 19 def call(self, population): 15 20 super(UnionStep, self).call(population) -
framspy/evolalg/examples/niching_novelty.py
r1145 r1146 141 141 142 142 143 def func_raw(ind): setattr(ind, "fitness", ind.fitness_raw) 144 145 146 def func_novelty(ind): setattr(ind, "fitness", ind.dissim) 147 148 149 def func_knn_novelty(ind): setattr(ind, "fitness", ind.dissim) 150 151 143 152 def func_niching(ind): setattr(ind, "fitness", ind.fitness_raw * (1 + ind.dissim)) 144 145 146 def func_raw(ind): setattr(ind, "fitness", ind.fitness_raw)147 148 149 def func_novelty(ind): setattr(ind, "fitness", ind.dissim)150 151 152 def func_knn_novelty(ind): setattr(ind, "fitness", ind.dissim)153 153 154 154 … … 180 180 new_generation_stages = [FramsCrossAndMutate(frams_lib, cross_prob=0.2, mutate_prob=0.9)] 181 181 182 # Steps after new population is created. Executed exac ly once per generation.182 # Steps after new population is created. Executed exactly once per generation. 183 183 generation_modifications = [] 184 184 … … 245 245 generation_modifications.append(raw) 246 246 247 if parsed_args.fit == Fitness.niching: 247 if parsed_args.fit == Fitness.niching: # TODO reduce redundancy in the four cases below: dictionary? 248 248 niching = UnionStep([ 249 249 dissim, … … 297 297 298 298 # ------------------------------------------------- 299 # End stages: this will execute exac ly once after all generations.299 # End stages: this will execute exactly once after all generations. 300 300 end_stages = [ 301 301 replace_with_hof, -
framspy/evolalg/examples/standard.py
r1140 r1146 8 8 # TODO add comments to all examples in this directory 9 9 # TODO add to standard.py and steadystate.py evaluating each genotype in HOF N (configurable, default 20) times when the evolution ends, as it is in niching_novelty.py 10 # TODO "- -debug" mode, indent nested steps (pre++, post-- of a static counter?) and print their arguments so it is easy to see what happens during evolution10 # TODO "-debug" mode, indent nested steps (pre++, post-- of a static counter?) and print their arguments so it is easy to see what happens during evolution 11 11 12 12 … … 80 80 ]) 81 81 82 fitness_remove = UnionStep( 82 fitness_remove = UnionStep( # evaluate performance and fitness, rename some of the fields, and remove some performance fields that we get from Framsticks, but we don't need them here 83 83 [ 84 84 FitnessStep(frams_lib, fields={"velocity": "fitness", "data->recording": "recording"}, 85 85 fields_defaults={"velocity": None, "data->recording": None}) # custom definitions and handling 86 86 if EVAL_LIFESPAN_BEHAVIOR else 87 FitnessStep(frams_lib, fields={parsed_args.opt: "fitness" ,}, fields_defaults={parsed_args.opt: None})87 FitnessStep(frams_lib, fields={parsed_args.opt: "fitness"}, fields_defaults={parsed_args.opt: None}) 88 88 ] 89 89 + -
framspy/evolalg/statistics/statistics_deap.py
r1139 r1146 26 26 if self.verbose: 27 27 print(self.logbook.stream) 28 29 def compile(self, data): 30 return self.stats.compile(data) 31 32 -
framspy/frams.py
r1141 r1146 14 14 15 15 For sample usage, see frams-test.py and FramsticksLib.py. 16 17 If you want to run many independent instances of this class in parallel, use the "multiprocessing" module and then each process 18 that uses this module will initialize it and get access to a separate instance of the Framsticks library. 16 19 17 20 For interfaces in other languages (e.g. using the Framsticks library in your C++ code), see ../cpp/frams/frams-objects.h … … 285 288 286 289 original_dir = os.getcwd() 287 os.chdir(lib_path) # because under Windows, frams-objects.dll requires other dll's which reside in the same directory, so we must change current dir for them to be found while loading the main dll 290 os.chdir(lib_path) # because under Windows, frams-objects.dll requires other dll's which reside in the same directory, so we must change current dir for them to be found while loading the main dll. 291 # TODO in python 3.8+ and Windows, use os.add_dll_directory(lib_path) instead of os.chdir()? And maybe for linux we no longer need chdir() and "./", but use absolute path? 288 292 abs_data = os.path.abspath('data') # use absolute path for -d and -D so python is free to cd anywhere without confusing Framsticks 289 293 # for the hypothetical case without lib_path the abs_data must be obtained from somewhere else … … 298 302 global c_api # access global variable 299 303 if lib_path is not None and os.name == 'posix': 300 lib_name = './' + lib_name # currently we always have lib_path (even if it is incorrect) but hypothetically it could work with lib_path==None andload .so from some default system path without './'304 lib_name = './' + lib_name # currently we always have lib_path (even if it is incorrect), but hypothetically it could work with lib_path==None and then load .so from some default system path without './' 301 305 try: 302 c_api = ctypes.CDLL(lib_name) # should be a separate instance and no globals if we want multiple threads to use this module (todo?)306 c_api = ctypes.CDLL(lib_name) # if accessing this module from multiple threads, they will all share a single c_api and access the same copy of the library and its data. If you want separate independent copies, read the comment at the top of this file on using the "multiprocessing" module. 303 307 except OSError as e: 304 308 print("*** Could not find or open '%s' from '%s'.\n*** Did you provide proper arguments and is this file readable?\n" % (lib_name, os.getcwd()))
Note: See TracChangeset
for help on using the changeset viewer.