sctk._pipeline.fit_gaussian
- sctk._pipeline.fit_gaussian(x, n_components=array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), threshold=0.05, xmin=None, xmax=None, plot=False, nbins=500, hist_bins=100) tuple
Fit a Gaussian mixture model to a 1D numpy array.
This function fits a Gaussian mixture model to a 1D numpy array using the specified number of components and threshold. It returns the lower and upper bounds of the fitted Gaussian distribution, as well as the fitted Gaussian mixture model.
- Parameters:
x – 1D numpy array to fit a Gaussian mixture model to.
n_components – Number of components to use for the Gaussian mixture model. The best GMM will be selected based on BIC.
threshold – Threshold value for determining the lower and upper bounds of the fitted Gaussian distribution.
xmin – Minimum value to use for the fitted Gaussian distribution. If not provided, this will be set to the minimum value of x.
xmax – Maximum value to use for the fitted Gaussian distribution. If not provided, this will be set to the maximum value of x.
plot – If True, plot the fitted Gaussian distribution.
nbins – Number of bins to use for the distribution of x.
hist_bins – Number of bins to use for the histogram of x in the plot.
- Returns:
Tuple containing the lower bound, upper bound, and Gaussian mixture model.
- Raises:
None. –
Examples
>>> import numpy as np >>> from sctk import fit_gaussian >>> x = np.random.normal(loc=0, scale=1, size=1000) >>> x_left, x_right, gmm = fit_gaussian(x, n_components=[2], threshold=0.1)