Scruff

Scruff.BELIEFConstant
BELIEF

The constant key used to store belief for a specific variable instance

source
Scruff.EVIDENCEConstant
EVIDENCE

The constant key used to store evidence for a specific variable instance

source
Scruff.INTERVENTIONConstant
INTERVENTION

The constant key used to store interventions for a specific variable instance

source
Scruff.NodeType

Node{O} = Union{Placeholder{O}, Variable{I,J,O} where {I,J}}

source
Scruff.DistType
Dist{T} = SFunc{Tuple{}, T}

Additional supported operators

  • make_factors
  • send_lambda
source
Scruff.DynamicRuntimeType
struct DynamicRuntime <: Runtime

A runtime that represents a network whose variables take on many instances at different times T.

source
Scruff.EnvType
struct Env

Holds all external state of a Runtime. The Env supports the following methods:

get_state(env::Env) :: Dict{Symbol, Any}
has_state(env::Env, key::Symbol) :: Bool
get_state(env::Env, key::Symbol)
set_state!(env::Env, key::Symbol, value)
delete_state!(env::Env, key::Symbol)
clear_state!(env::Env)
clone(env::Env)
source
Scruff.InstanceType
Instance{O}

An abstract base type for variable and placeholder instances.

This is instance can have values associated with it in the runtime. O is the output type of the node.

source
Scruff.InstantNetworkType
struct InstantNetwork{I,J,O} <: Network{I,Nothing,O}

A network that only supports initial models. The Nothing in the supertype shows that there is no transition to another time.

See Network for the type parameters

source
Scruff.InstantRuntimeType
struct InstantRuntime <: Runtime

A runtime that represents a network whose variables take on a single instance. As a convenience, the following methods create an InstantRuntime:

Runtime()
Runtime(net :: InstantNetwork)
Runtime(net :: DynamicNetwork)
source
Scruff.ModelType
Model{I, J, O} <: ValueTyped{O}

Supertype for all Scruff models. The model represents a variable that varies over time and has output type O. The model may return an initial sfunc with input type I using make_initial, which takes the current time as argument, and a transition sfunc with input type J using make_transition, which takes both the parent times (a tuple of times of the same length as J) and the current time as arguments. These two functions need to be defined for every sfunc.

Type parameters

  • I: the input type to the SFunc returned by the model's make_initial function
  • J: the input type to the SFunc used during the make_transition function call
  • O: the actual type of the variables represented by this model
source
Scruff.NetworkType
abstract type Network{I,J,O}

Collects variables, with placeholders for inputs, and defined outputs, along with up to two directed graphs for initial and transition. Must implement get_nodes, get_outputs, get_initial_graph, get_transition_graph (which returns a VariableGraph)

For the type parameters, see the underlying Model class for the mapped Variables.

source
Scruff.PlaceholderType
Placeholder{O} <: ValueTyped{O}

A type for typing Scruff variables that do not reference models

source
Scruff.PlaceholderInstanceType
PlaceholderInstance

An instance of placeholder node at time. This instance has no sfunc, but can still take values in the runtime.

source
Scruff.RuntimeType
abstract type Runtime

A struct that contains the state of the compute graph. This code makes the assumption that values are associated with instances but messages are passed between variables and applied to the relevant instances later. It has to be this way because the receiving instance might not exist at the time the message is sent.

source
Scruff.SFuncType
abstract type SFunc{I<:Tuple, O}

A Stochastic Function type with input variables defined by I and output type O. This is an abstract representation for a collection of operators with the same input and output types.

All sfuncs have the following operators defined:

  • compute_lambda
  • compute_bel
  • send_pi
  • outgoing_pis
  • outgoing_lambdas

SFunc also has both the operators cpdf and logcpdf defined in terms of the other. All sfuncs should implement one or the other of these operators.

source
Scruff.ScoreType
Score{I} = SFunc{Tuple{I}, Nothing}

Score supports two (2) operators: get_score and get_log_score. get_log_score is defined, by default, using get_score. Every subtype of Score must implement get_score.

source
Scruff.ValueTypedType
abstract type ValueTyped{O}

Supertype for typing all Scruff Variables; O is the actual type of the variable

source
Scruff.VariableType
mutable struct Variable{I,J,O} <: ValueTyped{O}

A Variable describes the (time-series) of some set of random values. It must be named, described by a model, and references to the model inputs must be defined.

For the type variables, see Model

source
Scruff.VariableParentTimeOffsetType
VariableParentTimeOffset = Set{Pair{Node, Node}}

Represents whether a child-parent pair of nodes is time-offset; if they are time-offset, they will be a set of this type.

source
Scruff.complete_graph!Method
complete_graph!(variables::Vector{<:Variable}, graph::VariableGraph)

Populate the graph with v=>Node[] for all variables not in the graph.

source
Scruff.current_instanceMethod
current_instance(runtime::InstantRuntime, node::Node)
current_instance(runtime::DynamicRuntime, node::Node)

Returns the current (last) instance for the given runtime and node; this method will throw an exception if there is no current instance for the given node

source
Scruff.delete_value!Method
delete_value!(runtime::Runtime{T}, instance::Instance, key::Symbol) where {T}

Deletes the mapping for the given instance and key in the runtime and returns it

source
Scruff.ensure_all!Function
ensure_all!(runtime::InstantRuntime, time=0) :: Dict{Symbol, Instance}
ensure_all!(runtime::DynamicRuntime, time = current_time(runtime)) :: Dict{Symbol, Instance}

Instantiate all the variables in the network at the given time and returns them as a dict from variable names to their corresponding instance; the default time is the current time of the runtime in unix time.

source
Scruff.ensure_instance!Method
ensure_instance!(runtime::Runtime{T}, node::Node{O}, time::T = current_time(runtime))::Instance{O} where {O,T}

Returns an instance for the given variable at the given time, either by using an existing one or creating a new one.

source
Scruff.get_all_instancesMethod
get_all_instances(runtime::DynamicRuntime, variable::Variable)
get_all_instances(runtime::InstantRuntime, variable::Variable)

Returns all instances in the runtime for the given variable, in order, as a Vector{Instance}.

source
Scruff.get_beliefMethod
get_belief(runtime::Runtime, inst::Instance)

Returns the last posted belief for the given instance; this will return nothing if no belief has been posted

source
Scruff.get_definitionMethod
get_definition(i::VariableInstance)::D where {D<:ValueTyped}

Get the instance's variable's underlying model.

source
Scruff.get_evidenceMethod
get_evidence(runtime::Runtime, inst::Instance)

Returns the last posted evidence for the given instance; this will return nothing if no evidence has been posted

source
Scruff.get_initial_childrenMethod
get_initial_children(n::Network, var::Node)::Vector{Node}

Returns a list of the initial child nodes in the network from the network's initial graph (i.e. the return graph from getinitialgraph(network)).

source
Scruff.get_initial_parentsMethod
get_initial_parents(n::Network, node::Node)::Vector{Node}

Returns a list of the initial parent nodes in the network from the network's initial graph (i.e. the return graph from getinitialgraph(network)).

source
Scruff.get_instanceMethod
function get_instance(runtime::DynamicRuntime{T}, node::Node, t::T)::Instance

Returns instance for the given variable at time T; throws an error if no such instance exists.

source
Scruff.get_interventionMethod
get_intervention(runtime::Runtime, inst::Instance)

Returns the last posted intervention for the given instance; this will return nothing if no intervention has been posted

source
Scruff.get_modelMethod
get_model(i::VariableInstance)::D where {D<:ValueTyped}

Get the instance's variable's underlying model.

source
Scruff.get_nodeMethod
get_node(i::Instance)::Node

Get the instance's node, whether it is a placeholder or a variable.

source
Scruff.get_nodeMethod
get_node(n::Network, name::Symbol)::Union{Node, Nothing}

Returns the node with the given name, or nothing.

source
Scruff.get_transition_childrenMethod
get_transition_children(n::Network, var::Node)::Vector{Node}

Returns a list of transitioned child nodes in the network from the network's transition graph (i.e. the return graph from gettransitiongraph(network))

source
Scruff.get_transition_parentsMethod
get_transition_parents(n::Network, node::Node)::Vector{Node}

Returns a list of transitioned parent nodes in the network from the network's transition graph (i.e. the return graph from gettransitiongraph(network))

source
Scruff.get_valueMethod
get_value(runtime::Runtime, instance::Instance, key::Symbol)

Get the value on an instance for the given key; this will throw an exception if the instance does not contain the given key

source
Scruff.has_instanceFunction
has_instance(runtime::DynamicRuntime, node::Node, time = current_time(runtime))
has_instance(runtime::InstantRuntime, node::Node)

Returns true if the given node has an instance in the given runtime at a time greater than or equal to the given time.

source
Scruff.has_previous_instanceMethod
has_previous_instance(runtime::DynamicRuntime, node::Node)

Checks if the specified node has an instance prior to the current one.

source
Scruff.input_typeMethod
input_type(::Type{<:SFunc{I,O}}) where {I,O}
input_type(::SFunc{I,O}) where {I,O}

Return the input type (i.e. I) of the SFunc

source
Scruff.instantiate!Function
instantiate!(runtime::InstantRuntime,variable::Variable,time = 0)
instantiate!(runtime::InstantRuntime,placeholder::Placeholder,time = 0)
instantiate!(runtime::DynamicRuntime{T}, node::Node,time::T = current_time(runtime))::Instance where {T}

Instantiate and return an instance for the given runtime at the given time; the default time is the current time of the runtime in unix time (an Int64). For an InstantRuntime, there is only a single instance for each variable.

source
Scruff.instantiateMethod
instantiate(model::Model, name::Symbol)

Create a new Variable with the given name for the given model. Every Model instance is also a function that, given a Symbol, will call this method.

source
Scruff.latest_instance_beforeMethod
latest_instance_before(runtime::DynamicRuntime{T}, node::Node, t::T, allow_equal::Bool) :: Union{Instance, Nothing} where T

Return the latest instance of the node before the given time. The allow_equal flag indicates whether instances at a time equal to t` are allowed.

If there is no such instance, returns nothing.

source
Scruff.output_typeMethod
output_type(::Type{<:SFunc{I,O}}) where {I,O}
output_type(::SFunc{I,O}) where {I,O}

Return the output type (i.e. O) of the SFunc

source
Scruff.output_typeMethod
output_type(::Variable{I,J,O})
output_type(::Placeholder{O})

returns the output type O of the given parameter

source
Scruff.post_belief!Method
post_belief!(runtime::Runtime, inst::Instance, belief)

Posts the given evidence for the given instance.

source
Scruff.post_evidence!Method
post_evidence!(runtime::Runtime, inst::Instance, evidence)

Posts the given evidence for the given instance.

source
Scruff.post_intervention!Method
post_intervention!(runtime::Runtime, inst::Instance, intervention::Dist)

Posts the given intervention for the given instance.

source
Scruff.previous_instanceMethod
previous_instance(runtime::DynamicRuntime, node::Node)

Returns the previous instance for the given runtime and node. This will throw and exception if there is no previous instance.

source
Scruff.set_time!Method
set_time(runtime::Runtime{T}, newtime::T) -> T

Sets the current time for the given Runtime

source
Scruff.set_value!Method
set_value!(runtime::Runtime, instance::Instance, key::Symbol, value)

Set the value on an instance for the given key

source
Scruff.start_algorithmMethod
start_algorithm(alg_fun::Function, runtime::Runtime, args...)

Starts the algorithm in the current thread

source
Scruff.value_typeMethod

value_type(v::ValueTyped{O}) where {O}

return the actual type (i.e. O) of the ValueTyped

source