Subject | Hash | Author | Date (UTC) |
---|---|---|---|
welford: yet another Welford's algoritm implementation | ec31907d6727c408306f4b25c09b7f87632b0ecf | I am | 2021-06-27 22:27:06 |
IS_stat.TrueIS: pridal jsem do komentářu vzpomínky | 1c5b4596a4da1206b02ed91954cbe8147ec1e208 | I am | 2021-06-27 15:23:42 |
IS_stat: add get_IS_estimation() function | d048b4cd4e90d8440e7ff2a3ad86bc0f3c160d4f | I am | 2021-06-26 19:55:14 |
spring: new brand hustý modul pro vyrovnání odhadů | 3fc5eb00de1eb65cff2db71640c340602687f52f | I am | 2021-06-25 00:52:06 |
convex_hull.Ghull.rvs: hloupá chyba | 7494eef4e2621ac9651037cd4a99e9f570704dee | I am | 2021-06-21 01:37:49 |
convex_hull.Ghull.rvs: ensure at least one node outside | 1c6d05935c83d11637ae566528cf65eb384215b5 | I am | 2021-06-19 19:04:40 |
convex_hull.Ghull: add nonGaussian hulls support, fix MC integration | 3e10c2cefff5f3e204c1d4118b195e37023a5a57 | I am | 2021-06-19 17:44:09 |
mart: add qhull polygon | c3da6bdd1b6412f178c828c1eb1a6368a02eb74c | I am | 2021-06-18 23:27:48 |
dicebox.Goal: implement csv export odhadů | abdb28f509e664c039a6e5ca4bf1036d00957349 | I am | 2021-06-15 15:06:15 |
reader: add export_estimation function. Jednoduchý jako busy | ef8fcada4b01be8db29836aa09459d8a7ef382b6 | I am | 2021-06-15 03:08:53 |
convex_hull: add meaningless method | 96a86b7eabceb15e6c937932c2002409c2df0178 | I am | 2021-06-14 16:35:39 |
dicebox: new brand box named Goal is ready | 725c2561b62769af6034c690005d1d22e6af41c7 | I am | 2021-06-05 13:40:15 |
convex_hull: last node fix in fire() function | ca938c11398dfb2e16441b989902dab1558336b3 | I am | 2021-06-05 13:25:55 |
convex_hull: small fix for QHull under single simplex integration | b0b236cd14ae614ecd1310b8c7cfcafe8d1b0851 | I am | 2021-05-30 05:57:45 |
convex_hull: ensure Ghull to always have some nodes for expansion | 7110d521d9fece58639a359c83773df904b1177f | I am | 2021-05-29 07:03:49 |
dicebox: throw away plot dependency, simplify increment function | 1cf0c481b8df1937ff7eda6e0373d5d6a72387db | I am | 2021-05-28 16:42:19 |
simplex: add JustCubatureTriangulation class separated from Shull | ea291f9deee9f3b5b8615ae1f14a49aecd327461 | I am | 2021-05-28 16:39:58 |
mart: add convex_hull routines | 90105552e7aecf3df8e84a1f5c4bdc1b04be249b | I am | 2021-04-25 20:11:34 |
convex_hull.Ghull: try to outthink OS's memory management | 116444dc08cc0261e149de02f21f14f74dc8816b | I am | 2021-04-25 08:02:25 |
convex_hull.Ghull: in case of memory error divide ns by 3 | 0f629139f7926107b0b4eeb55452e745a2c23487 | I am | 2021-04-25 06:50:02 |
File | Lines added | Lines deleted |
---|---|---|
welford.py | 61 | 0 |
File welford.py added (mode: 100644) (index 0000000..6c167c5) | |||
1 | #!/usr/bin/env python | ||
2 | # coding: utf-8 | ||
3 | |||
4 | # One does not simply calculate the sample variance. | ||
5 | # https://github.com/numpy/numpy/issues/6231 | ||
6 | # Only one citation from: | ||
7 | # "Online calculations happen all the time (due to resource limitations), | ||
8 | # and a np.welford function would be convenient so that not everyone | ||
9 | # has to implement welford on its own over and over again." | ||
10 | |||
11 | # There are actually some code can be found in internet, | ||
12 | # but those I've seen supposed one-by-one data addition. | ||
13 | |||
14 | """ | ||
15 | This is implementation of generalized (for arbitrary sample sizes) | ||
16 | Welford's updating (online) algorithm, given by Chan et al. in two papers: | ||
17 | "Algorithms for computing the sample variance: Analysis and recommendations" | ||
18 | https://doi.org/10.1080%2F00031305.1983.10483115 | ||
19 | and | ||
20 | "Updating Formulae and a Pairwise Algorithm for Computing Sample Variances." | ||
21 | http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf | ||
22 | """ | ||
23 | |||
24 | |||
25 | import numpy as np | ||
26 | |||
27 | |||
28 | |||
29 | class Welford: | ||
30 | def __init__(self): | ||
31 | self.n = 0 | ||
32 | |||
33 | |||
34 | def add(self, data): | ||
35 | n = len(data) | ||
36 | T = np.sum(data) | ||
37 | #č takhle je to numericky nejstabilnější | ||
38 | S = np.sum(np.square(data - T/len(data))) | ||
39 | |||
40 | if self.n == 0: | ||
41 | self.n = n | ||
42 | self.T = T | ||
43 | self.S = S | ||
44 | else: | ||
45 | m = self.n #č to, co bylo | ||
46 | self.S += S + m /n /(m+n) * (n/m * self.T - T)**2 | ||
47 | self.n += n | ||
48 | self.T += T | ||
49 | |||
50 | @property | ||
51 | def mean(self): | ||
52 | return self.T / self.n | ||
53 | |||
54 | @property | ||
55 | def var(self): | ||
56 | return self.S / self.n | ||
57 | |||
58 | @property | ||
59 | def s2(self): | ||
60 | return self.S / (self.n - 1) | ||
61 |