本文整理汇总了Python中openamos.core.data_array.DataArray.calculate_equation方法的典型用法代码示例。如果您正苦于以下问题:Python DataArray.calculate_equation方法的具体用法?Python DataArray.calculate_equation怎么用?Python DataArray.calculate_equation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openamos.core.data_array.DataArray
的用法示例。
在下文中一共展示了DataArray.calculate_equation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestOrderedProbitModel
# 需要导入模块: from openamos.core.data_array import DataArray [as 别名]
# 或者: from openamos.core.data_array.DataArray import calculate_equation [as 别名]
class TestOrderedProbitModel(unittest.TestCase):
def setUp(self):
choices = ['Veh1', 'Veh2', 'Veh3']
self.coefficients = [{'Constant':2, 'Var1':2.11}]
self.thresholds = [1.2, 2.1]
self.data = DataArray(array([[1, 1.1], [1, -0.25], [1, 3.13], [1, -0.11]]),
['CONSTANT', 'VAR1'])
specification = OLSpecification(choices, self.coefficients, self.thresholds)
self.model = OrderedModel(specification)
specification1 = OLSpecification(choices, self.coefficients, self.thresholds,
distribution='probit')
self.model1 = OrderedModel(specification1)
def testprobabilitieslogit(self):
prob = zeros((4,3))
obs_utility = self.data.calculate_equation(self.coefficients[0])
[shape_param] = [1,]*genlogistic.numargs
prob[:,0] = genlogistic.cdf(self.thresholds[0] - obs_utility, shape_param)
prob[:,1] = (genlogistic.cdf(self.thresholds[1] - obs_utility, shape_param) -
genlogistic.cdf(self.thresholds[0] - obs_utility, shape_param))
prob[:,2] = 1 - genlogistic.cdf(self.thresholds[1] -
obs_utility, shape_param)
prob_model = self.model.calc_probabilities(self.data)
prob_diff = all(prob == prob_model)
self.assertEqual(True, prob_diff)
def testselectionlogit(self):
choice_act = array([['veh3'], ['veh3'], ['veh1'], ['veh1']])
choice_model = self.model.calc_chosenalternative(self.data)
choice_diff = all(choice_act == choice_model)
self.assertEqual(True, choice_diff)
def testprobabilitiesprobit(self):
prob = zeros((4,3))
obs_utility = self.data.calculate_equation(self.coefficients[0])
prob[:,0] = norm.cdf(self.thresholds[0] - obs_utility)
prob[:,1] = (norm.cdf(self.thresholds[1] - obs_utility) -
norm.cdf(self.thresholds[0] - obs_utility))
prob[:,2] = 1 - norm.cdf(self.thresholds[1] - obs_utility)
prob_model = self.model1.calc_probabilities(self.data)
prob_diff = all(prob == prob_model)
self.assertEqual(True, prob_diff)
def testselectionprobit(self):
choice_act = array([['veh3'], ['veh2'], ['veh3'], ['veh2']])
choice_model = self.model1.calc_chosenalternative(self.data)
choice_diff = all(choice_act == choice_model)
self.assertEqual(True, choice_diff)
示例2: TestCountRegressionModel
# 需要导入模块: from openamos.core.data_array import DataArray [as 别名]
# 或者: from openamos.core.data_array.DataArray import calculate_equation [as 别名]
class TestCountRegressionModel(unittest.TestCase):
def setUp(self):
choices = ['Episodes1', 'Episodes2', 'Episodes3']
self.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 = CountSpecification(choices, self.coefficients)
self.model = CountRegressionModel(self.specification)
def testprobabilitiespoisson(self):
prob = zeros((4,3))
exp_value = self.data.calculate_equation(self.coefficients[0])
prob[:,0] = poisson.pmf(0, exp_value)
prob[:,1] = poisson.pmf(1, exp_value)
prob[:,2] = 1 - poisson.cdf(1, exp_value)
prob_model = self.model.calc_probabilities(self.data)
prob_diff = all(prob == prob_model)
self.assertEqual(True, prob_diff)
def testselectionpoisson(self):
choice_act = array([['episodes3'], ['episodes3'], ['episodes1'],
['episodes2']])
choice_model = self.model.calc_chosenalternative(self.data)
choice_diff = all(choice_act == choice_model)
self.assertEqual(True, choice_diff)
示例3: TestLinearRegressionModel
# 需要导入模块: from openamos.core.data_array import DataArray [as 别名]
# 或者: from openamos.core.data_array.DataArray import calculate_equation [as 别名]
class TestLinearRegressionModel(unittest.TestCase):
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 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)
示例4: TestStocFronRegressionModel
# 需要导入模块: from openamos.core.data_array import DataArray [as 别名]
# 或者: from openamos.core.data_array.DataArray import calculate_equation [as 别名]
class TestStocFronRegressionModel(unittest.TestCase):
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 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)
开发者ID:foss-transportationmodeling,项目名称:simtravel,代码行数:31,代码来源:stochastic_frontier_regression_model.py
示例5: update_houseids
# 需要导入模块: from openamos.core.data_array import DataArray [as 别名]
# 或者: from openamos.core.data_array.DataArray import calculate_equation [as 别名]
def update_houseids(self, hhldSyn, persSyn, hhldVars, persVars, highestHid):
hhldSynDataObj = DataArray(hhldSyn, hhldVars)
persSynDataObj = DataArray(persSyn, persVars)
maxFreqCol = amax(hhldSynDataObj.columns(['frequency']).data)
powFreqCol = floor(log(maxFreqCol, 10)) + 1
coefficients = {'frequency':1, 'hhid':10**powFreqCol}
newHid = hhldSynDataObj.calculate_equation(coefficients)
hhldSynDataObj.setcolumn('hhid', newHid)
newHid = persSynDataObj.calculate_equation(coefficients)
persSynDataObj.setcolumn('hhid', newHid)
hhldSynDataObj.sort([self.idSpec.hidName])
persSynDataObj.sort([self.idSpec.hidName, self.idSpec.pidName])
hidIndex_popgenH = hhldVars.index('hhid')
hidIndex_popgenP = persVars.index('hhid')
self.create_indices(persSynDataObj)
hhldSyn = hhldSynDataObj.data
persSyn = persSynDataObj.data
row = 0
for hhldIndex in self.hhldIndicesOfPersons:
firstPersonRec = hhldIndex[1]
lastPersonRec = hhldIndex[2]
#print hhldIndex[0], highestHid + 1, firstPersonRec, lastPersonRec
hhldSyn[row,hidIndex_popgenH] = highestHid + 1
persSyn[firstPersonRec:lastPersonRec,hidIndex_popgenP] = highestHid + 1
highestHid += 1
row += 1
return hhldSyn, persSyn