Exemplo n.º 1
0
    def compute_d1(self):
        # To stay consistent with numpy, we must upgrade 1D arrays to 2D
        ar = row(self.a.r) if len(self.a.r.shape)<2 else self.a.r.reshape((-1, self.a.r.shape[-1]))
        br = col(self.b.r) if len(self.b.r.shape)<2 else self.b.r.reshape((self.b.r.shape[0], -1))

        if ar.ndim <= 2:
            return sp.kron(sp.eye(ar.shape[0], ar.shape[0]),br.T)
        else:
            raise NotImplementedError
Exemplo n.º 2
0
    def compute_dr_wrt(self, wrt):
        if wrt is self.x:
            if visualize:
                import matplotlib.pyplot as plt
                residuals = np.sum(self.r**2)
                print('------> RESIDUALS %.2e' % (residuals, ))
                print('------> CURRENT GUESS %s' % (str(self.x.r), ))
                plt.figure(123)

                if not hasattr(self, 'vs'):
                    self.vs = []
                    self.xs = []
                    self.ys = []
                self.vs.append(residuals)
                self.xs.append(self.x.r[0])
                self.ys.append(self.x.r[1])
                plt.clf()
                plt.subplot(1, 2, 1)
                plt.plot(self.vs)
                plt.subplot(1, 2, 2)
                plt.plot(self.xs, self.ys)
                plt.draw()

            return row(rosen_der(self.x.r))
Exemplo n.º 3
0
 def compute_dr_wrt(self, wrt):
     if wrt is self.x:
         return row(self.x.r.ravel()*2.)