generate_continuous_piecewise_linear_data#

generate_continuous_piecewise_linear_data(slopes: float | list[float] | None = None, lengths: int | list[int] | ndarray | None = None, *, n_segments: int = 3, n_samples: int = 100, intercept: float = 0.0, noise_std: float = 1.0, seed: int | None = None, return_params: bool = False) DataFrame | tuple[DataFrame, dict][source][source]#

Generate a continuous piecewise linear signal with noise.

Parameters:
slopesfloat, list of floats, optional (default=None)

Slopes for each segment. They are recycled to match the number of segments specified by lengths or n_segments. If None, slopes alternate between 1.0 and -1.0.

lengthsint, list of int or np.ndarray, optional (default=None)

The segment lengths. There are three possible cases:

  1. list or numpy array: Custom set of segment lengths.

  2. int: Length of n_segments equal segments.

  3. None: Generate n_segments random segment lengths with a total sample size of n_samples.

n_segmentsint (default=3)

Number of segments to generate if lengths is an integer or None.

n_samplesint (default=100)

Total number of samples to generate if lengths is not specified.

interceptfloat, default=0

Starting intercept value.

noise_stdfloat, default=0.1

Standard deviation of the Gaussian noise to add.

seednp.random.Generator | int | None, optional

Seed for the random number generator or a numpy random generator instance. If specified, this ensures reproducible output across multiple calls.

return_paramsbool, optional (default=False)

If True, the function returns a tuple of the generated DataFrame and a dictionary with the parameters used to generate the data.

Returns:
pd.DataFrame

DataFrame with a single column containing the generated data.

dict, optional

If return_params is True, a dictionary containing the parameters used to generate the data, including:

  • n_segments: Number of segments.

  • n_samples: Total number of samples.

  • lengths: Segment lengths.

  • slopes: Slopes for each segment.

  • intercept: Intercept value.

  • noise_std: Standard deviation of the noise.

  • change_points: Indices where the slope changes.