com.cra.figaro.language

Element

abstract class Element[T] extends AnyRef

An Element is the core component of a probabilistic model. Elements can be understood as defining a probabilistic process. Elements are parameterized by the type of Value the process produces.

Each Element is a mix of a random component and a deterministic component. The random component has type Randomness. The generateRandomness method generates the Randomness according to a probability distribution. The generateValue method is a deterministic function that generates the output Value of the Element from the Randomness. Thus, Elements can be understood as defining a generative process in which first the Randomness is generated and then the output Value is generated given the Randomness.

Elements also have a current outcome, represented by the value field. Naturally, the generateValue function can refer to the current value of related Elements. However, generateValue is not allowed to call generateValue on another Element. We use the notation generateValue(r | w) to denote the value it produces given randomness r when the current value of related Elements is w.

Elements can have hard conditions and soft constraints. A condition is a predicate on Values that must be satisfied by the output of the Element. Values that violate the condition have probability zero. A constraint is a function that maps Values to Doubles. The probability of a Value is multiplied by the constraint, and then normalized. Conditions and constraints can be contingent on other elements taking on particular values. Ordinarily, these contingencies will not be specified by the user, but automatically by other Figaro code. In particular, specifying named evidence on a reference can result in contingencies.

Thus, an Element represents a conditional probability distribution over Values given the current values w of related Elements. The probability of an outcome v is defined by:

P(v | w) is proportional to (\sum_{r: generateValue(r | w) = v} P(generateRandomness() = r) * constraint(v)) if condition(v); 0 otherwise

An element has a name and belongs to an element collection that is used to find the element the name.

Elements can be cacheable or non-cacheable, which determines what type of Chain will be created for them. If you create a new Element class that you want to be cached, you should declare it to implement the Cachable or IfArgsCachable traits.

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Element
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Element(name: Name[T], collection: ElementCollection)

    name

    The name of the element

    collection

    The element collection to which this element belongs

Type Members

  1. type Condition = (T) ⇒ Boolean

    The type of conditions on the element.

    The type of conditions on the element. A condition is a function from a value to a Boolean.

  2. type Constraint = (T) ⇒ Double

    The type of soft constraints on the element.

    The type of soft constraints on the element. A constraint is a function from a value to a Double.

  3. abstract type Randomness

    The type of randomness content of the element.

  4. type Value = T

    The type of values over which the element is defined.

Abstract Value Members

  1. abstract def args: List[Element[_]]

    The arguments on which the element depends.

  2. abstract def generateRandomness(): Randomness

    Generate the randomness content.

  3. abstract def generateValue(rand: Randomness): Value

    Generate the value of the element determinstically given its randomness and the values of its arguments.

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. def !==(that: Element[Value])(implicit universe: Universe): Neq[Value]

    The element that tests inequality of this element with another element.

  4. final def ##(): Int

    Definition Classes
    AnyRef → Any
  5. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  6. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  7. def ===(that: Value)(implicit universe: Universe): Apply1[T, Boolean]

    The element that tests whether the value of this element is equal to a particular value.

  8. def ===(that: Element[Value])(implicit universe: Universe): Eq[Value]

    The element that tests equality of this element with another element.

  9. def activate(): Unit

    Activate the element in its universe.

  10. var active: Boolean

    Flag indicating whether the element is currently active in its universe.

  11. def addCondition(condition: (T) ⇒ Boolean, contingency: Contingency = List()): Unit

    Add the given condition to the existing conditions of the element.

    Add the given condition to the existing conditions of the element. By default, the contingency is empty.

  12. def addConstraint(constraint: (T) ⇒ Double, contingency: Contingency = List()): Unit

    Add a contingent constraint to the element.

    Add a contingent constraint to the element. By default, the contingency is empty.

  13. def addLogConstraint(constraint: (T) ⇒ Double, contingency: Contingency = List()): Unit

    Add a log contingent constraint to the element.

    Add a log contingent constraint to the element. By default, the contingency is empty.

  14. def addPragma(pragma: Pragma[Value]): Unit

    Add a pragma to the element.

  15. def allConditions: List[((T) ⇒ Boolean, Contingency)]

    All the conditions defined on this element.

  16. def allConstraints: List[((T) ⇒ Double, Contingency)]

    The current soft constraints on the element.

  17. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  18. def clearContext(): Unit

    Clears all the temporary elements associated with this element (all elements created in it's context)

  19. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. val collection: ElementCollection

    The element collection to which this element belongs

  21. def condition(value: Any): Boolean

    Tests whether all the element's contingent conditions are satisfied for the given value.

  22. def conditionSatisfied: Boolean

    Determines whether the condition on the element is satisfied by the current value.

  23. def constraint(value: Any): Double

    Gets the result of all the element's contingent constraints for the given value.

  24. def constraintValue: Double

    Determines the value of the constraint on the element applied to the current value.

  25. def context: List[Element[_]]

    The elements on which the existence of this element depends

  26. def deactivate(): Unit

    Deactivate the element in its universe.

  27. def directContextContents: Set[Element[_]]

    Returns the set of elements directly created in the context of this element

  28. def elementsIAmContingentOn: Set[Element[_]]

  29. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  30. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  31. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  32. def flatMap[U](fn: (Value) ⇒ Element[U])(implicit name: Name[U], collection: ElementCollection): Element[U]

  33. final def generate(): Unit

    First generate the randomness, then generate the value given the randomness.

    First generate the randomness, then generate the value given the randomness. Store the results in randomness and value.

  34. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  35. val hashCode: Int

    Definition Classes
    Element → AnyRef → Any
  36. def isCachable(): Boolean

    The cacheability of the element.

    The cacheability of the element. Chains create caches of their parent values, and it is useful to know when these values can be effectively cached and reused. In general, continuous distributions are not cacheable

  37. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  38. def isTemporary: Boolean

    Returns true if this element is temporary, that is, was created in the context of another element

  39. def map[U](fn: (Value) ⇒ U)(implicit name: Name[U], collection: ElementCollection): Element[U]

  40. val name: Name[T]

    The name of the element

  41. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  42. def nextRandomness(rand: Randomness): (Randomness, Double, Double)

    Generate the next randomness given the current randomness.

    Generate the next randomness given the current randomness. Returns three values: The next randomness, the Metropolis-Hastings proposal probability ratio, which is

    P(new -> old) / P(old -> new)

    and the model probability ratio, which is

    P(new) / P(old)

    The default implementation is to use generateRandomness and returns ones for the proposal and model probability ratios.

  43. final def notify(): Unit

    Definition Classes
    AnyRef
  44. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  45. def observe(observation: Value): Unit

    Condition the element by observing a particular value.

    Condition the element by observing a particular value. Propagates the effect to dependent elements and ensures that no other value for the element can be generated.

  46. def pragmas: List[Pragma[Value]]

    The pragmas attached to the element.

  47. var randomness: Randomness

    The current randomness content of the element.

  48. def removeConditions(contingency: Contingency = List()): Unit

    Remove all conditions associated with the given contingency.

    Remove all conditions associated with the given contingency. By default, the contingency is empty.

  49. def removeConstraints(contingency: Contingency = List()): Unit

    Remove all constraints associated with the given contingency.

    Remove all constraints associated with the given contingency. By default, the contingency is empty.

  50. def removePragma(pragma: Pragma[Value]): Unit

    Remove a pragma from the element.

  51. def score(oldValue: Value, newValue: Value): Double

    Compute the constraints on the new value divided by the constraints on the old value.

  52. def set(newValue: Value): Unit

    Set the value of this element and propagate the effects to elements that depend on it without changing their randomness.

    Set the value of this element and propagate the effects to elements that depend on it without changing their randomness. Also disallows the value of the element to change until unobserve or unset is called.

  53. def setCondition(newCondition: (T) ⇒ Boolean, contingency: Contingency = List()): Unit

    Set the condition associated with the contingency.

    Set the condition associated with the contingency. Removes previous conditions associated with the contingency. By default, the contingency is empty.

  54. def setConstraint(newConstraint: (T) ⇒ Double, contingency: Contingency = List()): Unit

    Set the constraint associated with the contingency.

    Set the constraint associated with the contingency. Removes previous constraints associated with the contingency. By default, the contingency is empty.

  55. def setLogConstraint(newConstraint: (T) ⇒ Double, contingency: Contingency = List()): Unit

    Set the log constraint associated with the contingency.

    Set the log constraint associated with the contingency. Removes previous constraints associated with the contingency. By default, the contingency is empty.

  56. def setRandomness(newRandomness: Randomness): Unit

    Set the randomness of this element.

    Set the randomness of this element.

    Will generate its value using the new randomness and propagate the effects to elements that depend on it without changing their randomness.

  57. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  58. def toNameString: String

    A string that is the element's name, if it has a non-empty one, otherwise the result of the element's toString

  59. def toString(): String

    Definition Classes
    AnyRef → Any
  60. val universe: Universe

    The universe in which the element is defined.

  61. def unobserve(): Unit

    Removes conditions on the element and allows different values of the element to be generated

  62. def unset(): Unit

    Allows different values of the element to be generated.

  63. var value: Value

    The current value of the element.

  64. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  65. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  66. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped