def __init__(self):
        """
        Constructor

        Parameters
        ----------
        value
            Constant value of the distribution
        """
        Uniform.__init__(self, loc=0, scale=0)
        self.priority = 1
 def test_uniform_variable(self):
     # to avoid static method warnings in tests,
     # that by construction of the unittest package have to be expressed in such way
     self.dummy_variable = "dummy_value"
     loc = 53
     scale = 32
     tol = 0.15
     unif = Uniform(loc=loc, scale=scale)
     values = unif.get_values(no_values=400)
     rand = RandomVariable()
     rand.calculate_parameters(values)
     if not rand.get_distribution_type() == "UNIFORM":
         raise Exception("Expected an uniform!")
     loc_r = rand.random_variable.loc
     scale_r = rand.random_variable.scale
     diff_value_loc = abs(loc - loc_r) / (max(abs(loc), abs(loc_r)))
     diff_value_scale = abs(scale - scale_r) / (max(abs(scale), abs(scale_r)))
     if diff_value_loc > tol or diff_value_scale > tol:
         raise Exception("parameters found outside tolerance")
    def read_from_string(self, distribution_type, distribution_parameters):
        """
        Read the random variable from string

        Parameters
        -----------
        distribution_type
            Distribution type
        distribution_parameters
            Distribution parameters splitted by ;
        """
        if distribution_type == "NORMAL":
            self.random_variable = Normal()
            self.random_variable.read_from_string(distribution_parameters)
        elif distribution_type == "UNIFORM":
            self.random_variable = Uniform()
            self.random_variable.read_from_string(distribution_parameters)
        elif distribution_type == "EXPONENTIAL":
            self.random_variable = Exponential()
            self.random_variable.read_from_string(distribution_parameters)
        elif distribution_type == "IMMEDIATE":
            self.random_variable = Constant0()
    def calculate_parameters(self,
                             values,
                             parameters=None,
                             force_distribution=None):
        """
        Calculate parameters of the current distribution

        Parameters
        -----------
        values
            Empirical values to work on
        parameters
            Possible parameters of the algorithm
        force_distribution
            If provided, distribution to force usage (e.g. EXPONENTIAL)

        """

        if parameters is None:
            parameters = {}

        debug_mode = parameters["debug"] if "debug" in parameters else False

        if self.random_variable is not None:
            self.random_variable.calculate_parameters(values)
        else:
            norm = Normal()
            unif = Uniform()
            expon = Exponential()
            constant = Constant0()

            if not force_distribution or not force_distribution == "EXPONENTIAL":
                likelihoods = list()
                likelihoods.append(
                    [constant,
                     constant.calculate_loglikelihood(values)])
                if force_distribution == "NORMAL" or force_distribution is None:
                    norm.calculate_parameters(values)
                    likelihoods.append(
                        [norm, norm.calculate_loglikelihood(values)])
                if force_distribution == "UNIFORM" or force_distribution is None:
                    unif.calculate_parameters(values)
                    likelihoods.append(
                        [unif, unif.calculate_loglikelihood(values)])
                if force_distribution == "EXPONENTIAL" or force_distribution is None:
                    expon.calculate_parameters(values)
                    likelihoods.append(
                        [expon, expon.calculate_loglikelihood(values)])
                likelihoods = [x for x in likelihoods if str(x[1]) != 'nan']
                likelihoods = sorted(likelihoods,
                                     key=lambda x: x[1],
                                     reverse=True)

                if debug_mode:
                    print("likelihoods = ", likelihoods)

                self.random_variable = likelihoods[0][0]
            else:
                avg_values = np.average(values)
                if values and avg_values > 0.00000:
                    expon.scale = avg_values
                    self.random_variable = expon
                else:
                    self.random_variable = constant
#saving possible traces in a dictionary
possible_traces = {}
possible_traces[0] = ['a', 'b', 'e']
possible_traces[1] = ['a', 'b', 'd', 'e']
possible_traces[2] = ['a', 'd', 'b', 'e']
possible_traces[3] = ['a', 'c', 'e']
possible_traces[4] = ['a', 'c', 'd', 'e']
possible_traces[5] = ['a', 'd', 'c', 'e']

#creating stochastic map assigning probabilities to transitions
smap = {}
for t in transitions:
    rand = RandomVariable()
    #we do not use the uniform distribution, but we need some kind of distribution to initialize
    #the random_variable of the RandomVariable() object, so that we can call set_weight and get_weight later
    rand.random_variable = Uniform()
    smap[t] = rand
    if t.label == "b":
        rand.set_weight(0.9)
    elif t.label == "c":
        rand.set_weight(0.1)
    elif t.label == "d":
        rand.set_weight(0.2)
    elif t.label == None:
        rand.set_weight(0.8)
    else:
        rand.set_weight(1)


simulated_log2 = simulator.apply(
    net,