Beispiel #1
0
 def testBijector(self):
     with self.test_session():
         scale = 5.
         concentration = 0.3
         bijector = tfb.Weibull(scale=scale,
                                concentration=concentration,
                                validate_args=True)
         self.assertEqual("weibull", bijector.name)
         x = np.array([[[0.], [1.], [14.], [20.], [100.]]],
                      dtype=np.float32)
         # Weibull distribution
         weibull_dist = stats.frechet_r(c=concentration, scale=scale)
         y = weibull_dist.cdf(x).astype(np.float32)
         self.assertAllClose(y, self.evaluate(bijector.forward(x)))
         self.assertAllClose(x, self.evaluate(bijector.inverse(y)))
         self.assertAllClose(
             weibull_dist.logpdf(x),
             self.evaluate(
                 bijector.forward_log_det_jacobian(x, event_ndims=0)))
         self.assertAllClose(self.evaluate(
             -bijector.inverse_log_det_jacobian(y, event_ndims=0)),
                             self.evaluate(
                                 bijector.forward_log_det_jacobian(
                                     x, event_ndims=0)),
                             rtol=1e-4,
                             atol=0.)
 def testBijector(self):
     with self.test_session():
         scale = 5.
         concentration = 0.3
         bijector = Weibull(scale=scale,
                            concentration=concentration,
                            event_ndims=1,
                            validate_args=True)
         self.assertEqual("weibull", bijector.name)
         x = np.array([[[0.], [1.], [14.], [20.], [100.]]],
                      dtype=np.float32)
         # Weibull distribution
         weibull_dist = stats.frechet_r(c=concentration, scale=scale)
         y = weibull_dist.cdf(x).astype(np.float32)
         self.assertAllClose(y, bijector.forward(x).eval())
         self.assertAllClose(x, bijector.inverse(y).eval())
         self.assertAllClose(
             # We should lose a dimension from calculating the determinant of the
             # jacobian.
             np.squeeze(weibull_dist.logpdf(x), axis=2),
             bijector.forward_log_det_jacobian(x).eval())
         self.assertAllClose(-bijector.inverse_log_det_jacobian(y).eval(),
                             bijector.forward_log_det_jacobian(x).eval(),
                             rtol=1e-4,
                             atol=0.)
Beispiel #3
0
 def testBijector(self):
   scale = 5.
   concentration = 0.3
   bijector = tfb.Weibull(
       scale=scale, concentration=concentration, validate_args=True)
   self.assertEqual("weibull", bijector.name)
   x = np.array([[[0.], [1.], [14.], [20.], [100.]]], dtype=np.float32)
   # Weibull distribution
   weibull_dist = stats.frechet_r(c=concentration, scale=scale)
   y = weibull_dist.cdf(x).astype(np.float32)
   self.assertAllClose(y, self.evaluate(bijector.forward(x)))
   self.assertAllClose(x, self.evaluate(bijector.inverse(y)))
   self.assertAllClose(
       weibull_dist.logpdf(x),
       self.evaluate(bijector.forward_log_det_jacobian(x, event_ndims=0)))
   self.assertAllClose(
       self.evaluate(-bijector.inverse_log_det_jacobian(y, event_ndims=0)),
       self.evaluate(bijector.forward_log_det_jacobian(x, event_ndims=0)),
       rtol=1e-4,
       atol=0.)
 def testBijector(self):
   with self.test_session():
     scale = 5.
     concentration = 0.3
     bijector = Weibull(
         scale=scale, concentration=concentration,
         event_ndims=1, validate_args=True)
     self.assertEqual("weibull", bijector.name)
     x = np.array([[[0.], [1.], [14.], [20.], [100.]]], dtype=np.float32)
     # Weibull distribution
     weibull_dist = stats.frechet_r(c=concentration, scale=scale)
     y = weibull_dist.cdf(x).astype(np.float32)
     self.assertAllClose(y, bijector.forward(x).eval())
     self.assertAllClose(x, bijector.inverse(y).eval())
     self.assertAllClose(
         # We should lose a dimension from calculating the determinant of the
         # jacobian.
         np.squeeze(weibull_dist.logpdf(x), axis=2),
         bijector.forward_log_det_jacobian(x).eval())
     self.assertAllClose(
         -bijector.inverse_log_det_jacobian(y).eval(),
         bijector.forward_log_det_jacobian(x).eval(),
         rtol=1e-4,
         atol=0.)
Beispiel #5
0
mean, var, skew, kurt = frechet_r.stats(c, moments='mvsk')

# Display the probability density function (``pdf``):

x = np.linspace(frechet_r.ppf(0.01, c),
                frechet_r.ppf(0.99, c), 100)
ax.plot(x, frechet_r.pdf(x, c),
       'r-', lw=5, alpha=0.6, label='frechet_r pdf')

# Alternatively, the distribution object can be called (as a function)
# to fix the shape, location and scale parameters. This returns a "frozen"
# RV object holding the given parameters fixed.

# Freeze the distribution and display the frozen ``pdf``:

rv = frechet_r(c)
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

# Check accuracy of ``cdf`` and ``ppf``:

vals = frechet_r.ppf([0.001, 0.5, 0.999], c)
np.allclose([0.001, 0.5, 0.999], frechet_r.cdf(vals, c))
# True

# Generate random numbers:

r = frechet_r.rvs(c, size=1000)

# And compare the histogram:

ax.hist(r, normed=True, histtype='stepfilled', alpha=0.2)
 def test_Exponential_to_Weibull(self):
     X = RV(Exponential(rate=5))
     sims = X.sim(Nsim)
     cdf = stats.frechet_r(scale=1 / 5, c=1).cdf
     pval = stats.kstest(sims, cdf).pvalue
     self.assertTrue(pval > .01)
Beispiel #7
0
from scipy.stats import frechet_r
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(1, 1)

F = frechet_r(loc=17.440, scale=8.153, c=0.198)
x = np.arange(0.01, 120, 0.01)
ax.plot(x, F.pdf(x), 'k-', lw=2)

plt.show()