dlsmicro.backend.utils

dlsmicro.backend.utils.get_cross_validation_score(t, y, func, p0=None)[source]

Obtain the leave-one-out cross-validation score for a functional model of a data set over a given fitting window.

Parameters:
  • t (1-d array) – Length N vector of values for the independent variable of a dataset.
  • y (1-d array) – Length N vector of values for the dependent variable of a dataset.
  • func (callable function) – Model to fit the data against. Must be of the form f(t, p1, p2, …, pM) where t is the independent variable and p1, p2, …, pM is a set of M parameters to fit.
  • p0 (1-d array or list, optional) – Initial guesses for the M parameters to fit, [p1, p2, …, pM]
Returns:

cv – Leave-one-out cross-validation score for the model

Return type:

float

dlsmicro.backend.utils.laplace_merge(omega, G1, G2, G1_Fdirect, G2_Fdirect)[source]

Find the interval where the Laplace transform is valid over the frequency space and replace the Fourier transform data with the Laplace transform modulus.

Parameters:
  • omega (1-d array) – Vector of angular frequencies in units of rad/s
  • G1 (1-d array) – Storage modulus at angular frequencies omega in units of Pa calculated using Fourier transform
  • G2 (1-d array) – Loss modulus at angular frequencies omega in units of Pa calculated using Fourier transform
  • G1_Fdirect (1-d array) – Storage modulus at angular frequencies omega in units of Pa calculated using direct Laplace transform
  • G2_Fdirect (1-d array) – Loss modulus at angular frequencies omega in units of Pa calculated using direct Laplace transform
Returns:

  • G1_plot (1-d array) – Loss modulus at angular frequencies omega in units of Pa after merging Laplace and Fourier transform moduli
  • G2_plot (1-d array) – Storage modulus at angular frequencies omega in units of Pa after merging Laplace and Fourier transform moduli

dlsmicro.backend.utils.minimize_cv_error(t, y, twindows, func, p0=None)[source]

Find the fitting interval that minimizes the cross-validation error for a model fitted to a sub-interval of a dataset, given a set of possible intervals in the independent variable over which to perform the fit.

Parameters:
  • t (1-d array) – Length N vector of values for the independent variable of a dataset.
  • y (1-d array) – Length N vector of values for the dependent variable of a dataset.
  • twindows (List of len 2 lists) – List of the form [[t0, tend1], [t0, tend2], …] where [t0, tendi] represents the ith closed interval over which to fit the data set and find the cross-validation score.
  • func (callable function) – Model to fit the data against. Must be of the form f(t, p1, p2, …, pM) where t is the independent variable and p1, p2, …, pM is a set of M parameters to fit.
  • p0 (1-d array or list, optional) – Initial guesses for the M parameters to fit, [p1, p2, …, pM]
Returns:

  • twindow_min (List) – List of the form [t0, tend]’ where t0 and tend are the beginning and end of the closed interval in ``t` that provides the lowest cross-validation score for the fitted model
  • pmin (list) – Optimal parameters for fitting the model func to the data over the sub-interval twindow_min
  • CV_min (float) – Leave-one-out cross-validation error for the model func over the interval twindow_min