neurotools.stats.circular module

Functions for circular statistics.

neurotools.stats.circular.logpolar_gaussian(frame, doplot=False)[source]

Generates major and minor axis and one-sigma ellipse contours for a log-polar complex Gaussian. Contours are returned as lists of complex numbers.

Parameters:
  • frame (np.array) – Complex-valued polar data to model

  • doplot (bool) – Whether to generate a plot of the resulting distribution

Returns:

  • axis 1 (np.array)

  • axis 2 (np.array)

  • 1-sigma ellipse (np.array)

neurotools.stats.circular.complex_gaussian(frame, doplot=False)[source]

Generate axis and 1-sigma contour for a complex gaussian distribution

Parameters:
  • frame (np.array) – Complex-valued polar data to model

  • doplot (bool) – Whether to generate a plot of the resulting distribution

Returns:

  • axis1 – Path for axis 1, encoded as z=x+iy

  • axis2 – Path for axis 2, encoded as z=x+iy

  • circle – Path for 1-sigma radius ellipse, encoded as z=x+iy

neurotools.stats.circular.logpolar_stats(frame, doplot=False)[source]

Generate summary statistics for a log-polar Gaussian distribution

Parameters:
  • frame (np.array) – Complex-valued polar data to model

  • doplot (bool) – Whether to generate a plot of the resulting distribution

Returns:

  • circle – Path for 1σ ellipse, encoded as z=x+iy.

  • arc – Path for angular arc, encoded as z=x+iy.

  • radial – Path for radial line, encoded as z=x+iy.

neurotools.stats.circular.abspolar_stats(frame, doplot=False)[source]

Generate summary statistics for a polar Gaussian distribution

Parameters:
  • frame (np.array) – Complex-valued polar data to model

  • doplot (bool) – Whether to generate a plot of the resulting distribution

Returns:

  • circle – Path for 1σ ellipse, encoded as z=x+iy.

  • arc – Path for angular arc, encoded as z=x+iy.

  • radial – Path for radial line, encoded as z=x+iy.

neurotools.stats.circular.squared_first_circular_moment(samples, axis=-1, unbiased=True, dof=None)[source]

Compute squared first circular moment

Parameters:
  • samples (np.array) – Complex-valued polar data to model

  • axis (int, default=-1) – Axis over which to compute moment

  • unbiased (bool, default=True) – Whether to apply a bias correction (small samples can have smaller circular variance than expected)

  • dof (int, defualts to None) – Optional degrees of freedome correction. If None, then the number of samples minus one will be used as the degrees of freedoms

Returns:

squared_average – Squared first circular moment

Return type:

float

neurotools.stats.circular.fit_vonmises(z)[source]

Fit a vonMises distribution using circular moments.

Parameters:

samples (np.array) – Complex-valued polar data to model

Returns:

  • location – von Mises location parameter μ

  • theta – Sample circular mean of the provided data.

  • scale – von Mises location parameter κ

neurotools.stats.circular.wrapped_circular_linear_error(x, xh, units='degrees', mode='L1')[source]

Compute error for polar measurements, wrapping the circular variable appropriately.

Parameters:
  • x (array-like) – true valies (in degrees)

  • hx (array-like) – estimated values (in degrees)

  • units (str, default "degrees") – Polar units to use. Either “radians” or “degrees”

  • mode (str, default 'L1') – Error method to use. Either ‘L1’ (mean absolute error) or ‘L2’ (root mean-squared error)

Returns:

Circularly-wrapped error

Return type:

err

neurotools.stats.circular.asunit(x)[source]
neurotools.stats.circular.circvar(x)[source]
neurotools.stats.circular.circwrap(x1)[source]
neurotools.stats.circular.circmce(x1, x2)[source]
neurotools.stats.circular.circdelta(x1, x2)[source]
neurotools.stats.circular.circmean(x)[source]
neurotools.stats.circular.circcenter(x)[source]
neurotools.stats.circular.circcorr(x1, x2)[source]
neurotools.stats.circular.circabsdelta(x1, x2)[source]
neurotools.stats.circular.degrees_to_survey_format(theta, mode='compass')[source]