inference_twostage.py
def infer_posterior(self,
                        iter_steps=1000,
                        num_particles=10,
                        optim_kwargs={'lr': .01}):
        """Perform SVI over free model parameters.
        """

        pyro.clear_param_store()

        svi = pyro.infer.SVI(model=self.model,
                  guide=self.guide,
                  optim=pyro.optim.Adam(optim_kwargs),
                  loss=pyro.infer.Trace_ELBO(num_particles=num_particles,
                                  #set below to true once code is vectorized
                                  vectorize_particles=True))

        loss = []
        pbar = tqdm(range(iter_steps), position=0)
        for step in pbar:
            loss.append(ar.tensor(svi.step()))
            pbar.set_description("Mean ELBO %6.2f" % ar.tensor(loss[-20:]).mean())
            if ar.isnan(loss[-1]):
                break

        self.loss = loss
        
        return self.loss
Perform SVI over free model parameters.
        
Perform SVI over free model parameters.
Perform SVI over free model parameters .
def infer_posterior(self,
                        iter_steps=1000,
                        num_particles=10,
                        optim_kwargs={'lr': .01}):
        pyro.clear_param_store()
        svi = pyro.infer.SVI(model=self.model,
                  guide=self.guide,
                  optim=pyro.optim.Adam(optim_kwargs),
                  loss=pyro.infer.Trace_ELBO(num_particles=num_particles,
                                  vectorize_particles=True))
        loss = []
        pbar = tqdm(range(iter_steps), position=0)
        for step in pbar:
            loss.append(ar.tensor(svi.step()))
            pbar.set_description("Mean ELBO %6.2f" % ar.tensor(loss[-20:]).mean())
            if ar.isnan(loss[-1]):
                break
        self.loss = loss
        return self.loss
def infer_posterior ( self , iter_steps = 1000 , num_particles = 10 , optim_kwargs = { 'lr' : .01 } ) : pyro . clear_param_store ( ) svi = pyro . infer . SVI ( model = self . model , guide = self . guide , optim = pyro . optim . Adam ( optim_kwargs ) , loss = pyro . infer . Trace_ELBO ( num_particles = num_particles , vectorize_particles = True ) ) loss = [ ] pbar = tqdm ( range ( iter_steps ) , position = 0 ) for step in pbar : loss . append ( ar . tensor ( svi . step ( ) ) ) pbar . set_description ( "Mean ELBO %6.2f" % ar . tensor ( loss [ - 20 : ] ) . mean ( ) ) if ar . isnan ( loss [ - 1 ] ) : break self . loss = loss return self . loss
Perform SVI over free model parameters.
Perform SVI over free model parameters .
"""Perform SVI over free model parameters.
        """ #set below to true once code is vectorized
self
iter_steps
num_particles
optim_kwargs