Infrared
Loading...
Searching...
No Matches
infrared.infrared.Model Class Reference

Public Member Functions

 __init__ (self, number=None, domain=None, name='X')
 Init model.
 
 add_variables (self, number, domain, name='X')
 Add variable domains.
 
 restrict_domains (self, vars, domain)
 Restrict the domain of a variable.
 
 add_constraints (self, constraints)
 Add constraints to the model.
 
 add_functions (self, functions, group='base')
 Add functions to the model.
 
 num_named_variables (self, name)
 Number of variables.
 
 has_empty_domains (self)
 Check inconsistency due to empty domains.
 
 add_feature (self, name, group, eval_fun)
 Add a (custom) feature.
 
 eval_feature (self, assignment, name)
 Evaluate named feature at assignment.
 
 set_feature_weight (self, weight, name)
 Set the weight of a feature and its function group.
 
 idx (self, variables)
 Raw indices of named variables.
 
 dependencies (self, non_redundant=True)
 Dependencies due to constraints and functions.
 
 bindependencies (self, non_redundant=True)
 
 write_graph (self, out, non_redundant=True)
 Write dependency graph.
 
 connected_components (self)
 Connected components of the model's dependency graph.
 

Protected Member Functions

 _automatic_feature (self, group)
 Automatic feature for function group.
 

Static Protected Member Functions

 _expand_to_cliques (dependencies)
 Expand non-binary dependencies to cliques of binary deps.
 
 _remove_subsumed_dependencies (deps)
 Removes redundant dependencies that are subsumed by others Removes all dependencies that are subsumed by other dependencies in deps.
 

Protected Attributes

 _constraints
 
 _functions
 
 _domains
 
 _features
 

Properties

 num_variables = property
 Number of all variables.
 
 constraints = property
 Constraints of the model.
 
 functions = property
 All functions of the model.
 
 domains = property
 Domains of the model.
 
 features = property
 Features of the model.
 

Constructor & Destructor Documentation

◆ __init__()

infrared.infrared.Model.__init__ (   self,
  number = None,
  domain = None,
  name = 'X' 
)

Init model.

   If number is not None, calls add_variables with the
   given parameters after initialization.
Parameters
numberif not None, number of variables
domaindomains of variables
namename of variable series. Defaults to X

Member Function Documentation

◆ _automatic_feature()

infrared.infrared.Model._automatic_feature (   self,
  group 
)
protected

Automatic feature for function group.

Feature with value that is derived as sum of the feature functions

Returns
the feature

◆ _expand_to_cliques()

infrared.infrared.Model._expand_to_cliques (   dependencies)
staticprotected

Expand non-binary dependencies to cliques of binary deps.

Parameters
dependencieslist of dependencies
Returns
list of binary dependencies

◆ _remove_subsumed_dependencies()

infrared.infrared.Model._remove_subsumed_dependencies (   deps)
staticprotected

Removes redundant dependencies that are subsumed by others Removes all dependencies that are subsumed by other dependencies in deps.

Parameters
depslist of dependencies (where a dependency is a list of indices)
Returns
pruned list of dependencies

◆ add_constraints()

infrared.infrared.Model.add_constraints (   self,
  constraints 
)

Add constraints to the model.

Parameters
constraintsan iterable of constraints or a single constraint
Note
supports optimizations via on_add and entailed methods of added constraints; see ValueIn

◆ add_feature()

infrared.infrared.Model.add_feature (   self,
  name,
  group,
  eval_fun 
)

Add a (custom) feature.

Parameters
namename of the feature
groupone or several groups of feature controlled functions
eval_funfunction to evaluate the feature at an assignment

◆ add_functions()

infrared.infrared.Model.add_functions (   self,
  functions,
  group = 'base' 
)

Add functions to the model.

Parameters
functions[const] an iterable of functions or a single function
groupindentifier of function group. Defaults to base
Note
deep copies the input functions

◆ add_variables()

infrared.infrared.Model.add_variables (   self,
  number,
  domain,
  name = 'X' 
)

Add variable domains.

Parameters
numbernumber of variables
domaindomain size; defines the domain values as 0..domain-1
nameassign a name to the variable(s)

◆ bindependencies()

infrared.infrared.Model.bindependencies (   self,
  non_redundant = True 
)

◆ connected_components()

infrared.infrared.Model.connected_components (   self)

Connected components of the model's dependency graph.

Returns
a list of sets of the connected components

◆ dependencies()

infrared.infrared.Model.dependencies (   self,
  non_redundant = True 
)

Dependencies due to constraints and functions.

Parameters
non_redundantwhether the dependency list is made non-redundant. Defaults to True
Returns
list of lists of indices of variables that depend on each other either through functions or constraints

◆ eval_feature()

infrared.infrared.Model.eval_feature (   self,
  assignment,
  name 
)

Evaluate named feature at assignment.

Parameters
assignmentthe assignment
namename of the feature
Returns
value of the feature

◆ has_empty_domains()

infrared.infrared.Model.has_empty_domains (   self)

Check inconsistency due to empty domains.

Returns
whether model has empty domains

◆ idx()

infrared.infrared.Model.idx (   self,
  variables 
)

Raw indices of named variables.

Parameters
variablessingle variable or list of variables; variables can be named; default name 'X'
Returns
list of (internal) variable indices

◆ num_named_variables()

infrared.infrared.Model.num_named_variables (   self,
  name 
)

Number of variables.

Parameters
namename of the variables series
Returns
number of variables of the given series

◆ restrict_domains()

infrared.infrared.Model.restrict_domains (   self,
  vars,
  domain 
)

Restrict the domain of a variable.

Parameters
varsvariable or list of variables, each specified by (name,index); or simply index, then addressing ('X',index)
domainthe domain
Note
the domain bounds are intersected with the original domain

◆ set_feature_weight()

infrared.infrared.Model.set_feature_weight (   self,
  weight,
  name 
)

Set the weight of a feature and its function group.

   This method sets the weight for the Feature itself and in
   all the functions (currently!) in its group.

   The method should be called after all functions of its group are
   defined. Otherwise, weights of the feature and its functions get out
   of sync (but can be re-synced by another call to this method.)
Parameters
weightthe weight
namethe feature name

◆ write_graph()

infrared.infrared.Model.write_graph (   self,
  out,
  non_redundant = True 
)

Write dependency graph.

Writes the dependency graph to file in dot format; hyper-edges are expanded to cliques.

Parameters
outa filehandle of name of the target file

Member Data Documentation

◆ _constraints

infrared.infrared.Model._constraints
protected

◆ _domains

infrared.infrared.Model._domains
protected

◆ _features

infrared.infrared.Model._features
protected

◆ _functions

infrared.infrared.Model._functions
protected

Property Documentation

◆ constraints

infrared.infrared.Model.constraints = property
static

Constraints of the model.

Returns
specification of the model's functions

◆ domains

infrared.infrared.Model.domains = property
static

Domains of the model.

Returns
list of all domain descriptions

◆ features

infrared.infrared.Model.features = property
static

Features of the model.

Returns
dictionary of features

◆ functions

infrared.infrared.Model.functions = property
static

All functions of the model.

Returns
list of all functions

◆ num_variables

infrared.infrared.Model.num_variables = property
static

Number of all variables.

Returns
number of all variables

The documentation for this class was generated from the following file: