def calc_ll(self,theta):
        """
        Computes the ll per measurments.
        """             
        cpa_space = self.cpa_space
        src = self.src
        dst = self.dst
        params_flow_int = self.params_flow_int
        transformed = self.transformed
        sigma_lm =  self.sigma_lm
        ll = self.ll         
          
        if src.shape[1]!=cpa_space.dim_domain:
            raise ValueError(src.shape)
       
                                   

        cpa_space.theta2Avees(theta)
        cpa_space.update_pat()        
        cpa_space.calc_T_fwd(pts = src, out=transformed,
                           **params_flow_int)          
        
        if transformed.shape != src.shape:
            raise ValueError(transformed.shape , src.shape)                   
        
        if 1:
            calc_err_per_sample(transformed.gpu,dst.gpu,self.err.gpu)   
            
            
    #       print  np.allclose(transformed.gpu.get()-dst.gpu.get(),
    #                          self.err.gpu.get())
                   
            calc_ll_per_sample(self.err.gpu,sigma_lm ,ll.gpu)       
          
    #        print np.allclose((-0.5/(sigma_lm**2)*
    #                          (transformed.gpu.get()-dst.gpu.get())**2).sum(axis=1), 
    #                          ll.gpu.get())
          
            
#            idx = (dst.cpu<0.5).nonzero()[0][-1]
#            idx = 499
#            
#            weight_it(ll.gpu,np.int32(idx))        
#            ipshell('hi')
#            1/0
        else:
            raise Exception("BAD IDEA")
            ll_by_der = self.ll_by_der
            der_dt = 0.002
           
            calc_err_by_der_per_sample(transformed.gpu,dst.gpu,self.err_by_der.gpu,
                                       der_dt)
            calc_ll_by_der_per_sample(self.err_by_der.gpu,.1 ,ll_by_der.gpu) 
            
        
            ll = ll_by_der
Esempio n. 2
0
    def calc_ll(self,theta):
        """
        Returns the ll per measurments.
        """             
        cpa_space = self.cpa_space
        src = self.src
        dst = self.dst
        params_flow_int = self.params_flow_int
        transformed = self.transformed
        sigma_lm =  self.sigma_lm
        ll = self.ll         
          
        if src.shape[1]!=cpa_space.dim_domain:
            raise ValueError(src.shape)
       
                                   
#        Avees = cpa_space.theta2Avees(theta)
#        pat = self._pat
#        pat.update(Avees=Avees)              
#        cpa_space.calc_T(pat,pts = src, mysign=1,out=transformed,
#                           **params_flow_int)       
        
        cpa_space.theta2Avees(theta)
        cpa_space.update_pat()        
        cpa_space.calc_T_fwd(pts = src,out=transformed,
                           **params_flow_int)          
        
        if transformed.shape != src.shape:
            raise ValueError(transformed.shape , src.shape)                   
         
        calc_err_per_sample(transformed.gpu,dst.gpu,self.err.gpu)   
        
        
#       print  np.allclose(transformed.gpu.get()-dst.gpu.get(),
#                          self.err.gpu.get())
               
        calc_ll_per_sample(self.err.gpu,sigma_lm ,ll.gpu)       
      
#        print np.allclose((-0.5/(sigma_lm**2)*
#                          (transformed.gpu.get()-dst.gpu.get())**2).sum(axis=1), 
#                          ll.gpu.get())

        
         
        return ll 
    def calc_ll(self, theta):
        """
        Returns the ll per measurments.
        """
        cpa_space = self.cpa_space
        src = self.src
        dst = self.dst
        params_flow_int = self.params_flow_int
        transformed = self.transformed
        sigma_lm = self.sigma_lm
        ll = self.ll

        if src.shape[1] != cpa_space.dim_domain:
            raise ValueError(src.shape)

        #        Avees = cpa_space.theta2Avees(theta)
        #        pat = self._pat
        #        pat.update(Avees=Avees)
        #        cpa_space.calc_T(pat,pts = src, mysign=1,out=transformed,
        #                           **params_flow_int)

        cpa_space.theta2Avees(theta)
        cpa_space.update_pat()
        cpa_space.calc_T_fwd(pts=src, out=transformed, **params_flow_int)

        if transformed.shape != src.shape:
            raise ValueError(transformed.shape, src.shape)

        calc_err_per_sample(transformed.gpu, dst.gpu, self.err.gpu)

        #       print  np.allclose(transformed.gpu.get()-dst.gpu.get(),
        #                          self.err.gpu.get())

        calc_ll_per_sample(self.err.gpu, sigma_lm, ll.gpu)

        #        print np.allclose((-0.5/(sigma_lm**2)*
        #                          (transformed.gpu.get()-dst.gpu.get())**2).sum(axis=1),
        #                          ll.gpu.get())

        return ll
    def calc_ll(self, theta):
        """
        Computes the ll per measurments.
        """
        cpa_space = self.cpa_space
        src = self.src
        signal = self.signal
        params_flow_int = self.params_flow_int
        transformed = self.transformed
        sigma_signal = self.sigma_signal
        ll = self.ll

        if src.shape[1] != cpa_space.dim_domain:
            raise ValueError(src.shape)

        cpa_space.theta2Avees(theta)
        cpa_space.update_pat()

        cpa_space.calc_T_inv(pts=src, out=transformed, **params_flow_int)

        if transformed.shape != src.shape:
            raise ValueError(transformed.shape, src.shape)

        if 0:
            # I think this is irrelevant here.
            # (it was relevant for the 1d case)
            scale_pts = src.shape[0]  # Assuming we normalized src
            # to [0,1],
            # we need to scale it
            # t0 [0,1,..,num_of_samples+1]

            transformed.gpu *= scale_pts

        if self.interp_type_for_ll == 'gpu_linear':
            resampler(pts_gpu=transformed.gpu,
                      img_gpu=signal.src.gpu,
                      img_wrapped_gpu=signal.transformed.gpu)
        else:
            remap_fwd_opencv(pts_inv=transformed,
                             img=signal.src,
                             img_wrapped_fwd=signal.transformed,
                             interp_method=self.interp_type_for_ll)

#        if signal.dst.shape[1]>1:
#            raise NotImplementedError("Only 1D signals for now")

#        plt.figure(17);
#        signal.transformed.gpu2cpu()
#        if not signal.transformed.cpu.any():
#            raise ValueError('wtf')
#        plt.subplot(221)
#        plt.imshow(signal.src.cpu.reshape(256,-1))
#        plt.subplot(222)
#        plt.imshow(signal.transformed.cpu.reshape(256,-1))
#
#        ipshell('hi')
#        2/0
        calc_signal_err_per_sample(signal.transformed.gpu, signal.dst.gpu,
                                   self.signal.err.gpu)

        #           print  np.allclose(signal.transformed.gpu.get()-
        #                              signal.dst.gpu.get(),
        #                              self.signal.err.gpu.get())
        #        if self.dim_signal != 1:
        #            raise NotImplementedError
        calc_ll_per_sample(ll=ll.gpu,
                           err=self.signal.err.gpu,
                           sigma=sigma_signal)

        if 0:
            res = -0.5 / (sigma_signal**2) * (
                (signal.transformed.gpu - signal.dst.gpu)**2).get()

            np.allclose(res.ravel(), ll.gpu.get())
            ipshell('stop')
            1 / 0


#        1/0
#        ipshell('stop');
#        if any(theta):
#            1/0
    def calc_ll(self, theta):
        """
        Computes the ll per measurments.
        """
        cpa_space = self.cpa_space
        src = self.src
        signal = self.signal
        params_flow_int = self.params_flow_int
        transformed = self.transformed
        sigma_signal = self.sigma_signal
        ll = self.ll

        if src.shape[1] != cpa_space.dim_domain:
            raise ValueError(src.shape)

        cpa_space.theta2Avees(theta)
        cpa_space.update_pat()

        cpa_space.calc_T_inv(pts=src, out=transformed, **params_flow_int)

        if transformed.shape != src.shape:
            raise ValueError(transformed.shape, src.shape)

        if 0:
            # I think this is irrelevant here.
            # (it was relevant for the 1d case)
            scale_pts = src.shape[0]  # Assuming we normalized src
            # to [0,1],
            # we need to scale it
            # t0 [0,1,..,num_of_samples+1]

            transformed.gpu *= scale_pts

        if self.interp_type_for_ll == "gpu_linear":
            resampler(pts_gpu=transformed.gpu, img_gpu=signal.src.gpu, img_wrapped_gpu=signal.transformed.gpu)
        else:
            remap_fwd_opencv(
                pts_inv=transformed,
                img=signal.src,
                img_wrapped_fwd=signal.transformed,
                interp_method=self.interp_type_for_ll,
            )

        #        if signal.dst.shape[1]>1:
        #            raise NotImplementedError("Only 1D signals for now")

        #        plt.figure(17);
        #        signal.transformed.gpu2cpu()
        #        if not signal.transformed.cpu.any():
        #            raise ValueError('wtf')
        #        plt.subplot(221)
        #        plt.imshow(signal.src.cpu.reshape(256,-1))
        #        plt.subplot(222)
        #        plt.imshow(signal.transformed.cpu.reshape(256,-1))
        #
        #        ipshell('hi')
        #        2/0
        calc_signal_err_per_sample(signal.transformed.gpu, signal.dst.gpu, self.signal.err.gpu)

        #           print  np.allclose(signal.transformed.gpu.get()-
        #                              signal.dst.gpu.get(),
        #                              self.signal.err.gpu.get())
        #        if self.dim_signal != 1:
        #            raise NotImplementedError
        calc_ll_per_sample(ll=ll.gpu, err=self.signal.err.gpu, sigma=sigma_signal)

        if 0:
            res = -0.5 / (sigma_signal ** 2) * ((signal.transformed.gpu - signal.dst.gpu) ** 2).get()

            np.allclose(res.ravel(), ll.gpu.get())
            ipshell("stop")
            1 / 0