so_magic.som.factory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 19
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A SelfOrganizingMapFactory.create() 0 10 2
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