imate.logdet#
This notebook demonstrate interactive examples of the function imate.logdet
Sparse matrix#
We compute the log-determinant of a sample sparse Toeplitz matrix created by imate.toeplitz() function.
[1]:
# Import packages
from imate import logdet
from imate import toeplitz
# Generate a sample matrix (a toeplitz matrix)
A = toeplitz(2, 1, size=100)
# Compute log-determinant with Cholesky method (default method)
logdet(A)
[1]:
69.31471805599453
[2]:
# Compute log-determinant of the Gramian of A^3:
logdet(A, p=3, gram=True)
[2]:
415.88830833596717
Output information#
Print information about the inner-computation:
[6]:
ld, info = logdet(A, return_info=True)
print(ld)
1386294.3611198922
[7]:
# Print dictionary neatly using pprint
from pprint import pprint
pprint(info)
{'device': {'num_cpu_threads': 8,
'num_gpu_devices': 0,
'num_gpu_multiprocessors': 0,
'num_gpu_threads_per_multiprocessor': 0},
'matrix': {'data_type': b'float64',
'density': 2.999998e-06,
'exponent': 1.0,
'gram': False,
'nnz': 2999998,
'num_inquiries': 1,
'size': 1000000,
'sparse': True},
'solver': {'cholmod_used': True, 'method': 'cholesky', 'version': '0.13.0'},
'time': {'alg_wall_time': 0.24651666499994462,
'cpu_proc_time': 0.24782623600000875,
'tot_wall_time': 0.24651666499994462}}
Very large matrix#
We compute log-determinant of a very large sparse matrix using slq method. This method does not compute log-determinant exactly, rather, the result is an approximation using Monte-Carlo sampling. Here we use at least 100 samples.
[8]:
# Generate a matrix of size one million
A = toeplitz(2, 1, size=1000000, gram=True)
# Approximate log-determinant using stochastic Lanczos quadrature
# with at least 100 Monte-Carlo sampling
ld, info = logdet(A, method='slq', min_num_samples=100,
max_num_samples=200, return_info=True)
print(ld)
1386263.6726923704
[9]:
# Find the time it took to compute the above
pprint(info['time'])
{'alg_wall_time': 17.218212127685547,
'cpu_proc_time': 126.28231630299999,
'tot_wall_time': 17.233046524999736}
[ ]: