def calc_errorcomponent(self, variance_norm, variance_halfnorm, 
                            vertex, size, seed):
        """
        The method returns the contribution of the error component in the 
        calculation of the predicted value for the different choices.
        
        Inputs:
        variance_norm - numeric value (variance of the normal portion of error)
        variance_halfnorm - numeric value (variance of the half normal portion of
                                        error)
        vertex - string (the vertext to predict -- start/end)
        size - numeric value (number of rows)

        """

        dist = RandomDistribution(seed=seed)
	err_halfnorm = dist.return_half_normal_variables(location=0, scale=variance_halfnorm**0.5, size=size)

	dist = RandomDistribution(seed=seed)
        err_norm = dist.return_normal_variables(location=0, scale=variance_norm**0.5, size=size)

        if vertex == 'start':
            return err_norm + err_halfnorm

        if vertex == 'end':
            return err_norm - err_halfnorm
Ejemplo n.º 2
0
    def testvalues(self):
        model = LinearRegressionModel(self.specification, self.errorspecification)
        pred_value = model.calc_predvalue(self.data)

        expected_act = self.data.calculate_equation(self.specification.coefficients[0])
        expected_act.shape = (4,1)

        dist = RandomDistribution(seed=1)
        pred_act = dist.return_normal_variables(location=expected_act, scale=1, size=(4,1))

        pred_diff = all(pred_value.data == pred_act)
        self.assertEqual(True, pred_diff)
Ejemplo n.º 3
0
 def calc_errorcomponent(self, size, mean=0, sd=1, seed=1):
     """
     The method returns the contribution of the error in the calculation 
     of the predicted value for the different choices.
     
     Inputs:
     size - numeric value (number of rows)
     mean - numeric value (mean)
     sd - numeric value (standard deviation)
     """
     dist = RandomDistribution(seed=seed)
     err_norm = dist.return_normal_variables(location=mean, scale=sd, size=size)
     return err_norm
    def testvalues(self):
        model = StocFronRegressionModel(self.specification, self.errorspecification)
        pred_value = model.calc_predvalue(self.data)

        expected_act = self.data.calculate_equation(self.specification.coefficients[0])
        expected_act.shape = (4, 1)
        variance = self.errorspecification.variance

        dist = RandomDistribution(seed=1)
        err_norm = dist.return_normal_variables(location=0, scale=variance[0, 0] ** 0.5, size=(4, 1))

        pred_act = expected_act + err_norm

        pred_diff = all(pred_value.data == pred_act)
        self.assertEquals(True, pred_diff)
Ejemplo n.º 5
0
    def calc_halfnormal_error(self, threshold, limit, seed, size):
	"""
	A draw from a half normal distribution with 3 s.d. = abs(threshold - limit)
	For smoothing about the boundaries

	"""

	dist = RandomDistribution(seed=seed)

	assu_scale = abs(threshold-limit)/3.0
	err_halfnorm = dist.return_half_normal_variables(location=0, scale=assu_scale, size=size)

	chkRowsMore = err_halfnorm > abs(threshold-limit)
	err_halfnorm[chkRowsMore] = abs(threshold-limit)
	
	return err_halfnorm
Ejemplo n.º 6
0
    def generate_random_numbers(self):
        """
        The method generates a random array for making the choice of
        the alternative.

        Inputs:
        None
        """
        #random.seed(seed=self.seed)
        #err = random.random((3,1))
        #f = open('test_res', 'a')
        #f.write('probability - %s' %self.seed)
        #f.write(str(list(err[:3,:])))
        #f.write('\n')
        #f.close()

        dist = RandomDistribution(self.seed)
        rand_numbers = dist.return_random_variables(self.num_agents)
        return rand_numbers
    def testvalues(self):
        model = StocFronRegressionModel(self.specification,
                                        self.errorspecification)
        pred_value = model.calc_predvalue(self.data)

        expected_act = self.data.calculate_equation(
            self.specification.coefficients[0])
        expected_act.shape = (4, 1)
        variance = self.errorspecification.variance

        dist = RandomDistribution(seed=1)
        err_norm = dist.return_normal_variables(location=0,
                                                scale=variance[0, 0]**0.5,
                                                size=(4, 1))

        pred_act = (expected_act + err_norm)

        pred_diff = all(pred_value.data == pred_act)
        self.assertEquals(True, pred_diff)
 def generate_random_numbers(self):
     """
     The method generates a random array for making the choice of 
     the alternative.
     
     Inputs:
     None
     """
     #random.seed(seed=self.seed)
     #err = random.random((3,1))
     #f = open('test_res', 'a')
     #f.write('probability - %s' %self.seed)
     #f.write(str(list(err[:3,:])))
     #f.write('\n')
     #f.close()
     
     dist = RandomDistribution(self.seed)
     rand_numbers = dist.return_random_variables(self.num_agents)
     return rand_numbers
    def calc_errorcomponent(self, variance_norm, variance_halfnorm, vertex,
                            size, seed):
        """
        The method returns the contribution of the error component in the
        calculation of the predicted value for the different choices.

        Inputs:
        variance_norm - numeric value (variance of the normal portion of error)
        variance_halfnorm - numeric value (variance of the half normal portion of
                                        error)
        vertex - string (the vertext to predict -- start/end)
        size - numeric value (number of rows)

        """

        dist = RandomDistribution(seed=seed)
        err_halfnorm = dist.return_half_normal_variables(
            location=0, scale=variance_halfnorm**0.5, size=size)

        dist = RandomDistribution(seed=seed)
        err_norm = dist.return_normal_variables(location=0,
                                                scale=variance_norm**0.5,
                                                size=size)

        if vertex == 'start':
            return err_norm + err_halfnorm

        if vertex == 'end':
            return err_norm - err_halfnorm