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
    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.º 3
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.º 4
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)
    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)