### Install and Import MultiMin Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_functions_tutorial.ipynb This code block handles the installation and importing of the MultiMin library. It includes a check for Google Colab to manage installation and sets up the environment by creating a directory. It also provides an option to install the development version from GitHub. ```python try: from google.colab import drive %pip install -Uq multimin except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p gallery/ # Uncomment to install from GitHub (development version) ``` -------------------------------- ### Install MultiMin Library Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Installs the MultiMin library from a GitHub repository. This command is typically run in a Python environment like Colab. If not in Colab, the installation is skipped. ```bash # !pip install git+https://github.com/seap-udea/MultiMin.git ``` -------------------------------- ### Install MultiMin from Source (Bash) Source: https://github.com/seap-udea/multimin/blob/main/README.md Installs the MultiMin package by cloning the GitHub repository and using pip. For development, an editable installation is recommended. This method requires git and pip to be installed. ```bash git clone https://github.com/seap-udea/multimin cd multimin pip install . ``` ```bash cd multimin pip install -e . ``` -------------------------------- ### Install and Import MultiMin and Dependencies Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Installs the MultiMin package and its dependencies, including handling Google Colab specific installations. It also imports core libraries like matplotlib, plotly, and numpy for data handling and visualization. Sets up a figure prefix for saving plots. ```python try: from google.colab import drive %pip install -Uq multimin except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p gallery/ # Uncomment to install from GitHub (development version) # !pip install git+https://github.com/seap-udea/MultiMin.git ``` ```python import multimin as mn mn.show_watermark = True import matplotlib.pyplot as plt import plotly.graph_objects as go import numpy as np np.random.seed(1) deg = np.pi/180 import warnings warnings.filterwarnings("ignore") figprefix = "quickstart" ``` -------------------------------- ### Install MultiMin Library Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_functions_tutorial.ipynb Installs the MultiMin library from a GitHub repository. This command is typically run in a Python environment like a Jupyter Notebook or Colab. It ensures the library is available for use in subsequent code. ```bash # !pip install git+https://github.com/seap-udea/MultiMin.git ``` -------------------------------- ### Install and Import MultiMin Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Installs the MultiMin package using pip, with specific handling for Google Colab environments. It also sets up a directory for galleries and enables autoreload for development. ```python try: from google.colab import drive %pip install -Uq multimin except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p gallery/ ``` -------------------------------- ### Install and Import MultiMin Package (Python) Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_mog_tutorial.ipynb Installs the MultiMin package and necessary libraries for use in Google Colab or local environments. It also sets up a directory for gallery images and imports core modules for plotting and data handling. ```python try: from google.colab import drive %pip install -Uq multimin except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p gallery/ # Uncomment to install from GitHub (development version) # !pip install git+https://github.com/seap-udea/MultiMin.git ``` ```python import multimin as mn mn.show_watermark = True import matplotlib.pyplot as plt import plotly.graph_objects as go from IPython.display import Markdown, display import numpy as np np.random.seed(1) deg = np.pi/180 import warnings warnings.filterwarnings("ignore") figprefix = "mog" ``` -------------------------------- ### Install and Import MultiMin Package Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_truncated_tutorial.ipynb Installs the MultiMin package and necessary libraries. It includes conditional logic for Google Colab and provides an option to install the development version from GitHub. Imports core MultiMin functionalities and plotting tools. ```python try: from google.colab import drive %pip install -Uq multimin except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p gallery/ # Uncomment to install from GitHub (development version) # !pip install git+https://github.com/seap-udea/MultiMin.git ``` ```python import multimin as mn import numpy as np import matplotlib.pyplot as plt from IPython.display import Markdown, display import warnings warnings.filterwarnings("ignore") figprefix = "truncated" ``` -------------------------------- ### List Available MultiPlot Methods (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Displays a list of available methods for the MultiPlot class. This is a utility function to understand the plotting and manipulation capabilities offered by MultiPlot. ```python mn.MultiPlot.describe() ``` -------------------------------- ### Create and Print Univariate Gaussian Mixture (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Initializes a MixtureOfGaussians object with two univariate Gaussian components and prints its summary. This demonstrates the basic structure and parameters of a univariate MoG. ```python MoG = mn.MixtureOfGaussians( mus=[0.0, 2.5], Sigmas=[1.0, 0.25], weights=[0.5, 0.5] ) print(MoG) ``` -------------------------------- ### Install MultiMin in Google Colab (Python/Bash) Source: https://github.com/seap-udea/multimin/blob/main/README.md Installs the MultiMin package within a Google Colab environment using pip. It supports installation from PyPI or directly from the GitHub repository. This method is suitable for users who need to run MultiMin in a cloud-based notebook environment. ```python !pip install -Uq multimin ``` ```bash pip install -Uq git+https://github.com/seap-udea/multimin ``` -------------------------------- ### Create and Plot Multi-Component Multivariate Gaussian Mixture (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Initializes and plots the PDF of a multivariate MixtureOfGaussians object with multiple components, specifying weights, means, and covariance matrices explicitly. This demonstrates the creation of more complex distributions. ```python weights=[0.1,0.9] mus=[[0,0],[5,5]] Sigmas=[[[1,0.2],[0,1]],[[1,0],[0,1]]] MND=mn.MixtureOfGaussians(mus=mus,weights=weights,Sigmas=Sigmas) print(MND) G = MND.plot_pdf( properties=["x", "y"], figsize=3, grid_size=400, colorbar=False, cmap="Spectral_r", marginals=True, ) plt.savefig(f'gallery/{figprefix}_2gauss_pdf.png') ``` -------------------------------- ### Install and Import MultiMin and Libraries (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_gmm.ipynb Installs the MultiMin package and imports necessary libraries like matplotlib, plotly, numpy, and IPython for data visualization and analysis. Includes a fallback for non-Colab environments. ```python try: from google.colab import drive %pip install -Uq multimin except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p gallery/ # Uncomment to install from GitHub (development version) # !pip install git+https://github.com/seap-udea/MultiMin.git ``` -------------------------------- ### Generate samples and plot PDF/contours (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Generates random samples from a fitted MixtureOfGaussians model and visualizes the probability density function (PDF) and contour plots. This snippet demonstrates sampling, scatter plotting, and contour plotting functionalities. ```python sample = MoG.rvs(10000) G=mn.MultiPlot(properties,figsize=5) sargs=dict(s=0.2,edgecolor='None',color='r') hist=G.sample_scatter(sample,**sargs) pargs=dict(cmap='Spectral_r') pdf=G.mog_pdf(MoG,colorbar=False, **pargs) cargs=dict(levels=10,decomp=True, legend=False) cont=G.mog_contour(MoG,**cargs) plt.savefig(f'gallery/{figprefix}_1gauss_sample_density.png') ``` -------------------------------- ### Plot Univariate Gaussian Mixture Sample (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Generates and plots a sample from a univariate MixtureOfGaussians distribution. It visualizes the distribution by plotting a histogram of the generated samples and saves the plot. ```python G = MoG.plot_sample( properties=["x"], sargs=dict(s=0.5, alpha=0.5), figsize=3 ) plt.savefig(f'gallery/{figprefix}_univariate_sample_hist.png') ``` -------------------------------- ### Create and Plot Multivariate Gaussian Mixture PDF (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Creates a multivariate MixtureOfGaussians object with one component and plots its PDF. This function visualizes the 2D distribution, including marginal distributions, and saves the plot. ```python MoG=mn.MixtureOfGaussians(ngauss=1,nvars=2) print(MoG) G = MoG.plot_pdf( properties=["x", "y"], figsize=3, grid_size=400, colorbar=False, cmap="Spectral_r", marginals=True, ) plt.savefig(f'gallery/{figprefix}_multivariate_1gauss_pdf.png') ``` -------------------------------- ### FitMoG: Set Initial Parameters for MoG Fitting Source: https://context7.com/seap-udea/multimin/llms.txt Explains how to control the starting point for the Mixture of Gaussians optimization by setting initial parameter values. This is particularly useful for complex distributions or when prior knowledge is available. Options include setting means, sigmas, and correlations directly, using broadcasted values, or initializing from a previously fitted MoG. ```python import numpy as np import multimin as mn # Create fitter F = mn.FitMoG(data=data, ngauss=3) # Option 1: Set initial means, sigmas, correlations directly F.set_initial_params( mus=[[0.2, 0.3], [0.5, 0.5], [0.8, 0.7]], # (ngauss, nvars) sigmas=[[0.1, 0.1], [0.2, 0.2], [0.1, 0.1]], # (ngauss, nvars) rhos=[[0.0], [0.3], [-0.2]] # Correlations (ngauss, nvars*(nvars-1)/2) ) # Option 2: Use same values for all components (broadcasts automatically) F.set_initial_params( mus=[0.5, 0.5], # Same mean for all 3 components sigmas=[0.2, 0.2] # Same sigma for all 3 components ) # Option 3: Initialize from an existing MoG F.set_initial_params(from_mog=previous_fitted_mog) F.fit_data() ``` -------------------------------- ### Generate a complex Gaussian spectrum (GaussPy adaptation) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_functions_tutorial.ipynb Generates a synthetic spectrum composed of multiple Gaussian components with varying amplitudes, FWHMs, and means, overlaid with Gaussian noise. This setup is used to create more complex spectral profiles for fitting. ```python import numpy as np import pickle def gaussian(amp, fwhm, mean): return lambda x: amp * np.exp(-4. * np.log(2) * (x-mean)**2 / fwhm**2) # Number of Gaussian functions per spectrum NCOMPS = 3 # Component properties AMPS = [3,2,1] FWHMS = [20,50,40] # channels MEANS = [220,250,300] # channels # Data properties RMS = 0.05 NCHANNELS = 512 # Initialize data = {} chan = np.arange(NCHANNELS) errors = np.ones(NCHANNELS) * RMS spectrum = np.random.randn(NCHANNELS) * RMS # Create spectrum for a, w, m in zip(AMPS, FWHMS, MEANS): spectrum += gaussian(a, w, m)(chan) ``` -------------------------------- ### Plot Multivariate Gaussian Mixture Sample and PDF (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Visualizes a sample from a multivariate MixtureOfGaussians distribution by plotting scatter points, histograms of marginals, and contour lines of the PDF. This provides a comprehensive view of the distribution and its samples. ```python MoG=mn.MixtureOfGaussians(ngauss=1,nvars=2) properties = dict( x=dict(label=r"$x$",range=None), y=dict(label=r"$y$",range=None), ) G = mn.MultiPlot(properties,figsize=3,marginals=True) sargs = dict(s=0.2,edgecolor='None',color='r') scat = G.sample_scatter(sample,**sargs) pargs = dict(cmap='Spectral_r') pdf = G.mog_pdf(MoG,**pargs) cargs = dict(levels=10,decomp=True,legend=False) cont = G.mog_contour(MoG, **cargs) plt.savefig(f'gallery/{figprefix}_2gauss_sample_density.png') ``` -------------------------------- ### Generate and fit a single Gaussian spectrum (GaussPy adaptation) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_functions_tutorial.ipynb Generates a synthetic spectrum with a single Gaussian component and adds Gaussian noise. It then fits this spectrum using a Gaussian Mixture Model with one component ('noisy_multimodal' mode). This example is adapted from the GaussPy tutorial. ```python # Code adapted from: https://github.com/gausspy/gausspy/blob/master/docs/tutorial.rst import numpy as np import pickle # create a function which returns the values of the Gaussian function for a # given x def gaussian(amp, fwhm, mean): return lambda x: amp * np.exp(-4. * np.log(2) * (x-mean)**2 / fwhm**2) # Data properties RMS = 0.05 NCHANNELS = 512 FILENAME = 'simple_gaussian.pickle' # Component properties AMP = 1.0 FWHM = 20 MEAN = 256 # Initialize data = {} chan = np.arange(NCHANNELS) errors = np.ones(NCHANNELS) * RMS spectrum = np.random.randn(NCHANNELS) * RMS spectrum += gaussian(AMP, FWHM, MEAN)(chan) fig = plt.figure() ax = fig.add_subplot(111) ax.plot(chan, spectrum, label='Data', color='black', linewidth=1.5) plt.savefig(f"gallery/{figprefix}_test_single_line.png") ``` ```python F = mn.FitFunctionMoG(data=(chan, spectrum), ngauss=1) F.fit_data( advance=10, mode='noisy_multimodal', ) fig = F.plot_fit() R2 = F.quality_of_fit() F.mog.tabulate() plt.savefig(f"gallery/{figprefix}_fit_test_single_line.png") ``` -------------------------------- ### Initialize MixtureOfGaussians with flattened parameters (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Initializes a MixtureOfGaussians object using a flattened list of parameters. This list can represent either covariance matrices or standard deviations and correlations. The `nvars` parameter specifies the number of random variables. ```python params = [0.1, 0.9, 0.0, 0.0, 5.0, 5.0, 0.8, 0.2, 1.0, 1.0, 0.0, 1.0] MoG = mn.MixtureOfGaussians(params=params,nvars=2) print(MoG) ``` -------------------------------- ### Install and Load MultiMin Package Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_asteroids_application.ipynb Installs the multimin package, either from PyPI or GitHub, and imports necessary libraries like pandas, numpy, and multimin. It also configures matplotlib and suppresses warnings. This setup is crucial for running the subsequent analysis. ```python import os import matplotlib.pyplot as plt os.makedirs('gallery', exist_ok=True) try: from google.colab import drive %pip install -Uq multimin except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p gallery/ # Uncomment to install from GitHub (development version) # !pip install git+https://github.com/seap-udea/MultiMin.git ``` ```python import pandas as pd import numpy as np import multimin as mn import warnings %matplotlib inline warnings.filterwarnings("ignore") figprefix="asteroids" ``` -------------------------------- ### Verify Multimin and GSL Installation Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_cmog.ipynb Verifies the installation of the Multimin package and its associated shared library. It also provides a command to install GSL if it's missing. ```bash !imultimin --verify ``` ```bash !imultimin --install-gsl ``` -------------------------------- ### Install and Load MultiMin Package (Python) Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_asteroids_application.ipynb Installs the multimin package and necessary libraries. It includes conditional logic for Google Colab environments and provides an option to install the development version from GitHub. It also sets up the plotting environment. ```python import os import matplotlib.pyplot as plt os.makedirs('gallery', exist_ok=True) try: from google.colab import drive %pip install -Uq multimin except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p gallery/ # Uncomment to install from GitHub (development version) # !pip install git+https://github.com/seap-udea/MultiMin.git ``` -------------------------------- ### Install MultiMin in Development Mode Source: https://github.com/seap-udea/multimin/blob/main/CONTRIBUTING.md Installs the MultiMin package in editable mode and its development dependencies. This allows you to make changes to the code and have them reflected immediately without reinstallation. ```bash pip install -e . pip install -r requirements-dev.txt ``` -------------------------------- ### Build Project Documentation Locally Source: https://github.com/seap-udea/multimin/blob/main/CONTRIBUTING.md Builds the project's documentation locally using the provided Makefile target. This allows you to preview documentation changes before submitting them. ```bash make docs ``` -------------------------------- ### Install and Import Multimin Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_cmog.ipynb Installs the Multimin package and imports necessary libraries like numpy and matplotlib. Includes conditional logic for Google Colab environments. ```python try: from google.colab import drive %pip install -Uq multimin except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p gallery/ # Uncomment to install from GitHub (development version) # !pip install git+https://github.com/seap-udea/MultiMin.git ``` -------------------------------- ### Import and Initialize MultiMin Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Imports necessary libraries including MultiMin, matplotlib, pandas, and numpy. It also sets up plotting configurations and suppresses warnings for cleaner output. ```python import multimin as mn mn.show_watermark = True import matplotlib.pyplot as plt import pandas as pd from scipy.interpolate import interp1d import numpy as np np.random.seed(1) deg = np.pi/180 import warnings warnings.filterwarnings("ignore") figprefix = "functions" ``` -------------------------------- ### Python Example: Advanced MultiMin Visualization Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_mog_gmm.ipynb An example demonstrating the advanced visualization capabilities of MultiMin, which are not available in scikit-learn. This snippet is intended to showcase MultiMin's unique plotting features. ```python # Example: Advanced MultiMin Visualization # This section would contain actual Python code demonstrating MultiMin's plotting functions. ``` -------------------------------- ### Running the MoG Fitting Procedure Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_tutorial.ipynb This snippet executes the fitting procedure for a FitMoG object. The `fit_data` method is called, and `progress='tqdm'` is used to display a progress bar during convergence, which is recommended for better visualization of the fitting process. ```python F.fit_data(progress="tqdm") ``` -------------------------------- ### Import Core Libraries for MultiMin Analysis Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_tutorial.ipynb Imports necessary libraries including MultiMin, Matplotlib, Plotly, IPython, and NumPy. It also sets a random seed for reproducibility and defines a degree conversion factor. ```python import multimin as mn mn.show_watermark = True import matplotlib.pyplot as plt import plotly.graph_objects as go from IPython.display import Markdown, display import numpy as np np.random.seed(1) deg = np.pi/180 import warnings warnings.filterwarnings("ignore") figprefix = "mog" ``` -------------------------------- ### Drop Gaussian Component and Refit Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Demonstrates how to manually drop a Gaussian component from a fitted model and then re-fit the data using the modified model. This allows for fine-tuning the fit by removing less significant components. It requires a pre-existing fit object. ```python import matplotlib.pyplot as plt import multimin as mn # Assuming 'F' is a previously fitted FitFunctionMoG object, 'chan', 'spectrum', and 'figprefix' are defined mog = F.mog.copy() mog.drop(2) F = mn.FitFunctionMoG(data=(chan, spectrum), ngauss=3) F.set_initial_params(from_mog=mog) F.fit_data(advance=10) R2 = F.quality_of_fit() fig = F.plot_fit(dargs=dict()) plt.savefig(f"gallery/{figprefix}_adaptive_fit_complex_line.png") ``` -------------------------------- ### Install and Import MultiMin Package Source: https://github.com/seap-udea/multimin/blob/main/examples/paper-codes.ipynb Installs the MultiMin package using pip, suitable for Google Colab environments. It also sets up autoreload for development and creates a 'gallery/' directory for saving figures. Dependencies include google.colab and multimin. ```python try: from google.colab import drive # noqa: F401 %pip install -Uq multimin except ImportError: print("Not running in Colab, skipping installation") %load_ext autoreload %autoreload 2 !mkdir -p gallery/ # Uncomment to install from GitHub (development version) # !pip install git+https://github.com/seap-udea/MultiMin.git figprefix = "paper" ``` -------------------------------- ### Save Data to File Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Saves data to a specified file, overwriting existing content. This is useful for preparing datasets for analysis. ```python %%file gallery/DSR-schema-TR_148.dat tau, ISR 0.6097656250000227, 0.005664062500000178 85.88125000000002, 0.005395507812500533 157.19921875000006, 0.005170898437500515 203.70742187499997, 0.010693359375000266 225.40234375, 0.027631835937500515 239.32421875000006, 0.0786083984374999 247.01640625, 0.1749560546875002 254.69453125, 0.29397949218750075 259.24023437499994, 0.46403320312500007 265.30820312500003, 0.6794335937500002 272.8175781250001, 1.0705664062500004 278.7765625, 1.4617041015625 283.1746093750001, 1.8698535156250002 287.583203125, 2.26099609375 290.592578125, 2.4083789062500003 292.0867187500001, 2.4990771484375003 295.1453125, 2.5670947265625004 298.2250000000001, 2.6010986328125 301.346875, 2.5670751953125004 302.93945312500006, 2.4990429687500004 306.0894531249999, 2.4196679687500002 309.2816406250001, 2.272265625 315.72578125, 1.8810888671875003 320.63359375, 1.4672412109375004 323.9734374999999, 1.0817431640625002 333.52187499999997, 0.6848876953125003 336.75624999999997, 0.46945800781250036 343.059765625, 0.3050390625000001 347.7777343750001, 0.19731445312500018 352.4781249999999, 0.11793457031250032 360.26875, 0.05555175781250021 369.59570312499994, 0.01583984375000025 378.9085937500001, -0.0011962890624999112 392.8410156249999, 0.03277343749999995 403.655078125, 0.0950976562500001 412.90820312500006, 0.1744335937499999 422.14375, 0.2821142578125002 429.8289062500001, 0.3897998046875002 437.49999999999994, 0.5201611328125004 445.16406250000006, 0.6618603515625003 449.744921875, 0.7752246093750004 457.440625, 0.8659033203125004 462.06015625000003, 0.9169091796875004 468.2511718750001, 0.9338964843750004 474.47031250000015, 0.9055322265625003 479.14609375000003, 0.8658349609375007 486.94726562499994, 0.7864453125000006 494.77304687500003, 0.6673730468750003 502.61640625, 0.5199560546875004 510.45273437500003, 0.38387695312500014 521.38984375, 0.24778808593750012 536.974609375, 0.11735351562500052 554.078125, 0.03793457031250025 572.7074218750001, -0.0018066406249999112 592.8625000000002, -0.0018701171874999645 613.0035156250001, 0.02074218750000023 634.6878906250001, 0.054687500000000444 651.717578125, 0.09431640624999993 671.833984375, 0.1566113281249999 690.4000000000001, 0.21891113281249996 705.8828125, 0.2528759765625006 721.3832031249999, 0.25849609375000027 735.3437500000002, 0.24711425781250007 747.7609375, 0.2243994140625003 761.7390625, 0.18467285156250002 780.3753906250001, 0.13359375000000018 799.0082031250001, 0.08818359375000062 819.1878906250001, 0.04843749999999991 842.4613281249999, 0.020019531250000444 870.3789062500002, 0.0029248046875003375 906.0414062499999, -0.0028564453124997335 960.3050781249999, -0.003027343749999911 1026.9683593750003, 0.002431640625000675 1079.674609375, 0.013603515625000284 1174.24140625, 0.02464355468750057 ``` -------------------------------- ### Generate and Plot Squared Sine Function Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Creates a dataset representing a squared sine wave function and plots it using matplotlib. This demonstrates fitting trigonometric functions. ```python xs = np.linspace(0, 2*np.pi, 100) ys = np.sin(xs)**2 plt.plot(xs, ys) ``` -------------------------------- ### Generate and Plot Exponential Function Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_functions_tutorial.ipynb Generates data points for an exponential decay function (e^-x) and plots it using Matplotlib. This serves as an example of fitting a non-Gaussian function. ```python xs = np.linspace(0, 10, 100) ys = np.exp(-xs) plt.plot(xs, ys) ``` -------------------------------- ### Initialize and Run MoG Fit Source: https://github.com/seap-udea/multimin/blob/main/README.md Initializes the `FitMoG` handler with sample data and the expected number of Gaussian components, then runs the fitting procedure to estimate the MoG parameters. Uses the `scipy.optimize.minimize` function internally. The `progress='text'` argument provides convergence feedback. ```python import multimin as mn # Initialize the fitter F = mn.FitMoG(data=sample, ngauss=2) # Run the fit (using progress="text" for better convergence on complex models) F.fit_data(progress="text") ``` -------------------------------- ### Generate and Plot Exponential Decay Function Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Creates a dataset representing an exponential decay function and plots it using matplotlib. This serves as an example for fitting non-Gaussian functions. ```python xs = np.linspace(0, 10, 100) ys = np.exp(-xs) plt.plot(xs, ys) ``` -------------------------------- ### Fit Squared Sine with Ten Gaussians Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Fits the squared sine function using ten Gaussian components to improve the approximation accuracy. The fitting process is performed, and the fit is visualized. ```python F = mn.FitFunctionMoG(data=(xs, ys), ngauss=10) F.fit_data(advance=100, tol=1e-8, options=dict(maxiter=2000)) fig = F.plot_fit() R2 = F.quality_of_fit() ``` -------------------------------- ### Save Data to File Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_functions_tutorial.ipynb Saves the provided data to a specified file. This is useful for preparing datasets for further analysis or for version control. ```python %%file gallery/DSR-schema-TR_148.dat tau,ISR 0.6097656250000227, 0.005664062500000178 85.88125000000002, 0.005395507812500533 157.19921875000006, 0.005170898437500515 203.70742187499997, 0.010693359375000266 225.40234375, 0.027631835937500515 239.32421875000006, 0.0786083984374999 247.01640625, 0.1749560546875002 254.69453125, 0.29397949218750075 259.24023437499994, 0.46403320312500007 265.30820312500003, 0.6794335937500002 272.8175781250001, 1.0705664062500004 278.7765625, 1.4617041015625 283.1746093750001, 1.8698535156250002 287.583203125, 2.26099609375 290.592578125, 2.4083789062500003 292.0867187500001, 2.4990771484375003 295.1453125, 2.5670947265625004 298.2250000000001, 2.6010986328125 301.346875, 2.5670751953125004 302.93945312500006, 2.4990429687500004 306.0894531249999, 2.4196679687500002 309.2816406250001, 2.272265625 315.72578125, 1.8810888671875003 320.63359375, 1.4672412109375004 323.9734374999999, 1.0817431640625002 333.52187499999997, 0.6848876953125003 336.75624999999997, 0.46945800781250036 343.059765625, 0.3050390625000001 347.7777343750001, 0.19731445312500018 352.4781249999999, 0.11793457031250032 360.26875, 0.05555175781250021 369.59570312499994, 0.01583984375000025 378.9085937500001, -0.0011962890624999112 392.8410156249999, 0.03277343749999995 403.655078125, 0.0950976562500001 412.90820312500006, 0.1744335937499999 422.14375, 0.2821142578125002 429.8289062500001, 0.3897998046875002 437.49999999999994, 0.5201611328125004 445.16406250000006, 0.6618603515625003 449.744921875, 0.7752246093750004 457.440625, 0.8659033203125004 462.06015625000003, 0.9169091796875004 468.2511718750001, 0.9338964843750004 474.47031250000015, 0.9055322265625003 479.14609375000003, 0.8658349609375007 486.94726562499994, 0.7864453125000006 494.77304687500003, 0.6673730468750003 502.61640625, 0.5199560546875004 510.45273437500003, 0.38387695312500014 521.38984375, 0.24778808593750012 536.974609375, 0.11735351562500052 554.078125, 0.03793457031250025 572.7074218750001, -0.0018066406249999112 592.8625000000002, -0.0018701171874999645 613.0035156250001, 0.02074218750000023 634.6878906250001, 0.054687500000000444 651.717578125, 0.09431640624999993 671.833984375, 0.1566113281249999 690.4000000000001, 0.21891113281249996 705.8828125, 0.2528759765625006 721.3832031249999, 0.25849609375000027 735.3437500000002, 0.24711425781250007 747.7609375, 0.2243994140625003 761.7390625, 0.18467285156250002 780.3753906250001, 0.13359375000000018 799.0082031250001, 0.08818359375000062 819.1878906250001, 0.04843749999999991 842.4613281249999, 0.020019531250000444 870.3789062500002, 0.0029248046875003375 906.0414062499999, -0.0028564453124997335 960.3050781249999, -0.003027343749999911 1026.9683593750003, 0.002431640625000675 1079.674609375, 0.013603515625000284 1174.24140625, 0.02464355468750057 ``` -------------------------------- ### Get Callable Truncated MoG Function Source: https://github.com/seap-udea/multimin/blob/main/README.md Retrieves a callable Python function representing the fitted truncated Mixture of Gaussians PDF. This function can be used to evaluate the PDF at any point, respecting the defined domain constraints. ```python function, mog = F_1d.mog.get_function() # Example usage: # Evaluate the fitted PDF at a point inside the domain and outside the domain: # mog(0.5), mog(-0.2) ``` -------------------------------- ### Get Function from 3D MoG (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_cmog.ipynb This Python snippet retrieves the function representation of the previously defined 3D Mixture of Gaussians (MoG). This function can then be used for calculations or further analysis. ```python function, pymog = MoG_3d.get_function() ``` -------------------------------- ### Generate and Plot Mixture of Gaussians Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Creates a synthetic dataset representing a mixture of two Gaussian distributions. The generated data is then plotted using matplotlib. ```python mog = mn.MixtureOfGaussians(mus=[20, 30], Sigmas=[4, 6], weights=[5.3, 1.5], normalize_weights=False) xs = np.linspace(10, 50, 1000) ys = mog.pdf(xs) plt.plot(xs, ys) plt.show() ``` -------------------------------- ### Generate Multivariate Gaussian Mixture Sample (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Generates a random sample of a specified size from a multivariate MixtureOfGaussians object. This is a core function for obtaining data points from the defined distribution. ```python sample = MoG.rvs(10000) ``` -------------------------------- ### Generate LaTeX Parameter Table for Multivariate Gaussian Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_tutorial.ipynb This code snippet demonstrates how to generate a parameter table for a multivariate Gaussian model in LaTeX format. It utilizes a function `tabulate` from `F.mog` to format the output. The input is assumed to be a pre-defined model object `F.mog`. ```python latex_table = F.mog.tabulate(type='latex') ``` -------------------------------- ### Fit Data with Gaussian Mixture Model (Python) Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Initializes a Gaussian Mixture Model (MoG) fitter with provided data and a specified number of Gaussian components. It configures the model for fitting by setting the number of variables and grid points. ```python import multimin as mn F = mn.FitFunctionMoG(data=(taus148, ISRs148), ngauss=3) ``` -------------------------------- ### Get Multivariate Gaussian Mixture Model Function (Python) Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_asteroids_application.ipynb Retrieves a function representing a multivariate Gaussian mixture model based on predefined properties. This function can be used for density estimation or sampling. ```python function, mog = F.mog.get_function(properties=properties) ``` -------------------------------- ### Generate and Plot Squared Sine Function Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_functions_tutorial.ipynb Generates data points for a squared sine function (sin(x)^2) and plots it using Matplotlib. This is another example of a non-Gaussian function to be fitted. ```python xs = np.linspace(0, 2*np.pi, 100) ys = np.sin(xs)**2 plt.plot(xs, ys) ``` -------------------------------- ### Initialize Univariate Mixture of Gaussians (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_tutorial.ipynb Creates a Mixture of Gaussians (MoG) with two univariate Gaussian components. It specifies the means (mus), variances (Sigmas), and weights of each component. This is a foundational step for defining simple probability distributions. ```python MoG = mn.MixtureOfGaussians( mus=[0.0, 2.5], Sigmas=[1.0, 0.25], weights=[0.2, 0.8] ) ``` -------------------------------- ### Fit Squared Sine with Two Gaussians Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_functions_tutorial.ipynb Fits the squared sine function using two Gaussian components. The fitting process is executed, and the resulting fit is visualized. ```python F = mn.FitFunctionMoG(data=(xs, ys), ngauss=2) F.fit_data(advance=100, tol=1e-8, options=dict(maxiter=2000)) fig = F.plot_fit() R2 = F.quality_of_fit() ``` -------------------------------- ### Import Libraries and Setup for Comparison (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_gmm.ipynb Imports core libraries for the comparison, including MultiMin, matplotlib, plotly, numpy, and IPython. It also sets up a random seed for reproducibility and configures warning filters. ```python import multimin as mn mn.show_watermark = True import matplotlib.pyplot as plt import plotly.graph_objects as go from IPython.display import Markdown, display import numpy as np np.random.seed(1) deg = np.pi/180 import warnings warnings.filterwarnings("ignore") figprefix = "gmmcompare" ``` -------------------------------- ### Import Libraries and Initialize MultiMin Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_functions_tutorial.ipynb Imports necessary libraries including MultiMin, Matplotlib, Pandas, SciPy, and NumPy. It also sets up a watermark for MultiMin and configures NumPy for random seeding and degree conversion. Warnings are filtered to keep the output clean. ```python import multimin as mn mn.show_watermark = True import matplotlib.pyplot as plt import pandas as pd from scipy.interpolate import interp1d import numpy as np np.random.seed(1) deg = np.pi/180 import warnings warnings.filterwarnings("ignore") figprefix = "functions" ``` -------------------------------- ### Import Libraries and Initialize MultiMin Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_density_plot_tutorial.ipynb Imports core libraries for plotting and data manipulation, and initializes MultiMin with watermark display enabled. Sets up plot prefix and warning filters. ```python import multimin as mn mn.show_watermark = True import matplotlib.pyplot as plt import plotly.graph_objects as go import numpy as np import pandas as pd np.random.seed(1) deg = np.pi/180 import warnings warnings.filterwarnings("ignore") figprefix = "multiplot" ``` -------------------------------- ### Plot Univariate Gaussian Mixture PDF (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_quickstart.ipynb Plots the Probability Density Function (PDF) of a univariate MixtureOfGaussians object. This function is useful for visualizing the distribution without generating samples and saves the plot to a file. ```python G_pdf = MoG.plot_pdf( properties=["x"], figsize=3 ) G_pdf.fig.savefig(f"gallery/{figprefix}_univariate_pdf.png") ``` -------------------------------- ### Get Constrained MoG Function (Python) Source: https://github.com/seap-udea/multimin/blob/main/examples/multimin_cmog.ipynb This code snippet retrieves the Constrained Mixture of Gaussians (C-MoG) version of the defined 3D MoG. The `cmog=True` argument ensures that the function returned incorporates the domain constraints efficiently. ```python function, cmog = MoG_3d.get_function(cmog=True) ``` -------------------------------- ### Export Fitted Mixture of Gaussians Function (LaTeX) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_tutorial.ipynb Exports the fitted Mixture of Gaussians (MoG) model parameters (weights, means, and covariance matrices) in LaTeX format. This is useful for including the model definition in academic papers or reports. Dependencies include the multimin library and IPython.display. ```python function, _ = F.mog.get_function(type='latex') display(Markdown(function)) ``` -------------------------------- ### Get Compiled C-MoG Function from 3D MoG (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_cmog.ipynb This Python snippet retrieves the compiled version (C-MoG) of the function from the 3D Mixture of Gaussians (MoG) object. The 'cmog=True' argument enables the compilation for potentially faster execution. ```python function, cmog = MoG_3d.get_function(cmog=True) ``` -------------------------------- ### Combine Scatter, PDF, and Contours Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_density_plot_tutorial.ipynb This advanced example shows how to combine multiple plotting elements on a single MultiPlot figure. It adds a scatter plot of data, the PDF of a Mixture of Gaussians, and its contour lines, all with customizable arguments for each element and their marginals. ```python G=mn.MultiPlot(properties,figsize=2,marginals=True) sargs=dict(s=0.2,edgecolor='None',color='w') scatter=G.sample_scatter(data_neas,**sargs) pargs = dict(cmap='Spectral',margs=dict(color='b')) G.mog_pdf(mog,**pargs) cargs = dict(levels=10,margs=dict(color='b')) G.mog_contour(mog,**cargs) plt.savefig(f'gallery/{figprefix}_multiple_content.png') ``` -------------------------------- ### Generate and Plot Mixture of Gaussians (MoG) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_functions_tutorial.ipynb Creates a Mixture of Gaussians (MoG) function with specified means, sigmas, and weights. It then generates data points (xs, ys) for this function and plots it using Matplotlib. This serves as a test case for the fitting capabilities. ```python mog = mn.MixtureOfGaussians(mus=[20, 30], Sigmas=[4, 6], weights=[5.3, 1.5], normalize_weights=False) xs = np.linspace(10, 50, 1000) ys = mog.pdf(xs) plt.plot(xs, ys) plt.show() ``` -------------------------------- ### Plot Mixture of Gaussians PDF Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_density_plot_tutorial.ipynb This example shows how to plot the probability density function (PDF) of a Mixture of Gaussians on a MultiPlot object. It initializes MultiPlot with marginals, defines plotting arguments for the PDF (colormap), and then calls the 'mog_pdf' method with the MoG object. ```python G=mn.MultiPlot(properties,figsize=2,marginals=True) pargs = dict(cmap='Spectral') G.mog_pdf(mog,**pargs) plt.savefig(f'gallery/{figprefix}_sample_mog.png') ``` -------------------------------- ### Export Fitted Mixture of Gaussians Function (Python) Source: https://github.com/seap-udea/multimin/blob/main/docs/examples/multimin_mog_tutorial.ipynb Retrieves the fitted Mixture of Gaussians (MoG) probability density function (PDF) as both explicit Python code and a callable function. This allows for further programmatic use or analysis of the fitted model. Dependencies include the multimin library. ```python code, pymog = F.mog.get_function(cmog=False) ```