metrics

class pydaddy.metrics.Metrics(**kwargs)

Bases: object

Helper/utility module

_R2(data, op, poly, k, adj=False)

R-square value between the predicted and expected values

Parameters
  • data (array) – depended variable values, expected values, data

  • op (array) – independent variable values

  • poly (numpy.poly1d) – numpy polynomial fitted object

  • k (int) – degree of the polynomial poly

  • adj (bool) – if True, use R2-adjusted method instead of R2

Returns

R2 – R2 or R2-adjusted depending upon ‘adj’ value

Return type

float

_R2_adj(data, op, poly, k)

Get R-squared adjusted parameter between data and fitted polynomial

Parameters
  • data (array) – depended variable values, expected values, data

  • op (array) – independent variable for which the data is defined

  • poly (numpy.poly1d) – numpy polynomial fitted object

  • k (int) – degree of polynomial

Returns

R2-adjusted – R2 adjusted parameter between data and fitted polynomial

Return type

folat

_closest_time_scale(time_scale, slider)

Gives closest matching time scale avaiable from the slider keys.

_combined_data_dict()

Get all drift and diffusion data in dictionary format.

_csv_header(prefix, file_name)

Generate headers for CSV file.

_divergence(a, b)

Get the divergence between two timeseries data, the divergence returned here is defined as follows: divergence = 0.5*(KL_divergence(p,q) + KL_divergence(q,p))

The probablity density of a and b input timeseries is calculated before finding the divergence.

Parameters
  • a (array) – observed timeseries data

  • b (array) – simulated timeseries data

Returns

divergence

Return type

float

_fit_plane(x, y, z, order=2)

Fits n-th order plane to data in the form z = f(x,y) where f(x,y) the best fit equation of plane for the data computed using least square method.

Parameters
  • x (2D array) – order parameter x

  • y (2D array) – order parameter y

  • z (2D array) – derrived drift or diffusion data

  • order (int) – order of the 2D plane to fit

Returns

A callable object takes in x and y as inputs and returns z = f(x,y), where f(x,y) is the fitted function of the plane.

Return type

pydaddy.metrics.Plane

_fit_poly(x, y, deg)

Fits polynomial of degree deg

Parameters
  • x (array) – independent variable

  • y (array) – depended variable

  • deg (int) – degree of the polynomial

Returns

  • poly (numpy.poly1d) – polynomial object

  • x (array) – values of x for where y in defined

Notes

The nan values in the input x and y (if any) will be ignored.

_fit_poly_sparse(x, y, deg, threshold=0.05, alpha=0, weights=None)

Fit a polynomial using sparse regression using STLSQ (Sequentially thresholded least-squares) :param x: (np.array) Independent and dependent variables :param y: (np.array) Independent and dependent variables :param deg: (int) Maximum degree of the polynomial :param threshold: (float) Threshold for sparse fit.

_get_data_from_slider(drift_time_scale=None, diff_time_scale=None)

Get drift and diffusion data from slider data dictionary, if key not valid, returns the data corresponding to closest matching one.

_get_data_range(x)

Get range of the values in x, (min(x), max(x)), rounded to 3 decimal places.

_get_num_points(drift_time_scale, diff_time_scale)
_get_stacked_data()

Get a dictionary of all (op_x, op_y, driftX, driftY, diffX, diffY) slider data stacked into numpy arrays.

_interpolate_missing(y, copy=True)

Interpolate missing data

Parameters
  • y (array) – data with missing (nan) values

  • copy (bool, optional(default=True)) – if True makes a copy of the input array object

Returns

y – interpolated data

Return type

array

_is_valid_slider_timescale_list(slider_list)

Checks if the given slider timescale lists contains valid entries

Parameters

slider_list (list, tuple) – timescales to include in the slider

Returns

True if all values are valid, else False

Return type

bool

_isnotebook()
_kl_divergence(p, q)

Calculates KL divergence between two probablity distrubitions p and q

Parameters
  • p (array) – distrubution p

  • q (array) – distrubution q

Returns

kl_divergence – kl divergence between p and q

Return type

float

_make_directory(p, i=1)

Recursively create directorie for a given path

Parameters

path (str) – destination path

Returns

path – path of created directory, same as input path.

Return type

str

_nan_helper(x)

Helper function used to handle missing data

Parameters

x (array) – data

Return type

callable function

_remove_nan(x, y)

Removes NaN’s by deleting the indices where both x and y have NaN’s

Parameters
  • x (array) – first input

  • y (array) – second input

Returns

x, y - with all nan’s removed

Return type

array

_rms(x)

Calculates root mean square error of x

Parameters

x (array) – input

Returns

rms – rms error

Return type

float

_save_csv(dir_path, file_name, data, fmt='%.4f', add_headers=True)

Save data to CSV file.

_stack_slider_data(d, slider_data, index)

Stack data from slider dictionary, corresponding to the given index, into columns of numpy array.

_zip_dir(dir_path)

Make ZIP file of the exported result.

class pydaddy.metrics.Plane(coefficients, order)

Bases: object

Create first or second order plane surfaces.

expr()