Title: | Landscape Construction and Simulation for Ising Networks |
---|---|
Description: | A toolbox for constructing potential landscapes for Ising networks. The parameters of the networks can be directly supplied by users or estimated by the 'IsingFit' package by van Borkulo and Epskamp (2016) <https://CRAN.R-project.org/package=IsingFit> from empirical data. The Ising model's Boltzmann distribution is preserved for the potential landscape function. The landscape functions can be used for quantifying and visualizing the stability of network states, as well as visualizing the simulation process. |
Authors: | Jingmeng Cui [aut, cre] |
Maintainer: | Jingmeng Cui <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.1.9000 |
Built: | 2025-02-07 05:46:12 UTC |
Source: | https://github.com/Sciurus365/Isinglandr |
Those layers can show how the stability metrics are calculated on the landscape.
## S3 method for class 'stability_2d_Isingland' autolayer( object, point = TRUE, line = TRUE, split_value = TRUE, interval = TRUE, stability_value = TRUE, ... ) ## S3 method for class 'stability_2d_Isingland_matrix' autolayer( object, point = TRUE, line = TRUE, split_value = TRUE, interval = TRUE, stability_value = TRUE, ... )
## S3 method for class 'stability_2d_Isingland' autolayer( object, point = TRUE, line = TRUE, split_value = TRUE, interval = TRUE, stability_value = TRUE, ... ) ## S3 method for class 'stability_2d_Isingland_matrix' autolayer( object, point = TRUE, line = TRUE, split_value = TRUE, interval = TRUE, stability_value = TRUE, ... )
object |
A |
point , line , split_value , interval , stability_value
|
Show those elements on the layer? Default is |
... |
Not in use. |
a ggplot layer
Calculate energy barrier for Ising landscapes
## S3 method for class ''2d_Isingland'' calculate_barrier(l, ...) ## S3 method for class ''2d_Isingland_matrix'' calculate_barrier(l, ...) ## S3 method for class 'barrier_2d_Isingland' print(x, simplify = FALSE, ...) ## S3 method for class 'barrier_2d_Isingland' summary(object, ...) ## S3 method for class 'barrier_2d_Isingland_matrix' summary(object, ...)
## S3 method for class ''2d_Isingland'' calculate_barrier(l, ...) ## S3 method for class ''2d_Isingland_matrix'' calculate_barrier(l, ...) ## S3 method for class 'barrier_2d_Isingland' print(x, simplify = FALSE, ...) ## S3 method for class 'barrier_2d_Isingland' summary(object, ...) ## S3 method for class 'barrier_2d_Isingland_matrix' summary(object, ...)
l |
An |
... |
Not in use. |
x |
a result of the default method of |
simplify |
Print a simplified version of the output? Default is |
object |
an object for which a summary is desired. |
A barrier_Isingland
object that contains the following components:
shape
A character describing the shape of the landscape.
local_min_start
,local_min_end
,saddle_point
The positions of the
two local minimums and the saddle point, described each by a list containing:
U
The potential value.
location
x_index
The row index in get_dist(l)
.
x_value
The number of active nodes.
delta_U_start
,delta_U_end
The barrier heights for both sides.
summary(barrier_2d_Isingland)
: Return a vector of
barrier heights.
summary(barrier_2d_Isingland_matrix)
: Return a tibble of
barrier heights and conditions.
The stability is calculated based on the shape of the potential landscape and the prior knowledge about the qualitatively different parts of the system. Two stability indicators are calculated separately, and their difference is used to represent a general stability of the system in favor of the first phase. Within each phase, the potential difference between the local maximum and the local minimum (if multiple minimums exist, use the one that is further from the other phase; and the local maximum should always be on the side to the other phase) is used to represent the stability of this phase.
calculate_stability(l, ...) ## S3 method for class ''2d_Isingland'' calculate_stability(l, split_value = 0.5 * l$Nvar, ...) ## S3 method for class ''2d_Isingland_matrix'' calculate_stability(l, split_value = 0.5 * l$Nvar, ...)
calculate_stability(l, ...) ## S3 method for class ''2d_Isingland'' calculate_stability(l, split_value = 0.5 * l$Nvar, ...) ## S3 method for class ''2d_Isingland_matrix'' calculate_stability(l, split_value = 0.5 * l$Nvar, ...)
l |
An |
... |
Not in use. |
split_value |
An integer to specify the number of active nodes used to split two stability ranges. Default is half of the number of nodes. |
calculate_stability.2d_Isingland()
Returns a calculate_stability.2d_Isingland
project, which contains the following elements:
The distribution tibble which is the same as in the input l
.
The (row)indices in dist
that were used as the positions of the local minimums and maximums in two parts.
The stability measures for the first (left) part, the second part (right), and their difference.
calculate_stability.2d_Isingland_matrix()
Returns a stability_2d_Isingland_matrix
object, which is a tibble containing columns of the varying parameters and a column stability
of the calculate_stability.2d_Isingland
objects for each landscape.
When print()
ed, a verbal description of the stability metrics is shown. Use the summary()
method for a tidy version of the outputs.
Note that the BCa method is used for stability differences, and the percentile method is used for stability measures of individual phases because the stability measures of individual phases are highly zero-inflated and may crash the BCa estimation procedure. The range estimation of the stability measures of individual phases should be interpreted with caution.
calculate_stability_se( data, split_value = 0.5 * ncol(data), R = 1000, IsingFit_options = list(plot = FALSE), Isingland_options = list(), ... ) ## S3 method for class 'stability_se' print(x, ...) compare_stability( data1, data2, split_value = 0.5 * ncol(data), R = 1000, IsingFit_options = list(plot = FALSE), Isingland_options = list(), ... )
calculate_stability_se( data, split_value = 0.5 * ncol(data), R = 1000, IsingFit_options = list(plot = FALSE), Isingland_options = list(), ... ) ## S3 method for class 'stability_se' print(x, ...) compare_stability( data1, data2, split_value = 0.5 * ncol(data), R = 1000, IsingFit_options = list(plot = FALSE), Isingland_options = list(), ... )
data |
A matrix of binary data |
split_value |
An integer to specify the number of active nodes used to split two stability ranges. Default is half of the number of nodes. |
R |
The number of bootstrap replicates. Usually this will be a single
positive integer. For importance resampling, some resamples may use
one set of weights and others use a different set of weights. In
this case |
IsingFit_options |
Parameters passed to |
Isingland_options |
Parameters passed to |
... |
Parameters passed to |
x |
An object of class |
data1 , data2
|
Two matrices of binary data |
Use calculate_stability_se()
for a single dataset, and use compare_stability()
for comparing the stability metrics of two groups.
If you encounter the error message "Error in if (any(ints)) out[inds[ints]] <- tstar[k[inds[ints]]] : missing value where TRUE/FALSE needed", you may need to install the patched version of the boot.pval
package with pak::pkg_install("Sciurus365/boot.pval@patch-1")
. See https://github.com/mthulin/boot.pval/issues/4.
If you encounter the error message "estimated adjustment 'a' is NA", that probably means you should increase the number of bootstrap samples (R
). See https://stats.stackexchange.com/questions/37918/why-is-the-error-estimated-adjustment-a-is-na-generated-from-r-boot-package.
Puth, M.-T., Neuhäuser, M., & Ruxton, G. D. (2015). On the variety of methods for calculating confidence intervals by bootstrapping. Journal of Animal Ecology, 84(4), 892–897. https://doi.org/10.1111/1365-2656.12382
First specify what is the network parameter in each time points, then perform a chain simulation based on it. An Ising chain can be generated from one or more Ising grid(s) with one changing condition each.
chain_simulate_Isingland( Ising_chain, transform = FALSE, initial = 0, beta2 = NULL ) make_Ising_chain(...)
chain_simulate_Isingland( Ising_chain, transform = FALSE, initial = 0, beta2 = NULL ) make_Ising_chain(...)
Ising_chain |
An |
transform |
By default, this function considers the Ising network
to use |
initial |
An integer indicating the initial number of active nodes for the simulation. Float numbers will be converted to an integer automatically. |
beta2 |
The |
... |
Ising grid(s) created by |
make_Ising_chain
returns an Ising_chain
object, which is a tibble, and each row
represents a set of parameters for an Ising network.
chain_simulate_Isingland
returns a chain_sim_Isingland
object,
which is a tibble containing the parameters, the landscape, and
the number of active nodes for each time step.
Calculate the potential value for each system state, represented by the
number of active nodes
. The potential value is determined so that the Boltzmann
distribution is preserved. The Boltzmann distribution is the basis and the
steady-state distribution of all dynamic methods for Ising models, including
those used in
IsingSampler::IsingSampler()
and Glauber dynamics. This means
that if you assume the real-life system has the same steady-state distribution
as the Boltzmann distribution of the Ising model, then possibility that their
are active nodes in the system is proportional to
.
Because of this property of
, it is aligned with the potential
landscape definition by Wang et al. (2008) and can quantitatively represent
the stability of different system states.
make_2d_Isingland(thresholds, weiadj, beta = 1, transform = FALSE)
make_2d_Isingland(thresholds, weiadj, beta = 1, transform = FALSE)
thresholds , weiadj
|
The thresholds and the weighted adjacency matrix
of the Ising network. If you have an |
beta |
The |
transform |
By default, this function considers the Ising network
to use |
The potential function is calculated by the following equation:
where represent a specific activation state of the network,
is the number of active nodes for
, and
is the
Hamiltonian function for Ising networks.
A 2d_Isingland
object that contains the following components:
dist_raw
,dist
Two tibbles containing the probability
distribution and the potential values for different states.
thresholds
,weiadj
,beta
The parameters supplied to the function.
Nvar
The number of variables (nodes) in the Ising network.
Wang, J., Xu, L., & Wang, E. (2008). Potential landscape and flux framework of nonequilibrium networks: Robustness, dissipation, and coherence of biochemical oscillations. Proceedings of the National Academy of Sciences, 105(34), 12271-12276. https://doi.org/10.1073/pnas.0800579105 Sacha Epskamp (2020). IsingSampler: Sampling methods and distribution functions for the Ising model. R package version 0.2.1. https://CRAN.R-project.org/package=IsingSampler Glauber, R. J. (1963). Time-dependent statistics of the Ising model. Journal of Mathematical Physics, 4(2), 294-307. https://doi.org/10.1063/1.1703954
make_3d_Isingland()
if you have two groups of nodes that you want
to count the number of active ones separately.
Nvar <- 10 m <- rep(0, Nvar) w <- matrix(0.1, Nvar, Nvar) diag(w) <- 0 result1 <- make_2d_Isingland(m, w) plot(result1)
Nvar <- 10 m <- rep(0, Nvar) w <- matrix(0.1, Nvar, Nvar) diag(w) <- 0 result1 <- make_2d_Isingland(m, w) plot(result1)
Make multiple landscapes together for different parameters.
make_2d_Isingland_matrix(Ising_grid, transform = FALSE)
make_2d_Isingland_matrix(Ising_grid, transform = FALSE)
Ising_grid |
Parameter values generated by |
transform |
By default, this function considers the Ising network
to use |
A 2d_Isingland_matrix
object that contains the following
components:
dist_raw
,dist
Two tibbles containing the probability
distribution and the potential values for different states.
Nvar
The number of variables (nodes) in the Ising network.
Nvar <- 10 m <- rep(0, Nvar) w <- matrix(0.1, Nvar, Nvar) diag(w) <- 0 result4 <- make_Ising_grid( all_thresholds(seq(-0.1, 0.1, 0.1), .f = `+`), whole_weiadj(seq(0.5, 1.5, 0.5)), m, w ) %>% make_2d_Isingland_matrix() plot(result4)
Nvar <- 10 m <- rep(0, Nvar) w <- matrix(0.1, Nvar, Nvar) diag(w) <- 0 result4 <- make_Ising_grid( all_thresholds(seq(-0.1, 0.1, 0.1), .f = `+`), whole_weiadj(seq(0.5, 1.5, 0.5)), m, w ) %>% make_2d_Isingland_matrix() plot(result4)
Similar to make_2d_Isingland()
, but two categories of nodes can
be specified so the number of active nodes can be calculated
separately.
make_3d_Isingland(thresholds, weiadj, x, y, beta = 1, transform = FALSE)
make_3d_Isingland(thresholds, weiadj, x, y, beta = 1, transform = FALSE)
thresholds , weiadj
|
The thresholds and the weighted adjacency matrix
of the Ising network. If you have an |
x , y
|
Two vectors specifying the indices or the names of the
nodes for two categories. If they are character vectors, the names
should match the row names of the |
beta |
The |
transform |
By default, this function considers the Ising network
to use |
A 3d_Isingland
object that contains the following components:
dist_raw
,dist
Two tibbles containing the probability
distribution and the potential values for different states.
thresholds
,weiadj
,beta
The parameters supplied to the function.
Nvar
The number of variables (nodes) in the Ising network.
make_2d_Isingland()
for the algorithm.
Specify one or two varying parameters for
Ising networks. The output of make_Ising_grid()
can be used to
make landscapes of multiple networks.
make_Ising_grid(par1, par2 = NULL, thresholds, weiadj, beta = 1)
make_Ising_grid(par1, par2 = NULL, thresholds, weiadj, beta = 1)
par1 , par2
|
Generated from one of |
thresholds , weiadj
|
The thresholds and the weighted adjacency matrix
of the Ising network. If you have an |
beta |
The |
There are five possible ways to vary the parameters for Ising networks, corresponding to five control functions:
single_threshold()
Vary a threshold value for a single variable.
all_thresholds()
Vary all threshold values together.
single_wei()
Vary a single weight value for a path between two
variables.
whole_weiadj()
Vary the whole weighted adjacency matrix.
beta_list()
Use a list of different beta values.
See make_Ising_grid-control-functions for details.
An Ising_grid
object that is based on a tibble and
contains the information of all simulation conditions.
Control Functions to Specify the Varying Parameters for an Ising Grid.
single_threshold(pos, seq, .f = `*`) single_wei(pos, seq, .f = `*`) all_thresholds(seq, .f = `*`) whole_weiadj(seq, .f = `*`) beta_list(seq, .f = `*`)
single_threshold(pos, seq, .f = `*`) single_wei(pos, seq, .f = `*`) all_thresholds(seq, .f = `*`) whole_weiadj(seq, .f = `*`) beta_list(seq, .f = `*`)
pos |
The position of the single threshold or the weight
value that should vary across Ising networks. Should be a single
number for |
seq |
A vector that specify the values. Can be generated
with |
.f |
What calculation should be done for |
An ctrl_*
object specifying the varying parameters.
Estimation data for the Ising network of major depressive disorder
MDDConnectivity MDDThresholds
MDDConnectivity MDDThresholds
An object of class matrix
(inherits from array
) with 9 rows and 9 columns.
An object of class numeric
of length 9.
MDDConnectivity
: The connectivity strength of the network,
represented in a weighted adjacency matrix.
MDDThresholds
: The thresholds of the network nodes,
represented in a vector.
A shiny app that shows the landscape for the Ising network of major depressive disorder
shiny_Isingland_MDD(...)
shiny_Isingland_MDD(...)
... |
Not in use. |
This function opens a Shiny app session without a return value.
Perform a numeric simulation using the landscape. The simulation is performed
using a similar algorithm as Glauber dynamics, that the transition possibility
is determined by the difference in the potential function, and the steady-state
distribution is the same as the Boltzmann distribution (if not setting beta2
).
Note that, the conditional transition possibility of this simulation
may be different from Glauber dynamics or other simulation methods.
simulate_Isingland(l, ...) ## S3 method for class ''2d_Isingland'' simulate_Isingland( l, mode = "single", initial = 0, length = 100, beta2 = l$beta, ... ) ## S3 method for class ''2d_Isingland_matrix'' simulate_Isingland( l, mode = "single", initial = 0, length = 100, beta2 = NULL, ... )
simulate_Isingland(l, ...) ## S3 method for class ''2d_Isingland'' simulate_Isingland( l, mode = "single", initial = 0, length = 100, beta2 = l$beta, ... ) ## S3 method for class ''2d_Isingland_matrix'' simulate_Isingland( l, mode = "single", initial = 0, length = 100, beta2 = NULL, ... )
l |
An |
... |
Not in use. |
mode |
One of |
initial |
An integer indicating the initial number of active nodes for the simulation. Float numbers will be converted to an integer automatically. |
length |
An integer indicating the simulation length. |
beta2 |
The |
In each simulation step, the system can have one more active node, one less active node, or the same number of active nodes (if possible; so if all nodes are already active then it is not possible to have one more active node). The possibility of the three cases is determined by their potential function:
where is the number of active nodes at the time
, and
is the potential function.
A sim_Isingland
object with the following components:
output
A tibble of the simulation output.
landscape
The landscape object supplied to this function.
mode
A character representing the mode of the simulation.
Nvar <- 10 m <- rep(0, Nvar) w <- matrix(0.1, Nvar, Nvar) diag(w) <- 0 result1 <- make_2d_Isingland(m, w) plot(result1) set.seed(1614) sim1 <- simulate_Isingland(result1, initial = 5) plot(sim1)
Nvar <- 10 m <- rep(0, Nvar) w <- matrix(0.1, Nvar, Nvar) diag(w) <- 0 result1 <- make_2d_Isingland(m, w) plot(result1) set.seed(1614) sim1 <- simulate_Isingland(result1, initial = 5) plot(sim1)