GithubHelp home page GithubHelp logo

gaussianrelations.jl's Introduction

GaussianRelations.jl

tests codecov

GaussianRelations.jl is a Julia library that provides tools for working with Gaussian linear systems. It accompanies the paper A Categorical Treatment of Open Linear Systems.

Example: A Noisy Resistor

In the paper Open Stochastic Systems, Jan Willems defines a Gaussian linear system that he calls the "noisy resistor."

Using our library, the noisy resistor can be implemented as follows.

using Catlab
using GaussianRelations

###############################
# Example 1: A Noisy Resistor #
###############################

σ₁ = 1/2
R₁ = 2

# ϵ₁ ~ N(0, σ₁²)
ϵ₁ = CovarianceForm(0, σ₁^2)

# Define the noisy resistor using a kernel representation.
#         [ I₁ ]
# [-R₁ 1] [ V₁ ] = ϵ₁
IV₁ = [-R₁ 1] \ ϵ₁

#################################################
# Example 3: The Noisy Resistor, Interconnected #
#################################################

σ₂ = 2/3
R₂ = 4
V₀ = 5

# ϵ₂ ~ N(0, σ₂²)
ϵ₂ = CovarianceForm(0, σ₂^2)

# Construct the second resistor.
#        [ I₁ ]
# [R₂ 1] [ V₂ ] = ϵ₂ + V₀
IV₂ = [R₂ 1] \ (ϵ₂ + V₀)

# The interconnected system solves the following equation:
# [ 1 0 ]         [ I₁ ]
# [ 0 1 ]         [ V₁ ]
# [ 1 0 ] [ I ]   [ I₂ ]
# [ 0 1 ] [ V ] = [ V₂ ]
IV = [1 0; 0 1; 1 0; 0 1] \ otimes(IV₁, IV₂)

# The interconnected system corresponds to the following undirected wiring diagram.
#       IV₁
#      /   \
# --- I     V ---
#      \   /
#       IV₂
diagram = @relation (I, V) begin
    IV₁(I, V)
    IV₂(I, V)
end

# We can also interconnect the systems by applying an operad algebra to the preceding
# diagram.
IV = oapply(diagram, Dict(:IV₁ => IV₁, :IV₂ => IV₂), Dict(:I => 1, :V => 1))

# If a system is classical, access its parameters by calling the functions mean and cov.
mean(IV)
cov(IV)

##################################################
# Example 5: The Noisy Resistor With Constraints #
##################################################

# I₂ = 1 amp.
I₂ = CovarianceForm(1, 0)

# The constrained system solves the following equation:
# [ 1 0 ]         [ I₁ ]
# [ 0 1 ] [ I ]   [ V₁ ]
# [ 1 0 ] [ V ] = [ I₂ ]
IV = [1 0; 0 1; 1 0] \ otimes(IV₁, I₂)

# Marginalize over I by computing
#           [ I ]
# V = [0 1] [ V ]
V = [0 1] * IV

# The constrained system corresponds to the following undirected wiring diagram.
#    IV₁
#   /   \
#  I     V ---
#   \
#    I₂
diagram = @relation (V,) begin
    IV₁(I, V)
    I₂(I)
end

# We can also constrain the system by applying an operad algebra to the preceding
# diagram.
V = oapply(diagram, Dict(:IV₁ => IV₁, :I₂ => I₂), Dict(:I => 1, :V => 1))

gaussianrelations.jl's People

Contributors

samuelsonric avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.