Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TutorGym
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Teachable AI Lab
TutorGym
Commits
25c47746
Commit
25c47746
authored
4 years ago
by
Chris MacLellan
Browse files
Options
Downloads
Patches
Plain Diff
removed py_rete dependency
parent
ffa9e0f0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
sandbox/multicolumn/run_al.py
+95
-95
95 additions, 95 deletions
sandbox/multicolumn/run_al.py
with
95 additions
and
95 deletions
sandbox/multicolumn/run_al.py
+
95
−
95
View file @
25c47746
...
@@ -2,10 +2,10 @@
...
@@ -2,10 +2,10 @@
# from apprentice.agents.pyrete_agent import PyReteAgent
# from apprentice.agents.pyrete_agent import PyReteAgent
from
apprentice.agents.WhereWhenHowNoFoa
import
WhereWhenHowNoFoa
from
apprentice.agents.WhereWhenHowNoFoa
import
WhereWhenHowNoFoa
from
apprentice.working_memory.representation
import
Sai
from
apprentice.working_memory.representation
import
Sai
from
py_rete
import
Production
#
from py_rete import Production
from
py_rete
import
Fact
#
from py_rete import Fact
from
py_rete
import
V
#
from py_rete import V
from
py_rete.conditions
import
Filter
#
from py_rete.conditions import Filter
from
tutorenvs.multicolumn
import
MultiColumnAdditionSymbolic
from
tutorenvs.multicolumn
import
MultiColumnAdditionSymbolic
...
@@ -50,97 +50,97 @@ def run_training(agent, n=10):
...
@@ -50,97 +50,97 @@ def run_training(agent, n=10):
p
+=
1
p
+=
1
@Production
(
#
@Production(
Fact
(
id
=
V
(
'
selection
'
),
type
=
"
TextField
"
,
contentEditable
=
True
,
value
=
""
)
#
Fact(id=V('selection'), type="TextField", contentEditable=True, value="")
&
Fact
(
value
=
V
(
'
value
'
))
&
Filter
(
#
& Fact(value=V('value')) & Filter(
lambda
value
:
value
!=
""
and
is_number
(
value
)
and
float
(
value
)
<
10
))
#
lambda value: value != "" and is_number(value) and float(value) < 10))
def
update_field
(
selection
,
value
):
#
def update_field(selection, value):
return
Sai
(
selection
,
'
UpdateField
'
,
{
'
value
'
:
value
})
#
return Sai(selection, 'UpdateField', {'value': value})
#
#
def
is_number
(
v
):
#
def is_number(v):
try
:
#
try:
float
(
v
)
#
float(v)
return
True
#
return True
except
Exception
:
#
except Exception:
return
False
#
return False
@Production
(
#
@Production(
V
(
'
f1
'
)
<<
Fact
(
id
=
V
(
'
id1
'
),
value
=
V
(
'
v1
'
))
#
V('f1') << Fact(id=V('id1'), value=V('v1'))
&
V
(
'
f2
'
)
<<
Fact
(
id
=
V
(
'
id2
'
),
value
=
V
(
'
v2
'
))
#
& V('f2') << Fact(id=V('id2'), value=V('v2'))
&
Filter
(
lambda
id1
,
id2
,
v1
,
v2
:
v1
!=
""
and
is_number
(
v1
)
and
v2
!=
""
#
& Filter(lambda id1, id2, v1, v2: v1 != "" and is_number(v1) and v2 != ""
and
is_number
(
v2
)
and
id1
<
id2
))
#
and is_number(v2) and id1 < id2))
def
add_values
(
net
,
f1
,
f2
,
id1
,
id2
,
v1
,
v2
):
#
def add_values(net, f1, f2, id1, id2, v1, v2):
if
'
depth
'
not
in
f1
:
#
if 'depth' not in f1:
depth1
=
0
#
depth1 = 0
else
:
#
else:
depth1
=
f1
[
'
depth
'
]
#
depth1 = f1['depth']
if
depth1
>
1
:
#
if depth1 > 1:
return
#
return
#
if
'
depth
'
not
in
f2
:
#
if 'depth' not in f2:
depth2
=
0
#
depth2 = 0
else
:
#
else:
depth2
=
f2
[
'
depth
'
]
#
depth2 = f2['depth']
#
if
depth1
+
depth2
>
1
:
#
if depth1 + depth2 > 1:
return
#
return
#
print
(
"
trying to add values
"
)
#
print("trying to add values")
v1
=
float
(
v1
)
#
v1 = float(v1)
v2
=
float
(
v2
)
#
v2 = float(v2)
v3
=
v1
+
v2
#
v3 = v1 + v2
if
v3
==
round
(
v3
):
#
if v3 == round(v3):
v3
=
int
(
v3
)
#
v3 = int(v3)
f
=
Fact
(
id
=
"
({}+{})
"
.
format
(
id1
,
id2
),
#
f = Fact(id="({}+{})".format(id1, id2),
value
=
str
(
v3
),
#
value=str(v3),
depth
=
max
(
depth1
,
depth2
)
+
1
)
#
depth=max(depth1, depth2) + 1)
net
.
add_fact
(
f
)
#
net.add_fact(f)
#
#
@Production
(
#
@Production(
V
(
'
f1
'
)
<<
Fact
(
id
=
V
(
'
id1
'
),
value
=
V
(
'
v1
'
))
#
V('f1') << Fact(id=V('id1'), value=V('v1'))
&
Filter
(
lambda
id1
,
v1
:
v1
!=
""
and
is_number
(
v1
)
and
float
(
v1
)
>=
10
))
#
& Filter(lambda id1, v1: v1 != "" and is_number(v1) and float(v1) >= 10))
def
mod10_value
(
net
,
f1
,
id1
,
v1
):
#
def mod10_value(net, f1, id1, v1):
if
'
depth
'
not
in
f1
:
#
if 'depth' not in f1:
depth1
=
0
#
depth1 = 0
else
:
#
else:
depth1
=
f1
[
'
depth
'
]
#
depth1 = f1['depth']
if
depth1
>
1
:
#
if depth1 > 1:
return
#
return
#
print
(
"
trying to mod10 value
"
)
#
print("trying to mod10 value")
v1
=
float
(
v1
)
#
v1 = float(v1)
v2
=
v1
%
10
#
v2 = v1 % 10
if
v2
==
round
(
v2
):
#
if v2 == round(v2):
v2
=
int
(
v2
)
#
v2 = int(v2)
f
=
Fact
(
id
=
"
({}%10)
"
.
format
(
id1
),
value
=
str
(
v2
),
depth
=
depth1
+
1
)
#
f = Fact(id="({}%10)".format(id1), value=str(v2), depth=depth1 + 1)
net
.
add_fact
(
f
)
#
net.add_fact(f)
#
print
(
net
)
#
print(net)
#
#
@Production
(
#
@Production(
V
(
'
f1
'
)
<<
Fact
(
id
=
V
(
'
id1
'
),
value
=
V
(
'
v1
'
))
#
V('f1') << Fact(id=V('id1'), value=V('v1'))
&
Filter
(
lambda
id1
,
v1
:
v1
!=
""
and
is_number
(
v1
)
and
float
(
v1
)
>=
10
))
#
& Filter(lambda id1, v1: v1 != "" and is_number(v1) and float(v1) >= 10))
def
div10_value
(
net
,
f1
,
id1
,
v1
):
#
def div10_value(net, f1, id1, v1):
if
'
depth
'
not
in
f1
:
#
if 'depth' not in f1:
depth1
=
0
#
depth1 = 0
else
:
#
else:
depth1
=
f1
[
'
depth
'
]
#
depth1 = f1['depth']
if
depth1
>
1
:
#
if depth1 > 1:
return
#
return
#
print
(
"
trying to div10 value
"
)
#
print("trying to div10 value")
v1
=
float
(
v1
)
#
v1 = float(v1)
v2
=
v1
//
10
#
v2 = v1 // 10
if
v2
==
round
(
v2
):
#
if v2 == round(v2):
v2
=
int
(
v2
)
#
v2 = int(v2)
f
=
Fact
(
id
=
"
({}//10)
"
.
format
(
id1
),
value
=
str
(
v2
),
depth
=
depth1
+
1
)
#
f = Fact(id="({}//10)".format(id1), value=str(v2), depth=depth1 + 1)
net
.
add_fact
(
f
)
#
net.add_fact(f)
#
print
(
net
)
#
print(net)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
...
...
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