pygeodesy 24.9.29__py2.py3-none-any.whl → 24.10.10__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pygeodesy/fstats.py CHANGED
@@ -2,7 +2,8 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  u'''Classes for I{running} statistics and regressions based on
5
- L{pygeodesy.Fsum}, precision floating point summation.
5
+ L{pygeodesy.Fsum}, precision floating point summation and accurate
6
+ multiplication.
6
7
  '''
7
8
  # make sure int/int division yields float quotient, see .basics
8
9
  from __future__ import division as _; del _ # PYCHOK semicolon
@@ -22,36 +23,35 @@ from pygeodesy.named import _name__, _Named, _NotImplemented, \
22
23
  # from pygeodesy.streprs import Fmt # from .fmath
23
24
 
24
25
  __all__ = _ALL_LAZY.fstats
25
- __version__ = '24.09.28'
26
+ __version__ = '24.10.08'
26
27
 
27
28
 
28
- def _2Floats(**xs):
29
+ def _sampled(n, sample):
30
+ '''(INTERNAL) Return the sample or the entire count.
31
+ '''
32
+ return (n - 1) if sample and n > 0 else n
33
+
34
+
35
+ def _Xs(**name_xs):
29
36
  '''(INTERNAL) Yield all C{xs} as C{float} or L{Fsum}.
30
37
  '''
31
- name, xs = _xkwds_item2(xs)
38
+ name, xs = _xkwds_item2(name_xs)
32
39
  try:
33
- i, x = None, xs
34
- for i, x in enumerate(_xiterable(xs)): # don't unravel Fsums
35
- yield x._Fsum if _isFsum_2Tuple(x) else _2finite(x)
40
+ i, x = 0, xs
41
+ for i, x in enumerate(xs): # don't unravel Fsums
42
+ yield x._Fsum if _isFsum_2Tuple(x) else x
36
43
  except Exception as X:
37
44
  raise _xsError(X, xs, i, x, name)
38
45
 
39
46
 
40
- def _sampled(n, sample):
41
- '''(INTERNAL) Return the sample or the entire count.
42
- '''
43
- return (n - 1) if sample and n > 0 else n
44
-
45
-
46
47
  class _FstatsNamed(_Named):
47
48
  '''(INTERNAL) Base class.
48
49
  '''
49
50
  _n = 0
50
51
 
51
52
  def __add__(self, other):
52
- '''Sum of this and an other instance or a C{scalar} or an
53
- L{Fsum}, L{Fsum2Tuple} or
54
- .
53
+ '''Sum of this and an other instance, a C{scalar}, an L{Fsum}
54
+ or L{Fsum2Tuple}.
55
55
  '''
56
56
  f = self.copy(name=self.__add__.__name__) # PYCHOK expected
57
57
  f += other
@@ -103,7 +103,7 @@ class _FstatsBase(_FstatsNamed):
103
103
  _Ms = ()
104
104
 
105
105
  def _copy(self, d, s):
106
- '''(INTERNAL) Copy C{B{c} = B{s}}.
106
+ '''(INTERNAL) Copy C{B{d} = B{s}}.
107
107
  '''
108
108
  _xinstanceof(self.__class__, d=d, s=s)
109
109
  d._Ms = tuple(M.copy() for M in s._Ms) # deep=False
@@ -124,8 +124,8 @@ class _FstatsBase(_FstatsNamed):
124
124
  def fmean(self, xs=None):
125
125
  '''Accumulate and return the current mean.
126
126
 
127
- @kwarg xs: Iterable of additional values (each C{scalar} or
128
- an L{Fsum} or L{Fsum2Tuple} instance).
127
+ @kwarg xs: Iterable of additional values (each C{scalar},
128
+ an L{Fsum} or L{Fsum2Tuple}).
129
129
 
130
130
  @return: Current, running mean (C{float}).
131
131
 
@@ -143,8 +143,8 @@ class _FstatsBase(_FstatsNamed):
143
143
  def fstdev(self, xs=None, **sample):
144
144
  '''Accumulate and return the current standard deviation.
145
145
 
146
- @arg xs: Iterable of additional values (each C{scalar} or an
147
- L{Fsum} or L{Fsum2Tuple} instance).
146
+ @arg xs: Iterable of additional values (each C{scalar}, an L{Fsum}
147
+ or L{Fsum2Tuple}).
148
148
  @kwarg sample: Use C{B{sample}=True} for the I{sample} deviation
149
149
  instead of the I{population} deviation (C{bool}).
150
150
 
@@ -164,8 +164,8 @@ class _FstatsBase(_FstatsNamed):
164
164
  def fvariance(self, xs=None, **sample):
165
165
  '''Accumulate and return the current variance.
166
166
 
167
- @arg xs: Iterable of additional values (each C{scalar} or an
168
- L{Fsum} or L{Fsum2Tuple} instance).
167
+ @arg xs: Iterable of additional values (each C{scalar}, an L{Fsum}
168
+ or L{Fsum2Tuple}).
169
169
  @kwarg sample: Use C{B{sample}=True} for the I{sample} variance
170
170
  instead of the I{population} variance (C{bool}).
171
171
 
@@ -238,8 +238,8 @@ class Fcook(_FstatsBase):
238
238
  def __init__(self, xs=None, **name):
239
239
  '''New L{Fcook} stats accumulator.
240
240
 
241
- @arg xs: Iterable of additional values (each C{scalar} or
242
- an L{Fsum} or L{Fsum2Tuple} instance).
241
+ @arg xs: Iterable of additional values (each C{scalar}, an
242
+ L{Fsum} or L{Fsum2Tuple}).
243
243
  @kwarg name: Optional C{B{name}=NN} (C{str}).
244
244
 
245
245
  @see: Method L{Fcook.fadd}.
@@ -254,8 +254,8 @@ class Fcook(_FstatsBase):
254
254
  '''Add B{C{other}} to this L{Fcook} instance.
255
255
 
256
256
  @arg other: An L{Fcook} instance or value or iterable
257
- of values (each C{scalar} or an L{Fsum}
258
- or L{Fsum2Tuple} instance).
257
+ of values (each C{scalar}, an L{Fsum} or
258
+ L{Fsum2Tuple}).
259
259
 
260
260
  @return: This instance, updated (L{Fcook}).
261
261
 
@@ -311,8 +311,8 @@ class Fcook(_FstatsBase):
311
311
  def fadd(self, xs, sample=False):
312
312
  '''Accumulate and return the current count.
313
313
 
314
- @arg xs: Iterable of additional values (each C{scalar} or an
315
- L{Fsum} or L{Fsum2Tuple} instance).
314
+ @arg xs: Iterable of additional values (each C{scalar}, an
315
+ L{Fsum} or L{Fsum2Tuple}).
316
316
  @kwarg sample: Use C{B{sample}=True} for the I{sample} count
317
317
  instead of the I{population} count (C{bool}).
318
318
 
@@ -330,7 +330,7 @@ class Fcook(_FstatsBase):
330
330
  n = self._n
331
331
  if xs:
332
332
  M1, M2, M3, M4 = self._Ms
333
- for x in _2Floats(xs=xs): # PYCHOK yield
333
+ for x in _Xs(xs=xs): # PYCHOK yield
334
334
  n1 = n
335
335
  n += 1
336
336
  D = x - M1
@@ -364,7 +364,7 @@ class Fcook(_FstatsBase):
364
364
  '''Accumulate and compute the current U{Jarque-Bera
365
365
  <https://WikiPedia.org/wiki/Jarque–Bera_test>} normality.
366
366
 
367
- @kwarg xs: Iterable of additional values (each C{scalar} or an
367
+ @kwarg xs: Iterable of additional values (each C{scalar}, an
368
368
  L{Fsum} or L{Fsum2Tuple}).
369
369
  @kwarg excess: Apply the I{excess} kurtosis (C{bool}), default.
370
370
  @kwarg sample: Use C{B{sample}=False} for the I{population}
@@ -387,8 +387,8 @@ class Fcook(_FstatsBase):
387
387
  def fkurtosis(self, xs=None, excess=True, **sample):
388
388
  '''Accumulate and return the current kurtosis.
389
389
 
390
- @arg xs: Iterable of additional values (each C{scalar} or an
391
- L{Fsum} or L{Fsum2Tuple} instance).
390
+ @arg xs: Iterable of additional values (each C{scalar}, an L{Fsum}
391
+ or L{Fsum2Tuple}).
392
392
  @kwarg excess: Return the I{excess} kurtosis (C{bool}), default.
393
393
  @kwarg sample: Use C{B{sample}=True} for the I{sample} kurtosis
394
394
  instead of the I{population} kurtosis (C{bool}).
@@ -413,8 +413,8 @@ class Fcook(_FstatsBase):
413
413
  def fmedian(self, xs=None):
414
414
  '''Accumulate and return the current median.
415
415
 
416
- @arg xs: Iterable of additional values (each C{scalar} or an
417
- L{Fsum} or L{Fsum2Tuple} instance).
416
+ @arg xs: Iterable of additional values (each C{scalar}, an L{Fsum} or
417
+ L{Fsum2Tuple}).
418
418
 
419
419
  @return: Current, running median (C{float}).
420
420
 
@@ -435,8 +435,8 @@ class Fcook(_FstatsBase):
435
435
  def fskewness(self, xs=None, **sample):
436
436
  '''Accumulate and return the current skewness.
437
437
 
438
- @arg xs: Iterable of additional values (each C{scalar} or an
439
- L{Fsum} or L{Fsum2Tuple} instance).
438
+ @arg xs: Iterable of additional values (each C{scalar}, an L{Fsum}
439
+ or L{Fsum2Tuple}).
440
440
  @kwarg sample: Use C{B{sample}=True} for the I{sample} skewness
441
441
  instead of the I{population} skewness (C{bool}).
442
442
 
@@ -526,8 +526,7 @@ class Fwelford(_FstatsBase):
526
526
  def __init__(self, xs=None, **name):
527
527
  '''New L{Fwelford} stats accumulator.
528
528
 
529
- @arg xs: Iterable of initial values (each C{scalar} or an
530
- L{Fsum} or L{Fsum2Tuple} instance).
529
+ @arg xs: Iterable of initial values (each C{scalar}, an L{Fsum} or L{Fsum2Tuple}).
531
530
  @kwarg name: Optional C{B{name}=NN} (C{str}).
532
531
 
533
532
  @see: Method L{Fwelford.fadd}.
@@ -541,9 +540,9 @@ class Fwelford(_FstatsBase):
541
540
  def __iadd__(self, other):
542
541
  '''Add B{C{other}} to this L{Fwelford} instance.
543
542
 
544
- @arg other: An L{Fwelford} or L{Fcook} instance or value
545
- or an iterable of values (each C{scalar} or
546
- an L{Fsum} or L{Fsum2Tuple} instance).
543
+ @arg other: An L{Fwelford} or L{Fcook} instance or value or an
544
+ iterable of values (each C{scalar}, an L{Fsum} or
545
+ L{Fsum2Tuple}).
547
546
 
548
547
  @return: This instance, updated (L{Fwelford}).
549
548
 
@@ -590,8 +589,8 @@ class Fwelford(_FstatsBase):
590
589
  def fadd(self, xs, sample=False):
591
590
  '''Accumulate and return the current count.
592
591
 
593
- @arg xs: Iterable of additional values (each C{scalar} or an
594
- L{Fsum} or L{Fsum2Tuple} instance).
592
+ @arg xs: Iterable of additional values (each C{scalar}, an
593
+ L{Fsum} or L{Fsum2Tuple}).
595
594
  @kwarg sample: Use C{B{sample}=True} for the I{sample} count
596
595
  instead of the I{population} count (C{bool}).
597
596
 
@@ -606,7 +605,7 @@ class Fwelford(_FstatsBase):
606
605
  n = self._n
607
606
  if xs:
608
607
  M, S = self._Ms
609
- for x in _2Floats(xs=xs): # PYCHOK yield
608
+ for x in _Xs(xs=xs): # PYCHOK yield
610
609
  n += 1
611
610
  D = x - M
612
611
  M += D / n
@@ -625,10 +624,10 @@ class Flinear(_FstatsNamed):
625
624
  def __init__(self, xs=None, ys=None, Fstats=Fwelford, **name):
626
625
  '''New L{Flinear} regression accumulator.
627
626
 
628
- @kwarg xs: Iterable of initial C{x} values (each C{scalar} or
629
- an L{Fsum} or L{Fsum2Tuple} instance).
630
- @kwarg ys: Iterable of initial C{y} values (each C{scalar} or
631
- an L{Fsum} or L{Fsum2Tuple} instance).
627
+ @kwarg xs: Iterable of initial C{x} values (each C{scalar},
628
+ an L{Fsum} or L{Fsum2Tuple}).
629
+ @kwarg ys: Iterable of initial C{y} values (each C{scalar},
630
+ an L{Fsum} or L{Fsum2Tuple}).
632
631
  @kwarg Fstats: Class for C{xs} and C{ys} values (L{Fcook} or
633
632
  L{Fwelford}).
634
633
  @kwarg name: Optional C{B{name}=NN} (C{str}).
@@ -704,10 +703,10 @@ class Flinear(_FstatsNamed):
704
703
  def fadd(self, xs, ys, sample=False):
705
704
  '''Accumulate and return the current count.
706
705
 
707
- @arg xs: Iterable of additional C{x} values (each C{scalar}
708
- or an L{Fsum} or L{Fsum2Tuple} instance).
709
- @arg ys: Iterable of additional C{y} values (each C{scalar}
710
- or an L{Fsum} or L{Fsum2Tuple} instance).
706
+ @arg xs: Iterable of additional C{x} values (each C{scalar},
707
+ an L{Fsum} or L{Fsum2Tuple}).
708
+ @arg ys: Iterable of additional C{y} values (each C{scalar},
709
+ an L{Fsum} or L{Fsum2Tuple}).
711
710
  @kwarg sample: Use C{B{sample}=True} for the I{sample} count
712
711
  instead of the I{population} count (C{bool}).
713
712
 
@@ -724,7 +723,7 @@ class Flinear(_FstatsNamed):
724
723
  S = self._S
725
724
  X = self._X
726
725
  Y = self._Y
727
- for x, y in _zip(_2Floats(xs=xs), _2Floats(ys=ys)): # PYCHOK strict=True
726
+ for x, y in _zip(_Xs(xs=xs), _Xs(ys=ys)): # PYCHOK strict=True
728
727
  n1 = n
729
728
  n += 1
730
729
  if n1 > 0:
@@ -738,8 +737,7 @@ class Flinear(_FstatsNamed):
738
737
  '''Accumulate and return the current count.
739
738
 
740
739
  @arg x_ys: Individual, alternating C{x, y, x, y, ...} values
741
- (each C{scalar} or an L{Fsum} or L{Fsum2Tuple}
742
- instance).
740
+ (each C{scalar}, an L{Fsum} or L{Fsum2Tuple}).
743
741
 
744
742
  @see: Method C{Flinear.fadd} for further details.
745
743
  '''