Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AI Progamming Exercises
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Michael Mutote
AI Progamming Exercises
Commits
4c2c6ea3
Commit
4c2c6ea3
authored
1 year ago
by
Michael Mutote
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/main'
parents
c49f7429
1880d96d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Reinforcement_Learning/Function.py
+117
-0
117 additions, 0 deletions
Reinforcement_Learning/Function.py
Reinforcement_Learning/Perceptrons.py
+2
-2
2 additions, 2 deletions
Reinforcement_Learning/Perceptrons.py
with
119 additions
and
2 deletions
Reinforcement_Learning/Function.py
0 → 100644
+
117
−
0
View file @
4c2c6ea3
# Trying again
class
Expression
:
def
__add__
(
self
,
other
):
if
isinstance
(
other
,
int
)
or
isinstance
(
other
,
float
):
other
=
Constant
(
other
)
return
Addition
(
self
,
other
)
class
Constant
(
Expression
):
def
__init__
(
self
,
val
):
if
isinstance
(
val
,
int
)
or
isinstance
(
val
,
float
):
self
.
val
=
val
else
:
raise
TypeError
def
__str__
(
self
):
return
f
"
{
self
.
val
}
"
def
__eq__
(
self
,
other
):
if
isinstance
(
other
,
Constant
):
return
self
.
val
==
other
.
val
return
False
def
evaluate
(
self
,
env
):
return
self
.
val
def
derivative
(
self
,
name
):
return
Constant
(
0
)
def
simplify
(
self
):
return
self
def
decompose
(
self
):
return
[]
class
Variable
(
Expression
):
def
__init__
(
self
,
name
):
if
name
[
0
].
isalpha
()
and
name
[
0
].
isascii
():
self
.
name
=
name
else
:
raise
TypeError
def
__str__
(
self
):
return
f
"
{
self
.
name
}
"
def
__eq__
(
self
,
other
):
if
isinstance
(
other
,
Variable
):
return
self
.
name
==
other
.
name
return
False
# def __neg__(self):
# pass
def
evaluate
(
self
,
env
):
return
Constant
(
env
[
self
.
name
]).
evaluate
(
env
)
def
derivative
(
self
,
name
):
return
Constant
(
1
if
self
.
name
==
name
else
0
)
def
decompose
(
self
):
return
[
self
.
name
]
class
UnaryOp
(
Expression
):
pass
class
BinaryOp
(
Expression
):
def
__init__
(
self
,
left
,
right
):
self
.
left
=
left
self
.
right
=
right
self
.
name
=
""
def
__str__
(
self
):
return
f
"
(
{
self
.
left
}
{
self
.
name
}
{
self
.
right
}
)
"
def
evaluate
(
self
,
env
):
return
self
.
operate
(
self
.
left
.
evaluate
(
env
),
self
.
right
.
evaluate
(
env
))
def
decompose
(
self
):
return
self
.
left
.
vs
()
+
self
.
right
.
vs
()
class
Addition
(
BinaryOp
):
def
__init__
(
self
,
left
,
right
):
super
().
__init__
(
left
,
right
)
self
.
name
=
"
+
"
def
operate
(
self
,
x
,
y
):
return
x
+
y
def
derivative
(
self
,
name
):
return
self
.
left
.
derivative
(
name
)
+
self
.
right
.
derivative
(
name
)
def
simplify
(
self
):
left
=
self
.
left
.
simplify
()
right
=
self
.
right
.
simplify
()
if
left
.
decompose
()
==
[]:
left
=
left
.
evaluate
({})
if
right
.
decompose
()
==
[]:
right
=
right
.
evaluate
({})
if
isinstance
(
left
,
Constant
)
and
isinstance
(
right
,
Constant
):
return
Constant
(
left
.
val
+
right
.
val
)
if
left
==
Constant
(
0
):
return
right
if
right
==
Constant
(
0
):
return
left
return
left
+
right
This diff is collapsed.
Click to expand it.
Reinforcement_Learning/Perceptrons.py
+
2
−
2
View file @
4c2c6ea3
...
...
@@ -3,7 +3,7 @@ import Training_data
import
matplotlib.pyplot
as
plt
rng
=
np
.
random
.
default_rng
(
123
)
TEACHDATA
=
9999
9
TEACHDATA
=
9999
TESTDATA
=
999
T_NUMBER
=
6
# Number to be detected 0-6
...
...
@@ -62,7 +62,7 @@ class ThresholdPerceptron(Neuron):
delta
=
ETA
*
err
*
ix
self
.
weights
=
self
.
weights
+
delta
self
.
errors
.
append
(
abs
(
err
))
# if np.linalg.norm(old_weights - self.weights) == 0.00:
# if np.linalg.norm(old_weights - self.weights) == 0.00
and i % 57 == 0
:
# return
return
...
...
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