Skip to content

Commit

Permalink
implement fisk distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
mbi6245 committed Jul 23, 2024
1 parent 2fbf37a commit 10e1011
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/ensemble/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ class Fisk(Distribution):
def _create_scipy_dist(self):
optim_params = scipy.optimize.minimize(
fun=self._shape_scale,
x0=[2, self.mean * 2 / np.pi * np.sin(np.pi / 2)],
# start beta at 1.1 and solve for alpha
x0=[self.mean * 1.1 * np.sin(np.pi / 1.1) / np.pi, 1.1],
args=(self.mean, self.variance),
# options={"disp": True},
)
shape, scale = np.abs(optim_params.x)
print("parameters from optimizer: ", shape, scale)
self._scipy_dist = scipy.stats.fisk(c=shape, scale=scale)
# print("parameters from optimizer: ", shape, scale)
self._scipy_dist = scipy.stats.fisk(c=scale, scale=shape)

def _shape_scale(self, x, samp_mean, samp_var) -> None:
alpha = x[0]
Expand Down
12 changes: 6 additions & 6 deletions tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# @pytest.mark.parametrize("a, b, expected", [(1, 2, 3), (2, 3, 5)])
# def test_add(a, b, expected):
# assert add(a, b) == expected
MEAN = 5
VARIANCE = 6.1
MEAN = 2
VARIANCE = 8


def test_exp():
Expand Down Expand Up @@ -49,10 +49,10 @@ def test_invgamma():
def test_fisk():
fisk = Fisk(MEAN, VARIANCE)
res = fisk.stats(moments="mv")
print("est mean and var: ", res)
assert False
# assert np.isclose(res[0], MEAN)
# assert np.isclose(res[1], VARIANCE)
print("resulting mean and var: ", res)
# assert False
assert np.isclose(res[0], MEAN)
assert np.isclose(res[1], VARIANCE)


def test_gumbel():
Expand Down

0 comments on commit 10e1011

Please sign in to comment.