Commit 694bdc94 authored by Chanelle Lee's avatar Chanelle Lee
Browse files

Updated the option weight setter to match the expected calculator one. Should...

Updated the option weight setter to match the expected calculator one. Should be more realistic now. Tests updated and all passed.
parent aca0f676
......@@ -63,7 +63,7 @@ class CMakeBuild(build_ext):
setup(name='noComparisonSimulation',
version='1.0.0',
version='1.0.1',
author='Chanelle Lee',
description='A module which calculates simple aggregation for a population',
long_description='',
......
......@@ -77,14 +77,22 @@ def retOptionWeights(n, case):
arr[0] = 1
return arr
def _ret_expo_weights(a, n):
"""
Returns weights exponentially distributed using:
w_i = ({1-a} / {1-a^{n}} * a^{i-1}
"""
return np.array([(((1 - a) / (1 - (a ** n))) * (a ** (i - 1)))
for i in range(1, n + 1)])
def _ret_decreasing_weights(n):
"""
Returns weights that decrease as they get worse
i.e.
w1 >~ w2 >~ ... >~wn
"""
return (np.linspace(1, 0, n + 2)[1: -1] /
sum(np.linspace(0, 1, n + 2)[1: -1]))
return _ret_expo_weights(0.2, n)
def _ret_outlier_weights(n):
"""
......@@ -93,8 +101,10 @@ def retOptionWeights(n, case):
i.e.
w1 >> w2 = ... = wn
"""
return np.append(np.array([2 * (1 / n)]),
(1 - 2 * (1 / n)) / (n - 1) * np.ones(n - 1))
w1 = _ret_expo_weights(0.2, n)[0]
wn = (1 - w1) / (n - 1)
return np.array((w1, ) + (n - 1) * (wn, ))
if n < 1:
raise ValueError("n must be positive")
......
......@@ -59,11 +59,13 @@ def test_params_invalid_type(num_options, pool_size, pop_size, total_its):
@pytest.mark.parametrize("n, case, expected", [
(3, "equal", np.array([1 / 3, 1 / 3, 1 / 3])),
(3, "noiseless", np.array([1, 0, 0])),
(3, "decreasing", np.array([0.5, 1 / 3, 1 / 6])),
(3, "outlier", np.array([2 / 3, 1 / 6, 1 / 6]))
(3, "decreasing", np.array([0.8065, 0.1613, 0.0323])),
(3, "outlier", np.array([0.8065, 0.0968, 0.0968]))
])
def test_retOptionWeights_valid(n, case, expected):
numpy.testing.assert_allclose(retOptionWeights(n, case), expected)
numpy.testing.assert_almost_equal(retOptionWeights(n, case),
expected,
decimal=4)
def test_retOptionWeights_invalid_case():
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment