Пример #1
0
    def __init__(self, model):
        """Initialize a ModelPrior.

        Parameters
        ----------
        model : ElfiModel

        """
        model = model.copy()
        self.parameter_names = model.parameter_names
        self.dim = len(self.parameter_names)
        self.client = Client()

        # Prepare nets for the pdf methods
        self._pdf_node = augmenter.add_pdf_nodes(model, log=False)[0]
        self._logpdf_node = augmenter.add_pdf_nodes(model, log=True)[0]

        self._rvs_net = self.client.compile(model.source_net, outputs=self.parameter_names)
        self._pdf_net = self.client.compile(model.source_net, outputs=self._pdf_node)
        self._logpdf_net = self.client.compile(model.source_net, outputs=self._logpdf_node)
Пример #2
0
    def __init__(self, model, discrepancy_name=None, output_names=None, **kwargs):
        model, discrepancy_name = self._resolve_model(model, discrepancy_name)

        # Add the prior pdf nodes to the model
        model = model.copy()
        logpdf_name = augmenter.add_pdf_nodes(model, log=True)[0]

        output_names = [discrepancy_name] + model.parameter_names + [logpdf_name] + \
                       (output_names or [])

        super(SMC, self).__init__(model, output_names, **kwargs)

        self.discrepancy_name = discrepancy_name
        self.prior_logpdf = logpdf_name
        self.state['round'] = 0
        self._populations = []
        self._rejection = None
        self._round_random_state = None