Added Algorithm: Artificial Neural Networks#7652
Conversation
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| grad_add: Gradient computation through the add operation | ||
| """ | ||
|
|
||
| def __add__(self, other): |
There was a problem hiding this comment.
Please provide return type hint for the function: __add__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: other
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
|
|
||
| pass | ||
|
|
||
| def backward(self, gradients=None): |
There was a problem hiding this comment.
Please provide return type hint for the function: backward. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: gradients
| mulgrad4 = np.array([[8.0, 8.0], [13.0, 13.0]]) | ||
|
|
||
|
|
||
| def test_case(): |
There was a problem hiding this comment.
Please provide return type hint for the function: test_case. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| (bool)(otherwise gradient dont apply to the tensor) | ||
| """ | ||
|
|
||
| def __init__(self, arr, requires_grad=True) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: arr
Please provide type hint for the parameter: requires_grad
| self.zero_grad() | ||
| self.shape = self.arr.shape | ||
|
|
||
| def zero_grad(self): |
There was a problem hiding this comment.
Please provide return type hint for the function: zero_grad. If the function does not return a value, please provide the type hint as: def function() -> None:
| """ | ||
| self.grad = np.zeros_like(self.arr) | ||
|
|
||
| def set_history(self, op, operand1, operand2): |
There was a problem hiding this comment.
Please provide return type hint for the function: set_history. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: op
Please provide type hint for the parameter: operand1
Please provide type hint for the parameter: operand2
| grad_add: Gradient computation through the add operation | ||
| """ | ||
|
|
||
| def __add__(self, other): |
There was a problem hiding this comment.
Please provide return type hint for the function: __add__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: other
| grad_matmul: Gradient computation through the matrix multiplication operation | ||
| """ | ||
|
|
||
| def __matmul__(self, other): |
There was a problem hiding this comment.
Please provide return type hint for the function: __matmul__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: other
|
|
||
| return out_tensor | ||
|
|
||
| def grad_add(self, gradients=None): |
There was a problem hiding this comment.
Please provide return type hint for the function: grad_add. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: gradients
|
|
||
| pass | ||
|
|
||
| def grad_matmul(self, gradients=None): |
There was a problem hiding this comment.
Please provide return type hint for the function: grad_matmul. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: gradients
|
|
||
| pass | ||
|
|
||
| def backward(self, gradients=None): |
There was a problem hiding this comment.
Please provide return type hint for the function: backward. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: gradients
| mulgrad4 = np.array([[8.0, 8.0], [13.0, 13.0]]) | ||
|
|
||
|
|
||
| def test_case(): |
There was a problem hiding this comment.
Please provide return type hint for the function: test_case. If the function does not return a value, please provide the type hint as: def function() -> None:
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| (bool)(otherwise gradient dont apply to the tensor) | ||
| """ | ||
|
|
||
| def __init__(self, arr, requires_grad=True) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: arr
Please provide type hint for the parameter: requires_grad
| """ | ||
| self.grad = np.zeros_like(self.arr) | ||
|
|
||
| def set_history(self, op, operand1, operand2) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: op
Please provide type hint for the parameter: operand1
Please provide type hint for the parameter: operand2
| grad_add: Gradient computation through the add operation | ||
| """ | ||
|
|
||
| def __add__(self, other) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: other
| grad_matmul: Gradient computation through the matrix multiplication operation | ||
| """ | ||
|
|
||
| def __matmul__(self, other) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: other
|
|
||
| return out_tensor | ||
|
|
||
| def grad_add(self, gradients=None) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: gradients
|
|
||
| pass | ||
|
|
||
| def grad_matmul(self, gradients=None) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: gradients
|
|
||
| pass | ||
|
|
||
| def backward(self, gradients=None) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: gradients
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
|
|
||
| y1 = np.array([1, 0, 2, 1, 2, 0, 0, 0, 0, 0, 1, 0, 2, 1, 2, 1, 0, 1, 1, 1]) | ||
|
|
||
| X1_test = np.array( |
There was a problem hiding this comment.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: X1_test
| pred1 = np.array([2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 1, 2, 1, 2]) | ||
|
|
||
|
|
||
| def assert_close(x, y): |
There was a problem hiding this comment.
Please provide return type hint for the function: assert_close. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file machine_learning/adaboost.py, please provide doctest for the function assert_close
Please provide type hint for the parameter: x
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: y
Please provide descriptive name for the parameter: y
| n_stumps: Number of stumps (int.) | ||
| """ | ||
|
|
||
| def __init__(self, n_stumps=20): |
There was a problem hiding this comment.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: n_stumps
| self.n_stumps = n_stumps | ||
| self.stumps = [] | ||
|
|
||
| def fit(self, x, y): |
There was a problem hiding this comment.
Please provide return type hint for the function: fit. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file machine_learning/adaboost.py, please provide doctest for the function fit
Please provide type hint for the parameter: x
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: y
Please provide descriptive name for the parameter: y
|
|
||
| return self | ||
|
|
||
| def stump_error(self, y, y_pred, sample_weights): |
There was a problem hiding this comment.
Please provide return type hint for the function: stump_error. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file machine_learning/adaboost.py, please provide doctest for the function stump_error
Please provide type hint for the parameter: y
Please provide descriptive name for the parameter: y
Please provide type hint for the parameter: y_pred
Please provide type hint for the parameter: sample_weights
| grad_add: Gradient computation through the add operation | ||
| """ | ||
|
|
||
| def __add__(self, other) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: other
| grad_matmul: Gradient computation through the matrix multiplication operation | ||
| """ | ||
|
|
||
| def __matmul__(self, other) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: other
|
|
||
| return out_tensor | ||
|
|
||
| def grad_add(self, gradients=None) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: gradients
|
|
||
| pass | ||
|
|
||
| def grad_matmul(self, gradients=None) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: gradients
|
|
||
| pass | ||
|
|
||
| def backward(self, gradients=None) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: gradients
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
|
|
||
| y1 = np.array([1, 0, 2, 1, 2, 0, 0, 0, 0, 0, 1, 0, 2, 1, 2, 1, 0, 1, 1, 1]) | ||
|
|
||
| X1_test = np.array( |
There was a problem hiding this comment.
Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: X1_test
| pred1 = np.array([2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 1, 2, 1, 2]) | ||
|
|
||
|
|
||
| def assert_close(x, y): |
There was a problem hiding this comment.
Please provide return type hint for the function: assert_close. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file machine_learning/adaboost.py, please provide doctest for the function assert_close
Please provide type hint for the parameter: x
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: y
Please provide descriptive name for the parameter: y
| n_stumps: Number of stumps (int.) | ||
| """ | ||
|
|
||
| def __init__(self, n_stumps=20): |
There was a problem hiding this comment.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: n_stumps
| self.n_stumps = n_stumps | ||
| self.stumps = [] | ||
|
|
||
| def fit(self, x, y): |
There was a problem hiding this comment.
Please provide return type hint for the function: fit. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file machine_learning/adaboost.py, please provide doctest for the function fit
Please provide type hint for the parameter: x
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: y
Please provide descriptive name for the parameter: y
|
|
||
| return self | ||
|
|
||
| def stump_error(self, y, y_pred, sample_weights): |
There was a problem hiding this comment.
Please provide return type hint for the function: stump_error. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file machine_learning/adaboost.py, please provide doctest for the function stump_error
Please provide type hint for the parameter: y
Please provide descriptive name for the parameter: y
Please provide type hint for the parameter: y_pred
Please provide type hint for the parameter: sample_weights
| grad_add: Gradient computation through the add operation | ||
| """ | ||
|
|
||
| def __add__(self, other) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: other
| grad_matmul: Gradient computation through the matrix multiplication operation | ||
| """ | ||
|
|
||
| def __matmul__(self, other) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: other
|
|
||
| return out_tensor | ||
|
|
||
| def grad_add(self, gradients=None) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: gradients
|
|
||
| pass | ||
|
|
||
| def grad_matmul(self, gradients=None) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: gradients
|
|
||
| pass | ||
|
|
||
| def backward(self, gradients=None) -> None: |
There was a problem hiding this comment.
Please provide type hint for the parameter: gradients
Describe your change:
Added python implementation of ANN (Artificial Neural Networks) algorithm
Checklist:
Fixes: #{$ISSUE_NO}.