Skip to content

Const

Constants used to create the full vocabulary of the dataset.

create_full_vocab(days_in_week, minutes, as_multiindex=True)

Create the full vocabulary of the dataset.

Parameters:

Name Type Description Default
days_in_week int

Number of days in the week.

required
minutes int

Number of minutes to discretize the hours by.

required
as_multiindex bool

Whether to return a multiindex or a list of strings.

True

Returns:

Type Description
MultiIndex | list[str]

The full vocabulary of the dataset. Either a MultiIndex or a list of strings.

Source code in latent_calendar/const.py
def create_full_vocab(
    days_in_week: int,
    minutes: int,
    as_multiindex: bool = True,
) -> pd.MultiIndex | list[str]:
    """Create the full vocabulary of the dataset.

    Args:
        days_in_week: Number of days in the week.
        minutes: Number of minutes to discretize the hours by.
        as_multiindex: Whether to return a multiindex or a list of strings.

    Returns:
        The full vocabulary of the dataset.
            Either a MultiIndex or a list of strings.

    """

    if not as_multiindex:
        return [
            format_dow_hour(day_of_week, hour)
            for day_of_week, hour in product(
                range(days_in_week), dicretized_hours(minutes)
            )
        ]

    return pd.MultiIndex.from_product(
        [range(days_in_week), dicretized_hours(minutes)], names=["day_of_week", "hour"]
    )

Comments