Esempio n. 1
0
def calculateFitnessLine(em: EvolutionModel, framsCLI: FramsticksCLI,
                         num_points: int, magnitude: float):
    zero_point = em.means
    #direction = np.random.multivariate_normal(em.means_mut, em.cov * magnitude, size=1)[0]
    direction = (np.random.rand(em.config['cells'] * 2) - 0.5) * 2
    direction /= np.linalg.norm(direction, ord=2)
    direction *= magnitude

    all_points = np.array([
        zero_point + direction * (i - num_points)
        for i in range(2 * num_points)
    ])

    frams = em.decode_latents(all_points)
    # print(frams)
    validity = framsCLI.isValid([em.config['prefix'] + fram for fram in frams],
                                '')
    frams_inds = [
        (fram, ind)
        for fram, valid, ind in zip(frams, validity, range(len(frams)))
        if valid
    ]
    validLen = len(frams)
    print("Valid points: " + str(validLen))
    frams = [fram for fram, ind in frams_inds]
    inds = [ind for fram, ind in frams_inds]
    eval_result = framsCLI.evaluate(
        tuple(prep_genos(frams, em.config['representation'])))
    fitness, bad_mutants_temp, good_inds = extractFitnesses(
        eval_result, list(range(len(frams))))
    frams = [fram for i, fram in enumerate(frams) if i in good_inds]
    inds = [ind for i, ind in enumerate(inds) if i in good_inds]
    frams_fitn = list(zip(frams, fitness))
    # print(frams_fitn)
    return inds, fitness
def checkValidity(genos, howMany, config):
    framsCLI = FramsticksCLI('C:/Users/Piotr/Desktop/Framsticks50rc17', None)

    total_acc, xs, accs, ys = get_Accs(genos, howMany, framsCLI, config)

    framsCLI.closeFramsticksCLI()

    return total_acc, xs, accs, ys
Esempio n. 3
0
 def createCLI(self, level=0):
     self.pid_version += 1
     if level > 20:
         raise ConnectionError("FramsCLI recursion over 20")
     try:
         if self.framsCLI is not None and level < 10:
             self.framsCLI.closeFramsticksCLI()
         framsCLId = FramsticksCLI(self.config['frams_path'], None if 'framsexe' not in self.config else self.config['framsexe'],
                                   pid=self.config['model_name'] + "_" + str(level) + (
                                       '' if 'pid_extension' not in self.config else self.config['pid_extension']) +
                                    "_" + self.pid_extra_extension + "_" + str(self.pid_version),
                                   importSim=self.config['importSim'], markers=self.config['markers'], config=self.config)
         print("OK_CORRECTLY CREATED__", level)
     except Exception as e:
         self.createCLI(level=level + 1)
         return
     self.framsCLI = framsCLId
     self.framsCLI.invalidCnt = self.invalidCnt
     self.framsCLI.validCnt = self.validCnt
     self.framsCLI.em = self
     if self.config['locality_type'] == 'dissim' or self.config['locality_type'] == 'fitness':
         self.dissimilarity = self.framsCLI.dissimilarity
     elif self.config['locality_type'] == 'levens':
         self.dissimilarity = dissimilarity_lev
     else:
         self.dissimilarity = dissimilarity_rand
def get_mutants_f9(framsCLI: FramsticksCLI,
                   evolutionModel,
                   centroid,
                   times,
                   diversity,
                   level=0):
    mutants = []
    while len(mutants) < times:
        mutant = prep_genos([centroid],
                            repr=evolutionModel.config['representation'])[0]
        for i in range(diversity):
            mutant = framsCLI.mutate(mutant)
        mutants.append(mutant)
    return mutants
def mutateF(framsCLI: FramsticksCLI,
            evolutionModel,
            centroid,
            times,
            diversity,
            level=0):
    try:
        return framsCLI.ask_for_genos(
            prep_genos([centroid],
                       repr=evolutionModel.config['representation']), times,
            diversity, 30)
    except:
        print('mutateF error level: ', level)
        return mutateF(framsCLI, evolutionModel, centroid, times, diversity,
                       level + 1)
Esempio n. 6
0
 def createCLI(self, level=0):
     if level > 20:
         raise ConnectionError("FramsCLI recursion over 20")
     try:
         if self.framsCLI is not None and level < 10:
             self.framsCLI.closeFramsticksCLI()
         framsCLId = FramsticksCLI(self.config['frams_path'], None if 'framsexe' not in self.config else self.config['framsexe'],
                                   pid=self.config['model_name'] + "_"+ str(level) + (
                                       '' if 'pid_extension' not in self.config else self.config['pid_extension']),
                                   importSim=self.config['importSim'], markers=self.config['markers'], config=self.config)
         print("OK_CORRECTLY CREATED__", level)
     except Exception as e:
         self.createCLI(level=level + 1)
         return
     self.framsCLI = framsCLId
     self.framsCLI.invalidCnt = self.invalidCnt
     self.framsCLI.validCnt = self.validCnt
     self.framsCLI.em = self
Esempio n. 7
0
def createCLI(config, oldCLI=None, level=0):
    if level > 20:
        raise ConnectionError("FramsCLI recursion over 20")
    try:
        if oldCLI is not None:
            importSim = oldCLI.importSim
            markers = oldCLI.markers
        else:
            importSim = config['importSim']
            markers = config['markers']
        if oldCLI is not None and level < 10:
            oldCLI.closeFramsticksCLI()
        framsCLId = FramsticksCLI(
            config['frams_path'],
            None if 'framsexe' not in config else config['framsexe'],
            pid=config['model_name'] + str(level) +
            ('' if 'pid_extension' not in config else config['pid_extension']),
            importSim=importSim,
            markers=markers,
            config=config)
        print("OK_CORRECTLY CREATED__", level)
    except:
        return createCLI(config, oldCLI, level=level + 1)
    return framsCLId
Esempio n. 8
0
 def ask_for_genos(self, starting_genos, generate_size, diversity, timeout=None):
     chosen_cli = self.find_not_busy()
     f = lambda cli_handler: FramsticksCLI.ask_for_genos(cli_handler.framsCLI,starting_genos, generate_size, diversity, timeout)
     # cli_f = partial(FramsticksCLI.ask_for_genos, chosen_cli, starting_genos, generate_size, diversity, timeout)
     return self.e.submit(clihandler_runf, chosen_cli, f, self.lock)
Esempio n. 9
0
 def get_simplest(self, genetic_format):
     chosen_cli = self.find_not_busy()
     f = lambda cli_handler : FramsticksCLI.getSimplest(cli_handler.framsCLI, genetic_format)
     # cli_f = partial(f, chosen_cli, genetic_format)
     return self.e.submit(clihandler_runf, chosen_cli, f, self.lock)