-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAPK.py
69 lines (49 loc) · 2.59 KB
/
MAPK.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import pandas as pd
import random
from pyeasyga import pyeasyga
from sklearn.metrics import mean_squared_error
import math
import scipy.optimize as optimize
from genetic_algorithms import *
from data import *
from odesolver import *
class Nelder_Mead():
def __init__(self, data, initial_estimates):
self.data = data
self.initial_estimates = initial_estimates
def findlsq(self, params):
param1, param2, param3 = params
ODE = solveODES(self.data, param1, param2, param3)
ODEsoln = ODE.solve()
error_sum = mean_squared_error(self.data['MKKK'], ODEsoln[:, 0]) + mean_squared_error(self.data['MKKK_P'],
ODEsoln[:, 1]) + mean_squared_error(
self.data['MKK'], ODEsoln[:, 2]) + mean_squared_error(self.data['MKK_P'], ODEsoln[:, 3]) + mean_squared_error(self.data['MKK_PP'], ODEsoln[:,
4]) + mean_squared_error(
self.data['MAPK'], ODEsoln[:, 5]) + mean_squared_error(self.data['MAPK_P'], ODEsoln[:, 6]) + mean_squared_error(self.data['MAPK_PP'],
ODEsoln[:, 7])
return error_sum
def run_NM(self):
if self.initial_estimates != None:
#Feed initial estimates to Nelder-Mead
initial=np.array([self.initial_estimates[1][0], self.initial_estimates[1][1], self.initial_estimates[1][2]])
else:
initial = np.array([4.5, 5, 5.5])
ret = optimize.minimize(self.findlsq, initial, method='Nelder-Mead', options={'maxiter':500})
#ret_random = optimize.minimize(self.findlsq, initial2, method='Nelder-Mead', options={'maxiter':500})
mybounds=[(0,10), (0,10), (0,10)]
#print('GA solution=', self.initial_estimates)
print('optimum after GA=', ret.x, ret.fun)
#print('optimum on random sampling=', ret_random.x, ret_random.fun)
return ret.x
if __name__=='__main__':
# prepare_data
data_dict = prepare_data("dataset2.dat")
Genetic_Algorithm = GA_custom(data_dict)
# get initial estimates from GA
initial_estimates = Genetic_Algorithm.run_GA(crossover_thresh=0.5)
print('GA Estimates:', initial_estimates[1][0], initial_estimates[1][1], initial_estimates[1][2])
NM = Nelder_Mead(data_dict, initial_estimates)
final_estimates = NM.run_NM()