Infrared
Loading...
Searching...
No Matches
infrared.infrared Namespace Reference

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.
 

Detailed Description

The infrared high-level Python interface.

Function Documentation

◆ def_constraint_class()

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.

Parameters
classnamename of the class to be defined
initinit function of generated class
valuevalue function of generated class
modulemodule 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.

Examples
_bpcomp_tab = [(0, 3), (1, 2), (2, 1), (2, 3), (3, 0), (3, 2)]
def_constraint_class('BPComp', lambda i, j: [i, j],
lambda x, y: (x, y) in _bpcomp_tab)
def_function_class('ConstrainDimer',
# define dependency on consecutive variables X_i, X_i+1,
# specify allowed dimers, e.g. xs=[(1,2),(2,1)]
init = lambda i, xs: [i, i+1],
# check at assigned values X_i->x, X_i+1->y for specified xs
value = lambda x, y, xs: (x,y) in xs)

More complex examples are provided in the accompanying Jupyter notebooks.

◆ def_function_class()

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.

Parameters
classnamename of the class to be defined
initinit function of generated class
valuevalue function of generated class
modulemodule 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.

Examples
def_function_class('GCCont', lambda i: [i], lambda x: 1 if x == 1 or x == 2 else 0)
def_function_class('CountDimer',
# define dependency on consecutive variables,
# specify to count pairs in xs, e.g. xs=[(1,2),(2,1)]
init = lambda i, xs: [i, i+1],
# evaluate at assigned values X_i->x, X_i+1->y for specified xs
value = lambda x, y, xs: (x,y) in xs)

More complex examples are provided in the accompanying Jupyter notebooks.

◆ dotfile_to_pdf()

infrared.infrared.dotfile_to_pdf (   graphfile,
  outfile = None 
)

Convert dot graph file to pdf.

See also
dotfile_to_tgt

◆ dotfile_to_png()

infrared.infrared.dotfile_to_png (   graphfile,
  outfile = None 
)

Convert dot graph file to png.

See also
dotfile_to_tgt

◆ dotfile_to_tgt()

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.

Parameters
graphfilefile of graph in dot format
tgttarget format ('png' or 'pdf')
outfileoptional output filename
Note
Unless specified, the output filename is composed from the input file name and the target format.

◆ mc_optimize()

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.

Parameters
modelInfrared model describing assignments
objectiveobjective function on assignments
stepsiterations
temptemperature for the Metropolis criterion
startoptional start assignment
Returns
Pair of best assignment and its objective value

◆ seed()

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.

Parameters
seedinteger used as seed
Note
Without argument or seed==None, use Pythons built-in random.seed() to generate a seed.

Variable Documentation

◆ Optimizer

infrared.infrared.Optimizer = ArcticOptimizer

Alias for default optimizer ArcticOptimizer.

◆ Sampler

infrared.infrared.Sampler = MultiDimensionalBoltzmannSampler

Alias for MultiDimensionalBoltzmannSampler.