23
23
velocity = [0 ] * len (parameter_vector )
24
24
25
25
26
- def _error (example_no , data_set = "train" ):
26
+ def _error (example_no , data_set = "train" ) -> float :
27
27
"""
28
28
Calculate the error for a given example.
29
29
Args:
@@ -37,7 +37,7 @@ def _error(example_no, data_set="train"):
37
37
return hypo_value - output_value
38
38
39
39
40
- def _hypothesis_value (data_input_tuple ):
40
+ def _hypothesis_value (data_input_tuple ) -> float :
41
41
"""
42
42
Compute the hypothesis value (predicted output) for a given input tuple.
43
43
Args:
@@ -52,7 +52,7 @@ def _hypothesis_value(data_input_tuple):
52
52
return hyp_val
53
53
54
54
55
- def output (example_no , data_set ):
55
+ def output (example_no , data_set ) -> int :
56
56
"""
57
57
Retrieve the actual output (label) for a given example
58
58
from the specified dataset.
@@ -69,7 +69,7 @@ def output(example_no, data_set):
69
69
return None
70
70
71
71
72
- def calculate_hypothesis_value (example_no , data_set ):
72
+ def calculate_hypothesis_value (example_no , data_set ) -> float :
73
73
"""
74
74
Calculate the hypothesis value (predicted output) for a given example.
75
75
Args:
@@ -85,7 +85,7 @@ def calculate_hypothesis_value(example_no, data_set):
85
85
return None
86
86
87
87
88
- def summation_of_cost_derivative (index , end = m ):
88
+ def summation_of_cost_derivative (index , end = m ) -> float :
89
89
"""
90
90
Calculate the summation of the cost derivative for a given index.
91
91
Args:
@@ -104,7 +104,7 @@ def summation_of_cost_derivative(index, end=m):
104
104
return summation_value
105
105
106
106
107
- def get_cost_derivative (index ):
107
+ def get_cost_derivative (index ) -> float :
108
108
"""
109
109
Compute the cost derivative with respect to a parameter.
110
110
Args:
@@ -115,7 +115,7 @@ def get_cost_derivative(index):
115
115
return summation_of_cost_derivative (index , m ) / m
116
116
117
117
118
- def run_gradient_descent_with_momentum ():
118
+ def run_gradient_descent_with_momentum () -> None :
119
119
"""
120
120
Run gradient descent with momentum to minimize the cost function.
121
121
This function updates the parameter vector using velocity and the learning rate.
@@ -143,7 +143,7 @@ def run_gradient_descent_with_momentum():
143
143
print (f"Number of iterations: { iteration } " )
144
144
145
145
146
- def test_gradient_descent ():
146
+ def test_gradient_descent () -> None :
147
147
"""
148
148
Test the trained model on the test dataset and print actual vs predicted outputs.
149
149
"""
0 commit comments