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()))
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))
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()))
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)
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)
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())
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()
def test_track(self, composable: topology.Composable): """Testing composable track.""" assert isinstance(composable, topology.Composable) assert isinstance(composable.expand(), pipeline.Segment)