Пример #1
0
def load_flu_data():
    path = os.path.dirname(__file__)
    fn = './data/1000 flu cases no policy.tar.gz'
    fn = os.path.join(path, fn)

    experiments, outcomes = load_results(fn)
    return experiments, outcomes
Пример #2
0
def load_eng_trans_data():
    path = os.path.dirname(__file__)
    fn = './data/eng_trans.tar.gz'
    fn = os.path.join(path, fn)

    experiments, outcomes = load_results(fn)
    return experiments, outcomes
    
    return experiments, outcomes
Пример #3
0
def load_scarcity_data():
    path = os.path.dirname(__file__)
    fn = './data/1000 runs scarcity.tar.gz'
    fn = os.path.join(path, fn)

    experiments, outcomes = load_results(fn)
    return experiments, outcomes
    
    return experiments, outcomes
Пример #4
0
    def test_load_results(self):
        # test for 1d
        # test for 2d
        # test for 3d
    
        nr_experiments = 10000
        experiments = np.recarray((nr_experiments,),
                               dtype=[('x', float), ('y', float)])
        outcome_a = np.zeros((nr_experiments,1))
        
        results = (experiments, {'a': outcome_a})
        
        save_results(results, u'../data/test.tar.gz')
        experiments, outcomes  = load_results(u'../data/test.tar.gz')
        
        logical = np.allclose(outcomes['a'],outcome_a)
        
        os.remove('../data/test.tar.gz')
        
#         if logical:
#             ema_logging.info('1d loaded successfully')
        
        nr_experiments = 1000
        nr_timesteps = 100
        nr_replications = 10
        experiments = np.recarray((nr_experiments,),
                               dtype=[('x', float), ('y', float)])
        outcome_a = np.zeros((nr_experiments,nr_timesteps,nr_replications))
         
        results = (experiments, {'a': outcome_a})
        save_results(results, u'../data/test.tar.gz')
        experiments, outcomes = load_results(u'../data/test.tar.gz')
        
        logical = np.allclose(outcomes['a'],outcome_a)
        
        os.remove('../data/test.tar.gz')
Пример #5
0
    def test_load_results(self):
        # test for 1d
        # test for 2d
        # test for 3d

        nr_experiments = 10000
        experiments = np.recarray((nr_experiments, ),
                                  dtype=[('x', float), ('y', float)])
        outcome_a = np.zeros((nr_experiments, 1))

        results = (experiments, {'a': outcome_a})

        save_results(results, u'../data/test.tar.gz')
        experiments, outcomes = load_results(u'../data/test.tar.gz')

        logical = np.allclose(outcomes['a'], outcome_a)

        os.remove('../data/test.tar.gz')

        #         if logical:
        #             ema_logging.info('1d loaded successfully')

        nr_experiments = 1000
        nr_timesteps = 100
        nr_replications = 10
        experiments = np.recarray((nr_experiments, ),
                                  dtype=[('x', float), ('y', float)])
        outcome_a = np.zeros((nr_experiments, nr_timesteps, nr_replications))

        results = (experiments, {'a': outcome_a})
        save_results(results, u'../data/test.tar.gz')
        experiments, outcomes = load_results(u'../data/test.tar.gz')

        logical = np.allclose(outcomes['a'], outcome_a)

        os.remove('../data/test.tar.gz')
def classify(data):
    #get the output for deceased population
    result = data['deceased population region 1']
    
    #make an empty array of length equal to number of cases 
    classes =  np.zeros(result.shape[0])
    
    #if deceased population is higher then 1.000.000 people, classify as 1 
    classes[result[:, -1] > 1000000] = 1
    
    return classes

#load data
fn = r'./data/1000 flu cases.tar.gz'
results = load_results(fn)
experiments, results = results

#extract results for 1 policy
logical = experiments['policy'] == 'no policy'
new_experiments = experiments[ logical ]
new_results = {}
for key, value in results.items():
    new_results[key] = value[logical]

results = (new_experiments, new_results)

#perform cart on modified results tuple

cart_alg = cart.setup_cart(results, classify, mass_min=0.05)
cart_alg.build_tree()

def periodDominance(ds):
    Y = np.fft.rfft(ds)
    n = len(Y)
    powerSpect = np.abs(Y)**2
    timeStep = 1
    freq = np.fft.fftfreq(n, d=timeStep)
    print len(freq), len(powerSpect)
    for i in range(len(freq) / 2 + 1):
        print freq[i], 1 / freq[i], powerSpect[i]


if __name__ == '__main__':

    cases, results = util.load_results('PatternSet_Periodic.cpickle')
    dataSeries = results.get('outcome')
    ds1 = dataSeries[25]
    ds2 = dataSeries[26]

    print linearFit(ds1)
    print quadraticFit(ds1)
    print mean(ds1), variance(ds1), stdDev(ds1)
    print autoCovariance(ds1, 0)
    for k in range(31):
        print k, autoCorrelation(ds1, k)

    for k in range(31):
        print k, crossCorrelation(ds1, ds2, k)

    periodDominance(ds1)
default_flow = 2.178849944502783e7


def classify(outcomes):
    ooi = 'throughput Rotterdam'
    outcome = outcomes[ooi]
    outcome = outcome / default_flow

    classes = np.zeros(outcome.shape[0])
    classes[outcome < 1] = 1
    return classes


fn = r'./data/5000 runs WCM.tar.gz'
results = load_results(fn)

prim_obj = prim.setup_prim(results, classify, mass_min=0.05, threshold=0.75)

# let's find a first box
box1 = prim_obj.find_box()

# let's analyze the peeling trajectory
box1.show_ppt()
box1.show_tradeoff()

box1.write_ppt_to_stdout()

# based on the peeling trajectory, we pick entry number 44
box1.select(44)
Пример #9
0
'''
Created on Jul 8, 2014

@author: [email protected]
'''
import matplotlib.pyplot as plt

from util import ema_logging
from util.util import load_results

from analysis.plotting import envelopes 
from analysis.plotting_util import KDE


ema_logging.log_to_stderr(ema_logging.INFO)

file_name = r'./data/1000 flu cases.tar.gz'
results = load_results(file_name)

# the plotting functions return the figure and a dict of axes
fig, axes = envelopes(results, group_by='policy', density=KDE, fill=True)

# we can access each of the axes and make changes
for key, value in axes.iteritems():
    # the key is the name of the outcome for the normal plot
    # and the name plus '_density' for the endstate distribution
    if key.endswith('_density'):
        value.set_xscale('log')

plt.show()
Пример #10
0
.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
                gonengyucel

'''
import matplotlib.pyplot as plt

from analysis.clusterer import cluster

from util import ema_logging
from util.util import load_results

ema_logging.log_to_stderr(ema_logging.INFO)

#load the data
data = load_results(r'..\examples\100 flu cases no policy.cPickle')

# specify the number of desired clusters
# note: the meaning of cValue is tied to the value for cMethod
cValue = 5

#perform cluster analysis
dist, clusteraloc, runlog, z = cluster(data=data, 
                                    outcome='deceased population region 1', 
                                    distance='gonenc', 
                                    interClusterDistance='complete', 
                                    cMethod = 'maxclust',
                                    cValue = cValue,
                                    plotDendrogram=False, 
                                    plotClusters=False, 
                                    groupPlot=False,
Пример #11
0
        '''
        Constructor
        '''
        self.no = cluster_no
        self.indices = all_ds_indices
        self.sample = int(sample_ds_index)
        self.size = self.indices.size
        self.runLogs = runLogs
        self.distances = dist_clust

    def error(self):
        return self.sample


if __name__ == '__main__':
    from util.util import load_results
    results = load_results(
        '../sandbox/cluster/datasets/PatternSet_Basics.cPickle')

    distance, liste, obekler, kosulog, zet = cluster(results,
                                                     'outcome',
                                                     cMethod='distance',
                                                     cValue=1,
                                                     groupPlot=True,
                                                     plotDendrogram=False)

    #clusters = np.array([3, 1, 2, 2, 1,2])
    #dRow = np.array([1,2,3,6,2,1,0,3,9,6,2,1,3,2,1])
    #samples = pick_cSamples(clusters, dRow)
    #print "ornekler", samples
Пример #12
0
Created on 20 sep. 2011

.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
'''
import numpy as np
import matplotlib.pyplot as plt

from analysis.pairs_plotting import pairs_lines, pairs_scatter, pairs_density
from util.util import load_results
from util import ema_logging

ema_logging.log_to_stderr(level=ema_logging.DEFAULT_LEVEL)

# load the data
fh = r'.\data\1000 flu cases no policy.tar.gz'
experiments, outcomes = load_results(fh)

# transform the results to the required format
# that is, we want to know the max peak and the casualties at the end of the
# run
tr = {}

# get time and remove it from the dict
time = outcomes.pop('TIME')

for key, value in outcomes.items():
    if key == 'deceased population region 1':
        tr[key] = value[:, -1]  #we want the end value
    else:
        # we want the maximum value of the peak
        max_peak = np.max(value, axis=1)
Пример #13
0
        Constructor
        '''
        self.no = cluster_no
        self.indices = all_ds_indices
        self.sample = int(sample_ds_index)
        self.size = self.indices.size
        self.runLogs = runLogs
        self.distances = dist_clust
        
        
    def error(self):
        return self.sample

if __name__ == '__main__':
    from util.util import load_results
    results = load_results('../sandbox/cluster/datasets/PatternSet_Basics.cPickle')
    
    
    distance, liste, obekler, kosulog, zet = cluster(results, 'outcome',cMethod='distance', cValue=1, groupPlot=True, plotDendrogram=False)
    
    #clusters = np.array([3, 1, 2, 2, 1,2])
    #dRow = np.array([1,2,3,6,2,1,0,3,9,6,2,1,3,2,1])
    #samples = pick_cSamples(clusters, dRow)
    #print "ornekler", samples
 
    
        
    


Пример #14
0
Created on 20 sep. 2011

.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
"""
import numpy as np
import matplotlib.pyplot as plt

from analysis.pairs_plotting import pairs_lines, pairs_scatter, pairs_density
from util.util import load_results
from util import ema_logging

ema_logging.log_to_stderr(level=ema_logging.DEFAULT_LEVEL)

# load the data
fh = r".\data\1000 flu cases no policy.tar.gz"
experiments, outcomes = load_results(fh)

# transform the results to the required format
# that is, we want to know the max peak and the casualties at the end of the
# run
tr = {}

# get time and remove it from the dict
time = outcomes.pop("TIME")

for key, value in outcomes.items():
    if key == "deceased population region 1":
        tr[key] = value[:, -1]  # we want the end value
    else:
        # we want the maximum value of the peak
        max_peak = np.max(value, axis=1)
    return var

def periodDominance(ds):
    Y = np.fft.rfft(ds)
    n = len(Y)
    powerSpect = np.abs(Y)**2
    timeStep = 1 
    freq = np.fft.fftfreq(n, d=timeStep)
    print len(freq), len(powerSpect)
    for i in range(len(freq)/2+1):
        print freq[i], 1/freq[i], powerSpect[i]


if __name__ == '__main__':
    
    cases, results = util.load_results('PatternSet_Periodic.cpickle')
    dataSeries = results.get('outcome')
    ds1 = dataSeries[25]
    ds2 = dataSeries[26]
    
    print linearFit(ds1)
    print quadraticFit(ds1)
    print mean(ds1), variance(ds1), stdDev(ds1)
    print autoCovariance(ds1,0)
    for k in range(31):
        print k,autoCorrelation(ds1,k)
    
    for k in range(31):
        print k, crossCorrelation(ds1,ds2,k)
    
    periodDominance(ds1)