From a1f555abca66bb6b93f91068f1fd5983756f809a Mon Sep 17 00:00:00 2001 From: Richard Samuelson Date: Mon, 25 Sep 2023 21:00:23 -0700 Subject: [PATCH] Fiddled with pixel array documentation. --- docs/literate/pixel.jl | 44 ++++++++++++++++++------------------ docs/src/generated/pixel.md | 45 +++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/docs/literate/pixel.jl b/docs/literate/pixel.jl index c33aba8..0fcc598 100644 --- a/docs/literate/pixel.jl +++ b/docs/literate/pixel.jl @@ -4,9 +4,9 @@ using Catlab using UnicodePlots using Catlab.CategoricalAlgebra.FinRelations: BoolRig -# Spivak, Dobson, Kumari, and Wu, *Pixel Arrays*: A fast and elementary method for solving nonlinear systems. +# Spivak, Dobson, Kumari, and Wu, *Pixel Arrays: A fast and elementary method for solving nonlinear systems.* # -# A pixel array is an array with entries in the boolean semiring. +# A pixel array is an array with entries in the boolean semiring. The function defined below constructs a pixel array by discretizing a relation of the form ``xRy \iff f(x, y) = 0``. const PixelArray{N} = Array{BoolRig, N} function PixelArray(f::Function, xdim::NamedTuple, ydim::NamedTuple, tol::Real) @@ -30,12 +30,12 @@ function PixelArray(f::Function, xdim::NamedTuple, ydim::NamedTuple, tol::Real) end result -end -# For plotting. +end; +# For plotting: function Base.isless(x::Int, y::BoolRig) y == true ? x < 1 : x < 0 end; -# Example 2.4.1 +# Example 2.4.1 in Spivak et. al. function f₁(x::Real, z::Real) 0 - (cos(log(z^2 + x / 10^3)) − x + 1 / z / 10^5) end @@ -52,35 +52,35 @@ w = x = y = z = (lower = -3, upper = 3, resolution = 125) tol = .2 -A₁ = PixelArray(f₁, x, z, tol) -A₂ = PixelArray(f₂, w, y, tol) -A₃ = PixelArray(f₃, x, y, tol); -# f₁(x, z) -spy(A₁) -# f₂(w, y) -spy(A₂) -# f₃(x, y) -spy(A₃) +R₁ = PixelArray(f₁, x, z, tol) +R₂ = PixelArray(f₂, w, y, tol) +R₃ = PixelArray(f₃, x, y, tol); +# +spy(R₁; title="f₁(x, z) = 0", xlabel="x", ylabel="z") +# +spy(R₂; title="f₂(w, y) = 0", xlabel="w", ylabel="y") +# +spy(R₃; title="f₃(x, y) = 0", xlabel="x", ylabel="y") # diagram = @relation (w, z) where (w::n, x::n, y::n, z::n) begin - f₁(x, z) - f₂(w, y) - f₃(x, y) + R₁(x, z) + R₂(w, y) + R₃(x, y) end to_graphviz(diagram; box_labels=:name, junction_labels=:variable) # hom_map = Dict{Symbol, PixelArray}( - :f₁ => A₁, - :f₂ => A₂, - :f₃ => A₃) + :R₁ => R₁, + :R₂ => R₂, + :R₃ => R₃) ob_map = Dict( :n => 125) problem = InferenceProblem(diagram, hom_map, ob_map) -A = solve(problem) +R = solve(problem) -spy(A) +spy(R; title="f₁(x, z) = 0 ∧ f₂(w, y) = 0 ∧ f₃(x, y) = 0", xlabel="w", ylabel="z") # diff --git a/docs/src/generated/pixel.md b/docs/src/generated/pixel.md index e303faa..31866fd 100644 --- a/docs/src/generated/pixel.md +++ b/docs/src/generated/pixel.md @@ -12,9 +12,9 @@ using UnicodePlots using Catlab.CategoricalAlgebra.FinRelations: BoolRig ```` -Spivak, Dobson, Kumari, and Wu, *Pixel Arrays*: A fast and elementary method for solving nonlinear systems. +Spivak, Dobson, Kumari, and Wu, *Pixel Arrays: A fast and elementary method for solving nonlinear systems.* -A pixel array is an array with entries in the boolean semiring. +A pixel array is an array with entries in the boolean semiring. The function defined below constructs a pixel array by discretizing a relation of the form ``xRy \iff f(x, y) = 0``. ````@example pixel const PixelArray{N} = Array{BoolRig, N} @@ -40,10 +40,11 @@ function PixelArray(f::Function, xdim::NamedTuple, ydim::NamedTuple, tol::Real) end result -end +end; +nothing #hide ```` -For plotting. +For plotting: ````@example pixel function Base.isless(x::Int, y::BoolRig) @@ -52,7 +53,7 @@ end; nothing #hide ```` -Example 2.4.1 +Example 2.4.1 in Spivak et. al. ````@example pixel function f₁(x::Real, z::Real) @@ -71,35 +72,29 @@ w = x = y = z = (lower = -3, upper = 3, resolution = 125) tol = .2 -A₁ = PixelArray(f₁, x, z, tol) -A₂ = PixelArray(f₂, w, y, tol) -A₃ = PixelArray(f₃, x, y, tol); +R₁ = PixelArray(f₁, x, z, tol) +R₂ = PixelArray(f₂, w, y, tol) +R₃ = PixelArray(f₃, x, y, tol); nothing #hide ```` -f₁(x, z) - ````@example pixel -spy(A₁) +spy(R₁; title="f₁(x, z) = 0", xlabel="x", ylabel="z") ```` -f₂(w, y) - ````@example pixel -spy(A₂) +spy(R₂; title="f₂(w, y) = 0", xlabel="w", ylabel="y") ```` -f₃(x, y) - ````@example pixel -spy(A₃) +spy(R₃; title="f₃(x, y) = 0", xlabel="x", ylabel="y") ```` ````@example pixel diagram = @relation (w, z) where (w::n, x::n, y::n, z::n) begin - f₁(x, z) - f₂(w, y) - f₃(x, y) + R₁(x, z) + R₂(w, y) + R₃(x, y) end to_graphviz(diagram; box_labels=:name, junction_labels=:variable) @@ -107,17 +102,17 @@ to_graphviz(diagram; box_labels=:name, junction_labels=:variable) ````@example pixel hom_map = Dict{Symbol, PixelArray}( - :f₁ => A₁, - :f₂ => A₂, - :f₃ => A₃) + :R₁ => R₁, + :R₂ => R₂, + :R₃ => R₃) ob_map = Dict( :n => 125) problem = InferenceProblem(diagram, hom_map, ob_map) -A = solve(problem) +R = solve(problem) -spy(A) +spy(R; title="f₁(x, z) = 0 ∧ f₂(w, y) = 0 ∧ f₃(x, y) = 0", xlabel="w", ylabel="z") ````