Exemplo n.º 1
0
    def test_covmodel_class(self):
        model_std = Gaussian(rescale=3, var=1.1, nugget=1.2, len_scale=1.3)
        model_var = Gau_var(rescale=3, var=1.1, nugget=1.2, len_scale=1.3)
        model_cov = Gau_cov(rescale=3, var=1.1, nugget=1.2, len_scale=1.3)
        model_cor = Gau_cor(rescale=3, var=1.1, nugget=1.2, len_scale=1.3)
        var = model_std.variogram(2.5)
        cov = model_std.covariance(2.5)
        corr = model_std.correlation(2.5)
        cor = model_std.cor(2.5)

        self.assertFalse(check_bounds(bounds=[0]))
        self.assertFalse(check_bounds(bounds=[1, -1]))
        self.assertFalse(check_bounds(bounds=[0, 1, 2, 3]))
        self.assertFalse(check_bounds(bounds=[0, 1, "kk"]))
        self.assertRaises(ValueError, model_std.set_arg_bounds, wrong_arg=[1])
        self.assertRaises(
            ValueError, model_std.set_arg_bounds, wrong_arg=[-1, 1]
        )

        # checking some properties
        model_par = Stable()
        self.assertEqual(len(model_par.arg), len(model_par.arg_list))
        self.assertEqual(len(model_par.iso_arg), len(model_par.iso_arg_list))
        self.assertEqual(len(model_par.arg), len(model_par.iso_arg) + 2)
        self.assertEqual(len(model_par.len_scale_vec), model_par.dim)
        self.assertFalse(Gaussian() == Stable())
        model_par.hankel_kw = {"N": 300}
        self.assertEqual(model_par.hankel_kw["N"], 300)

        # arg in bounds check
        model_std.set_arg_bounds(var=[0.5, 1.5])
        with self.assertRaises(ValueError):
            model_std.var = 0.4
        with self.assertRaises(ValueError):
            model_std.var = 1.6
        model_std.set_arg_bounds(var=[0.5, 1.5, "oo"])
        with self.assertRaises(ValueError):
            model_std.var = 0.5
        with self.assertRaises(ValueError):
            model_std.var = 1.5
        with self.assertRaises(ValueError):
            model_std.var_bounds = [1, -1]
        with self.assertRaises(ValueError):
            model_std.len_scale_bounds = [1, -1]
        with self.assertRaises(ValueError):
            model_std.nugget_bounds = [1, -1]
        with self.assertRaises(ValueError):
            model_std.anis_bounds = [1, -1]
        # reset the standard model
        model_std = Gaussian(rescale=3, var=1.1, nugget=1.2, len_scale=1.3)
        # std value from bounds with neg. inf and finit bound
        model_add = Mod_add()
        model_add.set_arg_bounds(alpha=[-np.inf, 0])
        self.assertAlmostEqual(model_add.alpha, -1)
        # special treatment of anis check
        model_std.set_arg_bounds(anis=[2, 4, "oo"])
        self.assertTrue(np.all(np.isclose(model_std.anis, 3)))
        # dim specific checks
        with self.assertWarns(AttributeWarning):
            Gau_fix(dim=1)
        self.assertRaises(ValueError, Gaussian, dim=0)
        # check inputs
        self.assertRaises(ValueError, model_std.percentile_scale, per=-1.0)
        self.assertRaises(ValueError, Gaussian, anis=-1.0)
        self.assertRaises(ValueError, Gaussian, len_scale=[1, -1])
        self.assertRaises(ValueError, check_arg_in_bounds, model_std, "wrong")
        self.assertWarns(AttributeWarning, Gaussian, wrong_arg=1.0)
        with self.assertWarns(AttributeWarning):
            self.assertRaises(ValueError, Gaussian, len_rescaled=1.0)

        # check correct subclassing
        with self.assertRaises(TypeError):

            class Gau_err(CovModel):
                pass

        self.assertAlmostEqual(var, model_var.variogram(2.5))
        self.assertAlmostEqual(var, model_cov.variogram(2.5))
        self.assertAlmostEqual(var, model_cor.variogram(2.5))
        self.assertAlmostEqual(cov, model_var.covariance(2.5))
        self.assertAlmostEqual(cov, model_cov.covariance(2.5))
        self.assertAlmostEqual(cov, model_cor.covariance(2.5))
        self.assertAlmostEqual(corr, model_var.correlation(2.5))
        self.assertAlmostEqual(corr, model_cov.correlation(2.5))
        self.assertAlmostEqual(corr, model_cor.correlation(2.5))
        self.assertAlmostEqual(cor, model_var.cor(2.5))
        self.assertAlmostEqual(cor, model_cov.cor(2.5))
        self.assertAlmostEqual(cor, model_cor.cor(2.5))
Exemplo n.º 2
0
 def len_scale_bounds(self, bounds):
     if not check_bounds(bounds):
         raise ValueError("Given bounds for 'len_scale' are not " +
                          "valid, got: " + str(bounds))
     self._len_scale_bounds = bounds
Exemplo n.º 3
0
 def nugget_bounds(self, bounds):
     if not check_bounds(bounds):
         raise ValueError("Given bounds for 'nugget' are not " +
                          "valid, got: " + str(bounds))
     self._nugget_bounds = bounds
Exemplo n.º 4
0
 def var_bounds(self, bounds):
     if not check_bounds(bounds):
         raise ValueError("Given bounds for 'var' are not " +
                          "valid, got: " + str(bounds))
     self._var_bounds = bounds