Scruff
Scruff.BELIEF
— ConstantBELIEF
The constant key used to store belief for a specific variable instance
Scruff.EVIDENCE
— ConstantEVIDENCE
The constant key used to store evidence for a specific variable instance
Scruff.INTERVENTION
— ConstantINTERVENTION
The constant key used to store interventions for a specific variable instance
Scruff.Node
— TypeNode{O} = Union{Placeholder{O}, Variable{I,J,O} where {I,J}}
Scruff.Dist
— TypeDist{T} = SFunc{Tuple{}, T}
Additional supported operators
make_factors
send_lambda
Scruff.DynamicNetwork
— TypeDynamicNetwork{I,J,O} <: Network{I,J,O}
A network that can transition over time. See Network
for the type parameters.
Scruff.DynamicRuntime
— Typestruct DynamicRuntime <: Runtime
A runtime that represents a network whose variables take on many instances at different times T
.
Scruff.Env
— Typestruct 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)
Scruff.Instance
— TypeInstance{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.
Scruff.InstantNetwork
— Typestruct 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
Scruff.InstantRuntime
— Typestruct 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)
Scruff.Model
— TypeModel{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 theSFunc
returned by the model'smake_initial
functionJ
: the input type to theSFunc
used during themake_transition
function callO
: the actual type of the variables represented by this model
Scruff.Network
— Typeabstract 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 Variable
s.
Scruff.Placeholder
— TypePlaceholder{O} <: ValueTyped{O}
A type for typing Scruff variables that do not reference models
Scruff.PlaceholderInstance
— TypePlaceholderInstance
An instance of placeholder node
at time
. This instance has no sfunc, but can still take values in the runtime.
Scruff.Runtime
— Typeabstract 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.
Scruff.SFunc
— Typeabstract 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.
Scruff.Score
— TypeScore{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
.
Scruff.ValueTyped
— Typeabstract type ValueTyped{O}
Supertype for typing all Scruff Variables; O
is the actual type of the variable
Scruff.Variable
— Typemutable 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
Scruff.VariableGraph
— TypeVariableGraph = Dict{Node, Vector{Node}}
Scruff.VariableInstance
— TypeVariableInstance
An instance of variable node at time
. sf
is an sfunc generated from the variable's model.
Scruff.VariableParentTimeOffset
— TypeVariableParentTimeOffset = 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.
Scruff.complete_graph!
— Methodcomplete_graph!(variables::Vector{<:Variable}, graph::VariableGraph)
Populate the graph
with v=>Node[]
for all variables
not in the graph.
Scruff.current_instance
— Methodcurrent_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
Scruff.current_time
— Methodcurrent_time(runtime::Runtime) -> T
Returns the currently set time of the given Runtime
Scruff.delete_value!
— Methoddelete_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
Scruff.ensure_all!
— Functionensure_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.
Scruff.ensure_instance!
— Methodensure_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.
Scruff.get_all_instances
— Methodget_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}
.
Scruff.get_belief
— Methodget_belief(runtime::Runtime, inst::Instance)
Returns the last posted belief for the given instance; this will return nothing
if no belief has been posted
Scruff.get_definition
— Methodget_definition(i::VariableInstance)::D where {D<:ValueTyped}
Get the instance's variable's underlying model.
Scruff.get_evidence
— Methodget_evidence(runtime::Runtime, inst::Instance)
Returns the last posted evidence for the given instance; this will return nothing
if no evidence has been posted
Scruff.get_initial_children
— Methodget_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)).
Scruff.get_initial_parents
— Methodget_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)).
Scruff.get_instance
— Methodfunction 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.
Scruff.get_intervention
— Methodget_intervention(runtime::Runtime, inst::Instance)
Returns the last posted intervention for the given instance; this will return nothing
if no intervention has been posted
Scruff.get_model
— Methodget_model(i::VariableInstance)::D where {D<:ValueTyped}
Get the instance's variable's underlying model.
Scruff.get_name
— Methodget_name(i::Instance)::Symbol
Get the name of the instance's node.
Scruff.get_node
— Methodget_node(i::Instance)::Node
Get the instance's node, whether it is a placeholder or a variable.
Scruff.get_node
— Methodget_node(n::Network, name::Symbol)::Union{Node, Nothing}
Returns the node with the given name, or nothing
.
Scruff.get_sfunc
— Methodget_sfunc(i::VariableInstance)::SFunc
Get the instance's sfunc.
Scruff.get_time
— Methodget_time(i::Instance)
Get the instance's time.
Scruff.get_transition_children
— Methodget_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))
Scruff.get_transition_parents
— Methodget_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))
Scruff.get_value
— Methodget_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
Scruff.has_instance
— Functionhas_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.
Scruff.has_previous_instance
— Methodhas_previous_instance(runtime::DynamicRuntime, node::Node)
Checks if the specified node has an instance prior to the current one.
Scruff.initialize_algorithm
— Methodinitialize_algorithm(alg_fun::Function, runtime::Runtime)
Initializes the given algorithm's Runtime
. By default, this does nothing.
Scruff.input_type
— Methodinput_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
Scruff.instantiate!
— Functioninstantiate!(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.
Scruff.instantiate
— Methodinstantiate(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.
Scruff.latest_instance_before
— Methodlatest_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
.
Scruff.output_type
— Methodoutput_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
Scruff.output_type
— Methodoutput_type(::Variable{I,J,O})
output_type(::Placeholder{O})
returns the output type O
of the given parameter
Scruff.post_belief!
— Methodpost_belief!(runtime::Runtime, inst::Instance, belief)
Posts the given evidence for the given instance.
Scruff.post_evidence!
— Methodpost_evidence!(runtime::Runtime, inst::Instance, evidence)
Posts the given evidence for the given instance.
Scruff.post_intervention!
— Methodpost_intervention!(runtime::Runtime, inst::Instance, intervention::Dist)
Posts the given intervention for the given instance.
Scruff.previous_instance
— Methodprevious_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.
Scruff.set_time!
— Methodset_time(runtime::Runtime{T}, newtime::T) -> T
Sets the current time for the given Runtime
Scruff.set_value!
— Methodset_value!(runtime::Runtime, instance::Instance, key::Symbol, value)
Set the value on an instance for the given key
Scruff.start_algorithm
— Methodstart_algorithm(alg_fun::Function, runtime::Runtime, args...)
Starts the algorithm in the current thread
Scruff.value_type
— Methodvalue_type(v::ValueTyped{O}) where {O}
return the actual type (i.e. O
) of the ValueTyped