Question

In: Computer Science

Using these four feature vectors in the order listed (See Below, the first vector is [0,...

Using these four feature vectors in the order listed (See Below, the first vector is [0, 1, 0, 1]) with a Bias of constant one and assume the random initial weights are [0.1, -0.6, 0.3, -0.7], calculate the next four iterations, calculate the next four weights using the perceptron learning algorithm. Assume the learning rate, alpha is equal to 0.2

X

Y

Z

Bias

Class

       0

1

0

1

A(+1)

1

0

0

1

A(+1)

1

1

1

1

A(+1)

0

0

0

1

B(-1)

Solutions

Expert Solution

Please find the code below,

Perceptron.ipynb

import numpy as np
R = int(input('Please input the no. of TRAINING DATA - '))
C = int(input('Please input the no. of NEURONS IN INPUT LAYER - '))
x = []
t = []
print('Please input TRAINING DATA & OUTPUT CLASS ASSOCIATED WITH IT - ')
for i in range(R):
    temp = list(map(float, input('X'+str(i+1)+' : ').split()))
    temp.append(1.0)
    x.append(temp)
    t.append(float(input('T'+str(i+1)+' : ')))
x = np.array(x)
t = np.array(t)
w = np.array(list(map(float, input('Please input value of WEIGHTS & BIAS : ').split())))
alpha = float(input('Please input the LEARNING RATE VALUE - '))
theta = float(input('Please input the THETA - '))
prev_w = np.random.random([R,C+1])
curr_w = np.random.random((R,C+1))
ep = 1;
while(np.array_equal(prev_w,curr_w)==False):
    print('\n******** EPOCH - ',ep,'********')
    ep += 1
    prev_w = np.array(curr_w)
    for i in range(R):
        yin = sum(x[i]*w)
        # apply activation func.
        if(yin>theta):
            y = 1
        elif(yin<(-1)*theta):
            y = -1
        else:
            y = 0
        delw = np.zeros(C+1, dtype=float)
        if(y!=t[i]):
            delw = alpha*t[i]*x[i]
        w = w + delw
        curr_w[i] = w
    print('NEW WEIGHTS & BIAS - \n',curr_w)
print('\nFINAL WEIGHTS & BIAS - ',w)

OUTPUT:

If you have any doubts ask in the comments, also don't forget to upvote the solution.


Related Solutions

Let a and b be non-parallel vectors (algebraically a1b2 −a2b1 /= 0). For a vector c...
Let a and b be non-parallel vectors (algebraically a1b2 −a2b1 /= 0). For a vector c there are unique λ, µ real numbers such that c = λ· a+µ·b. proof?
Below is a proof of Theorem 4.1.1 (b): For the zero vector ⃗0 in any vector...
Below is a proof of Theorem 4.1.1 (b): For the zero vector ⃗0 in any vector space V and k ∈ R, k⃗0 = ⃗0. Justify for each of the eight steps why it is true. k⃗0+k⃗0=k(⃗0+⃗0) = k ⃗0 k⃗0 is in V and therefore −(k⃗0) is in V . It follows that (k⃗0 + k⃗0) + (−k⃗0) = (k⃗0) + (−k⃗0) and thus k⃗0 + (k⃗0 + (−k⃗0)) = (k⃗0) + (−k⃗0). We conclude that k⃗0 + ⃗0...
Determine the resultant vector D when the three vectors below are added together. Express your result...
Determine the resultant vector D when the three vectors below are added together. Express your result in a magnitude and direction. A = 5kN@40* B = 10kN@140* C = 25kN@240*
Four displacement vectors, A, B, C, and D, are shown in the diagram below. Their magnitudes...
Four displacement vectors, A, B, C, and D, are shown in the diagram below. Their magnitudes are:  A = 16.2 m, B = 11.0 m, C = 12.0 m, and D =  24.0 m What is the magnitude, in meters, and direction, in degrees, of the resultant vector sum of A, B, C, and D? Give the direction as an angle measured counterclockwise from the +x direction.
Beta is the measure of market risk. Look at the businesses listed below and see if...
Beta is the measure of market risk. Look at the businesses listed below and see if you can identify one that could very likely have a relatively high total risk but a lowbeta. Explain your reasoning. Beta is the measure of market risk. Look at the businesses listed below and see if you can identify one that could very likely have a relatively high total risk but a low beta. Explain your reasoning. a. The manufacturer of diamond-encrusted dog collars....
In the table, below, the number of correctly remembered words are listed for both tests (see...
In the table, below, the number of correctly remembered words are listed for both tests (see #1, above). Based on these results, calculate the appropriate test for these data (assume a = .05) to determine if the memory enhancement training program produces better recall. Be sure to state the calculated and critical values of the statistic for this test. Would you reject or fail to reject the null hypothesis in this situation? Why? Show your work and include all formulas...
Assume that the transactions listed in the first column of the table below are anticipated by...
Assume that the transactions listed in the first column of the table below are anticipated by U.S. firms that have no other foreign transactions. Place an “X” in the table wherever you see possible ways to hedge the transaction exposure. Forward Contract Futures Contract Options Contract Long Short Long Short Call Put a. A Inc. plans to sell goods to Portugal, denominated in euro b. B Co. will import automobiles from Germany, denominated in euro c. C Corp has a...
Place the following patients in order for which you would see first as they come in...
Place the following patients in order for which you would see first as they come in through the emergency department. Explain why you would see them in this order. A. A patient with myasthenia gravis experiencing eye droop B. A 65 year old man with a blood pressure of 140/80 C. A 30 year old type II diabetic with a BS of 250
Listed below (in alphabetical order) are the general ledger and budgetary accounts for the City of...
Listed below (in alphabetical order) are the general ledger and budgetary accounts for the City of Walland. All balances are year-end, unless otherwise noted. All accounts have a normal balance. At the end of the year, the City Council passed an ordinance that all outstanding orders would be honored in the following fiscal year. Also, the Finance Officer set aside $40 for equipment replacement. City of Walland Preclosing Trial Balance For the Year Ended June 30, 20X9 Advance to Enterprise...
Listed below (in alphabetical order) are the general ledger and budgetary accounts for the City of...
Listed below (in alphabetical order) are the general ledger and budgetary accounts for the City of Walland. All balances are year-end, unless otherwise noted. All accounts have a normal balance. At the end of the year, the City Council passed an ordinance that all outstanding orders would be honored in the following fiscal year. Also, the Finance Officer set aside $40 for equipment replacement. City of Walland Preclosing Trial Balance For the Year Ended June 30, 20X4 Advance to Enterprise...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT