Skip to content

Commit

Permalink
Merge pull request #93 from cmaclell/dummy-fix
Browse files Browse the repository at this point in the history
Fixed DummyTree's structure mapping pipeline
  • Loading branch information
cmaclell committed Jul 9, 2021
2 parents df4e9bd + 51fd045 commit e179e07
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ sudo: required
dist: xenial
python:
- '3.7'
- '2.7'
- 'pypy2.7-6.0'
- 'pypy3.5-6.0'
install:
- pip install tox-travis
Expand Down
6 changes: 3 additions & 3 deletions concept_formation/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ def CU(cluster, leaves):
for c in set(cluster):
temp_child = cluster[0].__class__()
temp_child.tree = c.tree
for l in leaves:
if c.is_parent(l):
temp_child.update_counts_from_node(l)
for leaf in leaves:
if c.is_parent(leaf):
temp_child.update_counts_from_node(leaf)
temp_root.update_counts_from_node(temp_child)
temp_root.children.append(temp_child)
return -temp_root.category_utility()
Expand Down
6 changes: 4 additions & 2 deletions concept_formation/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from concept_formation.preprocessor import SubComponentProcessor
from concept_formation.preprocessor import Flattener
from concept_formation.preprocessor import Pipeline
from concept_formation.preprocessor import NameStandardizer


class DummyTree(TrestleTree):
Expand Down Expand Up @@ -60,8 +61,9 @@ def ifit(self, instance, do_mapping=False):
:rtype: Cobweb3Node
"""
if do_mapping:
pipeline = Pipeline(SubComponentProcessor(), Flattener(),
StructureMapper(self.root, gensym=self.gensym))
pipeline = Pipeline(NameStandardizer(self.gensym),
Flattener(), SubComponentProcessor(),
StructureMapper(self.root))
else:
pipeline = Pipeline(SubComponentProcessor(), Flattener())
temp_instance = pipeline.transform(instance)
Expand Down
22 changes: 11 additions & 11 deletions concept_formation/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,43 +1113,43 @@ def _relations_to_lists(self, instance, path=None):
else:
new_instance[attr] = instance[attr]

for l in elements:
new_list = [elements[l].pop(0)]
for ele in elements:
new_list = [elements[ele].pop(0)]
change = True

while len(elements[l]) > 0 and change:
while len(elements[ele]) > 0 and change:
change = False

# chain to front
front = True
while front is not None:
front = None
for a, b in order[l]:
for a, b in order[ele]:
if b == new_list[0]:
change = True
front = (a, b)
elements[l].remove(a)
elements[ele].remove(a)
new_list.insert(0, a)
break
if front is not None:
order[l].remove(front)
order[ele].remove(front)

# chain to end
back = True
while back is not None:
back = None
for a, b in order[l]:
for a, b in order[ele]:
if a == new_list[-1]:
change = True
back = (a, b)
elements[l].remove(b)
elements[ele].remove(b)
new_list.append(b)
break
if back is not None:
order[l].remove(back)
order[ele].remove(back)

if len(elements[l]) == 0:
path = self._get_path(l)
if len(elements[ele]) == 0:
path = self._get_path(ele)
current = new_instance
while len(path) > 1:
current = current[path.pop(0)]
Expand Down

0 comments on commit e179e07

Please sign in to comment.