pynol.utils¶
data_generator¶
- class pynol.utils.data_generator.LinearRegressionGenerator[source]¶
Bases:
DataGeneratorGenerate data for linear regression.
- generate_data(T: int, dimension: int, stage: int = 1, radius: float = 1.0, Gamma: float = 1.0, mu: float = 0.0, sigma: float = 0.05, seed: int | None = None)[source]¶
Generate linear data with with abrupt changing environment.
The synthetic data are generated as follows: at each round, the feature \(\varphi_t \in \mathbb{R}^d\) is is randomly generated from a ball with a radius of \(\Gamma\), i.e., \(\{\varphi \in \mathbb{R}^d \mid \lVert \varphi \rVert_2 \leq \Gamma\}\); the associated label is set as \(y_t = \varphi_t^\top x_t^* + \epsilon_t\), where \(\epsilon_t\) is a random Gaussian noise and \(x_t^*\) is the underlying model. The underlying model \(x_t^*\) is randomly sampled from a ball with a radius of \(R\). To simulate the non-stationary environments with abrupt changes. The total rounds are divided into \(S\) stages in which the underlying model is forced to be stationary.
- Parameters:
T (int) – Number of total rounds.
dimension (int) – Dimension of the feature.
stage (int) – Numbers of stages.
radius (float) – radius of the underlying model.
Gamma (float) – radius of the feature.
mu (float) – Mean (“center”) of the noise distribution.
sigma (float) – Standard deviation (spread or “width”) of the noise distribution. Must be non-negative.
seed (Optional) – Random seed to generate data.
plot¶
- pynol.utils.plot.plot(loss: ndarray, labels: list, cum: bool = True, title: str | None = None, file_path: str | None = None, x_label: str | None = 'Iteration', y_label: str | None = 'Cumulative Loss', loc: str = 'upper left', scale='linear')[source]¶
Visualize the results of multiple learners.:
- Parameters:
loss (numpy.ndarray) – Losses of multiple learners.
labels (list) – labels of learners.
cum (bool) – Show the cumulative loss or instantaneous loss.
title (str, optional) – Title of the figure.
file_path (str, optional) – File path to save the results.
x_lable (str, optional) – Label of \(x\) axis.
y_lable (str, optional) – Label of \(y\) axis.
loc (str, optional) – Location of the legend.
scale (str, optional) – Scale of the \(y\) axis, ‘linear’ or ‘log’.