Skip to content

Commit

Permalink
auto ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekyadav26 committed Sep 19, 2023
1 parent b392750 commit 9fb33ec
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
28 changes: 23 additions & 5 deletions activitysim/abm/models/auto_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,47 @@
import logging

import pandas as pd
from pydantic import validator

from activitysim.core import config, estimation, simulate, tracing, workflow
from activitysim.core.configuration.base import PreprocessorSettings, PydanticReadable
from activitysim.core.configuration.logit import LogitComponentSettings

logger = logging.getLogger(__name__)


class AutoOwnershipSettings(PydanticReadable):
"""
Settings for the `auto_ownership` component.
"""

SPEC: str = "auto_ownership.csv"
"""Filename for the auto ownership specification (csv) file."""


@workflow.step
def auto_ownership_simulate(
state: workflow.State,
households: pd.DataFrame,
households_merged: pd.DataFrame,
model_settings: AutoOwnershipSettings | None = None,
model_settings_file_name: str = "auto_ownership.yaml",
trace_label: str = "auto_ownership_simulate",
trace_hh_id: bool = False,
) -> None:
"""
Auto ownership is a standard model which predicts how many cars a household
with given characteristics owns
"""
trace_label = "auto_ownership_simulate"
model_settings_file_name = "auto_ownership.yaml"
model_settings = state.filesystem.read_model_settings(model_settings_file_name)
trace_hh_id = state.settings.trace_hh_id

if model_settings is None:
model_settings = AutoOwnershipSettings.read_settings_file(
state.filesystem,
model_settings_file_name,
)

estimator = estimation.manager.begin_estimation(state, "auto_ownership")
model_spec = state.filesystem.read_model_spec(file_name=model_settings["SPEC"])
model_spec = state.filesystem.read_model_spec(file_name=model_settings.SPEC)
coefficients_df = state.filesystem.read_model_coefficients(model_settings)
model_spec = simulate.eval_coefficients(
state, model_spec, coefficients_df, estimator
Expand Down
36 changes: 36 additions & 0 deletions docs/dev-guide/components/auto_ownership.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(component-auto-ownership)=
# Auto Ownership

```{eval-rst}
.. currentmodule:: activitysim.abm.models.auto_owenership
```

The auto ownership model selects a number of autos for each household in the simulation.
The primary model components are household demographics, zonal density, and accessibility.

## Structure

- *Configuration File*: `auto_ownership.yaml`
- *Core Table*: `households`
- *Result Field*: `auto_owenership`

This model is structured as nested logit model.

## Configuration

```{eval-rst}
.. autopydantic_model::
:inherited-members: BaseModel, PydanticReadable
:show-inheritance:
```

### Examples

- [Prototype MTC](https://github.com/ActivitySim/activitysim/blob/main/activitysim/examples/prototype_mtc/configs/auto_ownership.yaml)
- [Prototype ARC](https://github.com/ActivitySim/activitysim/blob/main/activitysim/examples/prototype_arc/configs/auto_ownership.yaml)

## Implementation

```{eval-rst}
.. autofunction:: auto_ownership
```

0 comments on commit 9fb33ec

Please sign in to comment.