
# !pip install numpy pandas matplotlib seaborn scikit-learn scipy
#question 14
import numpy as np

# ---------------------------------------------
# 1. Define tanh activation function
# ---------------------------------------------
def tanh(z):
    return np.tanh(z)

# ---------------------------------------------
# 2. Given Parameters
# ---------------------------------------------
X = np.array([0.8, 0.6])

# Input-to-hidden weights and bias
W_ih = np.array([[0.1, 0.3],
                 [0.2, 0.4]])
B_h = np.array([0.05, 0.15])

# Hidden-to-output weights and bias
W_ho = np.array([[0.5],
                 [0.6]])
B_o = np.array([0.2])

# ---------------------------------------------
# 3. Hidden layer computation
# ---------------------------------------------
Z_h = np.dot(X, W_ih) + B_h     # Weighted sum for hidden layer
A_h = tanh(Z_h)                 # Apply tanh activation

# ---------------------------------------------
# 4. Output layer computation
# ---------------------------------------------
Z_o = np.dot(A_h, W_ho) + B_o   # Weighted sum for output layer
Y = tanh(Z_o)                   # Final output with tanh activation

# ---------------------------------------------
# 5. Display all intermediate values
# ---------------------------------------------
print("===== Neural Network with tanh Activation =====")
print(f"Input Vector (X): {X}")
print(f"Hidden Layer Weighted Sum (Z_h): {Z_h}")
print(f"Hidden Layer Output (A_h): {A_h}")
print(f"Output Layer Weighted Sum (Z_o): {Z_o}")
print(f"Final Output (Y): {Y}")
print("================================================")
