pyro/infer/trace_elbo.py

Killed 48 out of 64 mutants

Survived

Survived mutation testing. These mutants show holes in your test suite.

Mutant 209

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -72,7 +72,7 @@
         return loss
 
     def _differentiable_loss_particle(self, model_trace, guide_trace):
-        elbo_particle = 0
+        elbo_particle = 1
         surrogate_elbo_particle = 0
         log_r = None
 

Mutant 211

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -73,7 +73,7 @@
 
     def _differentiable_loss_particle(self, model_trace, guide_trace):
         elbo_particle = 0
-        surrogate_elbo_particle = 0
+        surrogate_elbo_particle = 1
         log_r = None
 
         # compute elbo and surrogate elbo

Mutant 216

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -78,7 +78,7 @@
 
         # compute elbo and surrogate elbo
         for name, site in model_trace.nodes.items():
-            if site["type"] == "sample":
+            if site["type"] == "XXsampleXX":
                 elbo_particle = elbo_particle + torch_item(site["log_prob_sum"])
                 surrogate_elbo_particle = surrogate_elbo_particle + site["log_prob_sum"]
 

Mutant 217

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -79,7 +79,7 @@
         # compute elbo and surrogate elbo
         for name, site in model_trace.nodes.items():
             if site["type"] == "sample":
-                elbo_particle = elbo_particle + torch_item(site["log_prob_sum"])
+                elbo_particle = elbo_particle - torch_item(site["log_prob_sum"])
                 surrogate_elbo_particle = surrogate_elbo_particle + site["log_prob_sum"]
 
         for name, site in guide_trace.nodes.items():

Mutant 220

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -80,7 +80,7 @@
         for name, site in model_trace.nodes.items():
             if site["type"] == "sample":
                 elbo_particle = elbo_particle + torch_item(site["log_prob_sum"])
-                surrogate_elbo_particle = surrogate_elbo_particle + site["log_prob_sum"]
+                surrogate_elbo_particle = surrogate_elbo_particle - site["log_prob_sum"]
 
         for name, site in guide_trace.nodes.items():
             if site["type"] == "sample":

Mutant 228

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -86,7 +86,7 @@
             if site["type"] == "sample":
                 log_prob, score_function_term, entropy_term = site["score_parts"]
 
-                elbo_particle = elbo_particle - torch_item(site["log_prob_sum"])
+                elbo_particle = elbo_particle + torch_item(site["log_prob_sum"])
 
                 if not is_identically_zero(entropy_term):
                     surrogate_elbo_particle = surrogate_elbo_particle - entropy_term.sum()

Mutant 240

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -97,7 +97,7 @@
                     site = log_r.sum_to(site["cond_indep_stack"])
                     surrogate_elbo_particle = surrogate_elbo_particle + (site * score_function_term).sum()
 
-        return -elbo_particle, -surrogate_elbo_particle
+        return +elbo_particle, -surrogate_elbo_particle
 
     def differentiable_loss(self, model, guide, *args, **kwargs):
         """

Mutant 242

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -121,7 +121,7 @@
         Computes the ELBO as well as the surrogate ELBO that is used to form the gradient estimator.
         Performs backward on the latter. Num_particle many samples are used to form the estimators.
         """
-        loss = 0.0
+        loss = 1.0
         # grab a trace from the generator
         for model_trace, guide_trace in self._get_traces(model, guide, args, kwargs):
             loss_particle, surrogate_loss_particle = self._differentiable_loss_particle(model_trace, guide_trace)

Mutant 245

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -125,7 +125,7 @@
         # grab a trace from the generator
         for model_trace, guide_trace in self._get_traces(model, guide, args, kwargs):
             loss_particle, surrogate_loss_particle = self._differentiable_loss_particle(model_trace, guide_trace)
-            loss += loss_particle / self.num_particles
+            loss = loss_particle / self.num_particles
 
             # collect parameters to train from model and guide
             trainable_params = any(site["type"] == "param"

Mutant 246

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -125,7 +125,7 @@
         # grab a trace from the generator
         for model_trace, guide_trace in self._get_traces(model, guide, args, kwargs):
             loss_particle, surrogate_loss_particle = self._differentiable_loss_particle(model_trace, guide_trace)
-            loss += loss_particle / self.num_particles
+            loss -= loss_particle / self.num_particles
 
             # collect parameters to train from model and guide
             trainable_params = any(site["type"] == "param"

Mutant 247

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -125,7 +125,7 @@
         # grab a trace from the generator
         for model_trace, guide_trace in self._get_traces(model, guide, args, kwargs):
             loss_particle, surrogate_loss_particle = self._differentiable_loss_particle(model_trace, guide_trace)
-            loss += loss_particle / self.num_particles
+            loss += loss_particle * self.num_particles
 
             # collect parameters to train from model and guide
             trainable_params = any(site["type"] == "param"

Mutant 249

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -128,7 +128,7 @@
             loss += loss_particle / self.num_particles
 
             # collect parameters to train from model and guide
-            trainable_params = any(site["type"] == "param"
+            trainable_params = any(site["type"] != "param"
                                    for trace in (model_trace, guide_trace)
                                    for site in trace.nodes.values())
 

Mutant 253

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -132,7 +132,7 @@
                                    for trace in (model_trace, guide_trace)
                                    for site in trace.nodes.values())
 
-            if trainable_params and getattr(surrogate_loss_particle, 'requires_grad', False):
+            if trainable_params and getattr(surrogate_loss_particle, 'requires_grad', True):
                 surrogate_loss_particle = surrogate_loss_particle / self.num_particles
                 surrogate_loss_particle.backward(retain_graph=self.retain_graph)
         warn_if_nan(loss, "loss")

Mutant 254

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -132,7 +132,7 @@
                                    for trace in (model_trace, guide_trace)
                                    for site in trace.nodes.values())
 
-            if trainable_params and getattr(surrogate_loss_particle, 'requires_grad', False):
+            if trainable_params or getattr(surrogate_loss_particle, 'requires_grad', False):
                 surrogate_loss_particle = surrogate_loss_particle / self.num_particles
                 surrogate_loss_particle.backward(retain_graph=self.retain_graph)
         warn_if_nan(loss, "loss")

Mutant 255

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -133,7 +133,7 @@
                                    for site in trace.nodes.values())
 
             if trainable_params and getattr(surrogate_loss_particle, 'requires_grad', False):
-                surrogate_loss_particle = surrogate_loss_particle / self.num_particles
+                surrogate_loss_particle = surrogate_loss_particle * self.num_particles
                 surrogate_loss_particle.backward(retain_graph=self.retain_graph)
         warn_if_nan(loss, "loss")
         return loss

Mutant 257

--- pyro/infer/trace_elbo.py
+++ pyro/infer/trace_elbo.py
@@ -135,7 +135,7 @@
             if trainable_params and getattr(surrogate_loss_particle, 'requires_grad', False):
                 surrogate_loss_particle = surrogate_loss_particle / self.num_particles
                 surrogate_loss_particle.backward(retain_graph=self.retain_graph)
-        warn_if_nan(loss, "loss")
+        warn_if_nan(loss, "XXlossXX")
         return loss