<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def energy(self, v, h=None):
 """Compute the global energy for the current joint state of all nodes j = int(i / num_hid_states) pv[i] = sum(pvh[k] for k in range(j * num_hid_states, (j + 1) * num_hid_states)) """

        h = np.zeros(self.Nh) if h is None else h
        negE = np.dot(v, self.bv)
        negE += np.dot(h, self.bh)
        for j in range(self.Nv):
            for i in range(j):
                negE += v[i] * v[j] * self.Wvv[i][j]
        for i in range(self.Nv):
            for k in range(self.Nh):
                negE += v[i] * h[k] * self.Wvh[i][k]
        for l in range(self.Nh):
            for k in range(l):
                negE += h[k] * h[l] * self.Whh[k][l]
        return -negE