Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2013 17:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6381240 to your computer and use it in GitHub Desktop.
Save anonymous/6381240 to your computer and use it in GitHub Desktop.
from pylab import *
from shogun.Mathematics import LogDetEstimator
from shogun.Mathematics import ProbingSampler
from shogun.Library import SerialComputationEngine
from shogun.Mathematics import LogRationalApproximationCGM
from shogun.Mathematics import RealSparseMatrixOperator
from shogun.Mathematics import LanczosEigenSolver
from shogun.Mathematics import CCGMShiftedFamilySolver
from shogun.Mathematics import Statistics
from scipy.sparse import csc_matrix
from scipy.sparse import spdiags
data=abs(randn(10))
matrix=spdiags(data, 0, 10, 10);
print matrix
op=RealSparseMatrixOperator(csc_matrix(matrix))
trace_sampler=ProbingSampler(op)
engine=SerialComputationEngine()
linear_solver=CCGMShiftedFamilySolver()
num_shifts=10
eigen_solver=LanczosEigenSolver(op)
op_func=LogRationalApproximationCGM(op, engine, eigen_solver, linear_solver, num_shifts)
log_det_estimator=LogDetEstimator(trace_sampler, op_func, engine)
print sum(log(data))
print Statistics.log_det(csc_matrix(matrix))
print mean(log_det_estimator.sample(10000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment