Discrete random variables
The joint probability distribution of random variables $X_1, \ldots, X_n$ is given by a tensor of order $n$. If the random variable $X_i$ takes $d_i$ states, the tensor is of format $d_1 \times \cdots \times d_n$ and consists of non-negative real numbers $p_{x_1 \cdots x_n}$, for all choices $x_i \in [d_i]$, which sum to $1$. The functions below deal with the ambient polynomial ring in these $p$ variables, special forms in them like marginals, and conditional independence ideals.
markov_ring — Function
markov_ring(F::Field, states::Int...; unknown::VarName="p", cached=false)::MarkovRing
markov_ring(states::Int...; unknown::VarName="p", cached=false)::MarkovRingThe polynomial ring whose unknowns are the entries of a probability tensor. The argument states specifies the state space sizes of the random variables, i.e., the dimensions of the tensor. The polynomial ring being constructed will have one variable for each element in the cartesian product of 1:s for s in states. It is a multivariate polynomial ring whose variables are named p[...] and whose coefficient field F is by default QQ.
If cached is true, the internally generated polynomial ring will be cached.
The name tensor_ring is an alias for the constructor markov_ring because that is really what a MarkovRing is: the coordinate ring of tensors of a fixed format. The name MarkovRing is kept for compatibility in terminology with the Macaulay2 package GraphicalModels.
Examples
julia> R = markov_ring(2,2,2,2)
Markov ring over rational field for 4 random variables and states (2, 2, 2, 2)This function is part of the experimental code in Oscar. Please read here for more details.
This function is part of the experimental code in Oscar. Please read here for more details.
ring — Method
ring(R::MarkovRing)Return the multivariate polynomial ring inside R.
Examples
julia> R = markov_ring(2,2,2,2)
Markov ring over rational field for 4 random variables and states (2, 2, 2, 2)
julia> ring(R)
Multivariate polynomial ring in 16 variables p[1, 1, 1, 1], p[2, 1, 1, 1], p[1, 2, 1, 1], p[2, 2, 1, 1], ..., p[2, 2, 2, 2]
over rational fieldThis function is part of the experimental code in Oscar. Please read here for more details.
random_variables — Method
random_variables(R::MarkovRing)Return the vector of [1, ..., n] where n is the number of random variables in the MarkovRing (equivalently n is the order of the tensor).
Examples
julia> R = markov_ring(2, 2, 2, 2)
Markov ring over rational field for 4 random variables and states (2, 2, 2, 2)
julia> random_variables(R)
4-element Vector{Int64}:
1
2
3
4This function is part of the experimental code in Oscar. Please read here for more details.
gens — Method
gens(R::MarkovRing)Return a dictionary for indexing the generators of R by their states.
Examples
julia> R = markov_ring(2,2,2,2)
Markov ring over rational field for 4 random variables and states (2, 2, 2, 2)
julia> gens(R)[1, 1, 2, 1]
p[1, 1, 2, 1]This function is part of the experimental code in Oscar. Please read here for more details.
state_space — Function
state_space(R::MarkovRing, K=random_variables(R))Return all states that the random subvector indexed by K can attain in the ring R. The result is an Iterators.product iterator unless K has only one element in which case it is a vector.
Examples
julia> R = markov_ring(2, 3, 2, 4)
Markov ring over rational field for 4 random variables and states (2, 3, 2, 4)
julia> collect(state_space(R, [1, 4]))
2×4 Matrix{Tuple{Int64, Int64}}:
(1, 1) (1, 2) (1, 3) (1, 4)
(2, 1) (2, 2) (2, 3) (2, 4)This function is part of the experimental code in Oscar. Please read here for more details.
parameter_ring — Method
parameter_ring(M::DiscreteGraphicalModel; cached=false)Return the ring of parameters of the statistical model, together with a Dict for indexing its generators.
julia> G = graph_from_edges([[1,2], [2,3]]);
julia> M = discrete_graphical_model(G, [2,2,2])
Discrete Graphical Model on a Undirected graph with 3 nodes and 2 edges with states [2, 2, 2]
julia> _, PR_gens = parameter_ring(M);
julia> PR_gens[[1, 2], (2, 2)]
t{1,2}(2, 2)
julia> C = maximal_cliques(G);
julia> PR_gens[Set([2, 3]), (1, 2)]
t{2,3}(1, 2)
julia> PR_gens[[2, 3], (1, 2)]
t{2,3}(1, 2)This function is part of the experimental code in Oscar. Please read here for more details.
parameter_ring(M::DiscreteGraphicalModel{Graph{Directed}, T}; cached=false)Return the ring of parameters of the statistical model, together with a Dict for indexing its generators.
There is a "hidden" homogenizing variable named "_h" in the ring. It can be obtained via last(gens(R)) but is not listed in the dictionary of generators.
julia> M = discrete_graphical_model(graph_from_edges(Directed, [[1,3], [2,3], [3,4]]), [2,2,2,2])
Discrete Graphical Model on a Directed graph with 4 nodes and 3 edges with states [2, 2, 2, 2]
julia> _, PR_gens = parameter_ring(M);
julia> PR_gens[3, 2, [2]]
q[3](2 | 2)
julia> PR_gens[1, 1, Set{Int}()]
q[1](1)This function is part of the experimental code in Oscar. Please read here for more details.
marginal — Method
marginal(R::MarkovRing, K, x)Return a marginal as a sum of unknowns from R. The argument K lists random variables which are fixed to the event x; all other random variables in R are summed over their respective state spaces.
Examples
julia> R = markov_ring(2, 3, 2, 4)
Markov ring over rational field for 4 random variables and states (2, 3, 2, 4)
julia> marginal(R, [1, 4], [2, 1]) # sum all p[i,j,k,k] where i=2 and l=1
p[2, 1, 1, 1] + p[2, 2, 1, 1] + p[2, 3, 1, 1] + p[2, 1, 2, 1] + p[2, 2, 2, 1] + p[2, 3, 2, 1]This function is part of the experimental code in Oscar. Please read here for more details.
indexed_ring — Method
indexed_ring(R::Ring, varnames::Vector{<:VarName}; kw...)
indexed_ring(R::Ring, varnames::Pair{String, <:Array{T}}; kw...) where TReturns a polynomial ring with coefficient ring R and the generators as a Dict. The keyword arguments kw will be passed to the underlying polynomial_ring function. Additional to the usual polynomial ring functionality one can also ask for the index of a given generator.
#Examples
julia> R, x = indexed_ring(QQ, "x" => collect(Iterators.product(1:5, 1:3)));
julia> x[1, 2]
x[1,2]
julia> x[(1, 2)]
x[1,2]
julia> Oscar.gen_index(R, x[1, 2])
(1, 2)
julia> R, d = indexed_ring(QQ, [:y, :z]);
julia> d[1]
y
julia> Oscar.gen_index(R, d[1])
1This function is part of the experimental code in Oscar. Please read here for more details.