Commit 1c1634f0 authored by Chanelle Lee's avatar Chanelle Lee
Browse files

Adding a trial runner functionality so we can just call it with the arguments...

Adding a trial runner functionality so we can just call it with the arguments without having to rewrite all the time. Not been tested yet.
parent 694bdc94
......@@ -63,7 +63,7 @@ class CMakeBuild(build_ext):
setup(name='noComparisonSimulation',
version='1.0.1',
version='1.0.3',
author='Chanelle Lee',
description='A module which calculates simple aggregation for a population',
long_description='',
......
import os
from itertools import product, starmap
from collections import namedtuple
from .trials import Trial
from .parameters import retParamsDict, retOptionWeights
def runSingleTrial(params, optionWeights, path, filePath, nSims):
"""
Intialises the trial, runs it and then returns it.
Parameters
----------
params : dict
Contains parameters as returned from parameters.py
optionWeights : list
Contains weights for the options returned from parameters.py
nSims : int
Number of simulations to run for the trial
filePath : str
Path and file name where to save result files
"""
trial = Trial(numSims=nSims,
parameters=params,
optionWeights=optionWeights,
path=path,
filePath=filePath)
trial.runSimulations()
return trial
def named_product(**items):
Product = namedtuple('Product', items.keys())
return starmap(Product, product(*items.values()))
def run(evidence_rates, num_options, distrusts, weights_cases, pop_sizes,
pool_sizes, num_sims, total_its, w_rate, path):
if not os.path.isdir(path):
raise ValueError("Path is invalid")
parameters = named_product(num_options=num_options,
evidence_rate=evidence_rates,
weights_case=weights_cases,
distrust=distrusts,
pop_size=pop_sizes,
pool_size=pool_sizes)
# Iterate through the parameters to calcuate the expected values for the
# different num_interactions using multiprocessing
for i, row in enumerate(parameters):
print(row)
filePath = ('Testn{}er{}a{}_{}'.format(str(row.num_options),
str(row.evidence_rate),
str(row.distrust),
str(row.weights_case))
).replace('.', '_')
params_dict = retParamsDict(num_options=row.num_options,
evidence_rate=row.evidence_rate,
w_rate=w_rate,
pool_size=row.pool_size,
pop_size=row.pop_size,
total_its=total_its,
distrust=row.distrust)
trial = runSingleTrial(params=params_dict,
optionWeights=retOptionWeights(row.num_options,
row.weights_case
),
nSims=num_sims,
path=path,
filePath=filePath)
trial.saveTrial()
del trial
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