Changeset 1138 for framspy/evolalg
- Timestamp:
- 05/01/21 22:32:21 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/evolalg/examples/niching_novelty.py
r1137 r1138 64 64 help='Dissimilarity measure, default = frams', choices=list(Dissim)) 65 65 parser.add_argument('-fit', required=False, default=Fitness.raw, type=Fitness, 66 help=' Fitness criteria DEFAULT= raw', choices=list(Fitness))66 help=' Fitness criteria, default = raw', choices=list(Fitness)) 67 67 parser.add_argument('-popsize', type=int, default=50, help="Population size, default 50.") 68 68 parser.add_argument('-generations', type=int, default=5, help="Number of generations, default 5.") 69 69 parser.add_argument('-tournament', type=int, default=5, help="Tournament size, default 5.") 70 parser.add_argument('-num_parts', type=int, default=None, help="Maximum number of Parts. Default: no limit") 70 71 parser.add_argument('-max_numparts', type=int, default=None, help="Maximum number of Parts. Default: no limit") 72 parser.add_argument('-max_numjoints', type=int, default=None, help="Maximum number of Joints. Default: no limit") 73 parser.add_argument('-max_numneurons', type=int, default=None, help="Maximum number of Neurons. Default: no limit") 74 parser.add_argument('-max_numconnections', type=int, default=None, help="Maximum number of Neural connections. Default: no limit") 75 71 76 parser.add_argument('-checkpoint_path', required=False, default=None, help="Path to the checkpoint file") 72 77 parser.add_argument('-checkpoint_interval', required=False, type=int, default=100, help="Checkpoint interval") … … 83 88 84 89 85 class NumParts Greater(Remove):86 def __init__(self, numparts):87 super(NumParts Greater, self).__init__()88 self. numparts = numparts90 class NumPartsHigher(Remove): 91 def __init__(self, max_number): 92 super(NumPartsHigher, self).__init__() 93 self.max_number = max_number 89 94 90 95 def remove(self, individual): 91 return individual.numparts > self.numparts 96 return individual.numparts > self.max_number 97 98 99 class NumJointsHigher(Remove): 100 def __init__(self, max_number): 101 super(NumJointsHigher, self).__init__() 102 self.max_number = max_number 103 104 def remove(self, individual): 105 return individual.numjoints > self.max_number 106 107 108 class NumNeuronsHigher(Remove): 109 def __init__(self, max_number): 110 super(NumNeuronsHigher, self).__init__() 111 self.max_number = max_number 112 113 def remove(self, individual): 114 return individual.numneurons > self.max_number 115 116 117 class NumConnectionsHigher(Remove): 118 def __init__(self, max_number): 119 super(NumConnectionsHigher, self).__init__() 120 self.max_number = max_number 121 122 def remove(self, individual): 123 return individual.numconnections > self.max_number 92 124 93 125 … … 110 142 def create_experiment(): 111 143 parsed_args = parseArguments() 112 frams = FramsticksLib(parsed_args.path, parsed_args.lib,144 frams_lib = FramsticksLib(parsed_args.path, parsed_args.lib, 113 145 parsed_args.sim) 114 146 # Steps for generating first population 115 147 init_stages = [ 116 FramsPopulation(frams , parsed_args.genformat, parsed_args.popsize)148 FramsPopulation(frams_lib, parsed_args.genformat, parsed_args.popsize) 117 149 ] 118 150 … … 123 155 # Procedure for generating new population. This steps will be run as long there is less than 124 156 # popsize individuals in the new population 125 new_generation_stages = [FramsCrossAndMutate(frams , cross_prob=0.2, mutate_prob=0.9)]157 new_generation_stages = [FramsCrossAndMutate(frams_lib, cross_prob=0.2, mutate_prob=0.9)] 126 158 127 159 # Steps after new population is created. Executed exacly once per generation. … … 131 163 # Fitness 132 164 133 fitness_raw = FitnessStep(frams, fields={parsed_args.opt: "fitness_raw", "numparts": "numparts"}, 134 fields_defaults={parsed_args.opt: None, "numparts": float("inf")}, 165 fitness_raw = FitnessStep(frams_lib, fields={parsed_args.opt: "fitness_raw", 166 "numparts": "numparts", 167 "numjoints": "numjoints", 168 "numneurons": "numneurons", 169 "numconnections": "numconnections"}, 170 fields_defaults={parsed_args.opt: None, "numparts": float("inf"), 171 "numjoints": float("inf"), "numneurons": float("inf"), 172 "numconnections": float("inf")}, 135 173 evaluation_count=1) 136 174 137 fitness_end = FitnessStep(frams , fields={parsed_args.opt: "fitness_raw"},175 fitness_end = FitnessStep(frams_lib, fields={parsed_args.opt: "fitness_raw"}, 138 176 fields_defaults={parsed_args.opt: None}, 139 177 evaluation_count=100) # evaluate the contents of the last population 100 times (TODO replace this approach and evaluate HOF instead of the last population) … … 141 179 remove = [] 142 180 remove.append(FieldRemove("fitness_raw", None)) # Remove individuals if they have default value for fitness 143 if parsed_args.num_parts is not None: 144 # This could be also implemented by "LambdaRemove(lambda x: x.numparts > parsed_args.num_parts) 145 # But this will not serialize in checkpoint. 146 remove.append(NumPartsGreater(parsed_args.num_parts)) 181 if parsed_args.max_numparts is not None: 182 # This could be also implemented by "LambdaRemove(lambda x: x.numparts > parsed_args.num_parts)" 183 # But this would not serialize in checkpoint. 184 remove.append(NumPartsHigher(parsed_args.max_numparts)) 185 if parsed_args.max_numjoints is not None: 186 remove.append(NumJointsHigher(parsed_args.max_numjoints)) 187 if parsed_args.max_numneurons is not None: 188 remove.append(NumNeuronsHigher(parsed_args.max_numneurons)) 189 if parsed_args.max_numconnections is not None: 190 remove.append(NumConnectionsHigher(parsed_args.max_numconnections)) 191 147 192 remove_step = UnionStep(remove) 148 193 … … 158 203 dissim = LevenshteinDissimilarity(reduction="mean", output_field="dissim") 159 204 elif parsed_args.dissim == Dissim.frams: 160 dissim = FramsDissimilarity(frams , reduction="mean", output_field="dissim")205 dissim = FramsDissimilarity(frams_lib, reduction="mean", output_field="dissim") 161 206 162 207 if parsed_args.fit == Fitness.raw:
Note: See TracChangeset
for help on using the changeset viewer.