### Manual Installation of PyDaddy Source: https://github.com/tee-lab/pydaddy/wiki/Home Install PyDaddy by cloning the repository and running the setup.py script. This method is useful for development or when direct installation from source is needed. ```bash git clone https://github.com/tee-lab/PyDaddy.git cd PyDaddy python setup.py install ``` -------------------------------- ### Install PyDaddy Source: https://context7.com/tee-lab/pydaddy/llms.txt Install PyDaddy from PyPI, conda, or directly from GitHub for the latest development version. Verify the installation by checking the version. ```bash pip install pydaddy ``` ```bash conda install -c tee-lab pydaddy ``` ```bash pip install git+https://github.com/tee-lab/PyDaddy.git ``` ```python python -c "import pydaddy; print(pydaddy.__version__)" # Output: 1.1.1 ``` -------------------------------- ### Check Git Installation Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/installation.md Verify if Git is installed on your system. This is a prerequisite for installing the development version. ```bash git --version ``` -------------------------------- ### Install PyDaddy using pip Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/installation.md Install the latest release version of PyDaddy using pip. Ensure Python 3 is set up. ```bash pip install pydaddy ``` -------------------------------- ### Verify PyDaddy Installation Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/installation.md Open an IPython terminal and import PyDaddy to verify the installation. This should not throw any errors. ```python import pydaddy ``` -------------------------------- ### Get PyDaddy Command-line Help Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/usage.md Display help information for PyDaddy's command-line interface, including available options and flags. ```default pydaddy --help ``` -------------------------------- ### Install Development Version using pip Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/installation.md Install the latest development version of PyDaddy directly from the GitHub repository using pip. ```bash pip install git+https://github.com/tee-lab/PyDaddy.git ``` -------------------------------- ### Start Jupyter Notebook Server Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/usage.md Start a Jupyter notebook server to use PyDaddy through its Python interface. This command is used to launch the server locally. ```default jupyter notebook ``` -------------------------------- ### Install PyDaddy using conda Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/installation.md Install the release version of PyDaddy using conda from the tee-lab channel. ```bash conda install -c tee-lab pydaddy ``` -------------------------------- ### Install PyDaddy on Google Colab Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/usage.md Install PyDaddy in a Google Colab notebook environment using pip. This command sets up the library for use within the notebook's session. ```default %pip install git+https://github.com/tee-lab/PyDaddy.git ``` -------------------------------- ### Define and simulate data with non-polynomial functions Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/6_non_poly_function_fitting.ipynb Defines custom drift and diffusion functions and simulates time-series data using sdeint. This setup is used to test the recovery of non-polynomial functions. ```python def f(x, t): return np.cos(x) + 0.5 * np.sin(2 * x) def g(x, t): return 1 # Simulate and plot data t_inc = 0.01 timepoints = 1e5 tspan = np.arange(0, t_inc * timepoints, step=t_inc) data = sdeint.itoint(f=f, G=g, y0=0.1, tspan=tspan) ``` -------------------------------- ### Export Drift and Diffusion Estimates with `export_data` Source: https://context7.com/tee-lab/pydaddy/llms.txt Returns a pandas DataFrame of binned drift and diffusion estimates or saves them as a CSV file. Use `raw=True` to get unbinned, per-timestep estimates. ```python import pydaddy data, t = pydaddy.load_sample_dataset('model-data-scalar-pairwise') ddsde = pydaddy.Characterize(data, t=t, bins=20, show_summary=False) # Get binned (averaged) drift and diffusion as a DataFrame df = ddsde.export_data() print(df.columns.tolist()) # ['x', 'drift', 'diffusion'] print(df.head()) # x drift diffusion # 0 -0.9500 -0.019850 0.002431 # 1 -0.8500 -0.018210 0.005342 # ... # Save directly to CSV ddsde.export_data(filename='drift_diffusion.csv') # Get raw (unbinned, per-timestep) drift and diffusion df_raw = ddsde.export_data(raw=True) print(df_raw.columns.tolist()) # ['x', 'drift', 'diffusion'] ``` -------------------------------- ### Get Fit Diagnostics Source: https://github.com/tee-lab/pydaddy/wiki/Home Use ddsde.fit_diagnostics() to obtain the quality of fits for the fitted drift and diffusion functions. It prints fitted polynomials, standard errors, R-squared values, and R-squared values excluding outliers. ```python ddsde.fit_diagnostics() ``` -------------------------------- ### Load Sample Dataset and Initialize Characterize Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/5_exporting_data.ipynb Load a sample dataset and initialize the PyDaddy Characterize object for analysis. Ensure the dataset is in the correct format for scalar or vector input. ```python data, t = pydaddy.load_sample_dataset('model-data-vector-ternary') ddsde = pydaddy.Characterize(data, t, bins=20, show_summary=False) ``` -------------------------------- ### Load Sample Dataset and Initialize Characterize Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/2_getting_started_vector.ipynb Load a sample 2D vector dataset and initialize the Characterize object for drift-diffusion analysis. ```python data, t = pydaddy.load_sample_dataset('model-data-vector-ternary') ddsde = pydaddy.Characterize(data, t, bins=20) ``` -------------------------------- ### Initialize PyDaddy Characterize Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/4_sdes_from_simulated_timeseries.ipynb Initializes the PyDaddy Characterize object with the simulated time series data (x), time vector (t), and number of bins for analysis. This prepares PyDaddy to estimate the SDE functions. ```python ddsde = pydaddy.Characterize([x], t, bins=20) ``` -------------------------------- ### Check PyDaddy Version Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/installation.md Within an IPython terminal, check the installed PyDaddy version by accessing its __version__ attribute. ```python pydaddy.__version__ ``` -------------------------------- ### Initialize Characterize Object Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/8_example_cell_migration.ipynb Initialize the Characterize object with simulated data, time points, and binning information for subsequent estimation. ```python ddsde_sim = pydaddy.Characterize(data=sim, t=t_sim, bins=21) ``` -------------------------------- ### Load sample dataset Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/8_example_cell_migration.ipynb Loads the 'cell-data-cellhopping' sample dataset and its corresponding time information. ```python data, t = pydaddy.load_sample_dataset('cell-data-cellhopping') ``` -------------------------------- ### Load Sample Dataset in PyDaddy Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/datasets.md Use this function to load any of the available sample datasets. Replace `` with the specific dataset identifier. ```python pydaddy.load_sample_dataset() ``` -------------------------------- ### Run PyDaddy from Command Line Source: https://context7.com/tee-lab/pydaddy/llms.txt Generate an HTML analysis report from a CSV file using the `pydaddy` command-line tool. Specify column format and sampling interval as needed. ```bash # CSV with x, y, and time columns (specify column order with --column_format) pydaddy my_data.csv --column_format xyt ``` ```bash # Scalar data CSV with no timestamp column; provide sampling interval via -t pydaddy scalar_data.csv --column_format x -t 0.12 ``` ```bash # See all options pydaddy --help ``` -------------------------------- ### Initialize PyDaddy Characterize Object Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/1_getting_started.ipynb Load sample dataset and initialize a PyDaddy Characterize object with the data, time information, and number of bins for analysis. This object computes drift and diffusion and generates summary plots. ```python data, t = pydaddy.load_sample_dataset('model-data-scalar-pairwise') ddsde = pydaddy.Characterize(data, t, bins=20) ``` -------------------------------- ### Load Sample Dataset Source: https://github.com/tee-lab/pydaddy/wiki/Home Use load_sample_dataset(dataset_name) to load one of the six sample datasets included with the PyDaddy package. ```python load_sample_dataset(dataset_name) ``` -------------------------------- ### Load Sample Dataset in PyDaddy Source: https://context7.com/tee-lab/pydaddy/llms.txt Load one of six pre-packaged datasets for SDE analysis. Returns time series arrays and sampling interval. Available datasets include real fish schooling data and simulated models. ```python import pydaddy # Available dataset names: # 'fish-data-etroplus' - Real 2D fish schooling polarization data # 'cell-data-cellhopping' - 2D cell migration (position + velocity) # 'model-data-scalar-pairwise' - 1D simulated pairwise interaction # 'model-data-scalar-ternary' - 1D simulated ternary interaction # 'model-data-vector-pairwise' - 2D simulated pairwise interaction # 'model-data-vector-ternary' - 2D simulated ternary interaction # Scalar dataset: data is [x_array], t is sampling interval (float) data, t = pydaddy.load_sample_dataset('model-data-scalar-pairwise') print(type(data), len(data)) # 1 print(data[0].shape) # (N,) — numpy array of scalar observations print(t[:5]) # array of time stamps # Vector dataset: data is [x_array, y_array], t is float data, t = pydaddy.load_sample_dataset('model-data-vector-pairwise') print(len(data), t) # 2 0.12 ``` -------------------------------- ### pydaddy.characterize.load_sample_dataset Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/api.md Loads one of the sample datasets provided by PyDaddy. Available datasets include various types of fish, cell, and model data. ```APIDOC ## pydaddy.characterize.load_sample_dataset ### Description Load one of the sample datasets. For more details on the datasets, see [Sample Datasets](datasets.md#sample-datasets). Available data sets: ```default 'fish-data-etroplus' 'cell-data-cellhopping' 'model-data-scalar-pairwise' 'model-data-scalar-ternary' 'model-data-vector-pairwise' 'model-data-vector-ternary' ``` ### Parameters **name** (*str*) – name of the data set ### Returns * **data** (*list*) – timeseries data * **t** (*float, array*) – timescale ``` -------------------------------- ### pydaddy.characterize.Characterize Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/api.md Initializes a PyDaddy object for further analysis. It takes time series data and various optional parameters to configure the analysis and visualization. ```APIDOC ## pydaddy.characterize.Characterize ### Description Intialize a PyDaddy object for further analysis. ### Parameters * **data** (*list*) – Time series data to be analysed. data = [x] for scalar data and data = [x1, x2] for vector where x, x1 and x2 are of numpy.array object type * **t** (*float* *,* *array* *,* *optional* *(**default=1.0* *)*) – t can be either a float representing the time-interval between observations, or a numpy array containing the time-stamps of the individual observations (Note: PyDaddy only supports uniformly spaced time-series, even when time-stamps are provided). * **bins** (*int* *,* *optional* *(**default=20* *)*) – Number of bins for computing bin-wise averages of drift and diffusion (Binwise averages are used only for visualization.) * **show_summary** (*bool* *,* *optional* *(**default=True* *)*) – If true, a summary text and summary figure will be shown. * **Dt** (*int* *,* *optional* *(**default=1* *)*) – Subsampling factor for drift computation. When provided, the time-series will be sub-sampled by this factor while computing drift. * **dt** (*int* *,* *optional* *(**default=1* *)*) – Subsampling factor for diffusion computation. When provided, the time-series will be sub-sampled by this factor while computing diffusion. * **inc** (*float* *,* *optional* *(**default=0.01* *)*) – For scalar data, instead of specifying bins, the widths (increments) of the bins can also be provided. * **inc_x** (*float* *,* *optional* *(**default=0.1* *)*) – For vector data, instead of specifying bins, the widths (increments) of the bins can also be provided. inc_x is the increment in the x-dimension. * **inc_y** (*float* *,* *optional* *(**default=0.1* *)*) – For vector data, instead of specifying bins, the widths (increments) of the bins can also be provided. inc_y is the increment in the y-dimension. * **n_trials** (*int* *,* *optional* *(**default=1* *)*) – Number of trials, concatenated timeseries of multiple trials is used. ### Returns **output** – Daddy object which can be used for further analysis and visualization. See `pyaddy.daddy.Daddy` for details. ### Return type [pydaddy.daddy.Daddy](#pydaddy.daddy.Daddy) ``` -------------------------------- ### Initialize PyDaddy Characterize object Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/6_non_poly_function_fitting.ipynb Initializes the Characterize object from PyDaddy with the simulated data and time span. This object is used for fitting the drift and diffusion functions. ```python ddsde = pydaddy.Characterize([data], tspan) ``` -------------------------------- ### Initialize SDE Analysis with Characterize Source: https://context7.com/tee-lab/pydaddy/llms.txt Initialize a `Characterize` object with time series data to estimate drift and diffusion. Supports scalar (1-D) and vector (2-D) time series. Automatically prints a summary and displays a summary plot. ```python import pydaddy import numpy as np # --- Scalar (1-D) example --- data, t = pydaddy.load_sample_dataset('model-data-scalar-pairwise') # data must be a list containing one numpy array for scalar case ddsde = pydaddy.Characterize( data, t=t, # float (sampling interval) or array of timestamps bins=20, # number of bins for computing conditional averages Dt=1, # subsampling factor for drift computation dt=1, # subsampling factor for diffusion computation show_summary=True # print text summary + show summary figure ) # Output printed automatically: # | x range : (-1.0, 1.0) | # | x mean : 0.014 | # | Autocorr time (x) : 53 | # --- Vector (2-D) example --- data_vec, t_vec = pydaddy.load_sample_dataset('model-data-vector-pairwise') # data must be a list of two numpy arrays [x, y] for vector case ddsde_vec = pydaddy.Characterize( data_vec, t=t_vec, bins=15, Dt=1, dt=1, show_summary=False ) ``` -------------------------------- ### Initialize PolyFitBase Fitter Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/9_higher_dimensions.ipynb Initializes the PolyFitBase fitter with a specified sparsification threshold (0.5) and the custom library. The max_degree argument is ignored when a custom library is provided. ```python # Ignore the max_degree argument. While fitting with a custom library, this is not relevant. fitter = PolyFitBase(threshold=.5, max_degree=1, library=library) ``` -------------------------------- ### Import necessary libraries Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/6_non_poly_function_fitting.ipynb Imports the required libraries for PyDaddy, sdeint, and numpy operations. ```python import pydaddy import sdeint import numpy as np ``` -------------------------------- ### Import PyDaddy and Pandas Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/5_exporting_data.ipynb Import necessary libraries for PyDaddy analysis and data manipulation with Pandas. ```python import pydaddy import pandas as pd ``` -------------------------------- ### Import necessary libraries Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/4_sdes_from_simulated_timeseries.ipynb Imports the required libraries for numerical operations, plotting, PyDaddy, and SDE simulation. ```python import numpy as np import matplotlib.pyplot as plt import pydaddy import sdeint ``` -------------------------------- ### Load Sample Fish School Dataset Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/7_example_fish_school.ipynb Loads the 'fish-data-etroplus' sample dataset provided with PyDaddy. This dataset contains 2D time series polarization vector data for schooling fish. ```python data, t = pydaddy.load_sample_dataset('fish-data-etroplus') ``` -------------------------------- ### Load Sample Dataset and Characterize Data Source: https://context7.com/tee-lab/pydaddy/llms.txt Loads sample datasets for scalar and vector data, and characterizes them using the Characterize class. Demonstrates handling of concatenated time series and subsampling for noise autocorrelation. ```python trial1, _ = pydaddy.load_sample_dataset('model-data-scalar-pairwise') trial2, _ = pydaddy.load_sample_dataset('model-data-scalar-ternary') combined = [np.concatenate([trial1[0], trial2[0]])] ddsde_multi = pydaddy.Characterize(combined, t=1.0, n_trials=2, bins=20) ``` ```python ddsde_sub = pydaddy.Characterize(data, t=t, Dt=5, dt=5, bins=20) ``` -------------------------------- ### Import necessary libraries Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/9_higher_dimensions.ipynb Imports NumPy for numerical operations, Matplotlib for plotting, and relevant fitting functions from PyDaddy. ```python import numpy as np import matplotlib.pyplot as plt from pydaddy.fitters import * ``` -------------------------------- ### Characterize SDEs for Fish School Data Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/7_example_fish_school.ipynb Initializes the Characterize object with the loaded fish school data and time vector. The 'bins' parameter controls the resolution for SDE characterization. ```python ddsde = pydaddy.Characterize(data, t, bins=20) ``` -------------------------------- ### pydaddy.load_sample_dataset Source: https://context7.com/tee-lab/pydaddy/llms.txt Loads one of six pre-packaged datasets for SDE analysis. Returns the time series arrays and sampling interval. ```APIDOC ## pydaddy.load_sample_dataset ### Description Loads one of six pre-packaged datasets (real fish schooling data, simulated fish models, and cell migration trajectories) and returns the time series arrays and sampling interval. ### Parameters * **dataset_name** (str) - Required - The name of the dataset to load. Available names include: * 'fish-data-etroplus' * 'cell-data-cellhopping' * 'model-data-scalar-pairwise' * 'model-data-scalar-ternary' * 'model-data-vector-pairwise' * 'model-data-vector-ternary' ### Returns * **data** (list) - A list containing numpy arrays of observations. For scalar data, it's a list with one array. For vector data, it's a list with two arrays (e.g., [x, y]). * **t** (float or numpy.ndarray) - The sampling interval (float) or an array of timestamps. ``` -------------------------------- ### Inspect Analysis Parameters Source: https://context7.com/tee-lab/pydaddy/llms.txt Returns a dictionary of all parameters used in the analysis. Useful for verifying settings like sampling intervals and bin counts. ```python import pydaddy data, t = pydaddy.load_sample_dataset('model-data-scalar-pairwise') ddsde = pydaddy.Characterize(data, t=t, bins=20, Dt=2, dt=3, show_summary=False) params = ddsde.parameters() print(params) ``` -------------------------------- ### Fit G11 with Automatic Threshold Tuning Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/3_advanced_function_fitting.ipynb Fit the G11 component using a quadratic polynomial order and enable automatic tuning for the sparsification threshold. ```python G11 = ddsde.fit('G11', order=2, tune=True) print(G11) ``` -------------------------------- ### pydaddy.Characterize Source: https://context7.com/tee-lab/pydaddy/llms.txt The main entry point for SDE analysis. Accepts scalar or vector time series and returns a Daddy object with estimated drift and diffusion. Automatically prints a summary and displays a summary plot. ```APIDOC ## pydaddy.Characterize ### Description The main entry point. Accepts scalar or vector time series and returns a `Daddy` object with estimated drift and diffusion. Also prints a summary and displays a summary plot automatically. ### Parameters * **data** (list) - Required - A list containing numpy arrays of observations. For scalar data, it must be a list with one array. For vector data, it must be a list of two arrays (e.g., [x, y]). * **t** (float or numpy.ndarray) - Required - The sampling interval (float) or an array of timestamps. * **bins** (int) - Optional - The number of bins for computing conditional averages. Defaults to 20. * **Dt** (int) - Optional - The subsampling factor for drift computation. Defaults to 1. * **dt** (int) - Optional - The subsampling factor for diffusion computation. Defaults to 1. * **show_summary** (bool) - Optional - Whether to print a text summary and display a summary figure. Defaults to True. ### Returns * **ddsde** (object) - A `Daddy` object containing the estimated drift and diffusion coefficients. ``` -------------------------------- ### Run PyDaddy One-line Operation Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/usage.md Invoke PyDaddy from the command-line for a quick analysis of a specified CSV file. Use --column_format to specify the order of columns if they are not in the default x, y, t order. ```default pydaddy --column_format xyt ``` -------------------------------- ### Simulate time series using sdeint Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/4_sdes_from_simulated_timeseries.ipynb Simulates a time series using the specified drift (f) and diffusion (g) functions, initial condition (x0), and time span (t). It uses the Ito-Euler method for simulation. ```python t = np.arange(0, dt * timepoints, step=dt) x0 = 0.0 # Initial condition # Simulate a time series with the given drift and diffusion functions, and given parameters. x = sdeint.itoEuler(f=lambda x, t: f(x), G=lambda x, t: g(x), y0=x0, tspan=t) ``` -------------------------------- ### Fit G22 with Automatic Threshold Tuning Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/3_advanced_function_fitting.ipynb Fit the G22 component using a quadratic polynomial order and enable automatic tuning for the sparsification threshold. ```python G22 = ddsde.fit('G22', order=2, tune=True) print(G22) ``` -------------------------------- ### parameters Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/api.md Retrieve all parameters used for the analysis, both given and assumed. ```APIDOC ## parameters() ### Description Get all given and assumed parameters used for the analysis ### Returns * **params** – all parameters given and assumed used for analysis * **Return type:** dict, json ``` -------------------------------- ### Characterize drift and diffusion Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/8_example_cell_migration.ipynb Initializes the Characterize object with the loaded data and time information, specifying the number of bins for analysis. ```python ddsde = pydaddy.Characterize(data=data, t=t, bins=21) ``` -------------------------------- ### Visualize simulated time series Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/4_sdes_from_simulated_timeseries.ipynb Plots the first 1000 points of the simulated time series and a histogram of the entire series to visualize its distribution. This helps verify that the simulation is stable and has explored the state space. ```python fig, ax = plt.subplots(1, 2, figsize=(10, 5)) ax[0].plot(t[:1000], x[:1000]) ax[1].hist(x, bins=100, density=True) ax[0].set(xlabel='Time ($t$)', ylabel='$x(t)$') ax[1].set(xlabel='$x$', ylabel='Density') plt.show() ``` -------------------------------- ### Interactive Visualization (Daddy.drift, Daddy.diffusion, Daddy.cross_diffusion) Source: https://context7.com/tee-lab/pydaddy/llms.txt Displays interactive plots for drift and diffusion functions. For scalar data, shows 2-D line plots with a timescale slider. For vector data, shows 3-D surface plots with fitted curves overlaid. Allows setting y-axis limits and customizing slider options. ```python data, t = pydaddy.load_sample_dataset('model-data-scalar-pairwise') ddsde = pydaddy.Characterize(data, t=t, bins=20, show_summary=False) ddsde.fit('F', order=3, tune=True) ddsde.fit('G', order=3, tune=True) ``` ```python ddsde.drift() # interactive drift plot with Dt slider ddsde.diffusion() # interactive diffusion plot with dt slider ``` ```python ddsde.drift(limits=(-0.5, 0.5)) ``` ```python ddsde.drift(slider_timescales=[1, 2, 5, 10, 20]) ``` ```python data_v, t_v = pydaddy.load_sample_dataset('model-data-vector-pairwise') ddsde_v = pydaddy.Characterize(data_v, t=t_v, bins=15, show_summary=False) ddsde_v.fit('F1', order=3, tune=True) ddsde_v.fit('G11', order=2, tune=True) ``` ```python ddsde_v.drift() # shows F1 and F2 surfaces ddsde_v.diffusion() # shows G11 and G22 surfaces ddsde_v.cross_diffusion() # shows G12 and G21 cross-diffusion surfaces ``` ```python ddsde_v.drift(polar=True) ddsde_v.diffusion(polar=True) ``` -------------------------------- ### Perform Model Diagnostics Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/2_getting_started_vector.ipynb Run model diagnostics to check for self-consistency by re-estimating drift and diffusion from a simulated time series. ```python ddsde.model_diagnostics(oversample=5) ``` -------------------------------- ### Fit Function with Threshold Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/3_advanced_function_fitting.ipynb Fit a function with a specified order and threshold. This is a basic application of the fit function. ```python print(ddsde.fit('F1', order=3, threshold=0.05)) ``` -------------------------------- ### Daddy.parameters Source: https://context7.com/tee-lab/pydaddy/llms.txt Returns a dictionary of all parameters used in the analysis, including sampling intervals, bin counts, and subsampling factors. ```APIDOC ## Daddy.parameters ### Description Returns a dictionary of all parameters used in the analysis, including sampling intervals, bin counts, and subsampling factors. ### Method ```python params = ddsde.parameters() ``` ### Parameters This method does not accept any parameters. ### Request Example ```python params = ddsde.parameters() print(params) ``` ### Response #### Success Response - **params** (dict) - A dictionary containing all parameters used in the analysis. ``` -------------------------------- ### Fit the drift function using the custom library Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/6_non_poly_function_fitting.ipynb Fits the drift function ('F') using the provided custom library. The 'tune=False' and 'threshold=0.2' parameters control the fitting process. ```python F = ddsde.fit('F', library=library, tune=False, threshold=0.2) F ``` -------------------------------- ### Estimate Coefficients for fx Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/9_higher_dimensions.ipynb Fits the instantaneous drift component F[:, 0] against the trajectory data using the initialized fitter to estimate the coefficients of the drift function fx. The result is an array of coefficients corresponding to the custom library. ```python fx, _ = fitter.fit( xyz[:-1, :], F[:, 0] ) fx ``` -------------------------------- ### Fit Drift and Diffusion Models with Auto Tuning Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/1_getting_started.ipynb Fit drift ('F') and diffusion ('G') models with automatic threshold tuning. Useful when the optimal threshold is unknown. ```python F = ddsde.fit('F', order=3, tune=True) print(F) ``` ```python G = ddsde.fit('G', order=3, tune=True) print(G) ``` -------------------------------- ### Visualize drift and diffusion functions Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/4_sdes_from_simulated_timeseries.ipynb Plots the defined drift function f(x) and the squared diffusion function g(x)^2 over a specified range of x. This helps in understanding the underlying SDE before simulation. ```python # Range of x over which to plot: edit as appropriate. xs = np.linspace(-1.5, 1.5, 100) fig, ax = plt.subplots(1, 2, figsize=(10, 5)) ax[0].plot(xs, f(xs), lw=3) ax[1].plot(xs, g(xs) ** 2, lw=3) ax[0].set(xlabel='$x$', ylabel='$f(x)$', title='Drift ($f(x)$)') ax[1].set(xlabel='$x$', ylabel='$g^2(x)$', title='Diffusion ($g^2(x)$)') plt.show() ``` -------------------------------- ### simulate Source: https://github.com/tee-lab/pydaddy/blob/master/docs/source/api.md Generate simulated time-series based on the fitted SDE model. ```APIDOC ## simulate(t_int, timepoints, x0=None) ### Description Generate simulated time-series with the fitted SDE model. Generates a simulated timeseries, with specified sampling time and duration, based on the SDE model discovered by PyDaddy. The drift and diffusion functions should be fit using fit() function before using simulate(). ### Parameters * **t_int** (*float*) – Sampling time for the simulated time-series * **timepoints** (*int*) – Number of time-points to simulate * **x0** (*float* (scalar) or list of two floats (vector), default=None) – Initial condition. If no value is passed, 0 ([0, 0] for vector) is taken as the initial condition. ### Returns * **x** – Simulated timeseries with timepoints timepoints. ``` -------------------------------- ### Compare Original and Re-estimated Functions Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/8_example_cell_migration.ipynb Plot the original and re-estimated drift and diffusion functions to visually compare their behavior and assess model self-consistency. ```python xx, vv = np.meshgrid(np.linspace(-1, 1, 201), np.linspace(-1, 1, 201)) fig, ax = plt.subplots(1, 2, figsize=(16, 7), subplot_kw=dict(projection='3d')) ax[0].plot_wireframe(xx, vv, ddsde.F2(xx, vv), color='r', alpha=0.5, label='Original') ax[0].plot_wireframe(xx, vv, ddsde_sim.F2(xx, vv), alpha=0.5, label='Re-estimated') ax[1].plot_wireframe(xx, vv, ddsde.G22(xx, vv), color='r', alpha=0.5, label='Original') ax[1].plot_wireframe(xx, vv, ddsde_sim.G22(xx, vv), alpha=0.5, label='Re-estimated') ax[0].set(title='Drift', xlabel='$x$', ylabel='$v$', zlabel='$f(x, v)$') ax[1].set(title='Diffusion', xlabel='$x$', ylabel='$v$', zlabel='$g^2(x, v)$') plt.legend() plt.show() ``` -------------------------------- ### Fit Drift Function (F) with Auto Tuning Source: https://github.com/tee-lab/pydaddy/wiki/Home Fit the drift function (F) using sparse regression with automatic threshold tuning. The 'order' parameter specifies the maximum polynomial degree, and 'tune=True' enables automatic sparsification threshold selection. ```python # Fitting with automatic threshold tuning F = ddsde.fit('F', order=3, tune=True) print(F) ``` -------------------------------- ### Fit diffusion function (G) with tuning Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/4_sdes_from_simulated_timeseries.ipynb Estimates the diffusion function 'G' from the time series data using PyDaddy's fit method. It employs polynomial fitting with automatic tuning to determine the optimal model order. ```python G = ddsde.fit('G', order=4, tune=True) G ``` -------------------------------- ### Fit the diffusion function using the custom library Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/6_non_poly_function_fitting.ipynb Fits the diffusion function ('G') using the same custom library. Similar to fitting the drift, 'tune=False' and 'threshold=0.2' are used. ```python G = ddsde.fit('G', library=library, tune=False, threshold=0.2) G ``` -------------------------------- ### Perform SDE Model Self-Consistency Check with `model_diagnostics` Source: https://context7.com/tee-lab/pydaddy/llms.txt Simulates a new time series from the fitted SDE model and re-estimates drift and diffusion from it to confirm model self-consistency. Requires the `sdeint` package. Use `oversample` to improve simulation accuracy when `t_int` is large. ```python import pydaddy data, t = pydaddy.load_sample_dataset('model-data-scalar-pairwise') ddsde = pydaddy.Characterize(data, t=t, bins=20, show_summary=False) ddsde.fit('F', order=3, tune=True) ddsde.fit('G', order=3, tune=True) ddsde.model_diagnostics() # Printed output: # Drift: # Original: (-0.021 ± 0.002)x # Reestimated: (-0.020 ± 0.003)x # Diffusion: # Original: (0.039 ± 0.000) + (-0.039 ± 0.000)x^2 # Reestimated: (0.038 ± 0.001) + (-0.038 ± 0.001)x^2 # Use oversample to improve simulation accuracy when t_int is large ddsde.model_diagnostics(oversample=10) # Vector self-consistency check data_v, t_v = pydaddy.load_sample_dataset('model-data-vector-pairwise') ddsde_v = pydaddy.Characterize(data_v, t=t_v, bins=15, show_summary=False) ddsde_v.fit('F1', order=3, tune=True) ddsde_v.fit('F2', order=3, tune=True) ddsde_v.fit('G11', order=2, tune=True) ddsde_v.fit('G22', order=2, tune=True) ddsde_v.fit('G12', order=2, tune=True) ddsde_v.model_diagnostics() ``` -------------------------------- ### Visualize diffusion coefficients Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/8_example_cell_migration.ipynb Generates a visualization of the diffusion coefficients within specified limits to help determine suitable polynomial orders for fitting. ```python ddsde.diffusion(limits=[0, 0.1]) ``` -------------------------------- ### Import necessary libraries Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/8_example_cell_migration.ipynb Imports the PyDaddy library along with NumPy and Matplotlib for numerical operations and plotting. ```python import pydaddy import numpy as np import matplotlib.pyplot as plt ``` -------------------------------- ### `Daddy.simulate` — Generate Simulated Time Series Source: https://context7.com/tee-lab/pydaddy/llms.txt Generates a synthetic time series by numerically integrating the fitted SDE model. Requires `fit()` to have been called first, and the optional `sdeint` package. ```APIDOC ## `Daddy.simulate` — Generate Simulated Time Series Generates a synthetic time series by numerically integrating the fitted SDE model. Requires `fit()` to have been called first, and the optional `sdeint` package. ### Parameters - **t_int** (float) - The time interval between simulation steps. - **timepoints** (int) - The total number of time steps to simulate. - **x0** (float or list, optional) - The initial state of the system. For scalar SDEs, a float. For vector SDEs, a list of floats. Defaults to 0.0 for scalar and [0.0, 0.0] for vector. ### Example ```python import pydaddy import matplotlib.pyplot as plt data, t = pydaddy.load_sample_dataset('model-data-scalar-pairwise') ddsde = pydaddy.Characterize(data, t=t, bins=20, show_summary=False) ddsde.fit('F', order=3, tune=True) ddsde.fit('G', order=3, tune=True) # Simulate 50,000 time steps with sampling interval t_int=1 x_sim = ddsde.simulate(t_int=1.0, timepoints=50000, x0=0.0) print(x_sim.shape) # (50000,) plt.plot(x_sim[:1000]) plt.title('Simulated time series') plt.show() # Hack: override fitted functions with custom ones for targeted simulation import numpy as np ddsde.F = lambda x: -0.5 * x # custom drift ddsde.G = lambda x: 0.1 + 0.0 * x # custom constant diffusion x_custom = ddsde.simulate(t_int=0.5, timepoints=10000, x0=0.5) # Vector simulation data_v, t_v = pydaddy.load_sample_dataset('model-data-vector-pairwise') ddsde_v = pydaddy.Characterize(data_v, t=t_v, bins=15, show_summary=False) ddsde_v.fit('F1', order=3, tune=True) ddsde_v.fit('F2', order=3, tune=True) ddsde_v.fit('G11', order=2, tune=True) ddsde_v.fit('G22', order=2, tune=True) ddsde_v.fit('G12', order=2, tune=True) xy_sim = ddsde_v.simulate(t_int=0.12, timepoints=10000, x0=[0.0, 0.0]) print(xy_sim.shape) # (2, 10000) — row 0 is x, row 1 is y ``` ``` -------------------------------- ### Fit Diffusion Function (G) with Auto Tuning Source: https://github.com/tee-lab/pydaddy/wiki/Home Fit the diffusion function (G) using sparse regression with automatic threshold tuning. The 'order' parameter specifies the maximum polynomial degree, and 'tune=True' enables automatic sparsification threshold selection. ```python G = ddsde.fit('G', order=3, tune=True) print(G) ``` -------------------------------- ### Fit Functions with Specific Thresholds Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/3_advanced_function_fitting.ipynb Fit functions with specific orders and a common threshold value. Useful for comparing fits across different functions with a consistent sparsity level. ```python print(ddsde.fit('F1', order=3, threshold=0.03)) ``` ```python print(ddsde.fit('G11', order=2, threshold=0.03)) ``` -------------------------------- ### Define SDE model parameters and functions Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/4_sdes_from_simulated_timeseries.ipynb Sets simulation parameters like time step (dt) and total time points. Defines drift (f) and diffusion (g) functions for the SDE. Uncomment a model (A, B, C, or D) or define custom functions. ```python ## ------ Model A ------ dt = 0.01 timepoints = 100000 def f(x): return -x def g(x): return np.ones_like(x) * np.sqrt(2) ## ------ Model B ------ # dt = 0.001 # timepoints = 1000000 # def f(x): # return x - x ** 3 # def g(x): # return np.sqrt(2 * (1 + x ** 2)) ## ------ Model C ------ # dt = 0.01 # timepoints = 1000000 # def f(x): # return 2 * x - 3 * x ** 3 # def g(x): # return np.ones_like(x) * 0.5 ## ------ Model D ------ # dt = 0.01 # timepoints = 1000000 # def f(x): # return - x # def g(x): # return np.sqrt(2) * (1 - x ** 2) ``` -------------------------------- ### Fit Diffusion Function (G11) Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/8_example_cell_migration.ipynb Fit the diffusion function 'G11' with a specified order and threshold. This approximates one component of the diffusion process. ```python ddsde_sim.fit('G11', order=3, threshold=1) ``` -------------------------------- ### Display First Rows of DataFrame Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/5_exporting_data.ipynb Show the first few rows of the exported Pandas DataFrame to inspect the data. ```python df.head() ``` -------------------------------- ### Define a custom library of candidate functions Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/6_non_poly_function_fitting.ipynb Defines a list of lambda functions representing the candidate functions for fitting. Each function must accept a numpy array and return an array of the same shape. ```python library = [ lambda x: np.ones_like(x), # Each function in the library, when called with an np.array, should return an array of the same shape. lambda x: np.sin(x), lambda x: np.cos(x), lambda x: np.sin(2 * x), lambda x: np.cos(2 * x), lambda x: np.sin(3 * x), lambda x: np.cos(3 * x), ] ``` -------------------------------- ### Simulate time series Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/8_example_cell_migration.ipynb Simulates a time series using the 'simulate' function with the discovered drift (ddsde.F2) and diffusion (ddsde.G22) functions, a specified time interval, a large number of time points, and initial conditions for position and velocity. ```python t_sim = 0.001 sim = simulate(ddsde.F2, ddsde.G22, t_int=t_sim, timepoints=1000000, x0=0.1, v0=0.1) ``` -------------------------------- ### Print Fitted Drift and Diffusion Functions Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/1_getting_started.ipynb Access and print the discovered drift (F) and diffusion (G) functions after fitting. These are callable objects. ```python print(ddsde.F) ``` ```python print(ddsde.G) ``` -------------------------------- ### Simulate Lorenz Attractor Trajectory Source: https://github.com/tee-lab/pydaddy/blob/master/notebooks/9_higher_dimensions.ipynb Defines the Lorenz system dynamics and simulates a 3D trajectory with added Gaussian noise. This trajectory serves as the input data for SDE estimation. ```python def lorenz(xyz, *, s=10, r=28, b=8/3): x, y, z = xyz x_dot = s*(y - x) y_dot = r*x - y - x*z z_dot = x*y - b*z return np.array([x_dot, y_dot, z_dot]) sigma = 3 dt = 0.001 T = 100000 xyz = np.empty((T, 3)) xyz[0] = (0., 1., 1.05) for i in range(T - 1): xyz[i + 1] = xyz[i] + lorenz(xyz[i]) * dt + sigma * np.random.normal(size=(1, 3)) * np.sqrt(dt) # Plot ax = plt.figure().add_subplot(projection='3d') ax.plot(*xyz.T, lw=0.5) ax.set_xlabel("$x$") ax.set_ylabel("$y$") ax.set_zlabel("$z$") ax.set_title("Trajectory") plt.show() ```