-
Notifications
You must be signed in to change notification settings - Fork 0
/
arithmetic_functions.py
65 lines (53 loc) · 1.17 KB
/
arithmetic_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import numpy as np
def sigmoid(z):
"""Sigmoid function
Parameters
----------
z : numpy array
Input data
Returns
-------
A : numpy array
Sigmoid of the input data
"""
return 1 / (1 + np.exp(-z))
def LR_arth_forward(x, w, b):
"""Forward propagation for the logistic regression model in arthmetic approach
Parameters
----------
x : numpy array
Input data
w : numpy array
Weights
b : float
Bias
Returns
-------
ye : numpy array
Predicted values
"""
z = np.dot(x, w) + b
A = sigmoid(z)
return A
def LR_arth_backward(x, y, ye, m):
"""Backward propagation for the logistic regression model in arthmetic approach
Parameters
----------
x : numpy array
Input data
y : numpy array
True values
ye : numpy array
Predicted values
m : int
Number of samples
Returns
-------
dw : numpy array
Gradient of the weights
db : float
Gradient of the bias
"""
gw = np.dot(x.T, (ye - y)) / m
gb = np.sum(ye - y) / m
return np.concatenate([gw.flatten(), gb.flatten()])