def _forward(self, x, *args, **kwds): d, n = 2 + 1, x.size p = n y = UTPM(np.zeros((d, p, n))) y.data[0, :] = x.ravel() y.data[1, :] = np.eye(n) z0 = self.fun(y, *args, **kwds) z = UTPM.as_utpm(z0) H = z.data[2, ...] * 2 return H
def _forward(self, x, *args, **kwds): x0 = np.asarray(x) shape = x0.shape P = 1 x = UTPM(np.zeros((self.n + 1, P) + shape)) x.data[0, 0] = x0 x.data[1, 0] = 1 z = self.f(x, *args, **kwds) y = UTPM.as_utpm(z) return y.data[self.n, 0] * misc.factorial(self.n)
def _forward(self, x, *args, **kwds): x0 = np.asarray(x) shape = x0.shape P = 1 x = UTPM(np.zeros((self.n + 1, P) + shape)) x.data[0, 0] = x0 x.data[1, 0] = 1 z = self.fun(x, *args, **kwds) y = UTPM.as_utpm(z) return y.data[self.n, 0] * special.factorial(self.n)
def _forward(self, x, *args, **kwds): d, n = 2+1, x.size p = n y = UTPM(np.zeros((d, p, n))) y.data[0, :] = x.ravel() y.data[1, :] = np.eye(n) z0 = self.fun(y, *args, **kwds) z = UTPM.as_utpm(z0) H = z.data[2, ...] * 2 return H
def _forward(self, x, *args, **kwds): # return np.diag(super(Hessdiag, self)._forward(x, *args, **kwds)) D, Nm = 2+1, x.size P = Nm y = UTPM(np.zeros((D, P, Nm))) y.data[0, :] = x.ravel() y.data[1, :] = np.eye(Nm) z0 = self.f(y, *args, **kwds) z = UTPM.as_utpm(z0) H = z.data[2, ...] * 2 return H
def _forward(self, x, *args, **kwds): # return np.diag(super(Hessdiag, self)._forward(x, *args, **kwds)) D, Nm = 2 + 1, x.size P = Nm y = UTPM(np.zeros((D, P, Nm))) y.data[0, :] = x.ravel() y.data[1, :] = np.eye(Nm) z0 = self.f(y, *args, **kwds) z = UTPM.as_utpm(z0) H = z.data[2, ...] * 2 return H
def _jacobian_forward(self, x, *args, **kwds): x = np.asarray(x, dtype=float) # shape = x.shape D, Nm = 2, x.size P = Nm y = UTPM(np.zeros((D, P, Nm))) y.data[0, :] = x.ravel() y.data[1, :] = np.eye(Nm) z0 = self.f(y, *args, **kwds) z = UTPM.as_utpm(z0) J = z.data[1, :, :, 0] return J
def hessian_forward(): def f(x, *args, **kwds): return x[0] + x[1] ** 2 + x[2] ** 3 x = np.asarray([1, 2, 3], dtype=float) # shape = x.shape D, Nm = 2+1, x.size P = Nm y = UTPM(np.zeros((D, P, Nm))) y.data[0, :] = x.ravel() y.data[1, :] = np.eye(Nm) z0 = f(y) z = UTPM.as_utpm(z0) J = z.data[2, ...] * 2 return J