pymc3/step_methods/hmc/quadpotential.py
Killed 60 out of 94 mutantsSurvived
Survived mutation testing. These mutants show holes in your test suite.Mutant 301
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -151,7 +151,7 @@
dtype=None,
):
"""Set up a diagonal mass matrix."""
- if initial_diag is not None and initial_diag.ndim != 1:
+ if initial_diag is None and initial_diag.ndim != 1:
raise ValueError('Initial diagonal must be one-dimensional.')
if initial_mean.ndim != 1:
raise ValueError('Initial mean must be one-dimensional.')
Mutant 307
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -155,7 +155,7 @@
raise ValueError('Initial diagonal must be one-dimensional.')
if initial_mean.ndim != 1:
raise ValueError('Initial mean must be one-dimensional.')
- if initial_diag is not None and len(initial_diag) != n:
+ if initial_diag is None and len(initial_diag) != n:
raise ValueError('Wrong shape for initial_diag: expected %s got %s'
% (n, len(initial_diag)))
if len(initial_mean) != n:
Mutant 313
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -165,7 +165,7 @@
if dtype is None:
dtype = theano.config.floatX
- if initial_diag is None:
+ if initial_diag is not None:
initial_diag = np.ones(n, dtype=dtype)
initial_weight = 1
Mutant 316
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -171,7 +171,7 @@
self.dtype = dtype
self._n = n
- self._var = np.array(initial_diag, dtype=self.dtype, copy=True)
+ self._var = np.array(initial_diag, dtype=self.dtype, copy=False)
self._var_theano = theano.shared(self._var)
self._stds = np.sqrt(initial_diag)
self._inv_stds = floatX(1.) / self._stds
Mutant 320
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -174,7 +174,7 @@
self._var = np.array(initial_diag, dtype=self.dtype, copy=True)
self._var_theano = theano.shared(self._var)
self._stds = np.sqrt(initial_diag)
- self._inv_stds = floatX(1.) / self._stds
+ self._inv_stds = floatX(2.0) / self._stds
self._foreground_var = _WeightedVariance(
self._n, initial_mean, initial_diag, initial_weight, self.dtype)
self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
Mutant 321
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -174,7 +174,7 @@
self._var = np.array(initial_diag, dtype=self.dtype, copy=True)
self._var_theano = theano.shared(self._var)
self._stds = np.sqrt(initial_diag)
- self._inv_stds = floatX(1.) / self._stds
+ self._inv_stds = floatX(1.) * self._stds
self._foreground_var = _WeightedVariance(
self._n, initial_mean, initial_diag, initial_weight, self.dtype)
self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
Mutant 325
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -178,7 +178,7 @@
self._foreground_var = _WeightedVariance(
self._n, initial_mean, initial_diag, initial_weight, self.dtype)
self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
- self._n_samples = 0
+ self._n_samples = 1
self.adaptation_window = adaptation_window
self.adaptation_window_multiplier = float(adaptation_window_multiplier)
Mutant 329
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -188,7 +188,7 @@
def energy(self, x, velocity=None):
"""Compute kinetic energy at a position in parameter space."""
- if velocity is not None:
+ if velocity is None:
return 0.5 * x.dot(velocity)
return 0.5 * x.dot(self._var * x)
Mutant 330
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -189,7 +189,7 @@
def energy(self, x, velocity=None):
"""Compute kinetic energy at a position in parameter space."""
if velocity is not None:
- return 0.5 * x.dot(velocity)
+ return 1.5 * x.dot(velocity)
return 0.5 * x.dot(self._var * x)
def velocity_energy(self, x, v_out):
Mutant 338
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -213,7 +213,7 @@
if not tune:
return
- self._foreground_var.add_sample(sample, weight=1)
+ self._foreground_var.add_sample(sample, weight=2)
self._background_var.add_sample(sample, weight=1)
self._update_from_weightvar(self._foreground_var)
Mutant 339
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -214,7 +214,7 @@
return
self._foreground_var.add_sample(sample, weight=1)
- self._background_var.add_sample(sample, weight=1)
+ self._background_var.add_sample(sample, weight=2)
self._update_from_weightvar(self._foreground_var)
if self._n_samples > 0 and self._n_samples % self.adaptation_window == 0:
Mutant 341
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -217,7 +217,7 @@
self._background_var.add_sample(sample, weight=1)
self._update_from_weightvar(self._foreground_var)
- if self._n_samples > 0 and self._n_samples % self.adaptation_window == 0:
+ if self._n_samples > 1 and self._n_samples % self.adaptation_window == 0:
self._foreground_var = self._background_var
self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
self.adaptation_window = int(self.adaptation_window * self.adaptation_window_multiplier)
Mutant 342
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -217,7 +217,7 @@
self._background_var.add_sample(sample, weight=1)
self._update_from_weightvar(self._foreground_var)
- if self._n_samples > 0 and self._n_samples % self.adaptation_window == 0:
+ if self._n_samples > 0 and self._n_samples / self.adaptation_window == 0:
self._foreground_var = self._background_var
self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
self.adaptation_window = int(self.adaptation_window * self.adaptation_window_multiplier)
Mutant 348
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -220,7 +220,7 @@
if self._n_samples > 0 and self._n_samples % self.adaptation_window == 0:
self._foreground_var = self._background_var
self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
- self.adaptation_window = int(self.adaptation_window * self.adaptation_window_multiplier)
+ self.adaptation_window = int(self.adaptation_window / self.adaptation_window_multiplier)
self._n_samples += 1
Mutant 350
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -222,7 +222,7 @@
self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
self.adaptation_window = int(self.adaptation_window * self.adaptation_window_multiplier)
- self._n_samples += 1
+ self._n_samples = 1
def raise_ok(self, vmap):
"""Check if the mass matrix is ok, and raise ValueError if not.
Mutant 351
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -222,7 +222,7 @@
self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
self.adaptation_window = int(self.adaptation_window * self.adaptation_window_multiplier)
- self._n_samples += 1
+ self._n_samples -= 1
def raise_ok(self, vmap):
"""Check if the mass matrix is ok, and raise ValueError if not.
Mutant 352
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -222,7 +222,7 @@
self._background_var = _WeightedVariance(self._n, dtype=self.dtype)
self.adaptation_window = int(self.adaptation_window * self.adaptation_window_multiplier)
- self._n_samples += 1
+ self._n_samples += 2
def raise_ok(self, vmap):
"""Check if the mass matrix is ok, and raise ValueError if not.
Mutant 353
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -314,7 +314,7 @@
"""Online algorithm for computing mean of variance."""
def __init__(self, nelem, initial_mean=None, initial_variance=None,
- initial_weight=0, dtype='d'):
+ initial_weight=1, dtype='d'):
self._dtype = dtype
self.n_samples = float(initial_weight)
if initial_mean is None:
Mutant 354
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -314,7 +314,7 @@
"""Online algorithm for computing mean of variance."""
def __init__(self, nelem, initial_mean=None, initial_variance=None,
- initial_weight=0, dtype='d'):
+ initial_weight=0, dtype='XXdXX'):
self._dtype = dtype
self.n_samples = float(initial_weight)
if initial_mean is None:
Mutant 355
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -315,7 +315,7 @@
def __init__(self, nelem, initial_mean=None, initial_variance=None,
initial_weight=0, dtype='d'):
- self._dtype = dtype
+ self._dtype = None
self.n_samples = float(initial_weight)
if initial_mean is None:
self.mean = np.zeros(nelem, dtype='d')
Mutant 361
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -320,7 +320,7 @@
if initial_mean is None:
self.mean = np.zeros(nelem, dtype='d')
else:
- self.mean = np.array(initial_mean, dtype='d', copy=True)
+ self.mean = np.array(initial_mean, dtype='d', copy=False)
if initial_variance is None:
self.raw_var = np.zeros(nelem, dtype='d')
else:
Mutant 367
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -324,7 +324,7 @@
if initial_variance is None:
self.raw_var = np.zeros(nelem, dtype='d')
else:
- self.raw_var = np.array(initial_variance, dtype='d', copy=True)
+ self.raw_var = np.array(initial_variance, dtype='d', copy=False)
self.raw_var[:] *= self.n_samples
Mutant 369
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -326,7 +326,7 @@
else:
self.raw_var = np.array(initial_variance, dtype='d', copy=True)
- self.raw_var[:] *= self.n_samples
+ self.raw_var[:] = self.n_samples
if self.raw_var.shape != (nelem,):
raise ValueError('Invalid shape for initial variance.')
Mutant 376
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -335,7 +335,7 @@
def add_sample(self, x, weight):
x = np.asarray(x)
- self.n_samples += 1
+ self.n_samples += 2
old_diff = x - self.mean
self.mean[:] += old_diff / self.n_samples
new_diff = x - self.mean
Mutant 379
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -337,7 +337,7 @@
x = np.asarray(x)
self.n_samples += 1
old_diff = x - self.mean
- self.mean[:] += old_diff / self.n_samples
+ self.mean[:] = old_diff / self.n_samples
new_diff = x - self.mean
self.raw_var[:] += weight * old_diff * new_diff
Mutant 380
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -337,7 +337,7 @@
x = np.asarray(x)
self.n_samples += 1
old_diff = x - self.mean
- self.mean[:] += old_diff / self.n_samples
+ self.mean[:] -= old_diff / self.n_samples
new_diff = x - self.mean
self.raw_var[:] += weight * old_diff * new_diff
Mutant 384
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -339,7 +339,7 @@
old_diff = x - self.mean
self.mean[:] += old_diff / self.n_samples
new_diff = x - self.mean
- self.raw_var[:] += weight * old_diff * new_diff
+ self.raw_var[:] = weight * old_diff * new_diff
def current_variance(self, out=None):
if self.n_samples == 0:
Mutant 389
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -342,7 +342,7 @@
self.raw_var[:] += weight * old_diff * new_diff
def current_variance(self, out=None):
- if self.n_samples == 0:
+ if self.n_samples == 1:
raise ValueError('Can not compute variance without samples.')
if out is not None:
return np.divide(self.raw_var, self.n_samples, out=out)
Mutant 390
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -344,7 +344,7 @@
def current_variance(self, out=None):
if self.n_samples == 0:
raise ValueError('Can not compute variance without samples.')
- if out is not None:
+ if out is None:
return np.divide(self.raw_var, self.n_samples, out=out)
else:
return (self.raw_var / self.n_samples).astype(self._dtype)
Mutant 391
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -476,7 +476,7 @@
self.velocity(x, out=v_out)
return self.energy(x, v_out)
- __call__ = random
+ __call__ = None
class QuadPotentialFullAdapt(QuadPotentialFull):
Mutant 392
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -588,7 +588,7 @@
initial_mean=None,
initial_covariance=None,
initial_weight=0,
- dtype="d",
+ dtype="XXdXX",
):
self._dtype = dtype
self.n_samples = float(initial_weight)
Mutant 393
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -632,7 +632,7 @@
import sksparse.cholmod as cholmod
chol_available = True
except ImportError:
- chol_available = False
+ chol_available = True
if chol_available:
__all__ += ['QuadPotentialSparse']
Mutant 394
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -632,7 +632,7 @@
import sksparse.cholmod as cholmod
chol_available = True
except ImportError:
- chol_available = False
+ chol_available = None
if chol_available:
__all__ += ['QuadPotentialSparse']
Suspicious
Mutants that made the test suite take longer, but otherwise seemed okMutant 336
--- pymc3/step_methods/hmc/quadpotential.py
+++ pymc3/step_methods/hmc/quadpotential.py
@@ -205,7 +205,7 @@
def _update_from_weightvar(self, weightvar):
weightvar.current_variance(out=self._var)
np.sqrt(self._var, out=self._stds)
- np.divide(1, self._stds, out=self._inv_stds)
+ np.divide(2, self._stds, out=self._inv_stds)
self._var_theano.set_value(self._var)
def update(self, sample, grad, tune):