Passed
Push — dev ( a34975...3b058b )
by Konstantinos
01:33
created

green_magic.som.factory.SomFactory.create_som()   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 9
rs 9.95
c 0
b 0
f 0
cc 2
nop 5
1
import attr
2
from green_magic.utils import Subject
3
from .self_organising_map import SomTrainer, SelfOrganizingMap
4
5
6
@attr.s
7
class SelfOrganizingMapFactory:
8
    trainer = attr.ib(init=True, default=SomTrainer())
9
    subject = attr.ib(init=True, default=Subject([]))
10
11
    def create(self, dataset, nb_cols, nb_rows, **kwargs):
12
        try:
13
            map_obj = self.trainer.infer_map(nb_cols, nb_rows, dataset, **kwargs)  # backend dependent (eg somoclu kind of object)
14
            self.subject.state = map_obj
15
            self.subject.notify()
16
            return SelfOrganizingMap(map_obj, dataset.name)
17
        except NoFeatureVectorsError as e:
18
            logger.info(f"{e}. Fire up an 'encode' command.")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable logger does not seem to be defined.
Loading history...
19
            raise e
20
21
22
class NoFeatureVectorsError(Exception): pass
23