pygeodesy 24.5.2__py2.py3-none-any.whl → 24.5.6__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
@@ -9,10 +9,11 @@ from __future__ import division as _; del _ # PYCHOK semicolon
9
9
 
10
10
  from pygeodesy.basics import isodd, islistuple, _xinstanceof, \
11
11
  _xsubclassof, _zip
12
- from pygeodesy.constants import _0_0, _2_0, _3_0, _4_0, _6_0, _xError
13
- # from pygeodesy.errors import _xError # from .constants
12
+ from pygeodesy.constants import _0_0, _2_0, _3_0, _4_0, _6_0
13
+ from pygeodesy.errors import _AssertionError, _xError
14
14
  from pygeodesy.fmath import hypot2, sqrt
15
- from pygeodesy.fsums import _2float, Fsum, _iadd_op_, Fmt
15
+ from pygeodesy.fsums import _Float, _2float, Fsum, _iadd_op_, \
16
+ _isAn, _Fsum_Fsum2Tuple_types, Fmt
16
17
  from pygeodesy.interns import NN, _invalid_, _other_, _SPACE_
17
18
  from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY
18
19
  from pygeodesy.named import _Named, _NotImplemented, property_RO
@@ -22,9 +23,9 @@ from pygeodesy.named import _Named, _NotImplemented, property_RO
22
23
  # from math import sqrt # from .fmath
23
24
 
24
25
  __all__ = _ALL_LAZY.fstats
25
- __version__ = '24.04.26'
26
+ __version__ = '24.05.06'
26
27
 
27
- _Floats = Fsum, float
28
+ _Floats = _Fsum_Fsum2Tuple_types + (_Float,)
28
29
  _Scalar = _Floats + (int,) # XXX basics._Ints is ABCMeta in Python 2
29
30
  try:
30
31
  _Scalar += (long,)
@@ -32,18 +33,17 @@ except NameError: # Python 3+
32
33
  pass
33
34
 
34
35
 
35
- def _2Floats(xs, ys=False):
36
+ def _2Floats(**xs):
36
37
  '''(INTERNAL) Yield each value as C{float} or L{Fsum}.
37
38
  '''
38
- if ys:
39
- def _2f(i, x):
40
- return _2float(index=i, ys=x)
41
- else:
42
- def _2f(i, x): # PYCHOK redef
43
- return _2float(index=i, xs=x)
39
+ try:
40
+ _s, xs = xs.popitem()
41
+ except Exception as x:
42
+ raise _AssertionError(xs=xs, cause=x)
44
43
 
45
44
  for i, x in enumerate(xs): # don't unravel Fsums
46
- yield x if isinstance(x, _Floats) else _2f(i, x)
45
+ yield x if _isAn(x, _Floats) else \
46
+ _2float(index=i, **{_s: x})
47
47
 
48
48
 
49
49
  def _sampled(n, sample):
@@ -86,7 +86,9 @@ class _FstatsNamed(_Named):
86
86
  return _NotImplemented(self, other)
87
87
 
88
88
  def __str__(self):
89
- return Fmt.SQUARE(self.named3, len(self))
89
+ n = self.name
90
+ n = _SPACE_(self.classname, n) if n else self.classname
91
+ return Fmt.SQUARE(n, len(self))
90
92
 
91
93
  def fcopy(self, deep=False, name=NN):
92
94
  '''Copy this instance, C{shallow} or B{C{deep}}.
@@ -175,7 +177,7 @@ class _FstatsBase(_FstatsNamed):
175
177
  @see: Method C{fadd}.
176
178
  '''
177
179
  n = self.fadd(xs, sample=sample)
178
- return float(self._M2 / float(n)) if n > 0 else _0_0
180
+ return _Float(self._M2 / _Float(n)) if n > 0 else _0_0
179
181
 
180
182
  def fvariance_(self, *xs, **sample):
181
183
  '''Accumulate and return the current variance.
@@ -187,7 +189,7 @@ class _FstatsBase(_FstatsNamed):
187
189
  def _iadd_other(self, other):
188
190
  '''(INTERNAL) Add Scalar or Scalars.
189
191
  '''
190
- if isinstance(other, _Scalar):
192
+ if _isAn(other, _Scalar):
191
193
  self.fadd_(other)
192
194
  else:
193
195
  try:
@@ -245,7 +247,7 @@ class Fcook(_FstatsBase):
245
247
 
246
248
  @see: Method L{Fcook.fadd}.
247
249
  '''
248
- if isinstance(other, Fcook):
250
+ if _isAn(other, Fcook):
249
251
  nb = len(other)
250
252
  if nb > 0:
251
253
  na = len(self)
@@ -253,13 +255,13 @@ class Fcook(_FstatsBase):
253
255
  A1, A2, A3, A4 = self._Ms
254
256
  B1, B2, B3, B4 = other._Ms
255
257
 
256
- n = na + nb
257
- n_ = float(n)
258
- D = A1 - B1 # b1 - a1
259
- Dn = D / n_
260
- Dn2 = Dn**2 # d**2 / n**2
261
- nab = na * nb
262
- Dn3 = Dn2 * (D * nab)
258
+ n = na + nb
259
+ n_ = _Float(n)
260
+ D = A1 - B1 # b1 - a1
261
+ Dn = D / n_
262
+ Dn2 = Dn**2 # d**2 / n**2
263
+ nab = na * nb
264
+ Dn3 = Dn2 * (D * nab)
263
265
 
264
266
  na2 = na**2
265
267
  nb2 = nb**2
@@ -270,7 +272,7 @@ class Fcook(_FstatsBase):
270
272
 
271
273
  A3 += B3
272
274
  A3 += (A2 * na - (B2 * nb)) * (Dn * _3_0)
273
- A3 += Dn3 * (na - nb)
275
+ A3 += Dn3 * (na - nb)
274
276
 
275
277
  A2 += B2
276
278
  A2 += Dn2 * (nab / n_)
@@ -310,7 +312,7 @@ class Fcook(_FstatsBase):
310
312
  n = self._n
311
313
  if xs:
312
314
  M1, M2, M3, M4 = self._Ms
313
- for x in _2Floats(xs):
315
+ for x in _2Floats(xs=xs):
314
316
  n1 = n
315
317
  n += 1
316
318
  D = x - M1
@@ -383,12 +385,12 @@ class Fcook(_FstatsBase):
383
385
  k, n = _0_0, self.fadd(xs, sample=sample)
384
386
  if n > 0:
385
387
  _, M2, _, M4 = self._Ms
386
- m2 = float(M2 * M2)
388
+ m2 = _Float(M2 * M2)
387
389
  if m2:
388
390
  K, x = (M4 * (n / m2)), _3_0
389
391
  if sample and 2 < n < len(self):
390
- d = float((n - 1) * (n - 2))
391
- K *= (n + 1) * (n + 2) / d
392
+ d = _Float((n - 1) * (n - 2))
393
+ K *= (n + 1) * (n + 2) / d
392
394
  x *= n**2 / d
393
395
  if excess:
394
396
  K -= x
@@ -416,7 +418,7 @@ class Fcook(_FstatsBase):
416
418
  '''
417
419
  # skewness = 3 * (mean - median) / stdev, i.e.
418
420
  # median = mean - skewness * stdef / 3
419
- m = float(self._M1) if xs is None else self.fmean(xs)
421
+ m = _Float(self._M1) if xs is None else self.fmean(xs)
420
422
  return m - self.fskewness() * self.fstdev() / _3_0
421
423
 
422
424
  def fmedian_(self, *xs):
@@ -443,11 +445,11 @@ class Fcook(_FstatsBase):
443
445
  s, n = _0_0, self.fadd(xs, sample=sample)
444
446
  if n > 0:
445
447
  _, M2, M3, _ = self._Ms
446
- m = float(M2**3)
448
+ m = _Float(M2**3)
447
449
  if m > 0:
448
- S = M3 * sqrt(float(n) / m)
450
+ S = M3 * sqrt(_Float(n) / m)
449
451
  if sample and 1 < n < len(self):
450
- S *= (n + 1) / float(n - 1)
452
+ S *= (n + 1) / _Float(n - 1)
451
453
  s = S.fsum()
452
454
  return s
453
455
 
@@ -502,7 +504,7 @@ class Fwelford(_FstatsBase):
502
504
  @see: Method L{Fwelford.fadd} and U{Parallel algorithm<https//
503
505
  WikiPedia.org/wiki/Algorithms_for_calculating_variance>}.
504
506
  '''
505
- if isinstance(other, Fwelford):
507
+ if _isAn(other, Fwelford):
506
508
  nb = len(other)
507
509
  if nb > 0:
508
510
  na = len(self)
@@ -510,8 +512,8 @@ class Fwelford(_FstatsBase):
510
512
  M, S = self._Ms
511
513
  M_, S_ = other._Ms
512
514
 
513
- n = na + nb
514
- n_ = float(n)
515
+ n = na + nb
516
+ n_ = _Float(n)
515
517
 
516
518
  D = M_ - M
517
519
  D *= D # D**2
@@ -529,7 +531,7 @@ class Fwelford(_FstatsBase):
529
531
  else:
530
532
  self._copy(self, other)
531
533
 
532
- elif isinstance(other, Fcook):
534
+ elif _isAn(other, Fcook):
533
535
  self += other.toFwelford()
534
536
  else:
535
537
  self._iadd_other(other)
@@ -554,7 +556,7 @@ class Fwelford(_FstatsBase):
554
556
  n = self._n
555
557
  if xs:
556
558
  M, S = self._Ms
557
- for x in _2Floats(xs):
559
+ for x in _2Floats(xs=xs):
558
560
  n += 1
559
561
  D = x - M
560
562
  M += D / n
@@ -609,7 +611,7 @@ class Flinear(_FstatsNamed):
609
611
 
610
612
  @see: Method L{Flinear.fadd_}.
611
613
  '''
612
- if isinstance(other, Flinear):
614
+ if _isAn(other, Flinear):
613
615
  if len(other) > 0:
614
616
  if len(self) > 0:
615
617
  n = other._n
@@ -618,7 +620,7 @@ class Flinear(_FstatsNamed):
618
620
  Y = other._Y
619
621
  D = (X._M1 - self._X._M1) * \
620
622
  (Y._M1 - self._Y._M1) * \
621
- (n * self._n / float(n + self._n))
623
+ (n * self._n / _Float(n + self._n))
622
624
  self._n += n
623
625
  self._S += S + D
624
626
  self._X += X
@@ -669,11 +671,11 @@ class Flinear(_FstatsNamed):
669
671
  S = self._S
670
672
  X = self._X
671
673
  Y = self._Y
672
- for x, y in _zip(_2Floats(xs), _2Floats(ys, ys=True)): # strict=True
674
+ for x, y in _zip(_2Floats(xs=xs), _2Floats(ys=ys)): # strict=True
673
675
  n1 = n
674
676
  n += 1
675
677
  if n1 > 0:
676
- S += (X._M1 - x) * (Y._M1 - y) * (n1 / float(n))
678
+ S += (X._M1 - x) * (Y._M1 - y) * (n1 / _Float(n))
677
679
  X += x
678
680
  Y += y
679
681
  self._n = n
@@ -704,8 +706,8 @@ class Flinear(_FstatsNamed):
704
706
  @kwarg sample: Return the I{sample} instead of the entire
705
707
  I{population} intercept (C{bool}).
706
708
  '''
707
- return float(self.y._M1 -
708
- (self.x._M1 * self.fslope(sample=sample)))
709
+ return _Float(self.y._M1 -
710
+ (self.x._M1 * self.fslope(sample=sample)))
709
711
 
710
712
  def fslope(self, sample=False):
711
713
  '''Return the current, running (sample) slope (C{float}).
@@ -718,8 +720,8 @@ class Flinear(_FstatsNamed):
718
720
  def _sampled(self, t, sample):
719
721
  '''(INTERNAL) Compute the sampled or entire population result.
720
722
  '''
721
- t *= float(_sampled(self._n, sample))
722
- return float(self._S / t) if t else _0_0
723
+ t *= _Float(_sampled(self._n, sample))
724
+ return _Float(self._S / t) if t else _0_0
723
725
 
724
726
  @property_RO
725
727
  def x(self):