def de(output_basename, parameter_names, transform, loglikelihood, prior, nsteps=<NUM_LIT>, vizfunc=None, printfunc=None, **problem):
import json<EOL>import inspyred<EOL>import random<EOL>prng = random.Random()<EOL>if '<STR_LIT>' in problem:<EOL><INDENT>prng.seed(problem['<STR_LIT>'])<EOL><DEDENT>n_params = len(parameter_names)<EOL>seeds = problem.get('<STR_LIT>', [])<EOL>if '<STR_LIT:start>' in problem:<EOL><INDENT>seeds.append(problem['<STR_LIT:start>'])<EOL><DEDENT>prefix = output_basename<EOL>def viz(candidate, args):<EOL><INDENT>if vizfunc is not None:<EOL><INDENT>vizfunc(candidate)<EOL><DEDENT><DEDENT>def print_candidate(candidate, l, args):<EOL><INDENT>if printfunc is not None:<EOL><INDENT>printfunc(cube=candidate, loglikelihood=l)<EOL><DEDENT>else:<EOL><INDENT>print(l, candidate)<EOL><DEDENT><DEDENT>def eval_candidate(candidate):<EOL><INDENT>params = transform(candidate)<EOL>l = loglikelihood(params)<EOL>p = prior(params)<EOL>if numpy.isinf(p) and p < <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>')<EOL>return -<NUM_LIT><EOL><DEDENT>if numpy.isnan(l):<EOL><INDENT>return -<NUM_LIT><EOL><DEDENT>return l, p<EOL><DEDENT>@inspyred.ec.utilities.memoize<EOL>@inspyred.ec.evaluators.evaluator<EOL>def fitness(candidate, args):<EOL><INDENT>l, p = eval_candidate(candidate)<EOL>return (l + p)<EOL><DEDENT>cutoff_store = <NUM_LIT:10><EOL>def solution_archiver(random, population, archive, args):<EOL><INDENT>psize = len(population)<EOL>population.sort(reverse=True)<EOL>best = population[<NUM_LIT:0>].fitness<EOL>all_candidates = sorted(population + archive, reverse=True)<EOL>all_fitness = numpy.array([c.fitness for c in all_candidates])<EOL>mask = best - all_fitness > cutoff_store / <NUM_LIT:3><EOL>if mask.sum() < <NUM_LIT:20>:<EOL><INDENT>mask = best - all_fitness > cutoff_store<EOL><DEDENT>newarchive = [c for i, c in enumerate(all_candidates) if i == <NUM_LIT:0> or all_fitness[i - <NUM_LIT:1>] != c.fitness]<EOL>print('<STR_LIT>', len(archive), len(newarchive))<EOL>json.dump([{'<STR_LIT>': [float(f) for f in c.candidate], '<STR_LIT>':c.fitness} for c in newarchive], <EOL>open(prefix + '<STR_LIT>', '<STR_LIT:w>'), indent=<NUM_LIT:4>)<EOL>return newarchive<EOL><DEDENT>def observer(population, num_generations, num_evaluations, args):<EOL><INDENT>population.sort(reverse=True)<EOL>candidate = population[<NUM_LIT:0>]<EOL>print(('<STR_LIT>'.format(num_evaluations)), '<STR_LIT>', end='<STR_LIT:U+0020>') <EOL>print_candidate(candidate.candidate, candidate.fitness, args)<EOL>if num_evaluations % len(population) == <NUM_LIT:0> or num_evaluations < len(population) or args.get('<STR_LIT>', False):<EOL><INDENT>viz(candidate.candidate, args)<EOL><DEDENT><DEDENT>def generator(random, args): <EOL><INDENT>u = [random.uniform(<NUM_LIT:0>, <NUM_LIT:1>) for _ in range(n_params)]<EOL>u = [random.gauss(<NUM_LIT:0.5>, <NUM_LIT:0.1>) for _ in range(n_params)]<EOL>return bounder(u, args)<EOL><DEDENT>ea = inspyred.ec.DEA(prng)<EOL>ea.terminator = inspyred.ec.terminators.evaluation_termination<EOL>ea.archiver = solution_archiver<EOL>bounder = inspyred.ec.Bounder(lower_bound=<NUM_LIT>, upper_bound=<NUM_LIT:1>-<NUM_LIT>)<EOL>import copy<EOL>from math import log<EOL>@inspyred.ec.variators.mutator<EOL>def double_exponential_mutation(random, candidate, args):<EOL><INDENT>mut_rate = args.setdefault('<STR_LIT>', <NUM_LIT:0.1>)<EOL>mean = args.setdefault('<STR_LIT>', <NUM_LIT:0.0>)<EOL>stdev = args.setdefault('<STR_LIT>', <NUM_LIT:1.0>)<EOL>scale = log(<NUM_LIT:0.5>) / - (stdev)<EOL>bounder = args['<STR_LIT>'].bounder<EOL>mutant = copy.copy(candidate)<EOL>for i, m in enumerate(mutant):<EOL><INDENT>dice = random.random()<EOL>if dice < mut_rate:<EOL><INDENT>sign = (dice < mut_rate / <NUM_LIT:2>) * <NUM_LIT:2> - <NUM_LIT:1><EOL>delta = -log(random.random()) / scale<EOL>mutant[i] += delta * sign<EOL><DEDENT>mutant = bounder(mutant, args)<EOL><DEDENT>return mutant<EOL><DEDENT>def minute_gaussian_mutation(random, candidates, args):<EOL><INDENT>args = dict(args)<EOL>args['<STR_LIT>'] = <NUM_LIT:1><EOL>args['<STR_LIT>'] = <NUM_LIT><EOL>return inspyred.ec.variators.gaussian_mutation(random, candidates, args)<EOL><DEDENT>ea.variator = [inspyred.ec.variators.n_point_crossover, inspyred.ec.variators.gaussian_mutation, minute_gaussian_mutation]<EOL>ea.replacer = inspyred.ec.replacers.steady_state_replacement<EOL>ea.observer = observer<EOL>pop_size = <NUM_LIT:20><EOL>final_pop = ea.evolve(pop_size=pop_size, <EOL>max_evaluations=nsteps, maximize=True, seeds=seeds, <EOL>gaussian_stdev=<NUM_LIT>, <EOL>bounder=bounder, generator=generator, evaluator=fitness,<EOL>)<EOL>best = max(final_pop)<EOL>seeds = [c.candidate for c in ea.archive]<EOL>print('<STR_LIT>', best)<EOL>return {'<STR_LIT:start>': best.candidate, '<STR_LIT:value>': best.fitness,<EOL>'<STR_LIT>': seeds, '<STR_LIT>': '<STR_LIT>'}<EOL>
**Differential evolution**

via `inspyred <http://inspyred.github.io/>`_

specially tuned. steady state replacement, n-point crossover, 
        pop size 20, gaussian mutation noise 0.01 & 1e-6.
stores intermediate results (can be used for resume, see seeds)

:param start: start point
:param seeds: list of start points
:param vizfunc: callback to do visualization of current best solution
:param printfunc: callback to summarize current best solution
:param seed: RNG initialization (if set)