started with gn_alg

master
Ruben-FreddyLoafers 2025-10-12 18:04:41 +02:00
parent 3bf9ec3d2e
commit 79800b9907
1 changed files with 39 additions and 1 deletions

View File

@ -1,2 +1,40 @@
import numpy as np
import matplotlib.pyplot as plt
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")