Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ai
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Claudio Scheer
ai
Commits
662ab4d8
Commit
662ab4d8
authored
5 years ago
by
Claudio Scheer
Browse files
Options
Downloads
Patches
Plain Diff
Perceptron neural network to handle OR operator
parent
1a369e1a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
perceptron-or/.gitignore
+1
-0
1 addition, 0 deletions
perceptron-or/.gitignore
perceptron-or/README.md
+3
-0
3 additions, 0 deletions
perceptron-or/README.md
perceptron-or/main.py
+41
-0
41 additions, 0 deletions
perceptron-or/main.py
with
45 additions
and
0 deletions
perceptron-or/.gitignore
0 → 100644
+
1
−
0
View file @
662ab4d8
.vscode
This diff is collapsed.
Click to expand it.
perceptron-or/README.md
0 → 100644
+
3
−
0
View file @
662ab4d8
# About
This is an example of a perceptron neural network that can learn how to deal with the OR operator. This neural network cannot handle XOR operator, because XOR cannot be expressed as a linear function like OR.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
perceptron-or/main.py
0 → 100644
+
41
−
0
View file @
662ab4d8
import
numpy
as
np
# np.random.seed(0)
train_data
=
np
.
array
([[
0
,
0
],
[
0
,
1
],
[
1
,
0
],
[
1
,
1
]])
train_data_y
=
np
.
array
([
-
1
,
1
,
1
,
1
])
def
threshold_activation_function
(
x
):
return
-
1
if
x
<
0
else
1
# Add the bias to the input data.
# size = 4x3
train_data
=
np
.
insert
(
train_data
,
0
,
1
,
axis
=
1
)
epochs
=
1000
random_weight_threshold
=
0.5
learning_rate
=
0.001
# Synapses that will be learned.
# size = 3x1
weigths
=
np
.
random
.
uniform
(
-
random_weight_threshold
,
random_weight_threshold
,
3
)
for
epoch
in
range
(
epochs
):
# Go through all the data.
for
t
in
zip
(
train_data
,
train_data_y
):
# Predict the y-value based on the weights.
predicted_y
=
threshold_activation_function
(
weigths
.
dot
(
t
[
0
]))
# The size of the input data is the size of the weights that must be updated.
for
entry
in
range
(
3
):
weigths
[
entry
]
=
weigths
[
entry
]
-
(
learning_rate
*
(
predicted_y
-
t
[
1
])
*
t
[
0
][
entry
]
)
# Test on training data if the output is correct.
# In this case, there is no data to test.
for
t
in
zip
(
train_data
,
train_data_y
):
predicted_y
=
threshold_activation_function
(
weigths
.
dot
(
t
[
0
]))
print
(
t
)
print
(
predicted_y
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment