示例#1
0
    def compose(self, left: topology.Composable) -> pipeline.Segment:
        """Composition implementation.

        Args:
            left: Left side.

        Returns:
            Composed track.
        """
        left: pipeline.Segment = left.expand()
        inserter: node.Worker = node.Worker(self.inserter, 1, 1)
        inserter.train(left.train.publisher, left.label.publisher)
        return left.extend(train=view.Path(inserter.fork()))
示例#2
0
    def compose(self, left: topology.Composable) -> pipeline.Segment:
        """Composition implementation.

        Args:
            left: Left side track builder.

        Returns:
            Composed track.
        """
        def worker(
                mode: typing.Optional[task.Spec]
        ) -> typing.Optional[node.Worker]:
            """Create a worker for given spec if not None.

            Args:
                mode: Task spec for given mode.

            Returns:
                Worker instance or None.
            """
            if mode:
                mode = node.Worker(mode, 1, 1)
            return mode

        return left.expand().extend(worker(self._apply), worker(self._train),
                                    worker(self._label))
示例#3
0
    def compose(self, left: topology.Composable) -> pipeline.Segment:
        """Composition implementation.

        Args:
            left: Left side.

        Returns:
            Composed track.
        """
        left: pipeline.Segment = left.expand()
        train_dumper: node.Worker = node.Worker(
            TrainDumper.spec(path=self._path('train'), label=self.label), 1, 1)
        apply_dumper: node.Worker = node.Worker(
            ApplyDumper.spec(path=self._path('apply')), 1, 1)
        train_dumper.train(left.train.publisher, left.label.publisher)
        self._instances += 1
        return left.extend(apply=view.Path(apply_dumper),
                           train=view.Path(train_dumper.fork()))
示例#4
0
    def compose(self, left: topology.Composable) -> pipeline.Segment:
        """Compose the publisher segment track.

        Returns:
            Sink segment track.
        """
        apply: node.Worker = node.Worker(self._writer, 1, 0)
        train: node.Worker = apply.fork()
        return left.expand().extend(apply, train)
示例#5
0
 def compose(self, left: topology.Composable) -> pipeline.Segment:
     """Dummy composition."""
     track = left.expand()
     trainer = node.Worker(spec, 1, 1)
     applier = trainer.fork()
     extractor = node.Worker(spec, 1, 1)
     trainer.train(track.train.publisher, extractor[0])
     return track.use(
         label=track.train.extend(extractor)).extend(applier)
示例#6
0
    def compose(self, left: topology.Composable) -> pipeline.Segment:
        """Abstract composition implementation.

        Args:
            left: Left side track builder.

        Returns:
            Composed track.
        """
        return self.apply(node.Worker(self.spec, self.SZIN, self.SZOUT), left.expand())
示例#7
0
    def compose(self, left: topology.Composable) -> pipeline.Segment:
        """Ensemble composition.

        Args:
            left: left segment.

        Returns:
            Composed segment track.
        """
        head: pipeline.Segment = pipeline.Segment()
        splitter = node.Worker(self.splitter, 1, 2 * self.nsplits)
        splitter.train(head.train.publisher, head.label.publisher)
        features: node.Worker = splitter.fork()
        features[0].subscribe(head.train.publisher)
        labels: node.Worker = splitter.fork()
        labels[0].subscribe(head.label.publisher)

        builder = self.builder(head, left.expand())
        for fold in range(self.nsplits):
            inner: pipeline.Segment = left.expand()
            self.fold(fold, builder, inner, features, labels)

        return builder.build()
示例#8
0
 def test_track(self, composable: topology.Composable):
     """Testing composable track."""
     assert isinstance(composable, topology.Composable)
     assert isinstance(composable.expand(), pipeline.Segment)