Пример #1
0
# Author: Brian Busemeyer [email protected].
# Released under GNU licence.
import numpy as np
from functools import partial
import time
import subprocess as sub
import multiprocessing as mp
import matplotlib.pyplot as plt
import plot_tools as pt
pt.matplotlib_header()
from copy import deepcopy


class GeneticOptimizer:
    def __init__(self, fitness, breed, nthreads=1):
        """ 
    fitness(sol) is a function that defines the fitness of a solution. Space of
    solutions is implicitly defined by fitness function. 
    breed(solist) takes a list of solutions and produces a new solution.
    mutate(sol,frac) takes a solution and perturbs a fraction of it. 
    """
        # FIXME Breed has issue when number of parents doesn't match what breed is expecting.
        self.fitness = fitness
        self.breed = breed
        self.best_fitness = -np.inf
        self.best_fitness_history = []
        self.best_solution = None
        self.population = None
        self.nthreads = nthreads

    def optimize(self,
Пример #2
0
#!/usr/bin/python3
import sys
import pandas as pd
import matplotlib.pyplot as plt
import plot_tools as pt
pt.matplotlib_header()

dat = pd.read_fwf(sys.argv[1],skiprows=1,
    names = ["CYC","cycle","ETOT","totenergy","DETOT","energydiff","TST","wf","PX","wf2"])
dmin = dat['totenergy'].min()
print(dmin)
print("Min: %f."%dmin)
dat['totenergy'] -= dmin
plt.plot(dat['totenergy'])
plt.show()