pyANOVAapprox 2.0.6__tar.gz → 2.0.7__tar.gz

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.
Files changed (38) hide show
  1. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/PKG-INFO +1 -1
  2. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/pyproject.toml +1 -1
  3. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/src/pyANOVAapprox/approx.py +3 -1
  4. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/src/pyANOVAapprox/bandwidth.py +68 -26
  5. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/.github/workflows/ci.yml +0 -0
  6. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/.github/workflows/documentation.yml +0 -0
  7. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/.github/workflows/format.yml +0 -0
  8. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/.github/workflows/release.yml +0 -0
  9. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/.gitignore +0 -0
  10. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/LICENSE +0 -0
  11. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/README.md +0 -0
  12. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/docs/Makefile +0 -0
  13. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/docs/source/Analysis.rst +0 -0
  14. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/docs/source/Approximation.rst +0 -0
  15. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/docs/source/Errors.rst +0 -0
  16. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/docs/source/conf.py +0 -0
  17. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/docs/source/index.rst +0 -0
  18. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/simpleTest/TestFunctionPeriodic.py +0 -0
  19. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/simpleTest/exampleAutoapproximate.py +0 -0
  20. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/simpleTest/exampleCheb.py +0 -0
  21. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/simpleTest/exampleClassification.py +0 -0
  22. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/simpleTest/exampleNonPeriodic.py +0 -0
  23. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/simpleTest/examplePeriodic.py +0 -0
  24. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/simpleTest/exampleWavelet.py +0 -0
  25. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/simpleTest/friedman.ipynb +0 -0
  26. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/src/pyANOVAapprox/__init__.py +0 -0
  27. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/src/pyANOVAapprox/analysis.py +0 -0
  28. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/src/pyANOVAapprox/errors.py +0 -0
  29. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/src/pyANOVAapprox/fista.py +0 -0
  30. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/src/pyANOVAapprox/trafos.py +0 -0
  31. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/tests/TestFunctionCheb.py +0 -0
  32. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/tests/TestFunctionPeriodic.py +0 -0
  33. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/tests/cheb_fista.py +0 -0
  34. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/tests/cheb_lsqr.py +0 -0
  35. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/tests/per_fista.py +0 -0
  36. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/tests/per_lsqr.py +0 -0
  37. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/tests/run_tests.py +0 -0
  38. {pyanovaapprox-2.0.6 → pyanovaapprox-2.0.7}/tests/wav_lsqr.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyANOVAapprox
3
- Version: 2.0.6
3
+ Version: 2.0.7
4
4
  Summary: Approximation Package for High-Dimensional Functions
5
5
  Project-URL: Homepage, https://github.com/NFFT/pyGroupedTransforms
6
6
  Author-email: Felix Wirth <fwi012001@gmail.com>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pyANOVAapprox"
7
- version = "2.0.6"
7
+ version = "2.0.7"
8
8
  authors = [
9
9
  { name="Felix Wirth", email="fwi012001@gmail.com" },
10
10
  ]
@@ -419,6 +419,8 @@ class approx:
419
419
 
420
420
  D = dict([(u, tuple([1.0] * len(u))) for u in setting.U])
421
421
  t = dict([(u, tuple([1.0] * len(u))) for u in setting.U])
422
+ fix = dict([(u, tuple([False] * len(u))) for u in setting.U])
423
+ bw = [tuple([0] * len(u)) for u in setting.U]
422
424
 
423
425
  if verbosity > 3:
424
426
  if not os.path.exists("log"):
@@ -430,7 +432,7 @@ class approx:
430
432
  for idx in range(maxiter):
431
433
  if verbosity > 0:
432
434
  print("===== Iteration ", str(idx + 1), " =====")
433
- bw = compute_bandwidth(B, D, t)
435
+ bw, fix = compute_bandwidth(B, D, t, fix, bw)
434
436
  if setting.N is not None:
435
437
  self.addSetting(setting)
436
438
  settingnr = self.aktsetting
@@ -9,6 +9,8 @@ def getfcu(ghat, u):
9
9
  # fcu = np.permute_dims(fcu, range(len(bws))[::-1])
10
10
  fcu = ghat[u].reshape(bws - 1)
11
11
  fcu = np.permute_dims(fcu, range(len(bws)))
12
+ #if(u == (3,7)):
13
+ # print(fcu)
12
14
 
13
15
  return fcu
14
16
 
@@ -30,50 +32,90 @@ def getaxissum(ghat, u, j, system):
30
32
  else:
31
33
  raise ValueError("For this basis is estimate rates not implemented")
32
34
  # fcuj = np.concatenate(fcuj[math.ceil(bws[j]/2):] + [fcuj[0]]) + fcuj[math.ceil(bws[j]/2)-1::-1]
35
+ #if(u == (3,7)):
36
+ # print(j,fcuj)
33
37
 
34
38
  return fcuj
35
39
 
36
-
37
- def compute_bandwidth(B, D, t):
40
+ def compute_bandwidth(B, D, t, fix, oldbw):
38
41
  us = set(D.keys()) - {()}
39
42
  bw = {u: [6] * len(u) for u in us}
40
43
  bw[()] = []
41
44
 
42
- minfreqs = sum(math.prod((bw[u][j] - 1) for j in range(len(u))) for u in us)
45
+ # fix erweitern: NaN-Einträge in t werden automatisch fixiert
46
+ fix = {u: list(fix[u]) for u in us} # deep copy
47
+ for u in us:
48
+ for j in range(len(u)):
49
+ if math.isnan(t[u][j]):
50
+ fix[u][j] = True
51
+
52
+ # Für fixierte Einträge: Bandbreite aus oldbw übernehmen
53
+ for u in us:
54
+ for j in range(len(u)):
55
+ if fix[u][j]:
56
+ bw[u][j] = oldbw[u][j]
57
+
58
+ minfreqs = sum(
59
+ math.prod(
60
+ (oldbw[u][j] - 1) if fix[u][j] else (6 - 1)
61
+ for j in range(len(u))
62
+ )
63
+ for u in us
64
+ )
43
65
  if B < minfreqs:
44
66
  raise ValueError(f"Budget too small: {B} < {minfreqs}")
45
67
 
46
- def fun_lmbda_u(lmbda, u):
47
- p1 = math.prod((bw[u][j] - 1) for j in range(len(u)) if not math.isnan(t[u][j]))
68
+ def A_u(u):
69
+ return sum(
70
+ 0.5 / t[u][j]
71
+ for j in range(len(u))
72
+ if not fix[u][j]
73
+ )
48
74
 
49
- p2 = math.prod(
50
- ((2 * t[u][j] * D[u][j]) / lmbda) ** (0.5 / t[u][j])
75
+ def B_u(u):
76
+ prod_C = math.prod(
77
+ D[u][j] ** (0.5 / t[u][j])
51
78
  for j in range(len(u))
52
- if not math.isnan(t[u][j])
79
+ if not fix[u][j]
53
80
  )
54
- denom_exp = 1 + sum(
55
- 0.5 / t[u][j] for j in range(len(u)) if not math.isnan(t[u][j])
81
+ prod_fix = math.prod(
82
+ (bw[u][j] - 1)
83
+ for j in range(len(u))
84
+ if fix[u][j]
56
85
  )
57
- return (p1 * p2) ** (1 / denom_exp)
58
-
59
- def fun_lmbda(lmbda, B):
60
- total = 0.0
61
- for u in us:
62
- total += fun_lmbda_u(math.exp(lmbda), u)
63
- return total - B
64
-
65
- lmbda = math.exp(bisect(lambda t: fun_lmbda(t, B), -100, 100))
86
+ return prod_C * prod_fix
66
87
 
88
+ def fun_lmbda_u(lmbda, u):
89
+ Au = A_u(u)
90
+ Bu = B_u(u)
91
+ if Au == 0:
92
+ # Alle Einträge in u sind fixiert: kein Beitrag zur Optimierung
93
+ return 0.0
94
+ exp = 1.0 / (1.0 + Au)
95
+ return Bu ** exp * (lmbda * Au) ** (-Au * exp)
96
+
97
+ def fun_lmbda(log_lmbda):
98
+ lmbda = math.exp(log_lmbda)
99
+ return sum(fun_lmbda_u(lmbda, u) for u in us) - (B - 1)
100
+
101
+ log_lmbda = bisect(fun_lmbda, -100, 100)
102
+ lmbda = math.exp(log_lmbda)
103
+
104
+ # Optimale Bandbreiten berechnen
67
105
  for u in us:
106
+ Au = A_u(u)
107
+ Bu = B_u(u)
108
+ if Au == 0:
109
+ continue # alle fixiert, bw[u] bereits gesetzt
68
110
  sizeIu = fun_lmbda_u(lmbda, u)
69
111
  for j in range(len(u)):
70
- if not math.isnan(t[u][j]):
71
- bwuj = ((2 * t[u][j] * D[u][j]) / (lmbda * sizeIu)) ** (
112
+ if not fix[u][j]:
113
+ bwuj = (D[u][j] / (lmbda * Bu * Au) ** (1.0 / (1.0 + Au))) ** (
72
114
  0.5 / t[u][j]
73
115
  ) + 1
74
116
  bw[u][j] = max(6, 2 * round(0.5 * bwuj))
75
117
 
76
- return bw
118
+ return bw, fix
77
119
 
78
120
 
79
121
  def fitrate_log(y):
@@ -158,7 +200,7 @@ def estimate_rates(self, lam, settingnr=None, verbosity=0):
158
200
 
159
201
  if verbosity > 5:
160
202
 
161
- y = np.cumsum(axissum)[::-1]
203
+ y = np.cumsum(axissum[::-1])[::-1]
162
204
  ax.plot(
163
205
  range(1, len(y) + 1),
164
206
  y,
@@ -171,9 +213,9 @@ def estimate_rates(self, lam, settingnr=None, verbosity=0):
171
213
  t[u][j] = math.nan
172
214
  else:
173
215
  idx = min(len(axissum), len(axissum) - idx + 2)
174
- Duj, tuj = fitrate_log((np.cumsum(axissum)[::-1])[0:idx])
175
-
176
- if tuj < 0.004:
216
+ Duj, tuj = fitrate_log((np.cumsum(axissum[::-1])[::-1])[0:idx])
217
+ #print(u,j,tuj)
218
+ if abs(tuj) < 0.004:
177
219
  D[u][j] = math.nan
178
220
  t[u][j] = math.nan
179
221
  else:
File without changes
File without changes
File without changes