Skip to content
Snippets Groups Projects
Commit a9ae22c9 authored by Quentin Ulmer's avatar Quentin Ulmer :construction_worker_tone2:
Browse files

Upload New File

parent 1c8f751a
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:initial_id tags:
``` python
import tensorflow as tf
#Forward Funktion
def hat_f(x, Theta):
a = 1 / (1 + tf.exp(-(Theta[0]*x[0] + Theta[1]*x[1] + Theta[2])))
b = 1 / (1 + tf.exp(-(Theta[3]*x[0] + Theta[4]*x[1] + Theta[5])))
c = 1 / (1 + tf.exp(-(Theta[6]*x[0] + Theta[7]*x[1] + Theta[8])))
d = 1 / (1 + tf.exp(-(Theta[9]*a + Theta[10]*b + Theta[11]*c + Theta[12])))
e = 1 / (1 + tf.exp(-(Theta[13]*a + Theta[14]*b + Theta[15]*c + Theta[16])))
hat_y = tf.math.tanh(Theta[17]*d + Theta[18]*e + Theta[19])
return hat_y
```
%% Cell type:code id:397dd97ca675d17e tags:
``` python
import numpy as np
# Initialize Theta (Page 3)
Theta = tf.constant([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], dtype=tf.float32)
# Create grid for plotting
n_points = int(np.sqrt(200))
x1_values = np.linspace(-6, 6, n_points)
x2_values = np.linspace(-6, 6, n_points)
X1, X2 = np.meshgrid(x1_values, x2_values)
Z = np.zeros(X1.shape)
```
%% Cell type:code id:ba9e53d42150ed66 tags:
``` python
import matplotlib.pyplot as plt
# Compute model outputs and plot
plt.figure()
for i in range(X1.shape[0]):
for j in range(X1.shape[1]):
x = np.array([X1[i, j], X2[i, j]], dtype=np.float32)
Z[i, j] = hat_f(x, Theta)
if Z[i, j] > 0:
plt.scatter(X1[i, j], X2[i, j], c='red')
else:
plt.scatter(X1[i, j], X2[i, j], c='green')
plt.title('2D Plot of hat_f(x, Theta) in the square Q=[-6,6]x[-6,6]')
plt.xlabel('x1')
plt.ylabel('x2')
plt.show()
# 3D Plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X1, X2, Z, c=np.sign(Z), cmap='bwr') # Use red for values > 0, blue for values < 0
ax.set_title('3D Plot of hat_f(x, Theta)')
ax.set_xlabel('x1')
ax.set_ylabel('x2')
ax.set_zlabel('hat_y')
plt.show()
```
%% Output
%% Cell type:code id:ecfee0a0dc0e75d2 tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment