This function samples states from the Ising model using one of three methods. See details.
IsingSampler(n, graph, thresholds, beta = 1, nIter = 100, responses = c(0L, 1L),
method = c("MH", "CFTP", "direct"), CFTPretry = 10, constrain)
A matrix containing samples of states.
Number of states to draw
Square matrix indicating the weights of the network. Must be symmetrical with 0 as diagonal.
Vector indicating the thresholds, also known as the external field.
Scalar indicating the inverse temperature.
Number of iterations in the Metropolis and exact sampling methods.
Response options. Typically set to c(-1L, 1L)
or c(0L, 1L)
(default). Must be integers!
The sampling method to use. Must be "MH"
, "CFTP"
or "direct"
. See details.
The amount of times a sample from CFTP may be retried. If after 100 couplings from the past the chain still results in NA
values the chain is reset with different random numbers. Be aware that data that requies a lot of CFTP resets might not resemble exact samples anymore.
A (number of samples) by (number of nodes) matrix with samples that need be constrained; NA
indicates that the sample is unconstrained. Defaults to a matrix of NA
s.
Sacha Epskamp (mail@sachaepskamp.com)
This function uses one of three sampling methods. "MH"
can be used to sample using a Metropolis-Hastings algorithm. The chain is initiated with random values from the response options, then for each iteration for each node a node is set to the second response option with the probability of that node being in the second response option given all other nodes and parameters. Typically, 100 of such iterations should suffice for the chain to converge.
The second method, "CFTP"
enhances the Metropolis-Hastings algorithm with Coupling from the Past (CFTP; Murray, 2007) to draw exact samples from the distribution. This is slower than the default Metropolis-Hastings but guarantees exact samples. However, it does depend on the graph structure and the number of nodes if these exact samples can be obtained in feasable time.
The third option, "direct"
, simply computes for every possibly state the probability and draws samples directly from the distribution of states by using these probabilities. This also guarantees exact samples, but quickly becomes intractible (roughly above 10 nodes).
Murray, I. (2007). Advances in Markov chain Monte Carlo methods.
IsingSampler-package
for examples
## See IsingSampler-package help page
Run the code above in your browser using DataLab