Infrared
|
Classes | |
class | ArcticClusterTree |
Cluster tree for maximization (in arctic semiring) More... | |
class | ArcticEvaluationAlgebra |
Maximization algebra for optimization. More... | |
class | ArcticFunctionAdapter |
Adapt function for maximization algebra. More... | |
class | ArcticOptimizer |
Maximizing optimizer (based on arctic algebra) More... | |
class | BoltzmannSampler |
Boltzmann sampler. More... | |
class | ClusterTreeBase |
Cluster tree base class. More... | |
class | ConsistencyError |
class | ConstraintFunctionDefinitionError |
class | EngineBase |
Abstract base class for samplers and optimizers. More... | |
class | EvaluationAlgebra |
Algebra for evaluating a constraint network. More... | |
class | Feature |
Feature in multi-dimensional Boltzmann sampling. More... | |
class | FeatureStatistics |
Keeping statistics on features. More... | |
class | Model |
class | MultiDimensionalBoltzmannSampler |
Multi-dimensional Boltzmann sampler. More... | |
class | PFClusterTree |
Cluster tree for partition function calculation and sampling. More... | |
class | PFEvaluationAlgebra |
Partition function algebra for sampling. More... | |
class | PFFunctionAdapter |
Adapt function for partition function algebra. More... | |
class | ValueIn |
Constrain variable to have a value from a specified set. More... | |
class | WeightedFunction |
Function of a constraint network. More... | |
Functions | |
seed (seed=None) | |
Seed random number generator of libinfrared and treedecomp. | |
def_function_class (classname, init, value, module="__main__") | |
Define a function class (of type WeightedFunction) | |
def_constraint_class (classname, init, value, module="__main__") | |
Define a Constraint class. | |
mc_optimize (model, objective, steps, temp, start=None) | |
Optimize by Monte-Carlo optimization with partial resampling. | |
dotfile_to_tgt (graphfile, tgt, outfile=None) | |
Convert dot graph file format to png/pdf. | |
dotfile_to_pdf (graphfile, outfile=None) | |
Convert dot graph file to pdf. | |
dotfile_to_png (graphfile, outfile=None) | |
Convert dot graph file to png. | |
Variables | |
Optimizer = ArcticOptimizer | |
Alias for default optimizer ArcticOptimizer. | |
Sampler = MultiDimensionalBoltzmannSampler | |
Alias for MultiDimensionalBoltzmannSampler. | |
The infrared high-level Python interface.
infrared.infrared.def_constraint_class | ( | classname, | |
init, | |||
value, | |||
module = "__main__" |
|||
) |
Define a Constraint class.
Defines a new class with name classname
(by default, in the main namespace) This defines a type of constraints that can be added to models.
classname | name of the class to be defined |
init | init function of generated class |
value | value function of generated class |
module | module where class is generated |
The definitions of constraint and function classes work in the same way, only differing in the return type of the value function. In the case of constraints, it indicates satisfaction of the constraint by a boolean (at concrete values of specified variables); in the case of functions, it returns a numerical value.
The function init
returns the dependency list, i.e. the list of indices of the variables on which the constraint depends.
The init function defines arguments that are passed when constructing the constraint. Typically, these include variable indices. Additional information required in the construction and/or evaluation of the constraint can be passed via arbitrary other parameters to init.
The value function computes the value of the constraint for determined values of the variables in the dependency list. These values are passed (in the order of the dependency list) as arguments of the init function; the names of these arguments must not occur in the signature of init.
The value function can then define further arguments with names that occur in the signature of the init function. These arguments are then stored at construction and due to this mechanism made available in the value function.
More complex examples are provided in the accompanying Jupyter notebooks.
infrared.infrared.def_function_class | ( | classname, | |
init, | |||
value, | |||
module = "__main__" |
|||
) |
Define a function class (of type WeightedFunction)
Defines a new class with name classname
(by default, in the main namespace) This defines a type of functions that can be added to models.
classname | name of the class to be defined |
init | init function of generated class |
value | value function of generated class |
module | module where class is generated |
The definitions of constraint and function classes work in the same way, only differing in the return type of the value function. In the case of constraints, it indicates satisfaction of the constraint by a boolean (at concrete values of specified variables); in the case of functions, it returns a numerical value.
The function init
returns the dependency list, i.e. the list of indices of the variables on which the function depends.
The init function defines arguments that are passed when constructing the constraint. Typically, these include variable indices. Additional information required in the construction and/or evaluation of the function can be passed via arbitrary other parameters to init.
The value function computes the value of the constraint for determined values of the variables in the dependency list. These values are passed (in the order of the dependency list) as arguments of the init function; the names of these arguments must not occur in the signature of init.
The value function can then define further arguments with names that occur in the signature of the init function. These arguments are then stored at construction and due to this mechanism made available in the value function.
More complex examples are provided in the accompanying Jupyter notebooks.
infrared.infrared.dotfile_to_pdf | ( | graphfile, | |
outfile = None |
|||
) |
Convert dot graph file to pdf.
infrared.infrared.dotfile_to_png | ( | graphfile, | |
outfile = None |
|||
) |
Convert dot graph file to png.
infrared.infrared.dotfile_to_tgt | ( | graphfile, | |
tgt, | |||
outfile = None |
|||
) |
Convert dot graph file format to png/pdf.
The graph is plotted and written to a pdf or png file by calling graphviz's dot tool on the dot file.
graphfile | file of graph in dot format |
tgt | target format ('png' or 'pdf') |
outfile | optional output filename |
infrared.infrared.mc_optimize | ( | model, | |
objective, | |||
steps, | |||
temp, | |||
start = None |
|||
) |
Optimize by Monte-Carlo optimization with partial resampling.
Maximizes an objective function over assignments of a Infrared model using a Monte-Carlo stochastic optimization strategy with component-wise resampling and Metropolis criterion.
In each iteration, the algorithm resamples connected components of the dependency graph such. This strategy is generally applicable and allows to keep constraints satisfied. Note that this strategy can even benefit from Boltzmann sampling that allows controling the resampling distribution based on functions. Naturally, a high degree of dependencies makes problems hard for this strategy; in the extreme, the strategy degenerates to optimization by iterated sampling.
model | Infrared model describing assignments |
objective | objective function on assignments |
steps | iterations |
temp | temperature for the Metropolis criterion |
start | optional start assignment |
infrared.infrared.seed | ( | seed = None | ) |
Seed random number generator of libinfrared and treedecomp.
This seeds the RNG of lib infrared (C++ side) and as well the random number generator used by randomization in the TreeDecomposition, both with the same number. It does NOT seed Python's global RNG.
seed | integer used as seed |
infrared.infrared.Optimizer = ArcticOptimizer |
Alias for default optimizer ArcticOptimizer.
infrared.infrared.Sampler = MultiDimensionalBoltzmannSampler |
Alias for MultiDimensionalBoltzmannSampler.