本文整理汇总了Python中openamos.core.data_array.DataArray类的典型用法代码示例。如果您正苦于以下问题:Python DataArray类的具体用法?Python DataArray怎么用?Python DataArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calc_probabilities
def calc_probabilities(self, data, choiceset):
"""
The method returns the selection probability associated with the
the different choices.
Inputs:
data - DataArray object
choiceset - DataArray object
"""
exp_expected_utilities = self.calc_exp_choice_utilities(
data, choiceset)
# missing_choices = choiceset.varnames
#spec_dict = self.specification.specification
for parent in self.parent_list:
child_names = self.specification.child_names(parent)
# calculating the sum of utilities across children in a branch
util_sum = 0
for child in child_names:
# For utils with missing values they are converted to zero
# before summing the utils across choices in a parent
# to avoid the case where missing + valid = missing
child_column = exp_expected_utilities.column(child)
child_column = child_column.filled(0)
util_sum = util_sum + child_column
# calculating the probability of children in a branch
for child in child_names:
exp_expected_utilities.setcolumn(child,
exp_expected_utilities.column(child) / util_sum)
# Dummy check to ensure that within any branch the probs add to one
prob_sum = 0
for child in child_names:
prob_sum = prob_sum + exp_expected_utilities.column(child)
for choice in self.specification.actual_choices:
parent_names = self.specification.all_parent_names(choice)
for parent in parent_names:
parent_column = exp_expected_utilities.column(parent)
choice_column = exp_expected_utilities.column(choice)
exp_expected_utilities.setcolumn(choice, choice_column *
parent_column)
self.specification.actual_choices.sort()
rows = exp_expected_utilities.rows
cols = len(self.specification.actual_choices)
probabilities = DataArray(zeros((rows, cols)),
self.specification.actual_choices,
data.index)
for choice in self.specification.actual_choices:
probabilities.setcolumn(
choice, exp_expected_utilities.column(choice))
return probabilities
示例2: TestOrderedProbitModel
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)
示例3: calculate_expected_values
def calculate_expected_values(self, data):
"""
The method returns the expected values for the different choices
using the coefficients in the specification input.
Inputs:
data - DataArray object
"""
num_choices = self.specification.number_choices
expected_value_array = DataArray(zeros((data.rows, num_choices)), self.choices)
for i in range(num_choices):
coefficients = self.coefficients[i]
expected_value_array.data[:, i] = data.calculate_equation(coefficients)
return expected_value_array
示例4: TestStocFronRegressionModel
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,代码行数:29,代码来源:stochastic_frontier_regression_model.py
示例5: TestLinearRegressionModel
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)
示例6: TestCountRegressionModel
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)
示例7: calculate_expected_values
def calculate_expected_values(self, data):
"""
The method returns the product using the coefficients
in the specification input as power.
Inputs:
data - DataArray object
"""
num_choices = self.specification.number_choices
expected_value_array = DataArray(zeros((data.rows, num_choices)),
self.choices)
self.inverse = self.specification.inverse[0]
for i in range(num_choices):
coefficients = self.coefficients[i]
expected_value_array.data[:,i] = data.calculate_product(coefficients, inverse=self.inverse)
return expected_value_array
示例8: TestReconcileModel
class TestReconcileModel(unittest.TestCase):
def setUp(self):
self.data = genfromtxt("/home/kkonduri/simtravel/test/mag_zone/schedule_txt.csv", delimiter=",", dtype=int)
colNames = [
"houseid",
"personid",
"scheduleid",
"activitytype",
"locationid",
"starttime",
"endtime",
"duration",
]
self.actSchedules = DataArray(self.data, colNames)
def test_retrieve_loop_ids(self):
houseIdsCol = self.actSchedules.columns(["houseid"]).data
houseIdsUnique = unique(houseIdsCol)
print houseIdsUnique
for hid in houseIdsUnique:
schedulesRowsIndForHh = houseIdsCol == hid
schedulesForHh = self.actSchedules.rowsof(schedulesRowsIndForHh)
pIdsCol = schedulesForHh.columns(["personid"]).data
pIdsUnique = unique(pIdsCol)
for pid in pIdsUnique:
schedulesRowIndForPer = pIdsCol == pid
schedulesForPerson = schedulesForHh.rowsof(schedulesRowIndForPer)
# print 'Raw schedules for hid:%s and pid:%s' %(hid, pid)
# print schedulesForPerson
activityList = []
for sch in schedulesForPerson.data:
scheduleid = sch[2]
activitytype = sch[3]
locationid = sch[4]
starttime = sch[5]
endtime = sch[6]
duration = sch[7]
actepisode = ActivityEpisode(scheduleid, activitytype, locationid, starttime, endtime, duration)
activityList.append(actepisode)
personObject = Person(hid, pid)
personObject.add_and_reconcile_episodes(activityList)
示例9: setUp
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)
示例10: setUp
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)
示例11: setUp
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)
示例12: setUp
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)
示例13: setUp
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], [0, 1.1]])
self.data = DataArray(data, ["Constant", "VaR1"])
self.specification = Specification(choice, coefficients)
self.errorspecification = StochasticRegErrorSpecification(variance, "start")
示例14: setUp
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')
开发者ID:foss-transportationmodeling,项目名称:simtravel,代码行数:9,代码来源:stochastic_frontier_regression_model.py
示例15: setUp
def setUp(self):
self.data = genfromtxt("/home/kkonduri/simtravel/test/mag_zone/schedule_txt.csv", delimiter=",", dtype=int)
colNames = [
"houseid",
"personid",
"scheduleid",
"activitytype",
"locationid",
"starttime",
"endtime",
"duration",
]
self.actSchedules = DataArray(self.data, colNames)