regressioninc.testing.complex module#
Functions for generating and visualising complex-valued testing data
- pydantic model regressioninc.testing.complex.ComplexGrid[source]#
Bases:
BaseModel
A class to generate a grid for complex data
Show JSON schema
{ "title": "ComplexGrid", "description": "A class to generate a grid for complex data", "type": "object", "properties": { "r1": { "title": "R1", "type": "number" }, "r2": { "title": "R2", "type": "number" }, "nr": { "title": "Nr", "type": "integer" }, "i1": { "title": "I1", "type": "number" }, "i2": { "title": "I2", "type": "number" }, "ni": { "title": "Ni", "type": "integer" } }, "required": [ "r1", "r2", "nr", "i1", "i2", "ni" ] }
- field r1: float [Required]#
Starting real pt
- field r2: float [Required]#
End real pt
- field nr: int [Required]#
Number of real pts
- field i1: float [Required]#
Start imaginary pt
- field i2: float [Required]#
End imaginary pt
- field ni: int [Required]#
Number of imaginary pts
- property n_pts: int#
Get the number of points grid
- Returns:
Number of points in grid
- Return type:
int
Examples
>>> from regressioninc.testing.complex import ComplexGrid >>> grid = ComplexGrid(r1=0, r2=5, nr=6, i1=0, i2=5, ni=6) >>> grid.n_pts 36
- grid() ndarray [source]#
Get the grid points as an 2-D array
- Returns:
The grid points as a 2-D array
- Return type:
np.ndarray
Examples
>>> from regressioninc.testing.complex import ComplexGrid >>> grid = ComplexGrid(r1=-1, r2=1, nr=3, i1=-1, i2=1, ni=3) >>> grid.grid() array([[-1.-1.j, -1.+0.j, -1.+1.j], [ 0.-1.j, 0.+0.j, 0.+1.j], [ 1.-1.j, 1.+0.j, 1.+1.j]])
- flat_grid() ndarray [source]#
Get the grid as a flat array
- Returns:
The grid of points as a 1-D flattened array
- Return type:
np.ndarray
Examples
>>> from regressioninc.testing.complex import ComplexGrid >>> grid = ComplexGrid(r1=-1, r2=1, nr=3, i1=-1, i2=1, ni=3) >>> grid.grid() array([[-1.-1.j, -1.+0.j, -1.+1.j], [ 0.-1.j, 0.+0.j, 0.+1.j], [ 1.-1.j, 1.+0.j, 1.+1.j]])
- regressioninc.testing.complex.generate_linear_grid(coef: ndarray, grids: list[regressioninc.testing.complex.ComplexGrid], intercept: complex = 0) tuple[numpy.ndarray, numpy.ndarray] [source]#
Generate complex regression data from coefficients and grids of regressors
- Parameters:
coef (np.ndarray) – The coefficients for the regressors
grids (list[ComplexGrid]) – The grid of points for each regressor
intercept (complex, optional) – The intercept, by default 0
- Returns:
X, y for the regression problem
- Return type:
tuple[np.ndarray, np.ndarray]
- Raises:
ValueError – If the number of grids provided does not equal the number of coefficients
ValueError – If the grids have different numbers of points
- regressioninc.testing.complex.generate_linear_random(coef: ndarray, n_samples: int, intercept: complex = 0, min_rand=-10, max_rand=10)[source]#
Produce complex data for testing without any noise
- regressioninc.testing.complex.add_gaussian_noise(data: ndarray, loc: tuple[float] | None = None, scale: tuple[float] | None = None) ndarray [source]#
Add Gaussian noise to data
- regressioninc.testing.complex.add_outliers(y: ndarray, outlier_percent: float = 5, mult_min=3, mult_max=5, random_signs_real: bool = False, random_signs_imag: bool = False) ndarray [source]#
Add outliers to a complex-valued 1-D observations array
- regressioninc.testing.complex.plot_observations(y: ndarray, size: int = 10, alpha: float = 1.0) None [source]#
Plot observation data
- regressioninc.testing.complex.plot_observations_original(y_orig: ndarray, size: int = 10, alpha: float = 1.0) None [source]#
Plot original observations, meant for data without noise
- regressioninc.testing.complex.plot_regressor(reg: ndarray, color: ndarray, size: int = 10, alpha: float = 1.0) None [source]#
Plot regression data
- regressioninc.testing.complex.plot_estimate(est: ndarray, color: ndarray, size: int = 10, alpha: float = 1.0, label: str = 'estimate') None [source]#
Plot model estimates
- regressioninc.testing.complex.plot_complex(X, y, models: dict[str, regressioninc.base.Regressor], y_orig: ndarray | None = None, size_obs: int = 10, size_reg: int = 10, size_est: int = 10)[source]#
Plot the complex data