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

Started adding tests. None of them currently work

parent 61e50f51
......@@ -10,6 +10,6 @@ include_directories(${SOURCE_DIR})
set(SOURCES "${SOURCE_DIR}/helperFunctions.cpp")
# Generate python module
#find_package(pybind11 REQUIRED)
add_subdirectory(pybind11)
find_package(pybind11 REQUIRED)
#add_subdirectory(pybind11)
pybind11_add_module(helperFunctions ${SOURCES} "${SOURCE_DIR}/bindings.cpp")
......@@ -63,7 +63,7 @@ class CMakeBuild(build_ext):
setup(name='noComparisonSimulation',
version='0.1.0',
version='0.1.3',
author='Chanelle Lee',
description='A module which calculates simple aggregation for a population',
long_description='',
......
import numpy as np
from operator import attrgetter
from collections import Counter
# C module written by CLL
from noComparisonSimulation import helperFunctions as hf
......@@ -37,6 +35,25 @@ class Agent(object):
numOptions : int
Number of options to choose between
"""
if not (isinstance(idNum, int) and isinstance(numOptions, int)):
raise TypeError("Passed value must be an integer")
if not (isinstance(distrust, float) and isinstance(w, float)):
raise TypeError("Passed value must be a float")
if not (0.0 < distrust < 0.5):
raise ValueError("Passed distrust invalid - must be in (0, 0.5)")
if not (0.0 <= w <= 1.0):
raise ValueError("Passed w invalid - must be in [0, 1]")
# Check that belief has the right shape, sums to 1 and all the values
# are positive
if not np.shape(belief) == (numOptions, ):
raise ValueError("Passed belief has incorrect shape")
if not np.isclose(sum(belief), 1):
raise ValueError("Passed belief must sum to 1")
if np.any(belief < 0):
raise ValueError("Passed belief must have positive values")
self.idNum = idNum
self._belief = belief
self._distrust = distrust
......
......@@ -43,11 +43,23 @@ def optionWeights(n, case):
"""
Returns a list of the option weights which will be different depending on
which case is being used
Calculate sigma values for n options in the cases:
-1 -> equivalence: s1 = ... = sn
0 -> noiselessness: s1=1, s2=...=sn=0
1 -> case 1: s1 >~ s2 >~ ... >~ sn
2 -> case 2: s1 >> s2 = ... = sn
"""
def ret_weights_sanity_check(n):
def ret_weights_equivalence(n):
"""Returns n equivalent weights"""
return (1/n) * np.ones(n)
def ret_weights_noiseless(n):
"""Returns weight only for the best option"""
arr = np.zeros(2)
arr[0] = 1
return arr
def ret_weights_case1(n):
"""Returns equally spaced weights from highest to lowest"""
return np.linspace(1, 0, n+2)[1:-1]/sum(np.linspace(0, 1, n+2)[1:-1])
......@@ -56,8 +68,10 @@ def optionWeights(n, case):
"""Returns one very high weight and then the rest are equivalent"""
return np.append(np.array([2*(1/n)]), (1-2*(1/n))/(n-1)*np.ones(n-1))
if case == -1:
weights = ret_weights_equivalence(n)
if case == 0:
weights = ret_weights_sanity_check(n)
weights = ret_weights_noiseless(n)
elif case == 1:
weights = ret_weights_case1(n)
elif case == 2:
......
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