40 lines
846 B
Python
40 lines
846 B
Python
import numpy as np
|
|
import random
|
|
import scipy.integrate
|
|
|
|
# import matplotlib.pyplot as plt
|
|
|
|
def generate_random_individuals():
|
|
a = random.randrange(10)
|
|
b = random.randrange(10)
|
|
c = random.randrange(10)
|
|
d = random.randrange(10)
|
|
|
|
return [a, b, c, d]
|
|
|
|
def integrate_individual(function):
|
|
result = scipy.integrate.quad(function, -3, 3)
|
|
return result
|
|
|
|
def quadratic_error(original_fn, approx_fn, n):
|
|
error = 0
|
|
|
|
for i in range(n):
|
|
error += (original_fn(i) - approx_fn(i))**2
|
|
|
|
return error
|
|
|
|
def e_fn_approx(a, b, c, d, x = 1):
|
|
return a*x**3 + b*x**2 + c*x + d
|
|
|
|
e_func = lambda x: np.e**x
|
|
fixed_approx = 1 # TODO
|
|
|
|
while quadratic_error(e_func, fixed_approx, n) > 0.01:
|
|
# berechne fitness
|
|
# selection
|
|
# crossover
|
|
# mutation
|
|
|
|
# neue population
|
|
print("Hello World") |