Thursday, January 23, 2020

Find weights and bias in neural nets in python.

weights, bias, neural nets
fig1: Weights and Bias
Given the combination of two new perceptrons as
w1*0.4 + w2*0.6 + b.
Which of the following values for the weights and the bias
would result in the final probability of the point to be
0.88 of being blue(positive region, above the line)?
 
A.       w1=2, w2=6, bias=2
B.       w1=3, w2=5, bias=-2.2
C.       w1=5, w2=4, bias=-3
 
weights=[(2,6),(3,5),(5,4)]
bias=[2,-2.2,-3]
score1 = weights[0][0] * 0.4 + weights[0][1] * 0.6 + bias[0]
score2 = weights[1][0] * 0.4 + weights[1][1] * 0.6 + bias[1]
score3 = weights[2][0] * 0.4 + weights[2][1] * 0.6 + bias[2]

def find_weights_bias():

#result of the probability function given, 0.88 with sigmoid activation 1/(1+e-score)score is 2

#Find w1, w2 and b, for score=w1*0.4+w2*0.6+b



    weights=[(2,6),(3,5),(5,4)]

    bias=[2,-2.2,-3]

    score1 = weights[0][0] * 0.4 + weights[0][1] * 0.6 + bias[0]

    score2 = weights[1][0] * 0.4 + weights[1][1] * 0.6 + bias[1]

    score3 = weights[2][0] * 0.4 + weights[2][1] * 0.6 + bias[2]

    print(score1,score2,score3)

    #condensed form

    score1, score2, score3 = (w1 * 0.4 + w2 * 0.6 + b for (w1, w2), b in zip(weights, bias))

    print(score1,score2,score3)


    if score1 == 2.0:

        print ("First choice is correct!")

    if score2 == 2.0:

        print ("Second choice is correct!")

    elif score3 == 2.0:

        print ("Third choice is correct!")

    return score1,score2,score3

find_weights_bias()

No comments:

Post a Comment