コード例 #1
0
    def reverseBetween(self, head, m, n):
        """

        :param head: ListNode
        :param m: int
        :param n: int
        :return: ListNode
        """
        dummyhead = Node()
        dummyhead.next = head
        cur = head
        index = 1
        pre = dummyhead
        while index <= n:
            if index >= m:
                """todo"""
                if index == m:
                    m_node = cur
                    m_pre = pre
                if index == n:
                    n_node = cur
                    n_next = cur.next
                next = cur.next
                cur.next = pre
                pre = cur
                cur = next
                index += 1
            else:
                pre = cur
                cur = cur.next
                index += 1
        m_pre.next = n_node
        m_node.next = n_next
        return dummyhead
コード例 #2
0
    def __init__(self, y, y_hat, reg=0.):
        """A node that represents the softmax loss.
        Should always be last node in a computational graph.
        Only useful for multinomial classification problems.
        """
        Node.__init__(self, [y_hat])

        self.y = y
        self.reg = reg
コード例 #3
0
    def reverseList(self, head):
        """

        :param head: ListNode
        :return: ListNode
        """
        dummyhead = Node()
        dummyhead.next = head
        cur = dummyhead.next
        pre = None
        while cur != None:
            next = cur.next
            cur.next = pre
            pre = cur
            cur = next
        dummyhead.next = pre
        return dummyhead
コード例 #4
0
ファイル: sigmoid_node.py プロジェクト: hug-0/gnarl
 def __init__(self, node):
     """Compute the sigmoid of a given input node."""
     Node.__init__(self, [node])
コード例 #5
0
ファイル: linear_node.py プロジェクト: hug-0/gnarl
 def __init__(self, *args):
     """A node that computes the linear combination of a list of input
     nodes features, a list of input weights, and a bias term."""
     Node.__init__(self, [*args])
コード例 #6
0
ファイル: input_node.py プロジェクト: hug-0/gnarl
 def __init__(self):
     """An input node. Input nodes don't perform any computations.
     Rather, they represent the input features that will be fed into
     the neural network.
     """
     Node.__init__(self)
コード例 #7
0
ファイル: mse_node.py プロジェクト: hug-0/gnarl
 def __init__(self, y, y_hat):
     """A node that computes the mean squared error.
     Should only be used at the last node in a network."""
     Node.__init__(self, [y, y_hat])
コード例 #8
0
 def __init__(self, node, epsilon=1e-4):
     """Computes rectified linear units for the node."""
     Node.__init__(self, [node])
     self.epsilon = epsilon
コード例 #9
0
 def __init__(self, node, epsilon=0., leak=1e-2):
     """Computes leaky rectified linear units for the node."""
     Node.__init__(self, [node])
     self.epsilon = epsilon
     self.leak = leak
コード例 #10
0
ファイル: softmax_node.py プロジェクト: hug-0/gnarl
 def __init__(self, node):
     """A node that represents the softmax activation function.
     Should always be last node in a graph before computing loss, and only useful for probabilistic
     outputs between 0 and 1."""
     Node.__init__(self, [node])