Last active
January 24, 2022 09:48
-
-
Save KhyatiMahendru/b7d7991f8cbaf09b5c43643f726ba3d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update_weights_BCE(m1, m2, b, X1, X2, Y, learning_rate): | |
m1_deriv = 0 | |
m2_deriv = 0 | |
b_deriv = 0 | |
N = len(X1) | |
for i in range(N): | |
s = 1 / (1 / (1 + math.exp(-m1*X1[i] - m2*X2[i] - b))) | |
# Calculate partial derivatives | |
m1_deriv += -X1[i] * (s - Y[i]) | |
m2_deriv += -X2[i] * (s - Y[i]) | |
b_deriv += -(s - Y[i]) | |
# We subtract because the derivatives point in direction of steepest ascent | |
m1 -= (m1_deriv / float(N)) * learning_rate | |
m2 -= (m2_deriv / float(N)) * learning_rate | |
b -= (b_deriv / float(N)) * learning_rate | |
return m1, m2, b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is line no 7 right for sigmoid function? I think you inverted twice.