microcalorimetry.math.fitting ============================= .. py:module:: microcalorimetry.math.fitting .. autoapi-nested-parse:: Analsysis functions for performing fitting using DataArrays. .. !! processed by numpydoc !! Functions --------- .. autoapisummary:: microcalorimetry.math.fitting.polyderive microcalorimetry.math.fitting.polyval microcalorimetry.math.fitting.polyfit microcalorimetry.math.fitting.polyval2 microcalorimetry.math.fitting.polyfit2 microcalorimetry.math.fitting.polysolve2 microcalorimetry.math.fitting.ordinary_least_squares Module Contents --------------- .. py:function:: polyderive(coeffs: xarray.DataArray, degree_dim: str = 'deg') -> xarray.DataArray Derive polynomial coefficients. :param coeffs: Coefficients along dim 'degree' as last dimension. :type coeffs: xr.DataArray :returns: **derivative** -- Derivative of the derived coefficients :rtype: xr.DataArray .. !! processed by numpydoc !! .. py:function:: polyval(coord: xarray.DataArray, coeffs: xarray.DataArray, degree_dim: str = 'deg') Evaluate a polynomial. :param coord: Array to evaluate :type coord: xr.DataArray :param coeffs: Coefficients along dim 'deg' as last dimension. :type coeffs: xr.DataArray :param degree_dim: Dimension that stores the degrees. The default is 'deg'. :type degree_dim: str, optional :returns: **val** -- Array of results of evaluated polynomial. :rtype: xr.DataArray .. !! processed by numpydoc !! .. py:function:: polyfit(xarr: xarray.DataArray, dim: str, deg: int) Polynomial fit a dataset. :param xarr: Data to fit. :type xarr: xr.DataArray :param dim: dimension to fit along. :type dim: str :param deg: degree of fit. :type deg: int :returns: **coeffs** -- Coefficients along dim 'degree' as last dimension. :rtype: xr.DataArray .. !! processed by numpydoc !! .. py:function:: polyval2(coeffs: xarray.DataArray, x: xarray.DataArray) Evaluate polynomial coefficients on x and y. coeffs x assumed to have dimension 'deg' with index corresponding to the power. I.E. deg = 2 is the coeffcient for c_2*x**2. :param coeffs: Coefficients along dimension 'deg'. Index of 'deg' corresponds to power of polynomial coefficient. coeffs should have shape (..., m) where m is the number of coefficients and (...) is the same shape as x. :type coeffs: xr.DataArray :param x: (..., n) shape, last dimension is the fit dimension. :type x: xr.DataArray. :returns: **y** -- x evaluated at polynomial coefficients shape (..., n) :rtype: xr.DataArray .. !! processed by numpydoc !! .. py:function:: polyfit2(x: xarray.DataArray, y: xarray.DataArray, deg: int, constrain_zero: bool = False, yunc: xarray.DataArray = None) Fit polynominal coefficients c_n for y = Sum(c_n * x^n) for n<=deg. :param x: (..., n) shape, last dimension is the fit dimension. :type x: xr.DataArray. :param y: (..., n) shape, last dimension is the fit dimension. Must be same shape as x. :type y: xr.DataArray. :param deg: Degree of polynomial fit. :type deg: int :param constrain_zero: Constrain fit to cross zero. :type constrain_zero: bool :param yunc: (n,) 1d-array. Uncertainty on the yvalues that is diagonalized and used as weighting in the ordinary least squares. If not provided, no weighting is used. :type yunc: xr.DataArray, optional :returns: **coeffs** -- Coefficients along dimension 'deg'. Index of 'deg' corresponds to power of polynomial coefficient. :rtype: xr.DataArray .. !! processed by numpydoc !! .. py:function:: polysolve2(coeffs: xarray.DataArray, y: xarray.DataArray) Solve's for solution to polynomial. Solve for x in y = Sum( c_n * x^n). :param coeffs: Coefficients with along last dimension called deg. Index is integer with ineteger value corresponding to coefficient degree. Shape (..., m) for degree m polynomial. The 0th degree coefficient can optionally be omitted. :type coeffs: xr.DataArray, :param y: Value to solve for solutions to polynomial at (if provided). Shape (..., n) where (...) matches the dimensions (...) in coeffs. Assumed to be zero if not provided. :type y: xr.DataArray, optional :returns: **result** -- Shape (..., n, m-1) solutions to polynomial equation at y. :rtype: xr.DataArray .. !! processed by numpydoc !! .. py:function:: ordinary_least_squares(X: xarray.DataArray, Y: xarray.DataArray, W: xarray.DataArray = None) -> xarray.DataArray Perform ordinary least squares on observation M and results y. This function is designed to operate on stacks of arrays,where the Last 2 dimensions of M are treated as regressor array and last 2 dimensions of Y are treated as the response matrix. Formulation follows the linear matrix formulation outlined in: https://en.wikipedia.org/wiki/Ordinary_least_squares. All dimensions '...' in (...,n,m) are treates as copies/stacks. It is assmued y has the same dimensions (...). Weight matrix defined as follows: https://online.stat.psu.edu/stat501/lesson/13/13.1 Typically a diagonal matrix of the uncertainties. :param X: With shape (...,n,m) :type X: xr.DataArray :param Y: With shape (...,n,1). :type Y: xr.DataArray :param W: Weight matrix with shape (..., n,m). If none is provide, identity matrix is used (i.e. no weighting). :type W: xr.DataArray, optional :returns: **coeff** -- Array of coefficiencts with dimensions (...,m) corresponding to the columns along dimension m in X. :rtype: xr.DataArray .. !! processed by numpydoc !!