Пример #1
0
    def test_get_targ(self, other, T = 5e-3, outlierprior=1e-1, outlierfrac=1e-2, outliercutoff=1e-2, norm_iters = DEFAULT_NORM_ITERS):
        self.transform_points()
        other.transform_points()
        init_prob_nm(self.pt_ptrs, other.pt_ptrs, 
                     self.pt_w_ptrs, other.pt_w_ptrs, 
                     self.dims_gpu, other.dims_gpu,
                     self.N, outlierprior, outlierfrac, T, 
                     self.corr_cm_ptrs, self.corr_rm_ptrs)
        norm_prob_nm(self.corr_cm_ptrs, self.corr_rm_ptrs, 
                     self.dims_gpu, other.dims_gpu, self.N, outlierfrac, norm_iters,
                     self.r_coef_ptrs, self.c_coef_rn_ptrs, self.c_coef_cn_ptrs)
        get_targ_pts(self.pt_ptrs, other.pt_ptrs,
                     self.pt_w_ptrs, other.pt_w_ptrs,
                     self.corr_cm_ptrs, self.corr_rm_ptrs,
                     self.r_coef_ptrs, self.c_coef_rn_ptrs, self.c_coef_cn_ptrs,
                     self.dims_gpu, other.dims_gpu, 
                     outliercutoff, self.N,
                     self.pt_t_ptrs, other.pt_t_ptrs)
        n, m = self.dims[0], other.dims[0]
        x = self.pts[0].get()[:n]
        xw = self.pts_w[0].get()[:n]
        xt = self.pts_t[0].get()[:n]
        y = other.pts[0].get()[:m]
        yw = other.pts_w[0].get()[:m]
        yt = other.pts_t[0].get()[:m]

        init_corr = self.corr_rm[0].get()        
        init_corr = init_corr.flatten()[:(n + 1) * (m + 1)].reshape(n+1, m+1).astype(np.float32)
        gpu_c_cn_coefs = self.c_coefs_cn[0].get().flatten()[:m + 1].reshape(m+1)
        gpu_c_rn_coefs = self.c_coefs_rn[0].get().flatten()[:m + 1].reshape(m+1)
        gpu_r_coefs = self.r_coefs[0].get().flatten()[:n + 1].reshape(n+1)

        rn_corr = (init_corr * gpu_c_rn_coefs[None, :]) * gpu_r_coefs[:, None]
        cn_corr = (init_corr * gpu_c_cn_coefs[None, :]) * gpu_r_coefs[:, None]        
        rn_corr = rn_corr[:n, :m]
        cn_corr = cn_corr[:n, :m]
        
        wt_n = rn_corr.sum(axis=1)
        inlier = wt_n > outliercutoff
        xtarg = np.empty((n, DATA_DIM))
        xtarg[inlier, :] = rn_corr.dot(y)[inlier, :]
        xtarg[~inlier, :] = xw[~inlier, :]

        if not np.allclose(xtarg, xt):
            print "xt values differ"
            ipy.embed()
            sys.exit(1)

        wt_m = cn_corr.sum(axis=0)
        inliner = wt_m > outliercutoff
        ytarg = np.empty((m, DATA_DIM))
        ytarg[inlier, :] = cn_corr.T.dot(x)[inliner, :]
        ytarg[~inlier, :] = yw[~inlier, :]
        if not np.allclose(ytarg, yt):
            print "yt values differ"
            ipy.embed()
            sys.exit(1)                            
Пример #2
0
 def get_target_points(
     self, other, outlierprior=1e-1, outlierfrac=1e-2, outliercutoff=1e-2, T=5e-3, norm_iters=DEFAULT_NORM_ITERS
 ):
     """
     computes the target points for self and other
     using the current warped points for both                
     """
     init_prob_nm(
         self.pt_ptrs,
         other.pt_ptrs,
         self.pt_w_ptrs,
         other.pt_w_ptrs,
         self.dims_gpu,
         other.dims_gpu,
         self.N,
         outlierprior,
         outlierfrac,
         T,
         self.corr_cm_ptrs,
         self.corr_rm_ptrs,
     )
     sync()
     norm_prob_nm(
         self.corr_cm_ptrs,
         self.corr_rm_ptrs,
         self.dims_gpu,
         other.dims_gpu,
         self.N,
         outlierfrac,
         norm_iters,
         self.r_coef_ptrs,
         self.c_coef_rn_ptrs,
         self.c_coef_cn_ptrs,
     )
     sync()
     get_targ_pts(
         self.pt_ptrs,
         other.pt_ptrs,
         self.pt_w_ptrs,
         other.pt_w_ptrs,
         self.corr_cm_ptrs,
         self.corr_rm_ptrs,
         self.r_coef_ptrs,
         self.c_coef_rn_ptrs,
         self.c_coef_cn_ptrs,
         self.dims_gpu,
         other.dims_gpu,
         outliercutoff,
         self.N,
         self.pt_t_ptrs,
         other.pt_t_ptrs,
     )
     sync()
Пример #3
0
    def test_norm_corr(self, other, T = 5e-3, outlierprior=1e-1, outlierfrac=1e-2, outliercutoff=1e-2, norm_iters = DEFAULT_NORM_ITERS):
        import sys
        self.transform_points()
        other.transform_points()
        init_prob_nm(self.pt_ptrs, other.pt_ptrs, 
                     self.pt_w_ptrs, other.pt_w_ptrs, 
                     self.dims_gpu, other.dims_gpu,
                     self.N, outlierprior, outlierfrac, T, 
                     self.corr_cm_ptrs, self.corr_rm_ptrs)
        n, m  = self.dims[0], other.dims[0]
        init_corr = self.corr_rm[0].get()        
        init_corr = init_corr.flatten()[:(n + 1) * (m + 1)].reshape(n+1, m+1).astype(np.float32)
        
        a_N = np.ones((n+1),dtype = np.float32)
        a_N[n] = m*outlierfrac
        b_M = np.ones((m+1), dtype = np.float32)
        b_M[m] = n*outlierfrac

        old_r_coefs = np.ones(n+1, dtype=np.float32)
        old_c_coefs = np.ones(m+1, dtype=np.float32)
        for n_iter in range(1, norm_iters):
            init_prob_nm(self.pt_ptrs, other.pt_ptrs, 
                         self.pt_w_ptrs, other.pt_w_ptrs, 
                         self.dims_gpu, other.dims_gpu,
                         self.N, outlierprior, outlierfrac, T, 
                         self.corr_cm_ptrs, self.corr_rm_ptrs)

            norm_prob_nm(self.corr_cm_ptrs, self.corr_rm_ptrs, 
                         self.dims_gpu, other.dims_gpu, self.N, outlierfrac, n_iter,
                         self.r_coef_ptrs, self.c_coef_rn_ptrs, self.c_coef_cn_ptrs)        
            new_r_coefs = a_N/init_corr.dot(old_c_coefs[:m+1])
            new_c_coefs = b_M/new_r_coefs[:n+1].dot(init_corr)
            gpu_c_coefs = self.c_coefs_cn[0].get().flatten()[:m + 1].reshape(m+1)
            gpu_r_coefs = self.r_coefs[0].get().flatten()[:n + 1].reshape(n+1)
            if not np.allclose(new_r_coefs, gpu_r_coefs):
                print "row coeficients don't match", n_iter
                ipy.embed()
                sys.exit(1)
            if not np.allclose(new_c_coefs, gpu_c_coefs):
                print "column coeficients don't match", n_iter
                ipy.embed()
                sys.exit(1)
            # old_r_coefs = gpu_r_coefs
            # old_c_coefs = gpu_c_coefs
            old_r_coefs = new_r_coefs
            old_c_coefs = new_c_coefs