Generate
Generate some fake data for various purposes.
LatentCalendarSampler
Sampler for generating synthetic calendar data from a fitted LatentCalendar model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
a fitted LatentCalendar model |
required | |
random_state
|
int | None
|
seed for reproducibility |
None
|
concentration_scale
|
float
|
scale for Gamma-perturbing each user's Dirichlet concentration before sampling mixture weights. 1.0 (default) means no perturbation. Values > 1.0 increase variance across users. |
1.0
|
Example
model = LatentCalendar(n_components=5).fit(X) sampler = model.create_sampler(random_state=42) df_weights, df_events = sampler.sample(n_samples=[10, 5, 20])
Source code in latent_calendar/generate.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
sample(n_samples)
Sample synthetic calendar events from the fitted model.
Component mixture weights for each user are drawn from the population-level Dirichlet prior derived from the fitted model's component distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
Union[int, list[int], ndarray]
|
number of events per user. A single int produces one user with that many events. A list/array produces one user per element. |
required |
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, DataFrame]
|
Tuple of: - df_weights: mixture weight DataFrame (n_users, n_components) - df_events: event count DataFrame (n_users, n_time_slots) |
Source code in latent_calendar/generate.py
sample_events(n)
Sample events for a single user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
number of events to draw |
required |
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, DataFrame]
|
Tuple of: - df_weights: mixture weight DataFrame (1, n_components) - df_events: event count DataFrame (1, n_time_slots) |
Source code in latent_calendar/generate.py
sample_from_latent_calendar(model, n_samples, random_state=None, concentration_scale=1.0)
Sample synthetic calendar data from a fitted LatentCalendar model.
Convenience wrapper around :class:LatentCalendarSampler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
fitted LatentCalendar model |
required | |
n_samples
|
Union[int, list[int], ndarray]
|
number of events per user. A single int produces one user with that many events. A list/array produces one user per element. |
required |
random_state
|
int | None
|
seed for reproducibility |
None
|
concentration_scale
|
float
|
scale for Gamma-perturbing each user's Dirichlet concentration before sampling mixture weights. 1.0 (default) means no perturbation. Values > 1.0 increase variance across users. |
1.0
|
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, DataFrame]
|
Tuple of: - df_weights: mixture weight DataFrame (n_users, n_components) - df_events: event count DataFrame (n_users, n_time_slots) |
Source code in latent_calendar/generate.py
sample_from_lda(components_prior, components_time_slots_prior, n_samples, random_state=None)
Deprecated. Use :func:sample_from_latent_calendar instead.
.. deprecated::
sample_from_lda has been removed. Build a :class:~latent_calendar.model.latent_calendar.DummyModel
from a prior and use :func:sample_from_latent_calendar instead.
Source code in latent_calendar/generate.py
wide_format_dataframe(n_rows, rate=1.0, random_state=None)
Generate some data from Poisson distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_rows
|
int
|
number of rows to generate |
required |
rate
|
float
|
rate parameter for Poisson distribution |
1.0
|
random_state
|
int | None
|
random state for reproducibility |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with columns from FULL_VOCAB and n_rows rows |