Exemple #1
0
    def setUp(self):
        
        
        data_ = zeros((5,8))
        
        random.seed(1)
        data_[:,:4] = random.rand(5,4)
        
        data_ = DataArray(data_, ['Const', 'Var1', 'Var2', 'Var3', 'choice2_ind', 
                                  'choice1', 'choice2', 'choice3'])

        var_list = [('table1', 'Var1'),
                    ('table1', 'Var2'),
                    ('table1', 'Var3'),
                    ('table1', 'Const')]
        
        variance = array([[1]])
        
        choice1 = ['choice1']
        choice2 = ['choice2']
        choice3 = ['SOV', 'HOV']
        
        coefficients1 = [{'const':2, 'Var1':2.11}]
        coefficients2 = [{'const':1.5, 'var2':-.2, 'var3':16.4}]
        coefficients3 = [{'Const':2, 'Var1':2.11}, {'Const':1.2}]
        
        specification1 = Specification(choice1, coefficients1)
        specification2 = Specification(choice2, coefficients2)
        specification3 = Specification(choice3, coefficients3) 
        
        errorspecification = LinearRegErrorSpecification(variance)

        model1 = LinearRegressionModel(specification1, errorspecification)
        model2 = LinearRegressionModel(specification2, errorspecification)
        model3 = LogitChoiceModel(specification3)
        
        data_filter2 = DataFilter('choice2_ind', 'less than', 25, 
                                  {'choice2_ind':1, 'choice2':1}) #Run Until Condition

        #Subset for the model condition
        data_filter1 = DataFilter('Const', 'less than', 0.3)

        
        model_seq1 = SubModel(model1, 'regression', 'choice1')
        model_seq2 = SubModel(model2, 'regression', 'choice2', 
                              data_filter=data_filter1, run_until_condition=data_filter2)
        model_seq3 = SubModel(model3, 'choice', 'choice3', 
                              run_until_condition=data_filter2)
        model_list = [model_seq1, model_seq2, model_seq3]
    
        # SPECIFY SEED TO REPLICATE RESULTS, DATA FILTER AND 
        # RUN UNTIL CONDITION
        component = AbstractComponent('DummyComponent', model_list, var_list)
    
        component.run(data_)
        print component.data.data
Exemple #2
0
 def __init__(self, choices, coefficients, logsumparameter=None):
     Specification.__init__(self, choices, coefficients)
     if self.number_choices > 1:
         raise SpecificationError, """not a valid inout - more than 1 """\
             """equations specified for the branch in the tree; only one """\
             """ choice expected"""
     if logsumparameter is not None:
         if logsumparameter > 1 or logsumparameter < 0:
             raise SpecificationError, """not a valid input - logsumparameter """\
                 """out of range; valid range [0-1]"""
     self.logsumparameter = logsumparameter
    def __init__(self, choices, coefficients, thresholds, distribution=None):
        self.thresholds = thresholds
        Specification.__init__(self, choices, coefficients)

        if distribution is None:
            self.distribution = "logit"
        else:
            self.distribution = distribution
            checkVal, checkText = self.check_text_only([self.distribution])
            if not checkVal:
                raise SpecificationError, """the distribution specification is not """ """a valid string"""
            if self.distribution not in ["logit", "probit"]:
                raise SpecificationError, """the ordered model formulations """ """supported are probit and logit specification"""
Exemple #4
0
    def __init__(self, choices, coefficients, distribution=None):
        Specification.__init__(self, choices, coefficients)

        if distribution is None:
            self.distribution = 'poisson'
        else:
            self.distribution = distribution
            checkVal, checkText = self.check_text_only([self.distribution])
            if not checkVal:
                raise SpecificationError, """the distribution specification is not """\
                    """a valid string"""
            if self.distribution not in ['poisson', 'negativebinomial']:
                raise SpecificationError, """the ordered model formulations """\
                    """ supported are poisson and negativebinomial specification"""
    def __init__(self, choices, coefficients, distribution=None):
        Specification.__init__(self, choices, coefficients)

        if distribution is None:
            self.distribution = 'poisson'
        else:
            self.distribution = distribution
            checkVal, checkText = self.check_text_only([self.distribution])
            if not checkVal:
                raise SpecificationError, """the distribution specification is not """\
                    """a valid string"""
            if self.distribution not in ['poisson', 'negativebinomial']:
                raise SpecificationError, """the ordered model formulations """\
                    """ supported are poisson and negativebinomial specification"""
    def __init__(self, choices, coefficients, thresholds, distribution=None):
        self.thresholds = thresholds
        Specification.__init__(self, choices, coefficients)

        if distribution is None:
            self.distribution = 'logit'
        else:
            self.distribution = distribution
            checkVal, checkText = self.check_text_only([self.distribution])
            if not checkVal:
                raise SpecificationError, """the distribution specification is not """\
                    """a valid string"""
            if self.distribution not in ['logit', 'probit']:
                raise SpecificationError, """the ordered model formulations """\
                    """supported are probit and logit specification"""
Exemple #7
0
    def setUp(self):
        choices = ['SOV', 'HOV']
        coefficients = [{'Constant': 2, 'Var1': 2.11}, {'Constant': 1.2}]
        data = array([[1, 1.1], [1, -0.25], [1, 3.13], [1, -0.11]])

        self.choiceset1 = DataArray(ma.array([[0, 1], [0, 1], [1, 1], [1, 1]]),
                                    ['SOV', 'HOV'])

        self.data = DataArray(data, ['Constant', 'Var1'])
        self.specification = Specification(choices, coefficients)

        self.utils_array_act = zeros(
            (self.data.rows, self.specification.number_choices))
        self.utils_array_act[:,
                             0] = self.data.data[:,
                                                 0] * 2 + self.data.data[:,
                                                                         1] * 2.11
        self.utils_array_act[:, 1] = self.data.data[:, 0] * 1.2
        self.exp_utils_array_act = exp(self.utils_array_act)
        self.prob_array_act = (
            self.exp_utils_array_act.transpose() /
            self.exp_utils_array_act.cumsum(-1)[:, -1]).transpose()

        # for the selected data, and seed = 1, chosen alternatives are
        self.selected_act = array([['sov'], ['hov'], ['sov'], ['sov']])
        self.selected_act1 = array([['hov'], ['hov'], ['sov'], ['sov']])
    def setUp(self):
        choice = ['SOV']
        coefficients = [{'constant': 2, 'Var1': 2.11}]
        data = array([[1, 1.1], [1, -0.25], [1, 3.13], [1, -0.11]])

        self.data = DataArray(data, ['Constant', 'VaR1'])
        self.specification = Specification(choice, coefficients)
    def setUp(self):
        choice = ['age_tt_product']
        coefficients = [{'age': 1, 'tt': 1}]

        data = array([[1, 15], [2, 10]])

        self.data = DataArray(data, ['Age', 'TT'])
        self.specification = Specification(choice, coefficients)
Exemple #10
0
    def setUp(self):
        choice = ['DURATION']
        coefficients = [{'constant':2, 'Var1':2.11}]
        data = array([[1, 1.1], [1, -0.25], [1, 3.13], [1, -0.11]])       
        variance = array([[1]])

        self.data = DataArray(data, ['Constant', 'VaR1'])
        self.specification = Specification(choice, coefficients)
        self.errorspecification = LinearRegErrorSpecification(variance)        
    def setUp(self):
        choices = ['SOV', 'HOV']
        variables = [['Constant', 'Var1'], ['Constant']]
        coefficients = [{'Constant': 2, 'Var1': 2.11}, {'Constant': 1.2}]

        self.data = DataArray(array([[1, 1.1], [1, -0.25]]),
                              ['Constant', 'Var1'])
        self.specification = Specification(choices, coefficients)
        self.model = Model(self.specification)
    def setUp(self):
        choice = ['Frontier']
        coefficients = [{'constant': 2, 'Var1': 2.11}]
        data = array([[1, 1.1], [1, -0.25], [1, 3.13], [1, -0.11]])
        variance = array([[1., 0], [0, 1.1]])

        self.data = DataArray(data, ['Constant', 'VaR1'])
        self.specification = Specification(choice, coefficients)
        self.errorspecification = StochasticRegErrorSpecification(
            variance, 'start')
    def setUp(self):
        choices = ['SOV', 'HOV']
        coefficients = [{'Constant': 2, 'Var1': 2.11}, {'Constant': 1.2}]
        data = array([[1, 1.1], [1, -0.25], [1, 3.13], [1, -0.11]])

        variance = array([[1.1]])
        variance1 = array([[1.1, 1.2], [2.1, 2.2]])

        self.data = DataArray(data, ['Constant', 'VAR1'])

        self.specification = Specification(choices, coefficients)

        self.errorspecification = ErrorSpecification(variance, 'normal')
        self.errorspecification1 = ErrorSpecification(variance1, 'normal')