Coverage for pygeodesy/fstats.py : 99%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
L{pygeodesy.Fsum}, precision floating point summation. ''' # make sure int/int division yields float quotient, see .basics
_0_0, _1_5, _2_0, _3_0, _4_0, _6_0 property_RO # from pygeodesy.props import property_RO # from .named # from pygeodesy.streprs import Fmt # from .fsums
# from math import sqrt # pow from .fmath
except NameError: # Python 3+ pass
'''(INTERNAL) Yield each value as C{float} or L{Fsum}. ''' if ys else _2float(index=i, xs=x))
'''(INTERNAL) Return the sample or the entire count. '''
'''(INTERNAL) Base class. '''
'''Sum of this and a scalar, an L{Fsum} or an other instance. '''
def __float__(self): # PYCHOK no cover '''Not implemented.''' return _NotImplemented(self)
def __int__(self): # PYCHOK no cover '''Not implemented.''' return _NotImplemented(self)
'''Return the I{total} number of accumulated values (C{int}). '''
def __neg__(self): # PYCHOK no cover '''Not implemented.''' return _NotImplemented(self)
def __radd__(self, other): # PYCHOK no cover '''Not implemented.''' return _NotImplemented(self, other)
'''Copy this instance, C{shallow} or B{C{deep}}. '''
'''(INTERNAL) Base running stats class. '''
'''(INTERNAL) Copy C{B{c} = B{s}}. '''
def fadd(self, xs, sample=False): # PYCHOK no cover '''(INTERNAL) I{Must be overloaded}, see function C{notOverloaded}. ''' notOverloaded(self, xs, sample=sample)
'''Accumulate and return the current count.
@see: Method C{fadd}. '''
'''Accumulate and return the current mean.
@kwarg xs: Iterable with additional values (C{Scalar}s).
@return: Current, running mean (C{float}).
@see: Method C{fadd}. ''' self.fadd(xs)
'''Accumulate and return the current mean.
@see: Method C{fmean}. '''
'''Accumulate and return the current standard deviation.
@kwarg xs: Iterable with additional values (C{Scalar}). @kwarg sample: Return the I{sample} instead of the entire I{population} value (C{bool}).
@return: Current, running (sample) standard deviation (C{float}).
@see: Method C{fadd}. '''
'''Accumulate and return the current standard deviation.
@see: Method C{fstdev}. '''
'''Accumulate and return the current variance.
@kwarg xs: Iterable with additional values (C{Scalar}s). @kwarg sample: Return the I{sample} instead of the entire I{population} value (C{bool}).
@return: Current, running (sample) variance (C{float}).
@see: Method C{fadd}. '''
'''Accumulate and return the current variance.
@see: Method C{fvariance}. '''
'''(INTERNAL) Add Scalar or Scalars. ''' else: raise TypeError(_SPACE_(_invalid_, _other_)) self.fadd(other) except Exception as x: raise _xError(x, _SPACE_(self, _iadd_, repr(other)))
'''(INTERNAL) get the 1st Moment accumulator.'''
'''(INTERNAL) get the 2nd Moment accumulator.'''
'''U{Cook<https://www.JohnDCook.com/blog/skewness_kurtosis>}'s C{RunningStats} computing the running mean, median and (sample) kurtosis, skewness, variance, standard deviation and Jarque-Bera normality.
@see: L{Fwelford} and U{Higher-order statistics<https:// WikiPedia.org/wiki/Algorithms_for_calculating_variance>}. ''' '''New L{Fcook} stats accumulator.
@kwarg xs: Iterable with initial values (C{Scalar}s). @kwarg name: Optional name (C{str}).
@see: Method L{Fcook.fadd}. '''
'''Add B{C{other}} to this L{Fcook} instance.
@arg other: An L{Fcook} instance or C{Scalar}s, meaning one or more C{scalar} or L{Fsum} instances.
@return: This instance, updated (L{Fcook}).
@raise TypeError: Invalid B{C{other}} type.
@raise ValueError: Invalid B{C{other}}.
@see: Method L{Fcook.fadd}. '''
# self._Ms = A1, A2, A3, A4 else: else:
'''Accumulate and return the current count.
@arg xs: Iterable with additional values (C{Scalar}s, meaning C{scalar} or L{Fsum} instances). @kwarg sample: Return the I{sample} instead of the entire I{population} value (C{bool}).
@return: Current, running (sample) count (C{int}).
@raise OverflowError: Partial C{2sum} overflow.
@raise TypeError: Non-scalar B{C{xs}} value.
@raise ValueError: Invalid or non-finite B{C{xs}} value.
@see: U{online_kurtosis<https://WikiPedia.org/wiki/ Algorithms_for_calculating_variance>}. ''' else:
# self._Ms = M1, M2, M3, M4
'''Accumulate and compute the current U{Jarque-Bera <https://WikiPedia.org/wiki/Jarque–Bera_test>} normality.
@kwarg xs: Iterable with additional values (C{Scalar}s). @kwarg sample: Return the I{sample} value (C{bool}), default. @kwarg excess: Return the I{excess} kurtosis (C{bool}), default.
@return: Current, running (sample) Jarque-Bera normality (C{float}).
@see: Method L{Fcook.fadd}. '''
'''Accumulate and compute the current U{Jarque-Bera <https://WikiPedia.org/wiki/Jarque–Bera_test>} normality.
@see: Method L{Fcook.fjb}. '''
'''Accumulate and return the current kurtosis.
@kwarg xs: Iterable with additional values (C{Scalar}s). @kwarg sample: Return the I{sample} instead of the entire I{population} value (C{bool}). @kwarg excess: Return the I{excess} kurtosis (C{bool}), default.
@return: Current, running (sample) kurtosis or I{excess} kurtosis (C{float}).
@see: U{Kurtosis Formula<https://www.Macroption.com/kurtosis-formula>} and U{Mantalos<https://www.researchgate.net/publication/ 227440210_Three_different_measures_of_sample_skewness_and_kurtosis_and_their_effects_on_the_JarqueBera_test_for_normality>}.
@see: Method L{Fcook.fadd}. '''
'''Accumulate and return the current kurtosis.
@see: Method L{Fcook.fkurtosis}. '''
'''Accumulate and return the current median.
@kwarg xs: Iterable with additional values (C{Scalar}s).
@return: Current, running median (C{float}).
@see: U{Pearson's Skewness Coefficients<https://MathWorld.Wolfram.com/ PearsonsSkewnessCoefficients.html>}, U{Skewness & Kurtosis Simplified https://TowardsDataScience.com/skewness-kurtosis-simplified-1338e094fc85>} and method L{Fcook.fadd}. ''' # skewness = 3 * (mean - median) / stdev, i.e. # median = mean - skewness * stdef / 3
'''Accumulate and return the current median.
@see: Method L{Fcook.fmedian}. '''
'''Accumulate and return the current skewness.
@kwarg xs: Iterable with additional values (C{Scalar}s). @kwarg sample: Return the I{sample} instead of the entire I{population} value (C{bool}).
@return: Current, running (sample) skewness (C{float}).
@see: U{Skewness Formula<https://www.Macroption.com/skewness-formula/>} and U{Mantalos<https://www.researchgate.net/publication/ 227440210_Three_different_measures_of_sample_skewness_and_kurtosis_and_their_effects_on_the_JarqueBera_test_for_normality>}.
@see: Method L{Fcook.fadd}. '''
'''Accumulate and return the current skewness.
@see: Method L{Fcook.fskewness}. '''
'''Return an L{Fwelford} equivalent. '''
'''U{Welford<https://WikiPedia.org/wiki/Algorithms_for_calculating_variance>}'s accumulator computing the running mean, (sample) variance and standard deviation.
@see: U{Cook<https://www.JohnDCook.com/blog/standard_deviation/>} and L{Fcook}. ''' '''New L{Fwelford} stats accumulator.
@kwarg xs: Iterable with initial values (C{Scalar}s). @kwarg name: Optional name (C{str}).
@see: Method L{Fwelford.fadd}. '''
'''Add B{C{other}} to this L{Fwelford} instance.
@arg other: An L{Fwelford} or L{Fcook} instance or C{Scalar}s, meaning one or more C{scalar} or L{Fsum} instances.
@return: This instance, updated (L{Fwelford}).
@raise TypeError: Invalid B{C{other}} type.
@raise ValueError: Invalid B{C{other}}.
@see: Method L{Fwelford.fadd} and U{Parallel algorithm<https// WikiPedia.org/wiki/Algorithms_for_calculating_variance>}. '''
# self._Ms = M, S else:
self += other.toFwelford() else:
'''Accumulate and return the current count.
@arg xs: Iterable with additional values (C{Scalar}s, meaning C{scalar} or L{Fsum} instances). @kwarg sample: Return the I{sample} instead of the entire I{population} value (C{bool}).
@return: Current, running (sample) count (C{int}).
@raise OverflowError: Partial C{2sum} overflow.
@raise TypeError: Non-scalar B{C{xs}} value.
@raise ValueError: Invalid or non-finite B{C{xs}} value. ''' # self._Ms = M, S
'''U{Cook<https://www.JohnDCook.com/blog/running_regression>}'s C{RunningRegression} computing the running slope, intercept and correlation of a linear regression. ''' '''New L{Flinear} regression accumulator.
@kwarg xs: Iterable with initial C{x} values (C{Scalar}s). @kwarg ys: Iterable with initial C{y} values (C{Scalar}s). @kwarg Fstats: Stats class for C{x} and C{y} values (L{Fcook} or L{Fwelford}). @kwarg name: Optional name (C{str}).
@raise TypeError: Invalid B{C{Fs}}, not L{Fcook} or L{Fwelford}. @see: Method L{Flinear.fadd}. '''
'''Add B{C{other}} to this instance.
@arg other: An L{Flinear} instance or C{Scalar} pairs, meaning C{scalar} or L{Fsum} instances.
@return: This instance, updated (L{Flinear}).
@raise TypeError: Invalid B{C{other}} or the B{C{other}} and these C{x} and C{y} accumulators are not compatible.
@raise ValueError: Invalid or odd-length B{C{other}}.
@see: Method L{Flinear.fadd_}. ''' (Y._M1 - self._Y._M1) * \ (n * self._n / float(n + self._n)) else: self._copy(self, other) else: raise TypeError(_SPACE_(_invalid_, _other_)) raise ValueError(Fmt.PAREN(isodd=Fmt.PAREN(len=_other_))) except Exception as x: raise _xError(x, _SPACE_(self, _iadd_, repr(other)))
'''(INTERNAL) Copy C{B{c} = B{s}}. '''
'''Accumulate and return the current count.
@arg xs: Iterable with additional C{x} values (C{Scalar}s), meaning C{scalar} or L{Fsum} instances). @arg ys: Iterable with additional C{y} values (C{Scalar}s, meaning C{scalar} or L{Fsum} instances). @kwarg sample: Return the I{sample} instead of the entire I{population} value (C{bool}).
@return: Current, running (sample) count (C{int}).
@raise OverflowError: Partial C{2sum} overflow.
@raise TypeError: Non-scalar B{C{xs}} or B{C{ys}} value.
@raise ValueError: Invalid or non-finite B{C{xs}} or B{C{ys}} value. '''
'''Accumulate and return the current count.
@arg x_ys: Individual, alternating C{x, y, x, y, ...} positional values (C{Scalar}s).
@see: Method C{Flinear.fadd}. '''
'''Return the current, running (sample) correlation (C{float}).
@kwarg sample: Return the I{sample} instead of the entire I{population} value (C{bool}). ''' self.y.fstdev(sample=sample), sample)
'''Return the current, running (sample) intercept (C{float}).
@kwarg sample: Return the I{sample} instead of the entire I{population} value (C{bool}). ''' (self.x._M1 * self.fslope(sample=sample)))
'''Return the current, running (sample) slope (C{float}).
@kwarg sample: Return the I{sample} instead of the entire I{population} value (C{bool}). '''
'''(INTERNAL) Compute the sampled or entire population result. '''
'''Get the C{x} accumulator (L{Fcook} or L{Fwelford}). '''
'''Get the C{y} accumulator (L{Fcook} or L{Fwelford}). '''
# **) MIT License # # Copyright (C) 2021-2022 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |