Esempio n. 1
0
 def init(sim):
     sim.schedule(exponential(sim.params.arrival_mean), arrive)
     # Record initial points in statistics:
     sim.data.system_size_trace.record(0, 0)
     sim.data.server_busy_trace.record(0, 0)
     sim.data.arrivals.record(0)
     sim.data.departures.record(0)
 def start_service(self):
     assert not self.__busy
     delay = exponential(self.service_mean)
     self.sim.schedule(delay, self.on_service_end)
     self.delays.append(delay)
     self.__busy = True
     self.busy_trace.record(self.sim.stime, 1)
Esempio n. 3
0
    def arrive(sim):
        if sim.data.server_busy:
            sim.data.queue_size += 1
        else:
            interval = exponential(sim.params.service_mean)
            sim.schedule(interval, depart)
            sim.data.server_busy = True

            # Write statistics about server status and service interval:
            sim.data.server_busy_trace.record(sim.stime, 1)
            sim.data.service_intervals.append(interval)

        sim.schedule(exponential(sim.params.arrival_mean), arrive)

        # Write statistics about system size and arrival timestamps:
        sim.data.system_size_trace.record(sim.stime, sim.data.system_size)
        sim.data.arrivals.record(sim.stime)
Esempio n. 4
0
def mVOR(alignment,n=1000,order=DNA_ORDER):
    """Returns sequence weights according to the modified Voronoi method.
    
    alignment: Alignment object
    n: sample size (=number of random profiles to be generated)
    order: specifies the order of the characters found in the alignment,
        used to build the sequence and random profiles.
    
    mVOR is a modification of the VOR method. Instead of generating discrete
    random sequences, it generates random profiles, to sample more equally from
    the sequence space and to prevent random sequences to be equidistant to 
    multiple sequences in the alignment. 

    See the Implementation notes to see how the random profiles are generated
    and compared to the 'sequence profiles' from the alignment.

    Random generalized sequences (or a profile filled with random numbers):
    Sequences that are equidistant to multiple sequences in the alignment
    can form a problem in small datasets. For longer sequences the likelihood
    of this event is negligable. Generating 'random generalized sequences' is 
    a solution, because we're then sampling from continuous sequence space. 
    Each column of a random profile is generated by normalizing a set of 
    independent, exponentially distributed random numbers. In other words, a 
    random profile is a two-dimensional array (rows are chars in the alphabet, 
    columns are positions in the alignment) filled with a random numbers, 
    sampled from the standard exponential distribution (lambda=1, and thus 
    the mean=1), where each column is normalized to one. These random profiles 
    are compared to the special profiles of just one sequence (ones for the 
    single character observed at that position). The distance between the 
    two profiles is simply the Euclidean distance.

    """
    
    weights = zeros(len(alignment.Names),Float64)

    #get seq profiles
    seq_profiles = {}
    for k,v in list(alignment.items()):
        #seq_profiles[k] = ProfileFromSeq(v,order=order)
        seq_profiles[k] = SeqToProfile(v,alphabet=order)

    for count in range(n):
        #generate a random profile
        exp = exponential(1,[alignment.SeqLen,len(order)])
        r = Profile(Data=exp,Alphabet=order)
        r.normalizePositions()
        #append the distance between the random profile and the sequence
        #profile to temp
        temp = [seq_profiles[key].distance(r) for key in alignment.Names]
        votes = row_to_vote(array(temp))
        weights += votes
    weight_dict = Weights(dict(list(zip(alignment.Names,weights))))
    weight_dict.normalize()
    return weight_dict
Esempio n. 5
0
def mVOR(alignment, n=1000, order=DNA_ORDER):
    """Returns sequence weights according to the modified Voronoi method.
    
    alignment: Alignment object
    n: sample size (=number of random profiles to be generated)
    order: specifies the order of the characters found in the alignment,
        used to build the sequence and random profiles.
    
    mVOR is a modification of the VOR method. Instead of generating discrete
    random sequences, it generates random profiles, to sample more equally from
    the sequence space and to prevent random sequences to be equidistant to 
    multiple sequences in the alignment. 

    See the Implementation notes to see how the random profiles are generated
    and compared to the 'sequence profiles' from the alignment.

    Random generalized sequences (or a profile filled with random numbers):
    Sequences that are equidistant to multiple sequences in the alignment
    can form a problem in small datasets. For longer sequences the likelihood
    of this event is negligable. Generating 'random generalized sequences' is 
    a solution, because we're then sampling from continuous sequence space. 
    Each column of a random profile is generated by normalizing a set of 
    independent, exponentially distributed random numbers. In other words, a 
    random profile is a two-dimensional array (rows are chars in the alphabet, 
    columns are positions in the alignment) filled with a random numbers, 
    sampled from the standard exponential distribution (lambda=1, and thus 
    the mean=1), where each column is normalized to one. These random profiles 
    are compared to the special profiles of just one sequence (ones for the 
    single character observed at that position). The distance between the 
    two profiles is simply the Euclidean distance.

    """

    weights = zeros(len(alignment.Names), Float64)

    #get seq profiles
    seq_profiles = {}
    for k, v in alignment.items():
        #seq_profiles[k] = ProfileFromSeq(v,order=order)
        seq_profiles[k] = SeqToProfile(v, alphabet=order)

    for count in range(n):
        #generate a random profile
        exp = exponential(1, [alignment.SeqLen, len(order)])
        r = Profile(Data=exp, Alphabet=order)
        r.normalizePositions()
        #append the distance between the random profile and the sequence
        #profile to temp
        temp = [seq_profiles[key].distance(r) for key in alignment.Names]
        votes = row_to_vote(array(temp))
        weights += votes
    weight_dict = Weights(dict(zip(alignment.Names, weights)))
    weight_dict.normalize()
    return weight_dict
Esempio n. 6
0
    def depart(sim):
        assert sim.data.system_size > 0
        if sim.data.queue_size > 0:
            sim.data.queue_size -= 1
            interval = exponential(sim.params.service_mean)
            sim.schedule(interval, depart)

            # Write statistics about service interval:
            sim.data.service_intervals.append(interval)
        else:
            sim.data.server_busy = False

            # Write statistics about server status update:
            sim.data.server_busy_trace.record(sim.stime, 0)

        # Write statistics about system size and departure timestamps:
        sim.data.system_size_trace.record(sim.stime, sim.data.system_size)
        sim.data.departures.record(sim.stime)
def exponential(mean, shape=[]):
    """exponential(mean, n) or exponential(mean, [n, m, ...]) returns array
      of random numbers exponentially distributed with specified mean"""
    if shape == []:
        shape = None
    return mt.exponential(mean, shape)
Esempio n. 8
0
def exponential(mean, shape=[]):
    """exponential(mean, n) or exponential(mean, [n, m, ...]) returns array
      of random numbers exponentially distributed with specified mean"""
    if shape == []:
        shape = None
    return mt.exponential(mean, shape)
Esempio n. 9
0
def generate_exp_data(lam=1.0, size=10):
    from numpy.random.mtrand import exponential
    return exponential(lam, size)
 def _schedule_next_arrival(self):
     self.intervals.record(self.sim.stime)
     self.sim.schedule(exponential(self.arrival_mean), self.on_timeout)