Commit b07d50ec authored by Chanelle Lee's avatar Chanelle Lee
Browse files

Added a bit more to agent testing and changed neighbourhood consistency. Now...

Added a bit more to agent testing and changed neighbourhood consistency. Now checks for a null belief and a conflicting total belief before declaring inconsistency.
parent 5b8ae234
......@@ -102,7 +102,8 @@ class Agent(object):
def checkNeighbourhoodConsistent(self, neighbourhood):
beliefs = [n.getBelief() for n in neighbourhood]
poolSize = len(neighbourhood)
beliefs.append(self.getBelief())
poolSize = len(neighbourhood) + 1
return hf.check_neighbourhood_consistent(self._numOptions,
poolSize,
beliefs)
......
......@@ -212,8 +212,18 @@ int check_neighbourhood_consistent(int num_options, int pool_size,
xj_prod *= beliefs_ptr[j*num_options + i];
}
if (xj_prod == 0)
/*
One of the agents has a belief of zero in this option. Now check to
make sure another agent does not have total faith in this option
*/
{
return 0;
for (int k = 0; k < pool_size; ++k)
{
if (beliefs_ptr[k*num_options + i] == 1)
{
return 0;
}
}
}
}
return 1;
......
......@@ -102,17 +102,17 @@ def test_updateOnEvidence_invalid(evidenceID):
@pytest.mark.parametrize("agent, neighbour, expected", [
(Agent(1, np.array([1.0, 0.0]), 0.001, 1, 2),
Agent(1, np.array([1.0, 0.0]), 0.001, 1, 2), True),
Agent(2, np.array([1.0, 0.0]), 0.001, 1, 2), True),
(Agent(1, np.array([0.6, 0.4]), 0.001, 1, 2),
Agent(1, np.array([0.4, 0.6]), 0.001, 1, 2), True),
Agent(2, np.array([0.4, 0.6]), 0.001, 1, 2), True),
(Agent(1, np.array([1.0, 0.0]), 0.001, 1, 2),
Agent(1, np.array([0.0, 1.0]), 0.001, 1, 2), False),
Agent(2, np.array([0.0, 1.0]), 0.001, 1, 2), False),
(Agent(1, np.array([0.6, 0.3, 0.1]), 0.001, 1, 3),
Agent(1, np.array([0.0, 0.25, 0.75]), 0.001, 1, 3), True),
Agent(2, np.array([0.0, 0.25, 0.75]), 0.001, 1, 3), True),
(Agent(1, np.array([1.0, 0.0, 0.0]), 0.001, 1, 3),
Agent(1, np.array([0.0, 0.0, 1.0]), 0.001, 1, 3), False),
Agent(2, np.array([0.0, 0.0, 1.0]), 0.001, 1, 3), False),
(Agent(1, np.array([1.0, 0.0, 0.0]), 0.001, 1, 3),
Agent(1, np.array([0.0, 1.0, 0.0]), 0.001, 1, 3), False)
Agent(2, np.array([0.0, 1.0, 0.0]), 0.001, 1, 3), False)
])
def test_checkNeighbourConsistent_valid(agent, neighbour, expected):
assert agent.checkNeighbourConsistent(neighbour) == expected
......@@ -124,13 +124,35 @@ def test_checkNeighbourConsistent_valid(agent, neighbour, expected):
@pytest.mark.parametrize("agent, neighbourhood, expected", [
(Agent(1, np.array([0.5, 0.5]), 0.001, 1, 2),
[Agent(1, np.array([0.5, 0.5]), 0.001, 1, 2)],
np.array([0.5, 0.5])),
[Agent(2, np.array([0.5, 0.5]), 0.001, 1, 2)],
np.array([0.5, 0.5])), # expected no change
(Agent(1, np.array([0.6, 0.4]), 0.001, 1, 2),
[Agent(1, np.array([0.6, 0.4]), 0.001, 1, 2)],
np.array([0.6923, 0.3077]))
[Agent(2, np.array([0.6, 0.4]), 0.001, 1, 2)],
np.array([0.6923, 0.3077])), # n=2, k=2 case
(Agent(1, np.array([0.6, 0.3, 0.1]), 0.001, 1, 3),
[Agent(2, np.array([0.0, 0.25, 0.75]), 0.001, 1, 3)],
np.array([0, 0.5, 0.5])), # n>2, k=2 case
(Agent(1, np.array([0.6, 0.0, 0.4]), 0.001, 1, 3),
[Agent(2, np.array([0.0, 0.25, 0.75]), 0.001, 1, 3)],
np.array([0.0, 0.0, 1.0])), # still consistent
(Agent(1, np.array([0.6, 0.4]), 0.001, 1, 2),
[Agent(2, np.array([0.6, 0.4]), 0.001, 1, 2),
Agent(3, np.array([0.6, 0.4]), 0.001, 1, 2)],
np.array([0.7714, 0.2286])), # n=2, k>2 case
(Agent(1, np.array([0.6, 0.3, 0.1]), 0.001, 1, 3),
[Agent(2, np.array([0.0, 0.25, 0.75]), 0.001, 1, 3),
Agent(3, np.array([0.1, 0.2, 0.7]), 0.001, 1, 3)],
np.array([0.0, 0.2222, 0.7778])), # n>2, k>2 case
])
def test_aggregate_valid(agent, neighbourhood, expected):
ret_belief = agent.aggregate(neighbourhood)
numpy.testing.assert_almost_equal(ret_belief, expected, decimal=4)
def test_aggregate_valid_inconsistent():
agent = Agent(1, np.array([1.0, 0.0]), 0.001, 1, 2)
neighbourhood = [Agent(1, np.array([0.0, 1.0]), 0.001, 1, 2)]
assert agent.aggregate(neighbourhood) is None
......@@ -5,7 +5,18 @@ import numpy as np
from noComparisonSimulation import helperFunctions as hf
def test_helperFunction_aggregate_MProdOp():
ret_belief = hf.aggregate_MProdOp(2, 2, np.array([[0.6, 0.4], [0.6, 0.4]]))
numpy.testing.assert_almost_equal(ret_belief, np.array([0.6923, 0.3077]),
decimal=4)
@pytest.mark.parametrize("num_options, pool_size, beliefs, expected", [
(2, 2, np.array([[0.6, 0.4], [0.6, 0.4]]), np.array([0.6923, 0.3077])),
(3, 2, np.array([[0.6, 0.3, 0.1], [0.0, 0.25, 0.75]]),
np.array([0.0, 0.5, 0.5])),
(3, 2, np.array([[0.6, 0.0, 0.4], [0.0, 0.25, 0.75]]),
np.array([0.0, 0.0, 1.0]))
])
def test_aggregate_MProdOp(num_options, pool_size, beliefs, expected):
ret_belief = hf.aggregate_MProdOp(num_options, pool_size, beliefs)
numpy.testing.assert_almost_equal(ret_belief, expected, decimal=4)
def test_check_neighbourhood_consistent():
beliefs = np.array([[0.6, 0.3, 0.1], [0.0, 0.25, 0.75]])
assert hf.check_neighbourhood_consistent(3, 2, beliefs) == 1
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