| Total Complexity | 2 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import logging |
||
| 2 | import attr |
||
| 3 | from so_magic.utils import Subject |
||
| 4 | from .self_organising_map import SomTrainer, SelfOrganizingMap, NoFeatureVectorsError |
||
| 5 | |||
| 6 | |||
| 7 | logger = logging.getLogger(__name__) |
||
| 8 | |||
| 9 | |||
| 10 | @attr.s |
||
| 11 | class SelfOrganizingMapFactory: |
||
| 12 | trainer = attr.ib(init=True, default=attr.Factory(SomTrainer.from_callable)) |
||
| 13 | subject = attr.ib(init=True, default=attr.Factory(lambda: Subject([]))) |
||
| 14 | |||
| 15 | def create(self, dataset, nb_cols, nb_rows, **kwargs): |
||
| 16 | try: |
||
| 17 | # run a backend algorithm and get a self-organising map representation object |
||
| 18 | somoclu_map = self.trainer.infer_map(nb_cols, nb_rows, dataset, **kwargs) |
||
| 19 | self.subject.state = somoclu_map |
||
| 20 | self.subject.notify() |
||
| 21 | return SelfOrganizingMap(somoclu_map, dataset.name) |
||
| 22 | except NoFeatureVectorsError as exception: |
||
| 23 | logger.info("%s Fire up an 'encode' command.", str(exception)) |
||
| 24 | raise exception |
||
| 25 |