Example #1
0
 def test_expr10(self):
     expr10 = ex.bioNormalCdf(self.Variable1 / 10 - 1)
     res = expr10.getValue_c(self.myData)
     for i, j in zip(res, [
             0.5, 0.8413447460685283, 0.9772498680518218, 0.99865010196837,
             0.9999683287581669
     ]):
         self.assertAlmostEqual(i, j, 5)
Example #2
0
 def test_expr12(self):
     expr1 = 2 * self.beta1 - ex.exp(-self.beta2) / (
         self.beta3 * (self.beta2 >= self.beta1))
     expr2 = 2 * self.beta1 * self.Variable1 - ex.exp(-self.beta2 * self.Variable2) / \
         (self.beta3 * (self.beta2 >= self.beta1))
     expr5 = ex.Elem({1: expr1, 2: expr2}, self.Person) / 10
     expr10 = ex.bioNormalCdf(self.Variable1 / 10 - 1)
     expr12 = ex.bioMax(expr5, expr10)
     res = expr12.getValue_c(self.myData)
     for i, j in zip(
             res, [0.5, 0.8413447460685283, 0.9772498680518218, 8.0, 10.0]):
         self.assertAlmostEqual(i, j, 5)
Example #3
0
 def test_expr11(self):
     expr1 = 2 * self.beta1 - ex.exp(-self.beta2) / (
         self.beta3 * (self.beta2 >= self.beta1))
     expr2 = 2 * self.beta1 * self.Variable1 - ex.exp(-self.beta2 * self.Variable2) / \
         (self.beta3 * (self.beta2 >= self.beta1))
     expr5 = ex.Elem({1: expr1, 2: expr2}, self.Person) / 10
     expr10 = ex.bioNormalCdf(self.Variable1 / 10 - 1)
     expr11 = ex.bioMin(expr5, expr10)
     res = expr11.getValue_c(self.myData)
     for i, j in zip(res, [
             0.19548882389211292, 0.19548882389211292, 0.19548882389211292,
             0.99865010196837, 0.9999683287581669
     ]):
         self.assertAlmostEqual(i, j, 5)
SIGMA_STAR_Mobil17 = Beta('SIGMA_STAR_Mobil17', betas['SIGMA_STAR_Mobil17'],
                          None, None, 0)

delta_1 = Beta('delta_1', betas['delta_1'], 0, 10, 0)
delta_2 = Beta('delta_2', betas['delta_2'], 0, 10, 0)
tau_1 = -delta_1 - delta_2
tau_2 = -delta_1
tau_3 = delta_1
tau_4 = delta_1 + delta_2

Envir01_tau_1 = (tau_1 - MODEL_Envir01) / SIGMA_STAR_Envir01
Envir01_tau_2 = (tau_2 - MODEL_Envir01) / SIGMA_STAR_Envir01
Envir01_tau_3 = (tau_3 - MODEL_Envir01) / SIGMA_STAR_Envir01
Envir01_tau_4 = (tau_4 - MODEL_Envir01) / SIGMA_STAR_Envir01
IndEnvir01 = {
    1: bioNormalCdf(Envir01_tau_1),
    2: bioNormalCdf(Envir01_tau_2) - bioNormalCdf(Envir01_tau_1),
    3: bioNormalCdf(Envir01_tau_3) - bioNormalCdf(Envir01_tau_2),
    4: bioNormalCdf(Envir01_tau_4) - bioNormalCdf(Envir01_tau_3),
    5: 1 - bioNormalCdf(Envir01_tau_4),
    6: 1.0,
    -1: 1.0,
    -2: 1.0
}

P_Envir01 = Elem(IndEnvir01, Envir01)

Envir02_tau_1 = (tau_1 - MODEL_Envir02) / SIGMA_STAR_Envir02
Envir02_tau_2 = (tau_2 - MODEL_Envir02) / SIGMA_STAR_Envir02
Envir02_tau_3 = (tau_3 - MODEL_Envir02) / SIGMA_STAR_Envir02
Envir02_tau_4 = (tau_4 - MODEL_Envir02) / SIGMA_STAR_Envir02
Example #5
0
TRAIN_COST_SCALED = DefineVariable('TRAIN_COST_SCALED',\
                                   TRAIN_COST / 100,database)
SM_TT_SCALED = DefineVariable('SM_TT_SCALED', SM_TT / 100.0, database)
SM_COST_SCALED = DefineVariable('SM_COST_SCALED', SM_COST / 100, database)
CAR_TT_SCALED = DefineVariable('CAR_TT_SCALED', CAR_TT / 100, database)
CAR_CO_SCALED = DefineVariable('CAR_CO_SCALED', CAR_CO / 100, database)

# We estimate a binary probit model. There are only two alternatives.
V1 = B_TIME * TRAIN_TT_SCALED + \
     B_COST * TRAIN_COST_SCALED
V3 = ASC_CAR + \
     B_TIME * CAR_TT_SCALED + \
     B_COST * CAR_CO_SCALED

# Associate choice probability with the numbering of alternatives

P = {1: bioNormalCdf(V1 - V3), 3: bioNormalCdf(V3 - V1)}

prob = Elem(P, CHOICE)


class test_02(unittest.TestCase):
    def testEstimation(self):
        biogeme = bio.BIOGEME(database, log(prob))
        results = biogeme.estimate()
        self.assertAlmostEqual(results.data.logLike, -986.1888, 2)


if __name__ == '__main__':
    unittest.main()