-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp_modeller.py
More file actions
45 lines (36 loc) · 997 Bytes
/
Copy pathexp_modeller.py
File metadata and controls
45 lines (36 loc) · 997 Bytes
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 14 10:51:35 2019
@author: thausmann
"""
import numpy as np
def train_model(data):
m1, m2 = train_exp(data),train_lin(data)
best_model = compare_r2(m1,m2,data)
return best_model
def train_exp(data):
a = (data[-1]-data[0])/(np.exp(len(data)-1)-1)
b = 1
c = data[0] - a
model = lambda a,b,c,x: a * np.exp(b*x) + c
for i in range(1000000):
da = 0
db = 0
dc = 0
error=0
for x in range(len(data)):
error += (model(a,b,c,x)-data[x])**2
dE = 2 * (model(a,b,c,x)-data[x])
da += -np.exp(b*x)*dE
db += -x*np.exp(b*x)*dE
dc += -dE
delta = np.multiply([da,db,dc],0.0001/len(data))
a,b,c=np.add([a,b,c],delta)
if i%100000==0:
print(error/len(data))
return lambda x: model(a,b,c,x)
def train_lin(data):
pass
def compare_r2(model1,model2,data):
pass