This file contains hidden or 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
using LinearAlgebra | |
using BenchmarkTools | |
using SparseArrays | |
# To exploit the sparsity of the matrix as much as possible, pre-compile the multiplication operation | |
# to skip the matrix entries look-up. Since the matrix is sparse this might generate only a few operations | |
# which are all inlined. | |
# Note that this only works with small matrices since otherwise the size of the function will just be to | |
# large. | |
# Note that this could also be avoided, but this is another topic. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
import multiprocessing as mp | |
import numpy as np | |
def multiprocessing(f, data, nproc): | |
chunks = np.array_split(data, nproc) | |
with mp.Pool(nproc) as ex: | |
res = ex.map(f, chunks) | |
return np.concatenate(list(res)) | |
def dosomething(xs): |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
def smc(M, steps, prior, potential, proposal_kernel, correction_steps=1, ess_ratio=2): | |
""" | |
smc(M, steps, prior, potential, proposal_kernel, correction_steps=1, ess_ratio=2) | |
Creates a particle approximation of a probability distribution using the Sequential | |
Monte Carlo (SMC) algorithm with Markov Chain Monte Carlo (MCMC) correction steps using | |
the Metropolis-Hastings algorithm. | |
Parameters |