Пример #1
0
 def __init__(self, predicted, target, name=None):
     MComputeNode.__init__(self, name)
     self.predicted = predicted
     self.target = target
     self._add_upstream_nodes([predicted, target])
     self.predicted_logs = None
     self.predicted_fixed = None
Пример #2
0
 def __init__(self,
              prediction_source: MComputeNode,
              target_source: MComputeNode,
              name: str = None):
     MComputeNode.__init__(self, name)
     self.prediction_node = prediction_source
     self.target_node = target_source
     self._add_upstream_nodes([prediction_source, target_source])
     self.probabilities = None
Пример #3
0
    def __init__(self, input_node, name=None):
        r"""

        :param pred:  mxn shape where m is output dimension (categories) and n is the number of instances
        in the batch
        :param target:  mxn one hot vectors where m in number of categories along 0 axis, and n is the number
        of instances in the batch (axis=1)
        :param name:
        """
        MComputeNode.__init__(self, name)
        self.input_node = input_node
        self._add_upstream_nodes([input_node])
        self.epsilon = 1e-15
Пример #4
0
    def __init__(self,
                 predicted: MComputeNode,
                 target: MComputeNode,
                 name: str = None):
        r"""

        :param predicted:  predicted values for different classes
        :param target: target values as one hot vector
        :param name:
        """
        MComputeNode.__init__(self, name)
        self.predicted = predicted
        self.target = target
        self._add_upstream_nodes([predicted, target])
Пример #5
0
    def __init__(self,
                 x_node: MComputeNode,
                 prev_rnn_node: RnnCell,
                 w: SharedParam,
                 w_b: SharedParam,
                 u: SharedParam,
                 u_b: SharedParam,
                 hidden_state_in: np.Array = None,
                 name: str = None):
        r"""
        Note that since the input dimension is determined at the first invocation of
        forward, this object does not yet know the input dimension and hecne cannot be
        initialized.
        :param x_node: source of x (input) value
        :param prev_rnn_node: used to get the previous state
        :param w: shared weight for X transformation
        :param w_b: shared bias for X
        :param u: shared weight for hidden state
        :param u_b:  shared bias for hidden state
        :param hidden_state_in: must be specified if this is the first cell in a sequence
        :param name: easy to track name. This is appended by an ID to make sure names are unique
        """
        MComputeNode.__init__(self, name, is_trainable=False)
        if prev_rnn_node is None:
            # this is the first node
            self._add_upstream_nodes([x_node])
            if hidden_state_in is None:
                raise Exception("No initial hidden state provided")
            self.hidden_state_in = hidden_state_in
        else:
            self._add_upstream_nodes([x_node, prev_rnn_node])
            self.hidden_state_in = hidden_state_in

        self.x_node = x_node
        self.prev_rnn_node = prev_rnn_node
        self.hidden_state_out = None

        self.W: SharedParam = w
        self.U: SharedParam = u
        self.Wb: SharedParam = w_b
        self.Ub: SharedParam = u_b
        self.output_shape = self.W.shape()
        self.hidden_shape = self.U.shape()
Пример #6
0
    def __init__(self,
                 prev_node: MComputeNode,
                 output_dim: int,
                 state_dim: int,
                 output_all_sequences: bool = False,
                 name: str = None):
        """

        :param prev_node: A non RNN previous node. This will be changed soon to make it more flexible
        :param output_dim: dimension of "Y"
        :param state_dim: dimension of "H", the hidden state
        :param output_all_sequences: Only False is supported at present.
        :param name:
        """
        MComputeNode.__init__(self, name=name, is_trainable=True)
        self.input_node = prev_node
        self._add_upstream_nodes([prev_node])
        self.output_dim = output_dim
        self.state_dim = state_dim
        self.output_all_sequences = output_all_sequences
        self.weights_initialized = False
        self.initial_state = np.zeros((self.state_dim, 1))
Пример #7
0
 def __init__(self, upstream_node, name=None):
     MComputeNode.__init__(self, name, False)
     self.input_node = upstream_node
     self._add_upstream_nodes([upstream_node])
Пример #8
0
 def __init__(self, time_idx, input_value):
     MComputeNode.__init__(self, str(time_idx), is_trainable=False)
     self.node_value_ref = input_value
     self.time_index = time_idx
     self.node_value = self.node_value_ref[:, :, self.time_index]