Example #1
0
 def fitnessFunction(self, individual, lambda_):
     if self.functionType_ != "gpTSNE":
         return super().fitnessFunction(individual, lambda_)
     else:
         fitness = evalTSNEMO(self.data_t, self.toolbox, individual)
         return self.skew_fitness(fitness, lambda_)
Example #2
0
def eval_pso(gp_ind, ephemerals_indxs, toolbox, data_t, reference, ind):
    update_ercs(ephemerals_indxs, gp_ind, ind, reference)
    return evalTSNEMO(data_t, toolbox, gp_ind)
Example #3
0
    creator.create("FitnessMin", base.Fitness, weights=(-1.0,) * tsnedata.nobj)
    creator.create("Individual", list, fitness=creator.FitnessMin, pset=pset)
    toolbox = ParallelToolbox()
    toolbox.register("compile", gp.compile, pset=pset)
    toolbox.register("evaluate", evalTSNEMO, tsnedata.data_t, toolbox)
    tree1 = from_string_np_terms(tree_1_str, pset)
    tree2 = from_string_np_terms(tree_2_str, pset)
    print(str(tree1))
    print(str(tree2))
    ind = creator.Individual([tree1, tree2])
    print(ind)

    tsnedata.fitnessCache = cachetools.LRUCache(maxsize=1e6)
    tsnedata.outdir = args.outdir
    tsnedata.dataset = args.dataset
    tsnedata.degrees_of_freedom = max(num_trees - 1, 1)
    tsnedata._DOF = (tsnedata.degrees_of_freedom + 1.0) / -2.0
    dists = t_sne.pairwise_distances(data, metric="euclidean", squared=True)
    tsnedata.P_tsne = t_sne._joint_probabilities(dists, perplexity, verbose=True)
    tsnedata.max_P_tsne = np.maximum(tsnedata.P_tsne, MACHINE_EPSILON)

    best, reference = do_pso(ind, toolbox, tsnedata.data_t, args.gens)
    print(best)
    # We still want to output ones that have no constants (even though the vals didn't change!)
    if best is not None:
        ephemerals_indxs = collect_ephemeral_indices(ind)  # [(0,5),....(1,4),...]
        update_ercs(ephemerals_indxs, ind, best, reference)
        ind.fitness.setValues(evalTSNEMO(tsnedata.data_t, toolbox, ind))
    output_ind(ind, toolbox, tsnedata, suffix="-pso", compress=False)
Example #4
0
def eval_cmaes(gp_ind, ephemerals_indxs, toolbox, data_t, ind):
    # ind is a list here.
    update_ercs(ephemerals_indxs, gp_ind, ind)

    return evalTSNEMO(data_t, toolbox, gp_ind)
Example #5
0
        output_ind(res, toolbox, tsnedata, compress=False)

    p = Path(tsnedata.outdir, args.logfile + '.gz')
    with gz.open(p, 'wt') as file:
        file.write(str(logbook))

    pop_stats = [str(p.fitness) for p in pop]
    pop_stats.sort()
    hof_stats = [str(h.fitness) for h in hof]

    # hof_stats.sort()
    print("POP:")
    print("\n".join(pop_stats))

    print("PF:")
    print("\n".join(hof_stats))

    # do it all after so if it's too slow at least the above is outputted already
    if post_cmaes:
        for res in hof:
            cmaes_res = do_pso(res, toolbox, tsnedata.data_t, 1000)
            if cmaes_res:  # since this is just the vector of consts...
                ephemerals_indxs = collect_ephemeral_indices(
                    res)  # [(0,5),....(1,4),...]
                for index, val in enumerate(cmaes_res):
                    ep_indx = ephemerals_indxs[index]
                    res[ep_indx[0]][ep_indx[1]].value = val
                res.fitness.setValues(evalTSNEMO(tsnedata.data_t, toolbox,
                                                 res))
            output_ind(res, toolbox, tsnedata, "-pso")