Exemple #1
0
 def likelihood(self, outcomes, modelparams, expparams):
     # We first call the superclass method, which basically
     # just makes sure that call count diagnostics are properly
     # logged.
     super(MultiCosModel, self).likelihood(outcomes, modelparams, expparams)
     
     # Next, since we have a two-outcome model, everything is defined by
     # Pr(0 | modelparams; expparams), so we find the probability of 0
     # for each model and each experiment.
     #
     # We do so by taking a product along the modelparam index (len 2,
     # indicating omega_1 or omega_2), then squaring the result.
     pr0 = np.prod(
         np.cos(
             # shape (n_models, 1, 2)
             modelparams[:, np.newaxis, :] *
             # shape (n_experiments, 2)
             expparams['ts']
         ), # <- broadcasts to shape (n_models, n_experiments, 2).
         axis=2 # <- product over the final index (len 2)
     ) ** 2 # square each element
     
     # Now we use pr0_to_likelihood_array to turn this two index array
     # above into the form expected by SMCUpdater and other consumers
     # of likelihood().
     return FiniteOutcomeModel.pr0_to_likelihood_array(outcomes, pr0)
    def likelihood(self, outcomes, modelparams, expparams):
        super(TomographyModel, self).likelihood(outcomes, modelparams, expparams)

        pr1 = np.empty((modelparams.shape[0], expparams.shape[0]))

        pr1[:, :] = np.einsum(
            'ei,mi->me',
            # This should be the Hermitian conjugate, but since
            # expparams['meas'] is real (that is, since the measurement)
            # is Hermitian, then that's not needed here.
            expparams['meas'],
            modelparams
        )
        np.clip(pr1, 0, 1, out=pr1)

        return FiniteOutcomeModel.pr0_to_likelihood_array(outcomes, 1 - pr1)
Exemple #3
0
    def likelihood(self, outcomes, modelparams, expparams):
        super(TomographyModel, self).likelihood(outcomes, modelparams,
                                                expparams)

        pr1 = np.empty((modelparams.shape[0], expparams.shape[0]))

        pr1[:, :] = np.einsum(
            'ei,mi->me',
            # This should be the Hermitian conjugate, but since
            # expparams['meas'] is real (that is, since the measurement)
            # is Hermitian, then that's not needed here.
            expparams['meas'],
            modelparams)
        np.clip(pr1, 0, 1, out=pr1)

        return FiniteOutcomeModel.pr0_to_likelihood_array(outcomes, 1 - pr1)
    def likelihood(self, outcomes, modelparams, expparams):

        # modelparams give particles
        # outcomes should be a length 1 list with a single outcome for the single experiment performed

        time = expparams["t"]
        print(
            f"Likelihood fnc given \nOutcomes:\n {outcomes} \nParticles:\n {modelparams} \nExperiment:\n {expparams}"
        )

        prob_measuring_zero = compute_prob_measuring_zero(
            modelparams,
            time=expparams["t"]  # particles
        )

        likelihood = FiniteOutcomeModel.pr0_to_likelihood_array(
            outcomes=outcomes,
            pr0=prob_measuring_zero,
        )

        return likelihood
 def likelihood(self, outcomes, modelparams, expparams):
     super(MockModel, self).likelihood(outcomes, modelparams, expparams)
     pr0 = np.ones((modelparams.shape[0], expparams.shape[0])) / 2
     return FiniteOutcomeModel.pr0_to_likelihood_array(outcomes, pr0)