Skip to content

Commit c59f4e6

Browse files
committed
merged in new changes to code, expanded rulesets and changes WherewhenHowNoFoa defaults
1 parent 7cd9089 commit c59f4e6

File tree

3 files changed

+83
-19
lines changed

3 files changed

+83
-19
lines changed

agents/WhereWhenHowNoFoa.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from concept_formation.structure_mapper import rename_flat
88

99
from agents.BaseAgent import BaseAgent
10-
# from learners.WhereLearner import SpecificToGeneral
10+
from learners.WhereLearner import SpecificToGeneral
1111
# from learners.WhereLearner import RelationalLearner
1212
from learners.WhereLearner import MostSpecific
1313
from learners.WhenLearner import when_learners
@@ -26,9 +26,9 @@ class WhereWhenHowNoFoa(BaseAgent):
2626
This is the basis for the 2 mechanism model.
2727
"""
2828
def __init__(self, action_set):
29-
# self.where = SpecificToGeneral
29+
self.where = SpecificToGeneral
3030
# self.where = RelationalLearner
31-
self.where = MostSpecific
31+
# self.where = MostSpecific
3232
# self.when = 'naive bayes'
3333
# self.when = 'always true'
3434
self.when = 'trestle'

learners/WhereLearner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def ifit(self, t, x, y):
412412

413413
class SpecificToGeneral(BaseILP):
414414

415-
def __init__(self, remove_attrs=None):
415+
def __init__(self, args=None, constraints=None, remove_attrs=None):
416416
self.pos = set()
417417
self.operator = None
418418
self.concept = Cobweb3Node()
@@ -424,10 +424,10 @@ def __init__(self, remove_attrs=None):
424424
self.remove_attrs = remove_attrs
425425

426426
def num_pos(self):
427-
return self.pos_concept.count()
427+
return self.pos_concept.count
428428

429429
def num_neg(self):
430-
return self.neg_concept.count()
430+
return self.neg_concept.count
431431

432432
def __len__(self):
433433
return self.count

planners/rulesets.py

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
# from nltk import ViterbiParser
44

5-
from planners.fo_planner import Operator
6-
from planners.fo_planner import FoPlanner
7-
from learners.Grammar import grammar
8-
from learners.WhatLearner import ViterbiParser
5+
from fo_planner import Operator
6+
from fo_planner import FoPlanner
7+
# from learners.Grammar import grammar
8+
# from learners.WhatLearner import ViterbiParser
99

1010
_then_gensym_counter = 0
1111

@@ -427,17 +427,81 @@ def concatenate_without_space(x, y):
427427

428428
if __name__ == "__main__":
429429

430-
facts = [(('value', 'a'), '3'),
431-
(('value', 'b'), '3x')]
432-
kb = FoPlanner(facts, [string_subtract_rule])
433-
kb.fc_infer()
434-
print(kb.facts)
430+
# facts = [(('value', 'a'), '3'),
431+
# (('value', 'b'), '3x')]
432+
433+
facts = [
434+
# (('x', ('bound', '?b1')), '?xv')
435+
(('x', ('pos','rect1')),2),
436+
(('y', ('pos','rect1')),1),
437+
(('x', ('bound','rect1')),3),
438+
(('y', ('bound','rect1')),1),
439+
440+
(('x', ('pos','block1')),1),
441+
(('y', ('pos','block1')),2),
442+
(('x', ('bound','block1')),1),
443+
(('y', ('bound','block1')),1),
444+
445+
(('x', ('bound','block2')),1),
446+
(('y', ('bound','block2')),1),
447+
448+
(('x', ('pos','check1')),1),
449+
(('y', ('pos','check1')),1),
450+
451+
(('x', ('pos','check2')),1),
452+
(('y', ('pos','check2')),3),
453+
454+
(('x', ('pos','check3')),3),
455+
(('y', ('pos','check3')),1),
456+
457+
(('x', ('pos','check4')),3),
458+
(('y', ('pos','check4')),3),
459+
460+
]
461+
462+
463+
# kb = FoPlanner(facts, [string_subtract_rule])
464+
# kb.fc_infer()
465+
# print(kb.facts)
435466

436467
# facts = [(('value', 'x'), '17'),
437468
# (('value', 'y'), '7')]
438-
# kb = FoPlanner(facts, arith_rules + [half_val])
439-
# from pprint import pprint
440-
# for sol in kb.fc_query([(('value', '?a'), '98')], 3):
469+
kb = FoPlanner(facts, rb_rules)
470+
from pprint import pprint
471+
472+
473+
print('X')
474+
i = 0
475+
for sol in kb.fc_query([(('x', '?a'),3)], 2):
476+
if i % 5 == 0:
477+
pprint(sol)
478+
if i > 5 * 10:
479+
break
480+
i += 1
481+
482+
483+
print('Y')
484+
i = 0
485+
for sol in kb.fc_query([(('y', '?a'),2)], 2):
486+
if i % 5 == 0:
487+
pprint(sol)
488+
if i > 5 * 10:
489+
break
490+
i += 1
491+
492+
493+
494+
# print(len(xs))
495+
# pprint(xs[:10])
496+
497+
# ys = [sol for sol in kb.fc_query([(('y', '?a'),2)], 2)]
498+
# print('Y')
499+
# print(len(ys))
500+
# pprint(ys[:10])
501+
502+
# print('Y')
503+
# for sol in kb.fc_query([(('y', '?a'),2)], 2):
441504
# pprint(sol)
442505
# kb.fc_infer()
443-
# print(kb.facts)
506+
# pprint(kb.facts)
507+

0 commit comments

Comments
 (0)