next up previous index
Next: Using Aggregation and Disaggregation Up: Opus Variables Previous: Expression Names and Aliasing   Index


Using Interaction Sets in Expressions

If you access an attribute of a component of an interaction set in the context of that interaction set, the result is converted into a 2-d array and returned. These 2-d arrays can then be multiplied, divided, compared, and so forth, using the numpy functions and operators. For example, suppose we have an interaction set household_x_gridcell. The component household set has an attribute income with values [100, 200, 300]. (These numbers are just to explain the concepts -- obviously they aren't realistic incomes.) The gridcell component has an attribute cost with values [1000, 1200]. Then evaluating

household_x_gridcell.compute_variables('urbansim.household.income')

will return a 2-d array

[ [100, 100],
  [200, 200],
  [300, 300] ]

and

household_x_gridcell.compute_variables('urbansim.gridcell.cost')

returns

[ [1000, 1200],
  [1000, 1200],
  [1000, 1200] ]

Then

household_x_gridcell.compute_variables(
            'urbansim.gridcell.cost*urbansim.household.income')

evaluates to

[ [100000, 120000],
  [200000, 240000],
  [300000, 360000] ]

Both the arguments to the operation and the result can be used in more complex expressions. For example, if we wanted to give everyone a $5000 income boost, and also scale the result, this could be done using (household.income+5000)*gridcell.cost * 1.2.

As another example, the model specification from page [*] can be modified by using an expression for the interaction and taking its log:

>>> specification = EquationSpecification(
      variables=("gridcell.cost",
         "ln(urbansim.gridcell.cost*urbansim.household.income)"),
      coefficients=("costcoef", "cti_coef"))


next up previous index
Next: Using Aggregation and Disaggregation Up: Opus Variables Previous: Expression Names and Aliasing   Index
info (at) urbansim.org