Skip to content
Snippets Groups Projects
Commit 418cf7bb authored by Friedrich Heitzer's avatar Friedrich Heitzer
Browse files

dfsdsf

:
parent 74602b58
Branches
Tags
No related merge requests found
%% Cell type:code id: tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
```
%% Cell type:code id: tags:
``` python
class Model:
def __init__(self, theta=None):
if theta is None:
theta = [0.12, 1.6, 3.2, 1.5, -1.1, 3.2, 1.4, 0.54, -3.3, 3.8,
2.6, -4.5, -3.4, -2.0, -3.3, 1.7, 3.2, 7.2, -6.0, -1.8]
self.theta = theta
def forward(self, x):
a = 1/(1+np.exp(-(self.theta[0]*x[0]+self.theta[1]*x[1]+self.theta[2])))
b = 1/(1+np.exp(-(self.theta[3]*x[0]+self.theta[4]*x[1]+self.theta[5])))
c = 1/(1+np.exp(-(self.theta[6]*x[0]+self.theta[7]*x[1]+self.theta[8])))
d = 1/(1+np.exp(-(self.theta[9]*a+self.theta[10]*b+self.theta[11]*c+self.theta[12])))
e = 1/(1+np.exp(-(self.theta[13]*a+self.theta[14]*b+self.theta[15]*c+self.theta[16])))
hat_y = np.tanh(self.theta[17]*d+self.theta[18]*e+self.theta[19])
return hat_y
def predict_list(self, x):
return np.asarray([self.forward(q) for q in x])
def predict_mgrid(self, x, y):
return np.asarray([self.predict_list(list(zip(i, j))) for i, j in zip(x, y)])
```
%% Cell type:code id: tags:
``` python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
from matplotlib.ticker import LinearLocator
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
# Make data.
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
f_hat = Model()
Z = f_hat.predict_mgrid(X, Y)
# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
# Customize the z axis.
ax.set_zlim(-1.0, 1.0)
plt.show()
plt.contourf(X, Y, Z, cmap='Paired')
plt.show()
```
%% Output
%% Cell type:code id: tags:
``` python
```
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment