How to use the deap.base function in deap

To help you get started, we’ve selected a few deap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kootenpv / xtoy / xtoy / evolutionary_search.py View on Github external
n_samples = _num_samples(X)
        X, y = indexable(X, y)

        if y is not None:
            if len(y) != n_samples:
                raise ValueError(
                    "Target variable (y) has a different number "
                    "of samples (%i) than data (X: %i samples)" % (len(y), n_samples)
                )
        cv = self.cv

        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=RuntimeWarning)
            #  * y.shape[1]
            creator.create("FitnessMax", base.Fitness, weights=(1.0,))
            creator.create(
                "Individual", list, est=clone(self.estimator), fitness=creator.FitnessMax
            )

        toolbox = base.Toolbox()

        name_values, gene_type, maxints = _get_param_types_maxint(parameter_dict)
        if self.gene_type is None:
            self.gene_type = gene_type

        if self.verbose:
            print("Types %s and maxint %s detected" % (self.gene_type, maxints))

        toolbox.register("individual", _initIndividual, creator.Individual, maxints=maxints)
        toolbox.register("population", tools.initRepeat, list, toolbox.individual)
github nilinswap / neuro-evolution / postmidsem / codes / main_folder / glass / main_bp_without_clustring.py View on Github external
from deap import algorithms
from deap import base
from deap import benchmarks
from deap.benchmarks.tools import diversity, convergence
from deap import creator
from deap import tools
import os
from population import *
from network import Neterr
from chromosome import Chromosome, crossover

n_hidden = 100
indim = 9
outdim = 7
network_obj = Neterr(indim, outdim, n_hidden, np.random)
creator.create("FitnessMin", base.Fitness, weights=(-1.0, -1.0, 0.0, 0.0))
creator.create("Individual", Chromosome, fitness=creator.FitnessMin)

toolbox = base.Toolbox()


def minimize(individual):
    outputarr = network_obj.feedforward_ne(individual)

    neg_log_likelihood_val = give_neg_log_likelihood(outputarr, network_obj.resty)
    mean_square_error_val = give_mse(outputarr, network_obj.resty)
    false_positve_rat = give_false_positive_ratio(outputarr, network_obj.resty)
    false_negative_rat = give_false_negative_ratio(outputarr, network_obj.resty)

    return neg_log_likelihood_val, mean_square_error_val, false_positve_rat, false_negative_rat
github nilinswap / neuro-evolution / main1_perc_nll_mse_misc_com.py View on Github external
from deap import tools
import os
from population import *
from network import Neterr
from chromosome import Chromosome, crossover
import traceback
n_hidden = 100
indim = 32
outdim = 5
#
network_obj_src = Neterr(indim, outdim, n_hidden, change_to_target = 0, rng = random)

network_obj_tar = Neterr(indim, outdim, n_hidden,change_to_target = 1, rng = random)
#creator.create("FitnessMin", base.Fitness, weights=(-1.0, -1.0, 0.0, 0.0))

creator.create("FitnessMin", base.Fitness, weights=(-1.0, -1.0, -1.0, -1.0))
creator.create("Individual", Chromosome, fitness=creator.FitnessMin)
print("here network object created")
toolbox = base.Toolbox()

def minimize_src(individual):
	outputarr = network_obj_src.feedforward_ne(individual, final_activation=network.softmax)

	neg_log_likelihood_val = give_neg_log_likelihood(outputarr, network_obj_src.resty)
	mean_square_error_val = give_mse(outputarr, network_obj_src.resty)
	mis_error = find_misclas_error(outputarr, network_obj_src.resty)
	complexity = lambda ind: len(ind.conn_arr)
	ind_complexity = complexity(individual)
	# anyways not using these as you can see in 'creator.create("FitnessMin", base.Fitness, weights=(-1.0, -1.0, 0.0, 0.0))'
	# return neg_log_likelihood_val, mean_square_error_val, false_positve_rat, false_negative_rat
	return (neg_log_likelihood_val, mean_square_error_val, mis_error, ind_complexity)
github DEAP / deap / examples / ga / ga_onemax_numpy.py View on Github external
**Keywords:** bit string, minimization, :class:`numpy.ndarray`
"""

import numpy
import random

from deap import algorithms
from deap import base
from deap import creator
from deap import tools

creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", numpy.ndarray, fitness=creator.FitnessMax)

toolbox = base.Toolbox()

toolbox.register("attr_bool", random.randint, 0, 1)
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_bool, n=100)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)

def evalOneMax(individual):
    return sum(individual),

toolbox.register("evaluate", evalOneMax)
toolbox.register("mate", tools.cxTwoPoints)
toolbox.register("mutate", tools.mutFlipBit, indpb=0.05)
toolbox.register("select", tools.selTournament, tournsize=3)

def main():
    random.seed(64)
github lumy / EternityII / puzzle.py View on Github external
def dynamique_type():
    """
      Static Method. Create dynamique Type used by deap.
      This method needs to be called before any loading file.

      Create static type:

      - FitnessInd
      - FitnessGroup
      - Individual

      Can be found at ```deap.creator.FitnessInd``` or \
      ```deap.creator.Individual```
    """
    creator.create("FitnessInd", base.Fitness, weights=(1,))
    creator.create("FitnessGroup", base.Fitness, weights=(1,))
    creator.create("Individual", Ind, fitness_ind=creator.FitnessInd, fitness_group=creator.FitnessGroup)
github ContinuumIO / elm / iamlp / model_averaging / kmeans.py View on Github external
def pareto_front(objectives, centroids, take, weights):
    creator.create("FitnessMulti", base.Fitness, weights=weights)
    creator.create("Individual", array.array, typecode='d', fitness=creator.FitnessMulti)
    toolbox.register('evaluate', lambda x: x)
    objectives = [creator.Individual(objectives[idx, :]) for idx in range(objectives.shape[0])]
    objectives2 = []
    for (idx, (obj, cen)) in enumerate(zip(objectives, centroids)):
        obj.idx = idx
        obj.cen = cen
        obj.fitness.values = toolbox.evaluate(obj)
    sel = selNSGA2(objectives, take)
    return tuple((item.cen, item.idx) for item in sel)
github DEAP / deap / doc / code / tutorials / part_2 / 2_1_fitness.py View on Github external
## 2.1 Fitness
from deap import base
from deap import creator

## FitnessMin
creator.create("FitnessMin", base.Fitness, weights=(-1.0,))

## FitnessMulti
creator.create("FitnessMulti", base.Fitness, weights=(-1.0, 1.0))
github nilinswap / neuro-evolution / main / codes / others / pilot2 / main1.py View on Github external
from deap import algorithms
from deap import base
from deap import benchmarks
from deap.benchmarks.tools import diversity, convergence
from deap import creator
from deap import tools
import os
from population import *
from network import Neterr
from chromosome import Chromosome, crossover

n_hidden = 100
indim = 8
outdim = 2
network_obj = Neterr(indim, outdim, n_hidden, np.random)
creator.create("FitnessMin", base.Fitness, weights=(-1.0, -1.0, 0.0, 0.0))
creator.create("Individual", Chromosome, fitness=creator.FitnessMin)

toolbox = base.Toolbox()


def minimize(individual):
    outputarr = network_obj.feedforward_ne(individual)

    neg_log_likelihood_val = give_neg_log_likelihood(outputarr, network_obj.resty)
    mean_square_error_val = give_mse(outputarr, network_obj.resty)
    false_positve_rat = give_false_positive_ratio(outputarr, network_obj.resty)
    false_negative_rat = give_false_negative_ratio(outputarr, network_obj.resty)

    return neg_log_likelihood_val, mean_square_error_val, false_positve_rat, false_negative_rat
github insilichem / gaudi / hyde6.py View on Github external
ind1_1[cxpoint:], ind2_1[cxpoint:] = ind2_1[cxpoint:], ind1_1[cxpoint:]

	ind1[:] = ind1_0 + ind1_1
	ind2[:] = ind2_0 + ind2_1

	return ind1, ind2


###
# Genetic Algorithm
####
# define individual, population, etc
deap.creator.create("FitnessMax", deap.base.Fitness, weights=(1.0, -1.0, -1.0))
deap.creator.create("Individual", list, fitness=deap.creator.FitnessMax)

toolbox = deap.base.Toolbox()
toolbox.register("rand_angle", random.randint, 0, 359)
toolbox.register("rand_rotamer", random.randint, 0, 8)
toolbox.register("individual", deap.tools.initCycle, 
	deap.creator.Individual, [toolbox.rand_angle] * len(bonds) + 
		[toolbox.rand_rotamer] * len(residues), n=1)
toolbox.register("population", deap.tools.initRepeat, 
	list, toolbox.individual)

LOW_BOUND = [0]*(len(bonds)+len(residues))
UP_BOUND = [360]*len(bonds) + [8]*len(residues)

toolbox.register("evaluate", evalCoord)
toolbox.register("mate", hetCxOnePoint, bound=len(bonds))
toolbox.register("mutate", deap.tools.mutPolynomialBounded,
	eta = 20.0, low = LOW_BOUND, up = UP_BOUND, indpb=0.05)
toolbox.register("select", deap.tools.selNSGA2)
github ronpandolfi / Xi-cam / xicam / plugins / cdsaxs_rsoxs / __init__.py View on Github external
import os, sys, time
import cdrsoxs, fitting, simulation
import pyqtgraph as pg
import numpy as np
from xicam.plugins import base, widgets
from xicam import threads
from modpkgs import guiinvoker
from functools import partial
from PySide import QtGui, QtCore
import multiprocessing
import deap.base as deap_base
import deap.base as deap_base
from deap import creator
from scipy import interpolate

creator.create('FitnessMin', deap_base.Fitness, weights=(-1.0,))  # want to minimize fitness
creator.create('Individual', list, fitness=creator.FitnessMin)

class plugin(base.plugin):
    name = "CDSOXS"

    def __init__(self, *args, **kwargs):

        self.centerwidget = QtGui.QTabWidget()
        self.rightwidget = self.parametertree = pg.parametertree.ParameterTree()
        self.topwidget = QtGui.QTabWidget()
        self.centerwidget.setDocumentMode(True)
        self.centerwidget.setTabsClosable(True)
        self.centerwidget.tabCloseRequested.connect(self.tabClose)
        self.centerwidget.currentChanged.connect(self.currentChanged)
        self.bottomwidget = CDLineProfileWidget()