Commits

Jing Wang  committed 3c8296a

Revise Markov, udpate part of the doucmentation, archive

  • Participants
  • Parent commits 482a215

Comments (0)

Files changed (249)

File .UNDO/settings.py_undo

Binary file modified.

File .ropeproject/globalnames

File contents unchanged.

File .ropeproject/objectdb

Binary file modified.

File Configure/.UNDO/Anomaly.py_undo

Binary file modified.

File Configure/.UNDO/Behaviour.py_undo

Binary file added.

File Configure/.UNDO/MarkovAnomaly.py_undo

Binary file removed.

File Configure/Behaviour.py

         abstract_method()
 
     def get_new_state(self):
-        return RandDist(self.P[self.cs])
+        # return RandDist(self.P[self.cs])
+        return RandDist(self.P) # FIXME use stationary prob
 
     def get_interval(self):
-        return exponential(1.0 / self.interval)
+        # return exponential(1.0 / self.interval)
+        return self.interval
 
     def behave_with_profile(self, start, profile):
         for dur, num in zip(*profile):

File Configure/MarkovAnomaly.py

 
 class MarkovAnomaly(Anomaly):
     def _infect_modulator(self, ano_t, m_id, mod):
-
         mod_start = eval(mod['start'])
         mod_profile = mod['profile']
         np1, ap, np2 = self.get_profile_with_ano(mod_start, mod_profile, ano_t)
 
     def _export_ano_flow_para(self):
         import settings
-        pickle.dump(self.ano_desc, open(settings.EXPORT_ABNORMAL_FLOW_PARA_FILE, 'w')) # For export abnormal flows
-
-
+        import copy
+        self.ano_flow_para = copy.deepcopy(self.ano_desc)
+        self.ano_flow_para['ano_node_ipdests'] = self.ano_node.ipdests
+        pickle.dump(self.ano_flow_para, open(settings.EXPORT_ABNORMAL_FLOW_PARA_FILE, 'w')) # For export abnormal flows

File Detector/.UNDO/AnomalyDetector.py_undo

Binary file added.

File Detector/AnomalyDetector.py

         title('model based')
         show()
 
-def detect(f_name, win_size, fea_option, detector_type):
+def detect(f_name, win_size, fea_option, detector_type, detector_desc):
     detector_map = {
             'mf':ModelFreeAnoDetector,
             'mb':ModelBaseAnoDetector,
             'mfmb':FBAnoDetector,
             }
-    # data_file = Detector.DataFile.DataFile(f_name,
-                # settings.DETECTOR_DESC['win_size'],
-                # settings.DETECTOR_DESC['fea_list'])
     data_file = DataFile(f_name, win_size, fea_option)
-    # data_file.plot_flow_size()
-    # detect = ModelFreeAnoDetector(settings.DETECTOR_DESC)
-    detector = detector_map[detector_type](settings.DETECTOR_DESC)
+    detector = detector_map[detector_type](detector_desc)
     detector(data_file)
     return detector
-    # detector.plot_entropy()
-
     # type_detector = ModelFreeAnoTypeTest(detect, 3000, settings.ANO_DESC['T'])
     # type_detector.detect_ano_type()
 

File Experiment/.UNDO/Experiment.py_undo

Binary file added.

File Experiment/.UNDO/MarkovExperiment.py_undo

Binary file modified.

File Experiment/.UNDO/MarkovSens.py_undo

Binary file added.

File Experiment/.UNDO/Sens.py_undo

Binary file modified.

File Experiment/Experiment.py

         cd(self.settings.ROOT)
 
     def detect(self):
-        return detect(self.flow_file, self.win_size, self.fea_option, self.detector_type)
+        return detect(self.flow_file, self.win_size, self.fea_option, self.detector_type, self.settings.DETECTOR_DESC)
 
 class AttriChangeExper(Experiment):
     def __init__(self, settings):

File Experiment/Experiment.pyc

Binary file modified.

File Experiment/MarkovExperiment.py

     def __init__(self, settings):
         self.g_size = 10
         self.srv_node_list = (0, 1)
-        self.normal_sta_prob = (0.1, 0.9)
-        self.ano_sta_prob = (0.9, 0.1)
-        H = {'TYPE':'harpoon', 'flow_size_mean':'4e4', 'flow_size_var':'100', 'flow_arrival_rate':'3'}
-        L = {'TYPE':'harpoon', 'flow_size_mean':'4e3', 'flow_size_var':'100', 'flow_arrival_rate':'0.3'}
+        # self.normal_sta_prob = (0.1, 0.9)
+        # self.ano_sta_prob = (0.9, 0.1)
+        self.normal_sta_prob = (0, 1)
+        self.ano_sta_prob = (1, 0)
+        H = {'TYPE':'harpoon', 'flow_size_mean':'4e5', 'flow_size_var':'10', 'flow_arrival_rate':'3'}
+        L = {'TYPE':'harpoon', 'flow_size_mean':'4e5', 'flow_size_var':'10', 'flow_arrival_rate':'0.3'}
         self.states = [H, L]
 
+        Experiment.__init__(self, settings)
 
-        Experiment.__init__(self, settings)
+    def configure(self):
         self.get_net_desc()
         self.get_norm_desc()
         self.get_ano_list()
+        Experiment.configure(self)
 
     def get_net_desc(self):
         self.net_desc['node_type'] = 'MarkovNode'
         self.net_desc['node_para'] = {
-                'P':Pi2P(self.normal_sta_prob),
-                'interval':10,
+                # 'P':Pi2P(self.normal_sta_prob),
+                'P': self.normal_sta_prob, # FIXME use stationary prob
+                # 'interval':10,
+                'interval':30,
                 }
 
     def get_norm_desc(self):
                 }
 
     def get_ano_list(self):
-        ano_markov_prob = Pi2P(self.ano_sta_prob)
+        # ano_markov_prob = Pi2P(self.ano_sta_prob)
+        ano_markov_prob = self.ano_sta_prob # FIXME use stationary prob
+
         ano_desc = {'anoType':'markov_anomaly',
                 'ano_node_seq':2,
                 'T':(1200, 1400),
-                'ano_markov_desc':{'P':ano_markov_prob, 'interval':10},
+                'ano_markov_desc':{'P':ano_markov_prob, 'interval':20},
                 'srv_id':0,
                 }
         self.ano_list = [ano_desc]

File Experiment/MarkovExperiment.pyc

Binary file added.

File Experiment/MarkovSens.py

+#!/usr/bin/env python
+from Sens import Sens
+from MarkovExperiment import MarkovExperiment
+import cPickle as pickle
+import copy
+
+class MarkovSens(MarkovExperiment, Sens):
+    """Sensitivity analysis of markov anomaly"""
+    def __init__(self, settings):
+        MarkovExperiment.__init__(self, settings)
+        Sens.__init__(self)
+        self.sens_ano = settings.ANO_LIST[0] # Only support one anomaly right now
+        self.shelve_file = self.settings.ROOT + '/Share/det_obj.out'
+
+    def run(self, sta_prob_option):
+        det_obj_shelf = dict()
+        self.sens_ano['ano_type'] = 'markov_anomaly'
+        self.sens_ano['change'] = {}
+
+        for sta_prob in sta_prob_option:
+            self.ano_sta_prob = sta_prob
+            self.configure()
+            self.simulate()
+            det_obj = copy.deepcopy( self.detect() )
+            det_obj_shelf[tuple(sta_prob)] = dict(winT=det_obj.record_data['winT'],
+                    entropy=det_obj.record_data['entropy'])
+            self.store_flow_file('markov_' + '_'.join([str(v) for v in sta_prob]))
+            # self.clear_tmp_file()
+
+        f_obj = open(self.shelve_file, 'w')
+        pickle.dump(det_obj_shelf, f_obj)
+        f_obj.close()
+
+if __name__ == "__main__":
+    import settings
+    exper = MarkovSens(settings)
+    # exper.run( [[0.9, 0.1],
+                # [0.7, 0.3],
+                # [0.5, 0.5],
+                # [0.8, 0.2]
+                # ])
+    exper.plot_entropy()

File Experiment/Sens.py

 import cPickle as pickle
 import copy
 
-class SensExper(AttriChangeExper):
-    """SensExper is experiment to get the sensitivity result.
-    it will change parameters and run the simulation for several times
-    and plot the both model based and model free entropy
-    ex:
-    .. code-block:: python
 
-        import settings
-        exper = SensExper(settings)
-        exper.run('flow_arrival_rate', [2, 4, 6])
-        exper.plot_entropy()
-
-    """
-    def __init__(self, settings):
-        AttriChangeExper.__init__(self, settings)
-        self.sens_ano = settings.ANO_LIST[0]
-        # self.shelve_file = '/home/jing/det_obj.out'
-        self.shelve_file = self.settings.ROOT + '/Share/det_obj.out'
-
-    def run(self, attr, rg):
-        """attr is the name of attribute that will be changed. possible
-        attrs are :
-            - flow_arrival_rate
-            - flow_size_mean
-            - flow_size_var
-        rg is the list of possible values for *attr*.
-        """
-        det_obj_shelf = dict()
-        self.sens_ano['ano_type'] = attr
-        self.sens_ano['change'] = {}
-        for i in rg:
-            self.sens_ano['change'][attr] = i;
-            self.configure()
-            self.simulate()
-            det_obj = copy.deepcopy( self.detect() )
-            det_obj_shelf[str(i)] = dict(winT=det_obj.record_data['winT'],
-                    entropy=det_obj.record_data['entropy'])
-            # v = det_obj.record_data['entropy']
-            self.store_flow_file(str(i))
-            self.clear_tmp_file()
-
-        f_obj = open(self.shelve_file, 'w')
-        pickle.dump(det_obj_shelf, f_obj)
-        f_obj.close()
-
+class Sens(object):
+    """base class for the sensitivity analysis"""
     def store_flow_file(self, suffix):
         import settings, shutil
         shutil.copyfile(settings.OUTPUT_FLOW_FILE, settings.ROOT+'/Share/n0_flow_%s.txt'%(suffix))
 
         title('model based')
         legend(det_obj_shelf.keys())
+        savefig(self.settings.ROOT + '/Share/res.eps')
         show()
-        savefig(self.settings.ROOT + '/Share/res.eps')
 
     def configure(self):
         gen_anomaly_dot([self.sens_ano], self.net_desc, self.norm_desc, self.dot_file)
 
+
+class AttriSensExper(AttriChangeExper, Sens):
+    """SensExper is experiment to get the sensitivity result.
+    it will change parameters and run the simulation for several times
+    and plot the both model based and model free entropy
+    ex:
+    .. code-block:: python
+
+        import settings
+        exper = SensExper(settings)
+        exper.run('flow_arrival_rate', [2, 4, 6])
+        exper.plot_entropy()
+
+    """
+    def __init__(self, settings):
+        AttriChangeExper.__init__(self, settings)
+        Sens.__init__(self)
+        self.sens_ano = settings.ANO_LIST[0]
+        # self.shelve_file = '/home/jing/det_obj.out'
+        self.shelve_file = self.settings.ROOT + '/Share/det_obj.out'
+
+    def run(self, attr, rg):
+        """attr is the name of attribute that will be changed. possible
+        attrs are :
+            - flow_arrival_rate
+            - flow_size_mean
+            - flow_size_var
+        rg is the list of possible values for *attr*.
+        """
+        det_obj_shelf = dict()
+        self.sens_ano['ano_type'] = attr
+        self.sens_ano['change'] = {}
+        for i in rg:
+            self.sens_ano['change'][attr] = i;
+            self.configure()
+            self.simulate()
+            det_obj = copy.deepcopy( self.detect() )
+            det_obj_shelf[str(i)] = dict(winT=det_obj.record_data['winT'],
+                    entropy=det_obj.record_data['entropy'])
+            # v = det_obj.record_data['entropy']
+            self.store_flow_file(str(i))
+            self.clear_tmp_file()
+
+        f_obj = open(self.shelve_file, 'w')
+        pickle.dump(det_obj_shelf, f_obj)
+        f_obj.close()
+
+
 if __name__ == "__main__":
     import settings
-    exper = SensExper(settings)
+    exper = AttriSensExper(settings)
+    exper.run('flow_arrival_rate', [2, 4, 6])
     # exper.run('flow_arrival_rate', [1, 2, 3, 4, 5, 6])
     # exper.run('flow_arrival_rate', [0.1, 0.3, 0.4, 0.6, 0.8])
     # exper.run('flow_arrival_rate', [0.2, 0.4, 0.6])

File Experiment/Sens.pyc

Binary file added.

File LOG

-Network
-
-NNode
-
-MarkovNode
-
-Network should be indepedent to NNode
-
-there should be a initialization parameter in the constructor 
-
-how to descript markov behaviour
-start-end. transition
-
-we use profile to describe a modulator in normal node
-
-we can also use  profile to describe a modulator in markov node.
-simply use profile
-
-modulator in markove case
-
-
-
-[2012-04-20 10:36:21]
-start to do the multi server case. 
-
-time information. 
-only consider the model-free case. 
-
-the margin probability is th probability that the received flow belongs to which states
-
-the joint probability is the probability that received flow belongs to which states. 
-
-which states.
-
-what we are trying to do this to characterize the 
-===================================================
-as simple as possible. 
-
-different temporal information. 
-
-A node send same traffic to server. 
-but the difference is the temporal different. 
-
-for the pespective of senders, there should be a probability distribution. 
-for a given time spot. the sender need to decide:
-    1. When to send the next packet
-    2. to whom it should send the packet
-    3. which type of flow it should send ---> specify the marginal distribution. 
-
-parameter of senders. 
-    1. specify the mariginal distribution
-    2. specify the relationship between the marginal distribution
-
-marginal distribution
-    1. decide which type of flow it should send
-
-joint distribution
-    1. specify to whom it should send the packet.
-
-We make the first parameter fixed to be the possion distribution. 
-
-if we change the pdf of "to whom it should send the packet", the flow rate will change. 
-    so this term is not specifed single probability distribution.
-
-[2012-04-20 13:33:14]
-the problem consits of two parts:
-    1 is the generation part.
-    2 detection part 
-to decide to whom the packet should be sent. 
-
-We need to consider the problem from the pespective of window.
-We determine the number of flows that will be sent in on window.
-Then we determine the destination of each slot repectively.
-
-We need to keep the portion for each server to be the same. However, the time will be different. 
-
-for example, in the normal case, the slots can be distributed evenly in terms of time.
-In the abnormal case, the previous parts will have a lot of flows to server 1, while in the second
-part, a lot flows will have destination to server 2
-
-
-we need have some sort of variables description
-
-for each sender X. suppose X_i is a random variable indicating the type of the flow that will be send to sever i.
-the send will maintain such as random variable
-
-
-consider the marignal
-there should be a general distribution 
-
-
-[2012-04-20 14:20:41]
-implementation.
-[Configure] part
-I need create a new class of Node.
-    class ProbNode: node send traffic with certain kind of probability
-in this class
-
-the freedom degree we have. 
-    1. we can add modulator to the server node. the modulator need to have,
-    (start time, profile, generator)
-    2. generator is a source with parameter flow_arrival_rate, flow_size_mean,
-    flow_size_var
-    3. flow_arrival is possion distributed.
-    4. one generator only target for one server.
-    5. we need select different servers, means select different types of
-    generators.
-    6. the original markov node method cannot work
-
-
-ideas:
-    1 a pool of generators. each generator represents one type of flows to one
-    specific server. 
-    2.our task is to select generators from the pool.
-    3. we need to change the way of selections so that the distribution for each
-    sever doesn't change at all.
-
-    X_1, X_2, ..., X_n, joint distribution.
-    for each time, we get a sequence of  X_1, X_2, ....  X_n
-    P(x_1, x_2, ..., x_n) is the probability distribution we want to
-    characterize
-    
-    the possible states are: 1 state for each quantized flow, and one state 
-    for sending no flows at all.
-
-    we need to maintains the marginal distribution for this set of variables
-    unchanged.
-
-    we need have a table. ---> this table specify the joint distribution probability distribution
-    for the 
-
-I need a method to keep each colomn and row unchanged, while change the term. We
-need a scale value to determine the degree of change.
-
-
-the previous analysis is only for a specific time spot. In generaal, it is a
-stochastic process.
-
-
-[2012-04-20 18:12:53]
-==========================================================
-Another important idea is that suppose the behaviour of
-users don't change, but the network condition changes. See
-what happens.
-==========================================================
-
-[2012-04-20 20:59:14]
-
-class MVBehaviour(MarkovBehaviour):
-    """The traffic is generated according to multi-variable distribution
-    if there are n servers, then the joint distribution will be n dimension
-    matrix. For each component, there are n possible values. So we need n possible
-    generators.
-
-    if we have the distribution matrix. we just generate random variable
-        according to the distribution and select generators according
-    """
-
-
-an important function is to generate a random value according to some certain 
-probability distribution.
-
-we need generate matrix with the same size of probability distribution.
-
-
-[2012-04-21 12:13:12]
-========================================================
-what's the difference between the Generator for Multi-Server Case and normal case.
-========================================================
-
-
-[2012-04-21 15:22:24]
-I have finished 
-1. Behaviour part and 
-2. Modulator part.
-
-
-
-

File LOG_Back

-Network
-
-NNode
-
-MarkovNode
-
-Network should be indepedent to NNode
-
-there should be a initialization parameter in the constructor 
-
-how to descript markov behaviour
-start-end. transition
-
-we use profile to describe a modulator in normal node
-
-we can also use  profile to describe a modulator in markov node.
-simply use profile
-
-modulator in markove case
-
-
-
-[2012-04-20 10:36:21]
-start to do the multi server case. 
-
-time information. 
-only consider the model-free case. 
-
-the margin probability is th probability that the received flow belongs to which states
-
-the joint probability is the probability that received flow belongs to which states. 
-
-which states.
-
-what we are trying to do this to characterize the 
-===================================================
-as simple as possible. 
-
-different temporal information. 
-
-A node send same traffic to server. 
-but the difference is the temporal different. 
-
-for the pespective of senders, there should be a probability distribution. 
-for a given time spot. the sender need to decide:
-    1. When to send the next packet
-    2. to whom it should send the packet
-    3. which type of flow it should send ---> specify the marginal distribution. 
-
-parameter of senders. 
-    1. specify the mariginal distribution
-    2. specify the relationship between the marginal distribution
-
-marginal distribution
-    1. decide which type of flow it should send
-
-joint distribution
-    1. specify to whom it should send the packet.
-
-We make the first parameter fixed to be the possion distribution. 
-
-if we change the pdf of "to whom it should send the packet", the flow rate will change. 
-    so this term is not specifed single probability distribution.
-
-[2012-04-20 13:33:14]
-the problem consits of two parts:
-    1 is the generation part.
-    2 detection part 
-to decide to whom the packet should be sent. 
-
-We need to consider the problem from the pespective of window.
-We determine the number of flows that will be sent in on window.
-Then we determine the destination of each slot repectively.
-
-We need to keep the portion for each server to be the same. However, the time will be different. 
-
-for example, in the normal case, the slots can be distributed evenly in terms of time.
-In the abnormal case, the previous parts will have a lot of flows to server 1, while in the second
-part, a lot flows will have destination to server 2
-
-
-we need have some sort of variables description
-
-for each sender X. suppose X_i is a random variable indicating the type of the flow that will be send to sever i.
-the send will maintain such as random variable
-
-
-consider the marignal
-there should be a general distribution 
-
-
-[2012-04-20 14:20:41]
-implementation.
-[Configure] part
-I need create a new class of Node.
-    class ProbNode: node send traffic with certain kind of probability
-in this class
-
-the freedom degree we have. 
-    1. we can add modulator to the server node. the modulator need to have,
-    (start time, profile, generator)
-    2. generator is a source with parameter flow_arrival_rate, flow_size_mean,
-    flow_size_var
-    3. flow_arrival is possion distributed.
-    4. one generator only target for one server.
-    5. we need select different servers, means select different types of
-    generators.
-    6. the original markov node method cannot work
-
-
-ideas:
-    1 a pool of generators. each generator represents one type of flows to one
-    specific server. 
-    2.our task is to select generators from the pool.
-    3. we need to change the way of selections so that the distribution for each
-    sever doesn't change at all.
-
-    X_1, X_2, ..., X_n, joint distribution.
-    for each time, we get a sequence of  X_1, X_2, ....  X_n
-    P(x_1, x_2, ..., x_n) is the probability distribution we want to
-    characterize
-    
-    the possible states are: 1 state for each quantized flow, and one state 
-    for sending no flows at all.
-
-    we need to maintains the marginal distribution for this set of variables
-    unchanged.
-
-    we need have a table. ---> this table specify the joint distribution probability distribution
-    for the 
-
-I need a method to keep each colomn and row unchanged, while change the term. We
-need a scale value to determine the degree of change.
-
-
-the previous analysis is only for a specific time spot. In generaal, it is a
-stochastic process.
-
-
-[2012-04-20 18:12:53]
-==========================================================
-Another important idea is that suppose the behaviour of
-users don't change, but the network condition changes. See
-what happens.
-==========================================================
-
-[2012-04-20 20:59:14]
-
-class MVBehaviour(MarkovBehaviour):
-    """The traffic is generated according to multi-variable distribution
-    if there are n servers, then the joint distribution will be n dimension
-    matrix. For each component, there are n possible values. So we need n possible
-    generators.
-
-    if we have the distribution matrix. we just generate random variable
-        according to the distribution and select generators according
-    """
-
-
-an important function is to generate a random value according to some certain 
-probability distribution.
-
-we need generate matrix with the same size of probability distribution.
-
-
-[2012-04-21 12:13:12]
-========================================================
-what's the difference between the Generator for Multi-Server Case and normal case.
-========================================================
-
-
-[2012-04-21 15:22:24]
-I have finished 
-1. Behaviour part and 
-2. Modulator part.
-
-
-
-

File Sensitivity.py

-#!/usr/bin/env python
-### -- [2012-03-01 14:45:51] Add FlowRateChange
-
-import os
-import cPickle as pickle
-
-import numpy as np
-from matplotlib.pyplot import *
-import settings
-
-from util import *
-
-from API import *
-def FlowRateChange(rg, case):
-    '''Simulate under different flow rate and store the simulation result'''
-    templateFilePath = './settings_template.py'
-    settingsFilePath = './settings.py'
-    dataDir = './Share/sens/%s/'%(case)
-
-    CreateSettings(templateFilePath, settingsFilePath,
-            ANOMALY_TYPE = 'FLOW_RATE')
-    GlobalGenerateNominalPDF()
-
-    if not os.path.exists(dataDir):
-        os.mkdir(dataDir)
-    i = 0
-    for FLOW_RATE in rg:
-        i += 1
-        # Write New Setting File
-        CreateSettings(templateFilePath, settingsFilePath,
-            ANOMALY_TYPE = 'FLOW_RATE',
-            FLOW_RATE = FLOW_RATE)
-        GlobalConfigure()
-        Simulate()
-        GlobalDetect(settings.OUTPUT_FLOW_FILE, '%s/%f.p'%(dataDir, FLOW_RATE))
-
-    Sensitivity(case)
-
-
-def Sensitivity(case):
-    '''Load the simulation results and show them in the same figure'''
-    PREFIX = './Share/sens/%s/' %(case)
-    fNameList = os.listdir(PREFIX)
-    fNameList = [x for x in fNameList if x[-1] == 'p']
-    print 'fNameList', fNameList
-
-    figure()
-    h1 = subplot(211)
-    h2 = subplot(212)
-    IF = list()
-    fv = map(lambda x: float(x.split('.p')[0]), fNameList)
-    idxSet = np.argsort(fv)
-    print 'fv: ', fv
-    print 'idxSet: ', idxSet
-
-    # for f in fNameList:
-    v = []
-    for i in idxSet:
-        f = fNameList[i]
-        print 'f, ', f
-        if case[0:6].lower() == 'markov':
-            v.append('pi: %f, %f' %(fv[i], 1-fv[i]))
-        elif case[0:4].lower() == 'flow':
-            v.append(str(fv[i] ) + ' x')
-        else:
-            raise ValueError('unknown case')
-
-        t2, IF2, IB2, sampleSize = pickle.load(open(PREFIX + f, 'r'))
-        h1.plot(t2, IF2)
-        h2.plot(t2, IB2) # v.reverse()
-
-    h1.legend(v)
-    h2.legend(v)
-    # epsilon = 1e-100
-    epsilon = settings.FALSE_ALARM_RATE
-    # import pdb; pdb.set_trace()
-    # trueThreshold = np.array(1.0 / np.array(sampleSize)) * (-1.0) * np.log(epsilon + np.log(sampleSize) / np.array(sampleSize) )
-    threshold = np.array(1.0 / np.array(sampleSize)) * (-1.0) * np.log(epsilon)
-    h1.plot(t2, threshold, 'g.-', linewidth=3.0)
-    h2.plot(t2, threshold, 'g.-', linewidth=3.0)
-
-    trueThreshold = np.array(1.0 / np.array(sampleSize)) * (-1.0) * np.log(epsilon) + np.log(sampleSize) / np.array(sampleSize)
-    h1.plot(t2, trueThreshold, 'r--', linewidth=3.0)
-    h2.plot(t2, trueThreshold, 'r--', linewidth=3.0)
-    # h2.plot(t2, trueThreshold * 1.5, '--', linewidth=3.0)
-    savefig('./res/sen_%s.eps' %(case))
-    # show()
-
-
-def SensitivityCompareThreshold(case, ratio):
-    PREFIX = './Share/sens/%s/' %(case)
-    fNameList = os.listdir(PREFIX)
-    fNameList = [x for x in fNameList if x[-1] == 'p']
-    print 'fNameList', fNameList
-
-    figure()
-    h1 = subplot(211)
-    h2 = subplot(212)
-    IF = list()
-    fv = map(lambda x: float(x.split('.p')[0]), fNameList)
-    idxSet = np.argsort(fv)
-    print 'fv: ', fv
-    print 'idxSet: ', idxSet
-
-    # for f in fNameList:
-    v = []
-    for i in idxSet:
-        f = fNameList[i]
-        print 'f, ', f
-        if case[0:6].lower() == 'markov':
-            v.append('pi: %f, %f' %(fv[i], 1-fv[i]))
-        elif case[0:4].lower() == 'flow':
-            v.append(str(fv[i] ) + ' x')
-        else:
-            raise ValueError('unknown case')
-
-        t2, IF2, IB2, sampleSize = pickle.load(open(PREFIX + f, 'r'))
-        h1.plot(t2, IF2)
-        h2.plot(t2, IB2) # v.reverse()
-
-    h1.legend(v)
-    h2.legend(v)
-    # epsilon = 1e-100
-    epsilon = settings.FALSE_ALARM_RATE
-
-    for i in ratio:
-        trueThreshold = np.array(1.0 / np.array(sampleSize)) * (-1.0) * np.log(epsilon) + i * np.log(sampleSize) / np.array(sampleSize)
-        h1.plot(t2, trueThreshold, '--', linewidth=1.0)
-        h2.plot(t2, trueThreshold, '--', linewidth=1.0)
-
-    savefig('./res/sen_%s_compare_theshold.eps' %(case))
-    show()
-
-
-if __name__ == "__main__":
-    # Sensitivity('flow_size_decr')
-    # Sensitivity('flow_size_incr')
-    # Sensitivity('flow_rate_incr')
-    # Sensitivity('window_size')
-    # Sensitivity('flow_rate_decr')
-    Sensitivity('FlowRateIncr')
-    SensitivityCompareThreshold('FlowRateIncr', [0, 3, 6, 9])
-    # Sensitivity('window_size_FLOW_RATE')
-    # import sys
-    # Sensitivity(sys.argv[1])