def gmrf_est(gmrf, process, experiment_name=None, gmrf_estimation_parameters=None): ''' Saves and creates a gmfr estimator from a GMRF. Arguments: gmrf: a GMRF object process: the name of the process (diagonal, jl, exact) experiment_name -- (string), the name of the experiment gmrf_estimation_parameters -- (dict) the parameters, if any. depends on process Returns: a GMRFEstimator object Side effects: May save some information, if experiment_name is providide ''' if process == 'diagonal': diag_variance = 1.0 / gmrf.diag_precision gmrf_estimator = DiagonalGMRFEstimator(gmrf.translations, gmrf.means, diag_variance) if experiment_name is not None: save_gmrf_estimator_DiagonalGMRFEstimator(gmrf_estimator, experiment_name=experiment_name) elif process == 'jl': precision = gmrf.precision k = gmrf_estimation_parameters['k'] Q = random_projection_cholmod_csc(precision, k) print "Q shape",Q.shape gmrf_estimator = JLGMRFEstimator(gmrf.translations, gmrf.means, Q) if experiment_name is not None: save_gmrf_estimator_JLGMRFEstimator(gmrf_estimator, experiment_name=experiment_name) elif process == 'exact': X = gmrf.precision.todense() covariance = np.linalg.inv(X) gmrf_estimator = ExactGMRFEstimator(gmrf.translations, gmrf.means, covariance) if experiment_name is not None: save_gmrf_estimator_ExactGMRFEstimator(gmrf_estimator, experiment_name=experiment_name) else: assert False return gmrf_estimator
return (D,P,rows,cols) (D,P,rows,cols) = star(5,4) X = build_dense(D, P, rows, cols) Xs = build_sparse(D, P, rows, cols) l1 = logdet_dense(D, P, rows, cols) l2 = logdet_dense_chol(D, P, rows, cols) l3 = logdet_cholmod(D, P, rows, cols) (M,Dn,Pn) = normalized_problem(D, P, rows, cols) test_data(D, P, rows, cols) W = la.inv(X) #Q = random_projection_cholmod(D, U, rows, cols, k, factor) Q = random_projection_cholmod_csc(Xs, k=1000) A = Q.T print A.shape R = np.sum(A*A,axis=1) U = np.sum(A[rows]*A[cols],axis=1) R_ = W.diagonal() U_ = W[rows,cols] #X = build_sparse(D, P, rows, cols) #(eis,_)=eigsh(X, k=1, sigma=-1, which='LM') #ei = eis[0] #is_psd_dense(R, U, rows, cols) #is_psd_cholmod(R, U, rows, cols) (R,U) = inv_dense(D, P, rows, cols)