def generate(self, batch_size=1, outputs=None, with_values=None): """Generate a batch of outputs using the global numpy seed. This method is useful for testing that the ELFI graph works. Parameters ---------- batch_size : int, optional outputs : list, optional with_values : dict, optional You can specify values for nodes to use when generating data """ if outputs is None: outputs = self.source_net.nodes() elif isinstance(outputs, str): outputs = [outputs] if not isinstance(outputs, list): raise ValueError('Outputs must be a list of node names') pool = None if with_values is not None: pool = OutputPool(with_values.keys()) pool.add_batch(with_values, 0) context = ComputationContext(batch_size, seed='global', pool=pool) client = elfi.client.get_client() compiled_net = client.compile(self.source_net, outputs) loaded_net = client.load_data(compiled_net, context, batch_index=0) return client.compute(loaded_net)
def generate(self, batch_size=1, outputs=None, with_values=None): """Generates a batch of outputs using the global seed. This method is useful for testing that the generative model works. Parameters ---------- batch_size : int outputs : list with_values : dict You can specify values for nodes to use when generating data """ if outputs is None: outputs = self.source_net.nodes() elif isinstance(outputs, str): outputs = [outputs] if not isinstance(outputs, list): raise ValueError('Outputs must be a list of node names') context = self.computation_context.copy() # Use the global random_state context.seed = 'global' context.batch_size = batch_size if with_values is not None: pool = OutputPool(with_values.keys()) pool.add_batch(with_values, 0) context.pool = pool client = elfi.client.get_client() compiled_net = client.compile(self.source_net, outputs) loaded_net = client.load_data(compiled_net, context, batch_index=0) return client.compute(loaded_net)