Esempio n. 1
0
    def info_for_analysis_factor(
            self,
            analysis_factor
    ) -> str:
        """
        A string describing a given AnalysisFactor in the context of this graph.
        """
        model = analysis_factor.prior_model
        formatter = TextFormatter()

        for path, prior in model.path_instance_tuples_for_class(
                Prior,
                ignore_children=True
        ):
            name = path[-1]
            related_factor_names = self._related_factor_names(
                prior,
                excluded_factor=analysis_factor
            )
            if len(related_factor_names) > 0:
                name = f"{name} ({related_factor_names})"
            path = path[:-1] + (name,)
            formatter.add(
                path,
                self.variable_formatter(
                    prior
                )
            )

        return f"{analysis_factor.name}\n\n{formatter.text}"
Esempio n. 2
0
    def info(self) -> str:
        """
        Use the priors that make up the model_mapper to generate information on each
        parameter of the overall model.
        This information is extracted from each priors *model_info* property.
        """
        formatter = TextFormatter()

        for t in self.path_instance_tuples_for_class((Prior, float, tuple)):
            formatter.add(t)

        return formatter.text
Esempio n. 3
0
    def info_for_prior_factor(
            self,
            prior_factor: PriorFactor
    ) -> str:
        """
        A string describing a given PriorFactor in the context of this graph.
        """
        related_factor_names = self._related_factor_names(
            variable=prior_factor.variable,
            excluded_factor=prior_factor
        )

        formatter = TextFormatter()
        formatter.add(
            (f"{prior_factor.name} ({related_factor_names})",),
            self.variable_formatter(
                prior_factor.variable
            )
        )
        return formatter.text
Esempio n. 4
0
    def info_for_hierarchical_factor(
            self,
            hierarchical_factor
    ):
        distribution_model_info = self.info_for_analysis_factor(
            hierarchical_factor
        )

        formatter = TextFormatter()

        for factor in hierarchical_factor.factors:
            related_factor_names = self._related_factor_names(
                variable=factor.variable,
                excluded_factor=factor
            )
            formatter.add(
                (related_factor_names,),
                self.variable_formatter(
                    factor.variable
                )
            )

        return f"{distribution_model_info}\n\nDrawn Variables\n\n{formatter.text}"
Esempio n. 5
0
    def make_results_text(self, model_approx) -> str:
        """
        Create a string describing the posterior values after this factor
        during or after an EPOptimisation.

        Parameters
        ----------
        model_approx: EPMeanField

        Returns
        -------
        A string containing the name of this factor with the names and
        values of each associated variable in the mean field.
        """
        arguments = {
            prior: model_approx.mean_field[prior] for prior in self.prior_model.priors
        }
        updated_model = self.prior_model.gaussian_prior_model_for_arguments(arguments)

        formatter = TextFormatter()

        for path, prior in updated_model.path_priors_tuples:
            formatter.add(path, prior.mean)
        return f"{self.name}\n\n{formatter.text}"