cmaclell / concept_formation

Python implementations of TRESTLE, COBWEB/3, and COBWEB
MIT License
61 stars 18 forks source link

Fix indexing errors #13

Closed eharpste closed 8 years ago

eharpste commented 8 years ago

This is a branch meant to address the #8 issue of numerical keys throwing indexing errors. Basically we've been assuming that attribute keys within an instance dictionary are subscriptable types (either str, or tuple). If you tried to pass in a dictionary with some other type as a key (which is totally valid in python) you would get some exception with a deep stack trace from the internals of the concept formation algorithm. Instead I've put a basic check at the root call (ifit() in the case of CobwebTree and Cobweb3Tree, and transform() in the case of the StructureMapper for Trestle) that checks to make sure all of the attributes will play nice with the internals of the algorithm and throws a more meaningful trace if they won't. I've done some testing and found that this adds a negligible overhead for correctly formatted instances.