Segments
Create hand picked segments on the calendar.
Examples:
Create some segments for a calendar:
mornings = create_box_segment(
day_start=0, day_end=7, hour_start=6, hour_end=11, name="Mornings"
)
afternoons = create_box_segment(
day_start=0, day_end=7, hour_start=11, hour_end=16, name="Afternoons"
)
evenings = create_box_segment(
day_start=0, day_end=7, hour_start=16, hour_end=21, name="Evenings"
)
df_segments = stack_segments([
mornings,
afternoons,
evenings,
])
df_segments.cal.plot_by_row()
create_blank_segment_series()
create_box_segment(day_start, day_end, hour_start, hour_end, name=None)
Programmatically make segment of box described by inputs.
Source code in latent_calendar/segments/hand_picked.py
create_dow_segments()
Programmatically make the DOW segments.
Each row is just each day of the week.
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame in the df_segments wide format |
Source code in latent_calendar/segments/hand_picked.py
create_empty_template()
Create blank template in order
create_every_hour_segments()
Programmatically segments for every hour
Each row is just each time slot
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame in the df_segments wide format |
Source code in latent_calendar/segments/hand_picked.py
create_hourly_segment(start, end, name)
create_series_for_range(start, end)
Create a series for a range of hours with ones for those in range.
Source code in latent_calendar/segments/hand_picked.py
get_vocab_for_range(start, end)
Get the vocab for a range of hours.
stack_segments(segments)
Stack segments into a single dataframe.
Processing off calendar distribution.
sum_array_over_segments(X_pred, X_segment)
Get the probability of the mask for the probabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X_pred
|
ndarray
|
(nrows, n_times) |
required |
X_segment
|
ndarray
|
(n_segments, n_times) |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Matrix of (nrows, n_segments) defining the probabilities of each segments |
Source code in latent_calendar/segments/convolution.py
sum_next_hours(df, hours)
Sum the next hours columns.
Useful for finding probability of having tour in the next 5 hours 00 00 column would be 06 06 23
TODO: Consider if negative hours should be allowed TODO: Handle when minutes are not 60
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
DataFrame of probabilities or counts in wide format |
required |
hours
|
int
|
Number of hours to sum after the current hour |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame summed over the next hours |
Source code in latent_calendar/segments/convolution.py
sum_over_segments(df, df_segments)
Sum DataFrame over user defined segments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
DataFrame of probabilities or counts in wide format |
required |
df_segments
|
DataFrame
|
DataFrame of segments in wide format |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame of probabilities or counts summed over the segments |
Source code in latent_calendar/segments/convolution.py
sum_over_vocab(df, aggregation='dow')
Sum the wide DataFrame columns to hours or dow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
DataFrame in wide format with vocab column names |
required |
aggregation
|
str
|
either dow or hour |
'dow'
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame columns associated with the aggregation |