예제 #1
0
def example_numerical_flow():
    def numerical_flow(flow, x, out):
        out += flow.is_even(x.features)
        out += flow.predict_positive(x.features) | out.is_even
        out += flow.multiple_three(x.features) | out.predict_positive
        return out

    def full_flow(flow, x, out):
        out += flow.is_interesting(x.features)
        out += flow.numerical_flow(x.features) | out.is_interesting
        return out

    tensor = torch.arange(8).unsqueeze(dim=-1)
    inputs = Values(keys=['inp'], values=[tensor], types=['int'])

    is_even_task = BinaryHardcodedTask(name='is_even', labels=(tensor % 2) == 0)
    predict_positive = BinaryHardcodedTask(name='predict_positive', labels=(tensor > 0.))
    multiple_three = BinaryHardcodedTask(name='multiple_three', labels=(tensor % 3) == 0)
    is_interesting_task = BinaryHardcodedTask(name='is_interesting', labels=torch.tensor(
        [True, True, False, False, False, True, True, True]))

    tasks = [is_even_task, predict_positive, multiple_three]

    numerical_flow_task = TaskFlow(name='numerical_flow', tasks=tasks, inputs=inputs, flow_func=numerical_flow)
    full_task_flow = TaskFlow(name='full_flow', tasks=[is_interesting_task, numerical_flow_task], inputs=inputs, flow_func=full_flow)
    return full_task_flow
예제 #2
0
 def create_flow(self, flow_func, flow_name=None):
     flow_name = flow_func.__name__ if flow_name is None else flow_name
     used_tasks_tracer = UsedTasksTracer()
     flow_func(used_tasks_tracer, UsedTasksTracer(), UsedTasksTracer())
     used_tasks = []
     for used_task_name in used_tasks_tracer.used_tasks:
         task = self._name_to_task.get(used_task_name, None)
         if task is not None:
             used_tasks.append(task)
     return TaskFlow(flow_name, used_tasks, flow_func, self.inputs)