Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Receiving an error saying : Traceback (most recent call last): File /Users/liasmith/Desktop/Chegg code.py, line 25, in nw = np.dot(weights + dhs / (x + 0.0000001))

Receiving an error saying :

Traceback (most recent call last): File "/Users/liasmith/Desktop/Chegg code.py", line 25, in nw = np.dot(weights + dhs / (x + 0.0000001)) ValueError: operands could not be broadcast together with shapes (3,) (2,)

This code is supposed to construct a neural network with 4 inputs and one set of 3 hidden nodes using backpropagation in Python.

import numpy as np

x1,x2 = input("Enter two values: ").split()

w1,w2,w3,w4,w5,w6 = input("Enter six values: ").split()

k1,k2,k3 = input("Enter three values: ").split()

x = np.array([int(x1), int(x2)], dtype=float) weights = np.array([float(w1), float(w2), float(w3), float(w4), float(w5), float(w6)], dtype=float).reshape(2, 3) k = np.array([float(k1), float(k2), float(k3)], dtype=float)

m = np.dot(x, weights) p = 1 / (1 + np.exp(-m)) sm = np.dot(p, k) y = 1 / (1 + np.exp(-sm))

print("y = ", y)

res = 0 - y q1 = res * (np.exp(-sm)) / ((1 + np.exp(-sm))**2) dw = q1 * p / (p + 0.0000001) nk = k + dw dhs = q1 * (1 + np.exp(-np.abs(m)))**2 / k * np.exp(-np.abs(m)) nw = (weights + dhs / (x + 0.0000001)

k = nk weights = nw

m = np.dot(x, weights) p = 1 / (1 + np.exp(-m)) sm = np.dot(p, k) y = 1 / (1 + np.exp(-sm))

print("y = ", y)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions