Last active
December 21, 2015 23:19
-
-
Save karlnapf/6381345 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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