Skip to content

Test the exception conditions #1853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions neural_network/perceptron.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,28 @@ def __init__(self, sample, target, learning_rate=0.01, epoch_number=1000, bias=-
:param learning_rate: learning rate used in optimizing.
:param epoch_number: number of epochs to train network on.
:param bias: bias value for the network.

>>> p = Perceptron([], (0, 1, 2))
Traceback (most recent call last):
...
ValueError: Sample data can not be empty
>>> p = Perceptron(([0], 1, 2), [])
Traceback (most recent call last):
...
ValueError: Target data can not be empty
>>> p = Perceptron(([0], 1, 2), (0, 1))
Traceback (most recent call last):
...
ValueError: Sample data and Target data do not have matching lengths
"""
self.sample = sample
if len(self.sample) == 0:
raise AttributeError("Sample data can not be empty")
raise ValueError("Sample data can not be empty")
self.target = target
if len(self.target) == 0:
raise AttributeError("Target data can not be empty")
raise ValueError("Target data can not be empty")
if len(self.sample) != len(self.target):
raise AttributeError(
"Sample data and Target data do not have matching lengths"
)
raise ValueError("Sample data and Target data do not have matching lengths")
self.learning_rate = learning_rate
self.epoch_number = epoch_number
self.bias = bias
Expand Down Expand Up @@ -98,7 +109,7 @@ def sort(self, sample) -> None:
classification: P...
"""
if len(self.sample) == 0:
raise AttributeError("Sample data can not be empty")
raise ValueError("Sample data can not be empty")
sample.insert(0, self.bias)
u = 0
for i in range(self.col_sample + 1):
Expand Down