Esempio n. 1
0
    def _install_experts(self):
        self._top_level_flock_node = SpatialPoolerFlockNode(
            self._create_expert_params())
        self._flock_nodes = [
            ExpertFlockNode(self._create_expert_params()),
            ExpertFlockNode(self._create_expert_params()),
            self._top_level_flock_node
        ]
        for node in self._flock_nodes:
            self.add_node(node)

        unsqueeze_node_0 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_0)

        unsqueeze_node_1 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_1)

        Connector.connect(self.se_io.outputs.image_output,
                          unsqueeze_node_0.inputs.input)
        Connector.connect(unsqueeze_node_0.outputs.output,
                          self._flock_nodes[0].inputs.sp.data_input)
        Connector.connect(self._flock_nodes[0].outputs.tp.projection_outputs,
                          self._flock_nodes[1].inputs.sp.data_input)
        Connector.connect(self._flock_nodes[1].outputs.tp.projection_outputs,
                          self._join_node.inputs[0])
        Connector.connect(self.se_io.outputs.task_to_agent_label,
                          self._join_node.inputs[1])
        Connector.connect(self._join_node.outputs.output,
                          unsqueeze_node_1.inputs.input)
        Connector.connect(unsqueeze_node_1.outputs.output,
                          self._top_level_flock_node.inputs.sp.data_input)
Esempio n. 2
0
    def topology_simple_dual_loop(self):
        dataset_node = DatasetSequenceMNISTNode(
            DatasetMNISTParams(one_hot_labels=False, examples_per_class=1),
            DatasetSequenceMNISTNodeParams(seqs=[[0, 1, 2], [0, 1, 3]]))
        flock_size = 1

        unsqueeze_node_child = UnsqueezeNode(0)
        unsqueeze_node_parent = UnsqueezeNode(0)
        expand_node_child = ExpandNode(0, flock_size)
        expand_node_parent = ExpandNode(0, flock_size)

        expert_node_child = ExpertFlockNode(
            ExpertParams(flock_size=flock_size,
                         n_cluster_centers=4,
                         spatial=SpatialPoolerParams(),
                         temporal=TemporalPoolerParams(incoming_context_size=2,
                                                       n_providers=2,
                                                       n_frequent_seqs=8,
                                                       seq_length=3,
                                                       seq_lookahead=1)))
        expert_node_parent = ExpertFlockNode(
            ExpertParams(flock_size=flock_size,
                         n_cluster_centers=2,
                         spatial=SpatialPoolerParams()))

        self.add_node(dataset_node)
        self.add_node(unsqueeze_node_child)
        self.add_node(unsqueeze_node_parent)
        self.add_node(expand_node_child)
        self.add_node(expand_node_parent)
        self.add_node(expert_node_child)
        self.add_node(expert_node_parent)

        Connector.connect(dataset_node.outputs.data,
                          unsqueeze_node_child.inputs.input)
        Connector.connect(dataset_node.outputs.sequence_id,
                          unsqueeze_node_parent.inputs.input)
        Connector.connect(unsqueeze_node_child.outputs.output,
                          expand_node_child.inputs.input)
        Connector.connect(unsqueeze_node_parent.outputs.output,
                          expand_node_parent.inputs.input)
        Connector.connect(expand_node_child.outputs.output,
                          expert_node_child.inputs.sp.data_input)
        Connector.connect(expand_node_parent.outputs.output,
                          expert_node_parent.inputs.sp.data_input)

        Connector.connect(expert_node_parent.outputs.output_context,
                          expert_node_child.inputs.tp.context_input,
                          is_backward=True)
    def _create_and_connect_agent(self, join_node: JoinNode, fork_node: ForkNode):
        params = ExpertParams()
        params.flock_size = 1
        params.n_cluster_centers = 28
        params.compute_reconstruction = True
        params.spatial.cluster_boost_threshold = 1000
        params.spatial.buffer_size = 500
        params.spatial.batch_size = 500
        params.spatial.learning_rate = 0.3
        params.spatial.learning_period = 50

        # conv_expert = ConvExpertFlockNode(params, name="Conv. expert")
        # conv_expert = SpatialPoolerFlockNode(params, name=" SP")
        conv_expert = ExpertFlockNode(params, name=" expert")

        self.add_node(conv_expert)

        unsqueeze_node_0 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_0)

        Connector.connect(join_node.outputs.output, unsqueeze_node_0.inputs.input)
        Connector.connect(unsqueeze_node_0.outputs.output, conv_expert.inputs.sp.data_input)

        def squeeze(inputs, outputs):
            outputs[0].copy_(inputs[0].squeeze(0))

        squeeze_node = LambdaNode(squeeze, 1, [(sum(fork_node._split_sizes),)],
                                  name="squeeze lambda node")

        self.add_node(squeeze_node)

        Connector.connect(conv_expert.outputs.sp.predicted_reconstructed_input, squeeze_node.inputs[0])
        Connector.connect(squeeze_node.outputs[0], fork_node.inputs.input)
Esempio n. 4
0
    def __init__(self):
        super().__init__("Single Expert")

        expert_params = ExpertParams()

        expert_params.flock_size = 1
        expert_params.n_cluster_centers = 24
        expert_params.produce_actions = True
        expert_params.temporal.seq_length = 9
        expert_params.temporal.seq_lookahead = 7
        expert_params.temporal.n_frequent_seqs = 700
        expert_params.temporal.max_encountered_seqs = 1000
        expert_params.temporal.exploration_probability = 0.01
        expert_params.temporal.batch_size = 200
        expert_params.temporal.own_rewards_weight = 20
        expert_params.temporal.compute_backward_pass = True

        expert_params.compute_reconstruction = True

        expert_node = ExpertFlockNode(expert_params)

        self.add_node(expert_node)

        Connector.connect(self.inputs.data.output, expert_node.inputs.sp.data_input)
        Connector.connect(self.inputs.reward.output, expert_node.inputs.tp.reward_input)

        Connector.connect(expert_node.outputs.sp.predicted_reconstructed_input,
                          self.outputs.predicted_reconstructed_input.input)
Esempio n. 5
0
    def _install_experts(self, flock_params: List[ExpertParams],
                         model_seed: int):

        self.flock_nodes = [
            ExpertFlockNode(flock_params[0], seed=model_seed),
            ExpertFlockNode(flock_params[1], seed=model_seed),
            SpatialPoolerFlockNode(flock_params[2], seed=model_seed)
        ]

        self._top_level_flock_node = self.flock_nodes[-1]

        for node in self.flock_nodes:
            self.add_node(node)

        self._join_node = JoinNode(flatten=True)
        self.add_node(self._join_node)

        self._install_rescale(self._label_scale)

        unsqueeze_node = UnsqueezeNode(0)
        self.add_node(unsqueeze_node)

        # image -> unsqueeze_node -> SP1 -> SP2 -> join
        Connector.connect(self.se_io.outputs.image_output,
                          unsqueeze_node.inputs.input)
        Connector.connect(unsqueeze_node.outputs.output,
                          self.flock_nodes[0].inputs.sp.data_input)
        Connector.connect(self.flock_nodes[0].outputs.tp.projection_outputs,
                          self.flock_nodes[1].inputs.sp.data_input)
        Connector.connect(self.flock_nodes[1].outputs.tp.projection_outputs,
                          self._join_node.inputs[0])

        # label -> rescale ----> join
        Connector.connect(self.se_io.outputs.task_to_agent_label,
                          self._rescale_node.inputs[0])
        Connector.connect(self._rescale_node.outputs[0],
                          self._join_node.inputs[1])

        unsqueeze_node_2 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_2)

        # join -> unsqueeze_node -> top_level_expert
        Connector.connect(self._join_node.outputs.output,
                          unsqueeze_node_2.inputs.input)
        Connector.connect(unsqueeze_node_2.outputs.output,
                          self._top_level_flock_node.inputs.sp.data_input)
Esempio n. 6
0
    def __init__(self, c_n_ccs, c_buffer_size, c_seq_length, c_seq_lookahead, p_seq_length, p_seq_lookahead, p_n_ccs,
                 flock_size):
        super().__init__("Two Experts")

        expert_params1 = ExpertParams()

        expert_params1.flock_size = flock_size
        expert_params1.n_cluster_centers = c_n_ccs
        expert_params1.produce_actions = True
        expert_params1.temporal.seq_length = c_seq_length
        expert_params1.temporal.seq_lookahead = c_seq_lookahead
        expert_params1.temporal.n_frequent_seqs = 700
        expert_params1.temporal.max_encountered_seqs = 1000
        expert_params1.temporal.exploration_probability = 0.05
        expert_params1.temporal.batch_size = 200
        expert_params1.temporal.compute_backward_pass = True
        expert_params1.temporal.frustration_threshold = 2

        expert_params2 = expert_params1.clone()

        expert_params1.spatial.buffer_size = c_buffer_size
        expert_params1.compute_reconstruction = True

        expert_params2.temporal.seq_length = p_seq_length
        expert_params2.temporal.seq_lookahead = p_seq_lookahead
        expert_params2.n_cluster_centers = p_n_ccs
        expert_params2.produce_actions = False
        expert_params2.temporal.frustration_threshold = 10

        expert_node1 = ExpertFlockNode(expert_params1)
        expert_node2 = ExpertFlockNode(expert_params2)

        self.add_node(expert_node1)
        self.add_node(expert_node2)

        Connector.connect(self.inputs.data.output, expert_node1.inputs.sp.data_input)
        Connector.connect(self.inputs.reward.output, expert_node1.inputs.tp.reward_input)
        Connector.connect(self.inputs.reward.output, expert_node2.inputs.tp.reward_input)

        # Connect the experts to each other.
        Connector.connect(expert_node1.outputs.tp.projection_outputs, expert_node2.inputs.sp.data_input)
        Connector.connect(expert_node2.outputs.output_context, expert_node1.inputs.tp.context_input, is_backward=True)

        # Connect the group output.
        Connector.connect(expert_node1.outputs.sp.predicted_reconstructed_input,
                          self.outputs.predicted_reconstructed_input.input)
Esempio n. 7
0
    def __init__(self):
        super().__init__(device='cuda')

        self._se_config = SpaceEngineersConnectorConfig()
        self.SX = self._se_config.render_width
        self.SY = self._se_config.render_height

        # setup the params
        # SeToyArchDebugTopology.config_se_communication()
        expert_params = self.get_expert_params()

        # create the nodes
        self._actions_descriptor = SpaceEngineersActionsDescriptor()
        self._node_se_connector = SpaceEngineersConnectorNode(
            self._actions_descriptor, self._se_config)
        self._node_action_monitor = ActionMonitorNode(self._actions_descriptor)

        self._blank_action = ConstantNode(
            shape=self._actions_descriptor.ACTION_COUNT, constant=0)
        self._blank_task_data = ConstantNode(
            shape=self._se_config.agent_to_task_buffer_size, constant=0)
        self._blank_task_control = ConstantNode(
            shape=self._se_config.TASK_CONTROL_SIZE, constant=0)

        # parent_rf_dims = (self.lrf_width, self.lrf_height, 3)
        self._node_lrf = ReceptiveFieldNode((self.SY, self.SX, 3),
                                            Size2D(self.SX // EOX,
                                                   self.SY // EOY))

        self._node_flock = ExpertFlockNode(expert_params)

        self.add_node(self._node_se_connector)
        self.add_node(self._node_action_monitor)
        self.add_node(self._blank_action)
        self.add_node(self._blank_task_data)
        self.add_node(self._blank_task_control)
        self.add_node(self._node_flock)
        self.add_node(self._node_lrf)

        Connector.connect(self._blank_action.outputs.output,
                          self._node_action_monitor.inputs.action_in)
        Connector.connect(self._node_action_monitor.outputs.action_out,
                          self._node_se_connector.inputs.agent_action)

        Connector.connect(self._blank_task_data.outputs.output,
                          self._node_se_connector.inputs.agent_to_task_label)
        Connector.connect(self._blank_task_control.outputs.output,
                          self._node_se_connector.inputs.task_control)

        # SE -> Flock (no LRF)
        # Connector.connect(self._node_se_connector.outputs.image_output,
        # self._node_flock.inputs.sp.data_input)

        # Image -> LRF -> Flock
        Connector.connect(self._node_se_connector.outputs.image_output,
                          self._node_lrf.inputs[0])
        Connector.connect(self._node_lrf.outputs[0],
                          self._node_flock.inputs.sp.data_input)
    def _install_experts(self):
        im_width = self.se_io.get_image_width()
        im_height = self.se_io.get_image_height()
        self.input_dims = torch.Size((im_height, im_width, 3))
        self.parent_rf_dims = Size2D(im_height // self.EXPERTS_IN_X,
                                     im_width // self.EXPERTS_IN_X)

        lrf_node = ReceptiveFieldNode(input_dims=self.input_dims,
                                      parent_rf_dims=self.parent_rf_dims)

        self.add_node(lrf_node)

        self._top_level_flock_node = SpatialPoolerFlockNode(self.parent_params)
        self._mid_node = ExpertFlockNode(self.mid_expert_params)
        self._conv_node = ConvExpertFlockNode(self.conv_flock_params)

        self.add_node(self._top_level_flock_node)
        self.add_node(self._mid_node)
        self.add_node(self._conv_node)

        def rescale(inputs, outputs):
            if self.TRAINING:
                outputs[0].copy_(
                    inputs[0] *
                    1000)  # large constant to make the label more important
            else:
                outputs[0].copy_(inputs[0] * float('nan'))

        self._rescale_node = LambdaNode(rescale, 1,
                                        [(self.se_io.get_num_labels(), )])
        self.add_node(self._rescale_node)

        unsqueeze_node_0 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_0)
        unsqueeze_node_1 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_1)

        Connector.connect(self.se_io.outputs.image_output,
                          lrf_node.inputs.input)

        Connector.connect(lrf_node.outputs.output,
                          self._conv_node.inputs.sp.data_input)
        Connector.connect(self._conv_node.outputs.tp.projection_outputs,
                          unsqueeze_node_0.inputs.input)
        Connector.connect(unsqueeze_node_0.outputs.output,
                          self._mid_node.inputs.sp.data_input)
        Connector.connect(self._mid_node.outputs.tp.projection_outputs,
                          self._join_node.inputs[0])

        Connector.connect(self.se_io.outputs.task_to_agent_label,
                          self._rescale_node.inputs[0])
        Connector.connect(self._rescale_node.outputs[0],
                          self._join_node.inputs[1])
        Connector.connect(self._join_node.outputs.output,
                          unsqueeze_node_1.inputs.input)
        Connector.connect(unsqueeze_node_1.outputs.output,
                          self._top_level_flock_node.inputs.sp.data_input)
    def _install_experts(self, flock_params: List[ExpertParams],
                         model_seed: int):

        self._flock_nodes = [
            ConvExpertFlockNode(flock_params[0], seed=model_seed),
            ExpertFlockNode(flock_params[1], seed=model_seed),
            SpatialPoolerFlockNode(flock_params[2], seed=model_seed)
        ]

        self._top_level_flock_node = self._flock_nodes[-1]

        for node in self._flock_nodes:
            self.add_node(node)

        # lrf
        self._install_lrf(self._image_size.value, self._experts_on_x)

        # join output of expert and label
        self._join_node = JoinNode(flatten=True)
        self.add_node(self._join_node)

        # scale node
        self._install_rescale(self._label_scale)

        unsqueeze_node_0 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_0)

        unsqueeze_node_1 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_1)

        # image -> LRF -> E1 -> E2 -> join
        Connector.connect(self.se_io.outputs.image_output,
                          self._node_lrf.inputs.input)
        Connector.connect(self._node_lrf.outputs.output,
                          self._flock_nodes[0].inputs.sp.data_input)
        Connector.connect(self._flock_nodes[0].outputs.tp.projection_outputs,
                          unsqueeze_node_0.inputs.input)
        Connector.connect(unsqueeze_node_0.outputs.output,
                          self._flock_nodes[1].inputs.sp.data_input)
        Connector.connect(self._flock_nodes[1].outputs.tp.projection_outputs,
                          self._join_node.inputs[0])

        # label -> rescale --------> join
        Connector.connect(self.se_io.outputs.task_to_agent_label,
                          self._rescale_node.inputs[0])
        Connector.connect(self._rescale_node.outputs[0],
                          self._join_node.inputs[1])

        # join -> top_level_expert
        Connector.connect(self._join_node.outputs.output,
                          unsqueeze_node_1.inputs.input)
        Connector.connect(unsqueeze_node_1.outputs.output,
                          self._top_level_flock_node.inputs.sp.data_input)
Esempio n. 10
0
    def topology_lookahead_goal(self):
        dataset_node = DatasetSequenceMNISTNode(
            DatasetMNISTParams(one_hot_labels=False, examples_per_class=1),
            DatasetSequenceMNISTNodeParams(
                seqs=[[0, 1, 2], [3, 4, 5], [6, 7, 8]],
                transition_probs=np.array([[0, 0.5, 0.5], [1, 0, 0], [1, 0,
                                                                      0]])))
        unsqueeze_node_child = UnsqueezeNode(0)
        unsqueeze_node_parent = UnsqueezeNode(0)

        expert_node_child = ExpertFlockNode(
            ExpertParams(flock_size=1,
                         n_cluster_centers=9,
                         spatial=SpatialPoolerParams(),
                         temporal=TemporalPoolerParams(n_frequent_seqs=20,
                                                       seq_length=3,
                                                       seq_lookahead=1)))
        expert_node_parent = ExpertFlockNode(
            ExpertParams(flock_size=1,
                         n_cluster_centers=3,
                         spatial=SpatialPoolerParams()))

        self.add_node(dataset_node)
        self.add_node(unsqueeze_node_child)
        self.add_node(unsqueeze_node_parent)
        self.add_node(expert_node_child)
        self.add_node(expert_node_parent)

        Connector.connect(dataset_node.outputs.data,
                          unsqueeze_node_child.inputs.input)
        Connector.connect(dataset_node.outputs.sequence_id,
                          unsqueeze_node_parent.inputs.input)
        Connector.connect(unsqueeze_node_child.outputs.output,
                          expert_node_child.inputs.sp.data_input)
        Connector.connect(unsqueeze_node_parent.outputs.output,
                          expert_node_parent.inputs.sp.data_input)

        Connector.connect(expert_node_parent.outputs.output_context,
                          expert_node_child.inputs.tp.context_input,
                          is_backward=True)
 def _make_middle_layer_expert(use_temporal_pooler: bool, n_middle_layer_cluster_centers: int) \
         -> (NodeBase, InputSlot, OutputSlotBase):
     params = ExpertParams()
     params.flock_size = 1
     params.n_cluster_centers = n_middle_layer_cluster_centers
     if use_temporal_pooler:
         expert_node: ExpertFlockNode = ExpertFlockNode(params)
         input_slot = expert_node.inputs.sp.data_input
         output_slot = expert_node.outputs.tp.projection_outputs
         node = expert_node
     else:
         sp_node: SpatialPoolerFlockNode = SpatialPoolerFlockNode(params)
         input_slot = sp_node.inputs.sp.data_input
         output_slot = sp_node.outputs.sp.forward_clusters
         node = sp_node
     return node, input_slot, output_slot
Esempio n. 12
0
    def __init__(self):
        super().__init__(device='cuda')
        # One MNIST producing two sequences, and one ExpertFlock learning to recognize them

        self.expert_params = ExpertParams()
        self.expert_params.flock_size = 1
        self.expert_params.spatial.input_size = 28 * 28
        self.expert_params.n_cluster_centers = 5
        self.expert_params.spatial.buffer_size = 100
        self.expert_params.spatial.batch_size = 50
        self.expert_params.spatial.learning_period = 10
        self.expert_params.spatial.cluster_boost_threshold = 100

        self.expert_params.temporal.seq_length = 3
        self.expert_params.temporal.seq_lookahead = 1
        self.expert_params.temporal.buffer_size = 100
        self.expert_params.temporal.batch_size = 50
        self.expert_params.temporal.learning_period = 50 + self.expert_params.temporal.seq_lookbehind
        self.expert_params.temporal.incoming_context_size = 1
        self.expert_params.temporal.max_encountered_seqs = 100
        self.expert_params.temporal.n_frequent_seqs = 20
        self.expert_params.temporal.forgetting_limit = 1000

        mnist_seq_params = DatasetSequenceMNISTNodeParams(
            [[0, 1, 2], [3, 1, 4]], np.array([[0.9, 0.1], [0.9, 0.1]]))
        mnist_params = DatasetMNISTParams(class_filter=[0, 1, 2, 3, 4],
                                          one_hot_labels=False,
                                          examples_per_class=1)

        mnist_seq_node = DatasetSequenceMNISTNode(params=mnist_params,
                                                  seq_params=mnist_seq_params,
                                                  seed=5)
        # mnist_node = DatasetMNISTNode(params=mnist_params, seed=5)
        expert_node = ExpertFlockNode(self.expert_params, seed=2)

        # self.add_node(mnist_node)
        self.add_node(mnist_seq_node)
        self.add_node(expert_node)

        unsqueeze_node_0 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_0)

        Connector.connect(mnist_seq_node.outputs.data,
                          unsqueeze_node_0.inputs.input)
        Connector.connect(unsqueeze_node_0.outputs.output,
                          expert_node.inputs.sp.data_input)
Esempio n. 13
0
    def __init__(self):
        super().__init__('cuda')
        # MNIST node producing two sequences.
        # Receptive field looking at the input with window size = 14, 14, stride 7, 7.
        # 3x3 experts looking at the outputs of the RF node.
        # 1 expert combining the outputs.

        mnist_seq_params: DatasetSequenceMNISTNodeParams = DatasetSequenceMNISTNodeParams(
            [[0, 1, 2], [3, 1, 4]])
        mnist_params = DatasetMNISTParams(class_filter=[0, 1, 2, 3, 4],
                                          one_hot_labels=False,
                                          examples_per_class=1)

        n_channels_1 = 1
        input_dims_1 = torch.Size((28, 28, n_channels_1))
        parent_rf_dims_1 = Size2D(14, 14)
        parent_rf_stride_dims_1 = Stride(7, 7)

        self.expert_params = ExpertParams()
        self.expert_params.flock_size = 9
        self.expert_params.spatial.input_size = reduce(
            lambda a, x: a * x, parent_rf_dims_1 + (n_channels_1, ))
        self.expert_params.n_cluster_centers = 10
        self.expert_params.spatial.buffer_size = 100
        self.expert_params.spatial.batch_size = 50
        self.expert_params.spatial.learning_period = 1
        self.expert_params.spatial.cluster_boost_threshold = 100
        self.expert_params.spatial.max_boost_time = 200

        self.expert_params.temporal.seq_length = 3
        self.expert_params.temporal.seq_lookahead = 1
        self.expert_params.temporal.buffer_size = 100
        self.expert_params.temporal.batch_size = 50
        self.expert_params.temporal.learning_period = 50 + self.expert_params.temporal.seq_lookbehind
        self.expert_params.temporal.incoming_context_size = 1
        self.expert_params.temporal.max_encountered_seqs = 100
        self.expert_params.temporal.n_frequent_seqs = 20
        self.expert_params.temporal.forgetting_limit = 1000

        self.parent_expert_params = self.expert_params.clone()
        self.parent_expert_params.flock_size = 1
        self.parent_expert_params.spatial.input_size = \
            self.expert_params.flock_size * 2 * self.expert_params.n_cluster_centers

        # Create the nodes.

        mnist_node_1 = DatasetSequenceMNISTNode(params=mnist_params,
                                                seq_params=mnist_seq_params)
        mnist_node_2 = DatasetSequenceMNISTNode(params=mnist_params,
                                                seq_params=mnist_seq_params)
        receptive_field_node_1_1 = ReceptiveFieldNode(input_dims_1,
                                                      parent_rf_dims_1,
                                                      parent_rf_stride_dims_1)
        receptive_field_node_1_2 = ReceptiveFieldNode(input_dims_1,
                                                      parent_rf_dims_1,
                                                      parent_rf_stride_dims_1)
        expert_flock_node_1 = ExpertFlockNode(self.expert_params)
        expert_flock_node_2 = ExpertFlockNode(self.expert_params)
        join_node = JoinNode(dim=0, n_inputs=2)
        expert_parent_node = ExpertFlockNode(self.parent_expert_params)

        self.add_node(mnist_node_1)
        self.add_node(receptive_field_node_1_1)
        self.add_node(expert_flock_node_1)

        self.add_node(mnist_node_2)
        self.add_node(receptive_field_node_1_2)
        self.add_node(expert_flock_node_2)

        self.add_node(join_node)
        self.add_node(expert_parent_node)

        unsqueeze_node_0 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_0)

        Connector.connect(mnist_node_1.outputs.data,
                          receptive_field_node_1_1.inputs.input)
        Connector.connect(receptive_field_node_1_1.outputs.output,
                          expert_flock_node_1.inputs.sp.data_input)
        Connector.connect(expert_flock_node_1.outputs.tp.projection_outputs,
                          join_node.inputs[0])

        Connector.connect(mnist_node_2.outputs.data,
                          receptive_field_node_1_2.inputs.input)
        Connector.connect(receptive_field_node_1_2.outputs.output,
                          expert_flock_node_2.inputs.sp.data_input)
        Connector.connect(expert_flock_node_2.outputs.tp.projection_outputs,
                          join_node.inputs[1])

        Connector.connect(join_node.outputs.output,
                          unsqueeze_node_0.inputs.input)
        Connector.connect(unsqueeze_node_0.outputs.output,
                          expert_parent_node.inputs.sp.data_input)
Esempio n. 14
0
    def __init__(self, curriculum: tuple = (1, -1)):
        super().__init__()

        se_config = SpaceEngineersConnectorConfig()
        se_config.render_width = 16
        se_config.render_height = 16
        se_config.curriculum = list(curriculum)

        base_expert_params = ExpertParams()
        base_expert_params.flock_size = 1
        base_expert_params.n_cluster_centers = 100
        base_expert_params.compute_reconstruction = False
        base_expert_params.spatial.cluster_boost_threshold = 1000
        base_expert_params.spatial.learning_rate = 0.2
        base_expert_params.spatial.batch_size = 1000
        base_expert_params.spatial.buffer_size = 1010
        base_expert_params.spatial.learning_period = 100

        base_expert_params.temporal.batch_size = 1000
        base_expert_params.temporal.buffer_size = 1010
        base_expert_params.temporal.learning_period = 200
        base_expert_params.temporal.forgetting_limit = 20000

        # parent_expert_params = ExpertParams()
        # parent_expert_params.flock_size = 1
        # parent_expert_params.n_cluster_centers = 20
        # parent_expert_params.compute_reconstruction = True
        # parent_expert_params.temporal.exploration_probability = 0.9
        # parent_expert_params.spatial.cluster_boost_threshold = 1000
        # parent_expert_params.spatial.learning_rate = 0.2
        # parent_expert_params.spatial.batch_size = 1000
        # parent_expert_params.spatial.buffer_size = 1010
        # parent_expert_params.spatial.learning_period = 100
        # parent_expert_params.temporal.context_without_rewards_size = se_config.LOCATION_SIZE_ONE_HOT

        # SE nodes
        actions_descriptor = SpaceEngineersActionsDescriptor()
        node_se_connector = SpaceEngineersConnectorNode(
            actions_descriptor, se_config)
        node_action_monitor = ActionMonitorNode(actions_descriptor)

        # flock-related nodes
        flock_node = ExpertFlockNode(base_expert_params)
        blank_task_control = ConstantNode((se_config.TASK_CONTROL_SIZE, ))
        blank_task_labels = ConstantNode((20, ))

        # parent_flock_node = ExpertFlockNode(parent_expert_params)

        join_node = JoinNode(flatten=True)

        actions = ['FORWARD', 'BACKWARD', 'LEFT', 'RIGHT']
        action_count = len(actions)

        pass_actions_node = PassNode(output_shape=(action_count, ),
                                     name="pass actions")
        fork_node = ForkNode(
            0, [base_expert_params.n_cluster_centers, action_count])

        def squeeze(inputs, outputs):
            outputs[0].copy_(inputs[0].squeeze())

        squeeze_node = LambdaNode(
            squeeze,
            1, [(base_expert_params.n_cluster_centers + action_count, )],
            name="squeeze lambda node")

        def stack_and_unsqueeze(inputs, outputs):
            outputs[0].copy_(torch.stack([inputs[0], inputs[1]]).unsqueeze(0))

        stack_unsqueeze_node = LambdaNode(
            stack_and_unsqueeze,
            2, [(1, 2, se_config.LOCATION_SIZE_ONE_HOT)],
            name="stack and unsqueeze node")

        to_one_hot_node = ToOneHotNode()

        action_parser_node = AgentActionsParserNode(actions_descriptor,
                                                    actions)

        random_node = RandomNumberNode(0,
                                       action_count,
                                       name="random action generator",
                                       generate_new_every_n=5,
                                       randomize_intervals=True)

        switch_node = SwitchNode(2)

        # add nodes to the graph
        self.add_node(flock_node)
        # self.add_node(parent_flock_node)
        self.add_node(node_se_connector)
        self.add_node(node_action_monitor)
        self.add_node(blank_task_control)
        self.add_node(blank_task_labels)
        # self.add_node(join_node)
        # self.add_node(fork_node)
        # self.add_node(pass_actions_node)
        # self.add_node(squeeze_node)
        # self.add_node(to_one_hot_node)
        # self.add_node(stack_unsqueeze_node)
        self.add_node(action_parser_node)
        self.add_node(random_node)
        # self.add_node(switch_node)

        # first layer
        Connector.connect(node_se_connector.outputs.image_output,
                          flock_node.inputs.sp.data_input)

        # Connector.connect(
        #     flock_node.outputs.tp.projection_outputs,
        #     join_node.inputs[0]
        # )
        # Connector.connect(
        #     pass_actions_node.outputs.output,
        #     join_node.inputs[1]
        # )

        # # second layer
        # Connector.connect(
        #     join_node.outputs.output,
        #     parent_flock_node.inputs.sp.data_input
        # )

        # Connector.connect(
        #     node_se_connector.outputs.task_to_agent_location_one_hot,
        #     stack_unsqueeze_node.inputs[0]
        # )
        # Connector.connect(
        #     node_se_connector.outputs.task_to_agent_location_target_one_hot,
        #     stack_unsqueeze_node.inputs[1]
        # )
        # Connector.connect(
        #     stack_unsqueeze_node.outputs[0],
        #     parent_flock_node.inputs.tp.context_input
        # )
        #
        # # actions
        # Connector.connect(
        #     parent_flock_node.outputs.sp.predicted_reconstructed_input,
        #     squeeze_node.inputs[0]
        # )
        # Connector.connect(
        #     squeeze_node.outputs[0],
        #     fork_node.inputs.input
        # )
        # Connector.connect(
        #     fork_node.outputs[1],
        #     to_one_hot_node.inputs.input
        # )
        # Connector.connect(
        #     random_node.outputs.one_hot_output,
        #     switch_node.inputs[0]
        # )
        # Connector.connect(
        #     to_one_hot_node.outputs.output,
        #     switch_node.inputs[1]
        # )
        # Connector.connect(
        #     switch_node.outputs.output,
        #     action_parser_node.inputs.input
        # )
        # directly use random exploration
        Connector.connect(random_node.outputs.one_hot_output,
                          action_parser_node.inputs.input)

        Connector.connect(action_parser_node.outputs.output,
                          node_action_monitor.inputs.action_in)
        # Connector.connect(
        #     switch_node.outputs.output,
        #     pass_actions_node.inputs.input,
        #     is_low_priority=True
        # )
        Connector.connect(
            node_action_monitor.outputs.action_out,
            node_se_connector.inputs.agent_action,
            # is_low_priority=True
            is_backward=False)

        # blank connection
        Connector.connect(blank_task_control.outputs.output,
                          node_se_connector.inputs.task_control)
        Connector.connect(blank_task_labels.outputs.output,
                          node_se_connector.inputs.agent_to_task_label)

        # Save the SE connector so we can check testing/training phase.
        # When the se_io interface has been added, this can be removed.
        self._node_se_connector = node_se_connector
Esempio n. 15
0
    def toploogy_dataset_test(self):
        dataset_params = DatasetAlphabetParams(
            symbols="abcd123456789",
            padding_right=1,
            sequence_probs=DatasetAlphabetSequenceProbsModeParams(
                seqs=['abc', '123', '456789', '468'],
                # transition_probs=[[0.7, 0.3], [0.3, 0.7], ]
            ))
        dataset_node = DatasetAlphabetNode(dataset_params)
        flock_size = 1
        # parent_cluster_centers = len(dataset_params.sequence_probs.seqs)
        parent_cluster_centers = 20  # len(dataset_params.sequence_probs.seqs)

        unsqueeze_node_child = UnsqueezeNode(0)
        unsqueeze_node_sequence_id = UnsqueezeNode(0)
        expand_node_child = ExpandNode(0, flock_size)
        expand_node_sequence_id = ExpandNode(0, flock_size)

        child_cluster_centers = len(dataset_params.symbols) - 1
        expert_node_child = ExpertFlockNode(
            ExpertParams(flock_size=flock_size,
                         n_cluster_centers=child_cluster_centers,
                         spatial=SpatialPoolerParams(),
                         temporal=TemporalPoolerParams(
                             incoming_context_size=parent_cluster_centers,
                             n_providers=2,
                             n_frequent_seqs=50,
                             seq_length=3,
                             seq_lookahead=1)))

        expert_node_parent = ExpertFlockNode(
            ExpertParams(flock_size=flock_size,
                         n_cluster_centers=parent_cluster_centers,
                         spatial=SpatialPoolerParams(),
                         temporal=TemporalPoolerParams(incoming_context_size=4,
                                                       n_frequent_seqs=50,
                                                       seq_length=3,
                                                       seq_lookahead=1)))

        expert_node_sequence_id = ExpertFlockNode(
            ExpertParams(flock_size=flock_size,
                         n_cluster_centers=2,
                         spatial=SpatialPoolerParams()))

        self.add_node(dataset_node)
        self.add_node(unsqueeze_node_child)
        # self.add_node(unsqueeze_node_sequence_id)
        self.add_node(expand_node_child)
        # self.add_node(expand_node_sequence_id)
        self.add_node(expert_node_child)
        self.add_node(expert_node_parent)
        # self.add_node(expert_node_sequence_id)

        Connector.connect(dataset_node.outputs.output,
                          unsqueeze_node_child.inputs.input)
        Connector.connect(unsqueeze_node_child.outputs.output,
                          expand_node_child.inputs.input)
        Connector.connect(expand_node_child.outputs.output,
                          expert_node_child.inputs.sp.data_input)
        # Connector.connect(dataset_node.outputs.sequence_id, unsqueeze_node_sequence_id.inputs.input)
        # Connector.connect(unsqueeze_node_sequence_id.outputs.output, expand_node_sequence_id.inputs.input)
        # Connector.connect(expand_node_sequence_id.outputs.output, expert_node_sequence_id.inputs.sp.data_input)

        Connector.connect(expert_node_child.outputs.tp.projection_outputs,
                          expert_node_parent.inputs.sp.data_input)
        # Parent context
        Connector.connect(expert_node_parent.outputs.output_context,
                          expert_node_child.inputs.tp.context_input,
                          is_backward=True)
Esempio n. 16
0
    def __init__(
        self,
        params: SpecialistNodeGroupParams,
        name: str = "SpecialistNodeGroup",
    ):
        super().__init__(name,
                         inputs=SpecialistInputs(self),
                         outputs=SpecialistOutputs(self))
        self._params = params

        # Create specialist
        specialist_node = ExpertFlockNode(ExpertParams(
            flock_size=self._params.flock_size,
            n_cluster_centers=self._params.n_symbols,
            spatial=SpatialPoolerParams(cluster_boost_threshold=100,
                                        enable_learning=False),
            temporal=TemporalPoolerParams(n_frequent_seqs=50,
                                          seq_length=2,
                                          seq_lookahead=1,
                                          incoming_context_size=3,
                                          forgetting_limit=5000,
                                          compute_best_matching_context=True),
        ),
                                          name="Specialist")
        self.add_node(specialist_node)
        self._specialist_node = specialist_node

        Connector.connect(self.inputs.input.output,
                          specialist_node.inputs.sp.data_input)
        Connector.connect(self.inputs.context_input.output,
                          specialist_node.inputs.tp.context_input)

        # Context feedback Output

        context_flatten_node = FlattenNode(1)
        context_enhance_node = self.create_node_context_enhance()
        self.add_node(context_flatten_node)
        self.add_node(context_enhance_node)

        Connector.connect(specialist_node.outputs.tp.best_matching_context,
                          context_flatten_node.inputs.input)

        if self._params.convert_context_to_one_hot:
            context_to_one_hot_node = ToOneHotNode(ToOneHotMode.MAX)
            self.add_node(context_to_one_hot_node)
            Connector.connect(context_flatten_node.outputs.output,
                              context_to_one_hot_node.inputs.input)
            Connector.connect(context_to_one_hot_node.outputs.output,
                              context_enhance_node.inputs[0])
        else:
            Connector.connect(context_flatten_node.outputs.output,
                              context_enhance_node.inputs[0])

        Connector.connect(context_enhance_node.outputs[0],
                          self.outputs.context_feedback.input)

        # predicted symbol evaluation
        extract_predicted_output_node = self.create_node_extract_predicted_output(
        )
        self.add_node(extract_predicted_output_node)
        Connector.connect(
            specialist_node.memory_blocks.tp.passive_predicted_clusters,
            extract_predicted_output_node.inputs[0])
        predicted_output_to_one_hot_node = ToOneHotNode(
            ToOneHotMode.MAX, name="Specialist predicted one hot output")
        self.add_node(predicted_output_to_one_hot_node)
        Connector.connect(extract_predicted_output_node.outputs[0],
                          predicted_output_to_one_hot_node.inputs.input)
        Connector.connect(predicted_output_to_one_hot_node.outputs.output,
                          self.outputs.output.input)
Esempio n. 17
0
    def __init__(self):
        super().__init__(device='cuda')

        params1 = ExpertParams()
        params1.flock_size = 1
        params1.n_cluster_centers = 10
        params1.spatial.buffer_size = 100
        params1.temporal.buffer_size = 100
        params1.temporal.incoming_context_size = 9
        params1.temporal.n_providers = 2
        params1.spatial.batch_size = 50
        params1.temporal.batch_size = 50
        params1.spatial.input_size = 28 * 28

        params2 = ExpertParams()
        params2.flock_size = 1
        params2.n_cluster_centers = 9
        params2.spatial.buffer_size = 100
        params2.temporal.buffer_size = 100
        params2.temporal.incoming_context_size = 5
        params2.temporal.n_providers = 2
        params2.spatial.batch_size = 50
        params2.temporal.batch_size = 50
        params2.spatial.input_size = params1.n_cluster_centers

        mnist_seq_params = DatasetSequenceMNISTNodeParams([[0, 1, 2],
                                                           [3, 1, 4]])
        mnist_params = DatasetMNISTParams(class_filter=[0, 1, 2, 3, 4],
                                          one_hot_labels=False,
                                          examples_per_class=1)
        mnist_node = DatasetSequenceMNISTNode(params=mnist_params,
                                              seq_params=mnist_seq_params)

        zero_context = ConstantNode(
            shape=(params2.flock_size, params2.temporal.n_providers,
                   NUMBER_OF_CONTEXT_TYPES,
                   params2.temporal.incoming_context_size),
            constant=0)

        node1 = ExpertFlockNode(params1)
        node2 = ExpertFlockNode(params2)

        self.add_node(mnist_node)
        self.add_node(node1)
        self.add_node(node2)
        self.add_node(zero_context)

        unsqueeze_node_0 = UnsqueezeNode(0)
        self.add_node(unsqueeze_node_0)

        Connector.connect(mnist_node.outputs.data,
                          unsqueeze_node_0.inputs.input)
        Connector.connect(unsqueeze_node_0.outputs.output,
                          node1.inputs.sp.data_input)
        Connector.connect(node1.outputs.tp.projection_outputs,
                          node2.inputs.sp.data_input)
        Connector.connect(node2.outputs.output_context,
                          node1.inputs.tp.context_input,
                          is_backward=True)
        Connector.connect(zero_context.outputs.output,
                          node2.inputs.tp.context_input)
Esempio n. 18
0
    def __init__(self,
                 action_count=4,
                 location_vector_size=100,
                 use_grayscale: bool = False):
        super().__init__("Task 1 - Basic expert",
                         inputs=Task1BasicExpertGroupInputs(self),
                         outputs=Task1BasicExpertGroupOutputs(self))

        base_expert_params = ExpertParams()
        base_expert_params.flock_size = 1
        base_expert_params.n_cluster_centers = 100
        base_expert_params.compute_reconstruction = False
        base_expert_params.spatial.cluster_boost_threshold = 1000
        base_expert_params.spatial.learning_rate = 0.2
        base_expert_params.spatial.batch_size = 1000
        base_expert_params.spatial.buffer_size = 1010
        base_expert_params.spatial.learning_period = 100

        parent_expert_params = ExpertParams()
        parent_expert_params.flock_size = 1
        parent_expert_params.n_cluster_centers = 20
        parent_expert_params.compute_reconstruction = True
        parent_expert_params.temporal.exploration_probability = 0.9
        parent_expert_params.spatial.cluster_boost_threshold = 1000
        parent_expert_params.spatial.learning_rate = 0.2
        parent_expert_params.spatial.batch_size = 1000
        parent_expert_params.spatial.buffer_size = 1010
        parent_expert_params.spatial.learning_period = 100
        parent_expert_params.temporal.context_without_rewards_size = location_vector_size

        # flock-related nodes
        flock_node = ExpertFlockNode(base_expert_params)

        parent_flock_node = ExpertFlockNode(parent_expert_params)

        join_node = JoinNode(flatten=True)

        unsqueeze_node_to_base_expert = UnsqueezeNode(0)

        unsqueeze_node_to_parent_expert = UnsqueezeNode(0)

        fork_node = ForkNode(
            0, [base_expert_params.n_cluster_centers, action_count])

        def squeeze(inputs, outputs):
            outputs[0].copy_(inputs[0].squeeze())

        squeeze_node = LambdaNode(
            squeeze,
            1, [(base_expert_params.n_cluster_centers + action_count, )],
            name="squeeze lambda node")

        def stack_and_unsqueeze(inputs, outputs):
            outputs[0].copy_(torch.stack([inputs[0], inputs[1]]).unsqueeze(0))

        stack_unsqueeze_node = LambdaNode(stack_and_unsqueeze,
                                          2, [(1, 2, location_vector_size)],
                                          name="stack and unsqueeze node")

        # add nodes to the graph
        self.add_node(flock_node)
        self.add_node(unsqueeze_node_to_base_expert)
        self.add_node(parent_flock_node)
        self.add_node(unsqueeze_node_to_parent_expert)
        self.add_node(join_node)
        self.add_node(fork_node)
        self.add_node(squeeze_node)
        self.add_node(stack_unsqueeze_node)

        Connector.connect(self.inputs.actions.output, join_node.inputs[1])

        if use_grayscale:
            grayscale_node = GrayscaleNode(squeeze_channel=True)
            self.add_node(grayscale_node)
            Connector.connect(self.inputs.image.output,
                              grayscale_node.inputs.input)
            Connector.connect(grayscale_node.outputs.output,
                              unsqueeze_node_to_base_expert.inputs.input)
        else:
            Connector.connect(self.inputs.image.output,
                              unsqueeze_node_to_base_expert.inputs.input)

        Connector.connect(unsqueeze_node_to_base_expert.outputs.output,
                          flock_node.inputs.sp.data_input)

        Connector.connect(self.inputs.current_location.output,
                          stack_unsqueeze_node.inputs[0])

        Connector.connect(self.inputs.target_location.output,
                          stack_unsqueeze_node.inputs[1])

        Connector.connect(fork_node.outputs[1], self.outputs.actions.input)

        # first layer
        Connector.connect(flock_node.outputs.tp.projection_outputs,
                          join_node.inputs[0])

        # second layer
        Connector.connect(join_node.outputs.output,
                          unsqueeze_node_to_parent_expert.inputs.input)

        # second layer
        Connector.connect(unsqueeze_node_to_parent_expert.outputs.output,
                          parent_flock_node.inputs.sp.data_input)

        Connector.connect(stack_unsqueeze_node.outputs[0],
                          parent_flock_node.inputs.tp.context_input)

        # actions
        Connector.connect(
            parent_flock_node.outputs.sp.predicted_reconstructed_input,
            squeeze_node.inputs[0])
        Connector.connect(squeeze_node.outputs[0], fork_node.inputs.input)
Esempio n. 19
0
    def __init__(self):
        super().__init__(device='cuda')
        actions_descriptor = GridWorldActionDescriptor()
        node_action_monitor = ActionMonitorNode(actions_descriptor)

        params = GridWorldParams(map_name='MapE')
        noise_params = RandomNoiseParams(amplitude=0.0001)
        node_grid_world = GridWorldNode(params)
        expert_params = ExpertParams()
        unsqueeze_node = UnsqueezeNode(dim=0)
        noise_node = RandomNoiseNode(noise_params)
        constant_node = ConstantNode(shape=(1, 1, 3, 48))
        one_hot_node = ToOneHotNode()

        def context(inputs, outputs):
            con = inputs[0]
            con[:, :, 1:, 24:] = float('nan')
            outputs[0].copy_(con)

        def f(inputs, outputs):
            probs = inputs[0]
            outputs[0].copy_(probs[0, -1, :4] + SMALL_CONSTANT)

        action_parser = LambdaNode(func=f, n_inputs=1, output_shapes=[(4,)])
        context_assembler = LambdaNode(func=context, n_inputs=1, output_shapes=[(1, 1, 3, 48)])

        expert_params.flock_size = 1
        expert_params.n_cluster_centers = 24
        expert_params.produce_actions = True
        expert_params.temporal.seq_length = 9
        expert_params.temporal.seq_lookahead = 7
        expert_params.temporal.n_frequent_seqs = 700
        expert_params.temporal.max_encountered_seqs = 1000
        expert_params.temporal.exploration_probability = 0.01
        expert_params.temporal.batch_size = 200
        expert_params.temporal.own_rewards_weight = 20
        expert_params.temporal.incoming_context_size = 48

        expert_params.compute_reconstruction = True

        #expert_node = ConvExpertFlockNode(expert_params)
        expert_node = ExpertFlockNode(expert_params)

        self.add_node(node_grid_world)
        self.add_node(node_action_monitor)
        self.add_node(expert_node)
        self.add_node(unsqueeze_node)
        self.add_node(action_parser)
        self.add_node(noise_node)
        self.add_node(constant_node)
        self.add_node(context_assembler)
        self.add_node(one_hot_node)

        Connector.connect(node_grid_world.outputs.egocentric_image_action, noise_node.inputs.input)
        Connector.connect(noise_node.outputs.output, unsqueeze_node.inputs.input)
        Connector.connect(unsqueeze_node.outputs.output, expert_node.inputs.sp.data_input)
        Connector.connect(node_grid_world.outputs.reward, expert_node.inputs.tp.reward_input)

        Connector.connect(constant_node.outputs.output, context_assembler.inputs[0])
        Connector.connect(context_assembler.outputs[0], expert_node.inputs.tp.context_input)

        Connector.connect(expert_node.outputs.sp.predicted_reconstructed_input, action_parser.inputs[0])
        Connector.connect(action_parser.outputs[0], one_hot_node.inputs.input)
        Connector.connect(one_hot_node.outputs.output, node_action_monitor.inputs.action_in)
        Connector.connect(node_action_monitor.outputs.action_out, node_grid_world.inputs.agent_action, is_backward=True)
Esempio n. 20
0
    def __init__(self):
        super().__init__(device='cuda')
        actions_descriptor = GridWorldActionDescriptor()
        node_action_monitor = ActionMonitorNode(actions_descriptor)

        params = GridWorldParams(map_name='MapE')
        noise_params = RandomNoiseParams(amplitude=0.0001)
        node_grid_world = GridWorldNode(params)
        expert_params1 = ExpertParams()
        unsqueeze_node = UnsqueezeNode(dim=0)
        noise_node = RandomNoiseNode(noise_params)
        one_hot_node = ToOneHotNode()

        def f(inputs, outputs):
            probs = inputs[0]
            outputs[0].copy_(probs[0, -1, :4] + SMALL_CONSTANT)

        action_parser = LambdaNode(func=f, n_inputs=1, output_shapes=[(4, )])

        expert_params1.flock_size = 1
        expert_params1.n_cluster_centers = 24
        expert_params1.produce_actions = True
        expert_params1.temporal.seq_length = 4
        expert_params1.temporal.seq_lookahead = 2
        expert_params1.temporal.n_frequent_seqs = 700
        expert_params1.temporal.max_encountered_seqs = 1000
        expert_params1.temporal.exploration_probability = 0.05
        expert_params1.temporal.batch_size = 200
        expert_params1.temporal.frustration_threshold = 2
        # expert_params.temporal.own_rewards_weight = 20

        expert_params1.compute_reconstruction = True

        expert_params2 = expert_params1.clone()
        expert_params2.temporal.seq_length = 5
        expert_params2.temporal.seq_lookahead = 4
        expert_params2.n_cluster_centers = 8
        expert_params2.produce_actions = False
        expert_params2.temporal.frustration_threshold = 10

        #expert_params1.temporal.incoming_context_size = 2 * expert_params2.n_cluster_centers

        expert_node1 = ExpertFlockNode(expert_params1)
        expert_node2 = ExpertFlockNode(expert_params2)

        self.add_node(node_grid_world)
        self.add_node(node_action_monitor)
        self.add_node(expert_node1)
        self.add_node(expert_node2)
        self.add_node(unsqueeze_node)
        self.add_node(action_parser)
        self.add_node(noise_node)
        self.add_node(one_hot_node)

        Connector.connect(node_grid_world.outputs.output_image_action,
                          noise_node.inputs.input)
        Connector.connect(noise_node.outputs.output,
                          unsqueeze_node.inputs.input)
        Connector.connect(unsqueeze_node.outputs.output,
                          expert_node1.inputs.sp.data_input)

        Connector.connect(expert_node1.outputs.tp.projection_outputs,
                          expert_node2.inputs.sp.data_input)
        Connector.connect(expert_node2.outputs.output_context,
                          expert_node1.inputs.tp.context_input,
                          is_backward=True)

        Connector.connect(
            expert_node1.outputs.sp.predicted_reconstructed_input,
            action_parser.inputs[0])

        Connector.connect(node_grid_world.outputs.reward,
                          expert_node1.inputs.tp.reward_input)
        Connector.connect(node_grid_world.outputs.reward,
                          expert_node2.inputs.tp.reward_input)

        Connector.connect(action_parser.outputs[0], one_hot_node.inputs.input)
        Connector.connect(one_hot_node.outputs.output,
                          node_action_monitor.inputs.action_in)

        Connector.connect(node_action_monitor.outputs.action_out,
                          node_grid_world.inputs.agent_action,
                          is_backward=True)