Skip to content

Instantly share code, notes, and snippets.

@karlnapf
Last active December 21, 2015 23:19
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 karlnapf/6381345 to your computer and use it in GitHub Desktop.
Save karlnapf/6381345 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=csc_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(matrix)
print mean(log_det_estimator.sample(100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment