Ejemplo n.º 1
0
    def _unpack_jacobian_out(self,
                             raw_jac: Any) -> Dict[Variable, VariableData]:
        jac = {}
        for v0, vjac in nested_filter(is_variable, self.factor_out, raw_jac):
            jac[v0] = VariableData()
            for v1, j in zip(self.args, vjac):
                jac[v0][v1] = j

        return jac
Ejemplo n.º 2
0
 def _factor_value(self, raw_fval) -> FactorValue:
     """Converts the raw output of the factor into a `FactorValue`
     where the values of the deterministic values are stored in a dict
     attribute `FactorValue.deterministic_values`
     """
     det_values = VariableData(
         nested_filter(is_variable, self.factor_out, raw_fval))
     fval = det_values.pop(FactorValue, 0.0)
     return FactorValue(fval, det_values)
Ejemplo n.º 3
0
    def calc_exact_update(self, mean_field) -> "MeanField":
        if self._calc_exact_update:
            from autofit.graphical.mean_field import MeanField

            projection = self._calc_exact_update(
                *self.resolve_args_and_out(mean_field))
            return MeanField(
                nested_filter(is_variable, self.args + (self.factor_out, ),
                              projection))
        else:
            raise NotImplementedError
Ejemplo n.º 4
0
 def out_variables(self):
     return set(v[0] for v in nested_filter(is_variable, self.factor_out))
Ejemplo n.º 5
0
 def deterministic_variables(self) -> Set[Variable]:
     deterministic_variables = set(
         v for v, in nested_filter(is_variable, self.factor_out))
     deterministic_variables.discard(FactorValue)
     return frozenset(deterministic_variables)