Skip to content

Commit

Permalink
Merge 340e337 into a58a33e
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaselsteiner committed Jul 2, 2020
2 parents a58a33e + 340e337 commit 73ce01d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,28 @@ def test_fitting_exponentiated_weibull(self):
self.assertGreater(dist.cdf(2), 0)
self.assertGreater(dist.pdf(2), 0)

def test_fit_exponentiated_weibull_with_zero(self):
"""
Tests fitting the exponentiated Weibull distribution if the dataset
contains 0s.
"""

dist = ExponentiatedWeibullDistribution()

# Draw 1000 samples from a Weibull distribution with shape=1.5 and scale=3,
# which represents significant wave height.
hs = sts.weibull_min.rvs(1.5, loc=0, scale=3, size=1000, random_state=42)

# Add zero-elements to the dataset.
hs = np.append(hs, [0, 0, 1.3])

params = dist.fit(hs)

self.assertAlmostEquals(params[0], 1.5, delta=0.5)
self.assertIsNone(params[1], 2) # location parameter should be None.
self.assertAlmostEquals(params[2], 3, delta=1)
self.assertAlmostEquals(params[3], 1, delta=0.5)


if __name__ == '__main__':
unittest.main()
7 changes: 7 additions & 0 deletions viroconcom/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,13 @@ def estimateAlphaBetaWithWLS(delta, xi, pi, do_return_parameters=True):
pi = np.array(pi)


# As xi = 0 causes problems when xstar is calculated, zero-elements
# are not considered in the parameter estimation.
indices = np.nonzero(xi)
xi = xi[indices]
pi = pi[indices]


# First, transform xi and pi to get a lienar relationship.
xstar_i = np.log10(xi)
power_term = np.power(pi, np.divide(1.0, delta))
Expand Down

0 comments on commit 73ce01d

Please sign in to comment.