pyANOVAapprox 2.0.0__tar.gz → 2.0.2__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.
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/PKG-INFO +1 -1
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/pyproject.toml +1 -1
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/simpleTest/exampleAutoapproximate.py +1 -1
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/simpleTest/exampleCheb.py +5 -5
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/simpleTest/exampleClassification.py +2 -2
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/simpleTest/exampleNonPeriodic.py +8 -8
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/simpleTest/examplePeriodic.py +1 -1
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/simpleTest/exampleWavelet.py +10 -10
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/src/pyANOVAapprox/__init__.py +2 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/src/pyANOVAapprox/approx.py +43 -20
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/src/pyANOVAapprox/bandwidth.py +41 -29
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/.github/workflows/ci.yml +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/.github/workflows/documentation.yml +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/.github/workflows/format.yml +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/.github/workflows/release.yml +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/.gitignore +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/LICENSE +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/README.md +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/docs/Makefile +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/docs/source/Analysis.rst +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/docs/source/Approximation.rst +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/docs/source/Errors.rst +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/docs/source/conf.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/docs/source/index.rst +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/simpleTest/TestFunctionPeriodic.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/src/pyANOVAapprox/analysis.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/src/pyANOVAapprox/errors.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/src/pyANOVAapprox/fista.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/src/pyANOVAapprox/trafos.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/tests/TestFunctionCheb.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/tests/TestFunctionPeriodic.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/tests/cheb_fista.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/tests/cheb_lsqr.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/tests/per_fista.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/tests/per_lsqr.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/tests/run_tests.py +0 -0
- {pyanovaapprox-2.0.0 → pyanovaapprox-2.0.2}/tests/wav_lsqr.py +0 -0
|
@@ -56,7 +56,7 @@ ads.autoapproximate()
|
|
|
56
56
|
## get approximation accuracy ##
|
|
57
57
|
################################
|
|
58
58
|
|
|
59
|
-
# mse =
|
|
59
|
+
# mse = ads.get_mse() # get mse error at the given training points
|
|
60
60
|
mse = ads.get_mse(X=X_test, y=y_test) # get mse error at the test points
|
|
61
61
|
λ_min = min(
|
|
62
62
|
mse, key=mse.get
|
|
@@ -86,8 +86,8 @@ ads.approximate(lam=lambdas, max_iter=max_iter, solver="lsqr")
|
|
|
86
86
|
## get approximation accuracy ##
|
|
87
87
|
################################
|
|
88
88
|
|
|
89
|
-
# mse =
|
|
90
|
-
mse =
|
|
89
|
+
# mse = ads.get_mse() # get mse error at the given training points
|
|
90
|
+
mse = ads.get_mse(X=X_test, y=y_test) # get mse error at the test points
|
|
91
91
|
λ_min = min(
|
|
92
92
|
mse, key=mse.get
|
|
93
93
|
) # get the regularisation parameter which leads to the minimal error
|
|
@@ -100,7 +100,7 @@ print("mse = " + str(mse_min))
|
|
|
100
100
|
###############################################
|
|
101
101
|
|
|
102
102
|
|
|
103
|
-
ar =
|
|
103
|
+
ar = ads.get_AttributeRanking(lam=λ_min) # get the attrbute ranking
|
|
104
104
|
|
|
105
105
|
plt.figure()
|
|
106
106
|
markers, stemlines, baseline = plt.stem(
|
|
@@ -121,7 +121,7 @@ plt.grid(True, which="both", ls="--", linewidth=0.5)
|
|
|
121
121
|
plt.show() # plot the arrtibute ranking in an logplot
|
|
122
122
|
print("active dimensions: " + str(ar[ar > 1e-2]))
|
|
123
123
|
|
|
124
|
-
gsis =
|
|
124
|
+
gsis = ads.get_GSI(lam=λ_min)
|
|
125
125
|
label = list(ads.U[1:])
|
|
126
126
|
l = len(label)
|
|
127
127
|
plt.figure()
|
|
@@ -166,7 +166,7 @@ a.approximate(
|
|
|
166
166
|
lam=lambdas, max_iter=max_iter, solver="lsqr"
|
|
167
167
|
) # do the approximation for all specified regularisation parameters
|
|
168
168
|
|
|
169
|
-
mse =
|
|
169
|
+
mse = a.get_mse(X=X_test, y=y_test) # get mse error at the test points
|
|
170
170
|
λ_min = min(
|
|
171
171
|
mse, key=mse.get
|
|
172
172
|
) # get the regularisation parameter which leads to the minimal error
|
|
@@ -97,7 +97,7 @@ print("accuracity = " + str(acc))
|
|
|
97
97
|
## Analyze the model to improve the accuracy ##
|
|
98
98
|
###############################################
|
|
99
99
|
|
|
100
|
-
ar =
|
|
100
|
+
ar = ads.get_AttributeRanking(lam=0.0) # get the attrbute ranking
|
|
101
101
|
|
|
102
102
|
plt.figure()
|
|
103
103
|
markers, stemlines, baseline = plt.stem(
|
|
@@ -118,7 +118,7 @@ plt.grid(True, which="both", ls="--", linewidth=0.5)
|
|
|
118
118
|
plt.show() # plot the arrtibute ranking in an logplot
|
|
119
119
|
print("active dimensions: " + str(ar[ar > 1e-2]))
|
|
120
120
|
|
|
121
|
-
gsis =
|
|
121
|
+
gsis = ads.get_GSI(lam=0.0)
|
|
122
122
|
label = list(ads.U[1:])
|
|
123
123
|
l = len(label)
|
|
124
124
|
plt.figure()
|
|
@@ -84,8 +84,8 @@ ads.approximate(lam=lambdas, max_iter=max_iter, solver="lsqr")
|
|
|
84
84
|
## get approximation accuracy ##
|
|
85
85
|
################################
|
|
86
86
|
|
|
87
|
-
# mse =
|
|
88
|
-
mse =
|
|
87
|
+
# mse = ads.get_mse() # get mse error at the given training points
|
|
88
|
+
mse = ads.get_mse(X=X_test, y=y_test) # get mse error at the test points
|
|
89
89
|
λ_min = min(
|
|
90
90
|
mse, key=mse.get
|
|
91
91
|
) # get the regularisation parameter which leads to the minimal error
|
|
@@ -98,7 +98,7 @@ print("mse = " + str(mse_min))
|
|
|
98
98
|
###############################################
|
|
99
99
|
|
|
100
100
|
|
|
101
|
-
ar =
|
|
101
|
+
ar = ads.get_AttributeRanking(lam=λ_min) # get the attrbute ranking
|
|
102
102
|
|
|
103
103
|
plt.figure()
|
|
104
104
|
markers, stemlines, baseline = plt.stem(
|
|
@@ -119,8 +119,8 @@ plt.grid(True, which="both", ls="--", linewidth=0.5)
|
|
|
119
119
|
plt.show() # plot the arrtibute ranking in an logplot
|
|
120
120
|
print("active dimensions: " + str(ar[ar > 1e-2]))
|
|
121
121
|
|
|
122
|
-
gsis =
|
|
123
|
-
label = list(ads.U[1:])
|
|
122
|
+
gsis = ads.get_GSI(lam=λ_min)
|
|
123
|
+
label = list(ads.getSetting().U[1:])
|
|
124
124
|
l = len(label)
|
|
125
125
|
plt.figure()
|
|
126
126
|
x_values = np.arange(1, l + 1)
|
|
@@ -150,7 +150,7 @@ print(
|
|
|
150
150
|
################################################
|
|
151
151
|
|
|
152
152
|
Umask = np.append(np.array([True]), gsis > 1e-2)
|
|
153
|
-
U = [ads.U[i] for i in np.arange(0, len(Umask))[Umask]] # get important subsets
|
|
153
|
+
U = [ads.getSetting().U[i] for i in np.arange(0, len(Umask))[Umask]] # get important subsets
|
|
154
154
|
bws = M / (math.log10(M) * (len(U) - 1)) # calculate frequencies per subset
|
|
155
155
|
N = [
|
|
156
156
|
math.floor(bws ** (1 / max(1, len(u))) / 2) * 2 for u in U
|
|
@@ -164,7 +164,7 @@ a.approximate(
|
|
|
164
164
|
lam=lambdas, max_iter=max_iter, solver="lsqr"
|
|
165
165
|
) # do the approximation for all specified regularisation parameters
|
|
166
166
|
|
|
167
|
-
mse =
|
|
167
|
+
mse = a.get_mse(X=X_test, y=y_test) # get mse error at the test points
|
|
168
168
|
λ_min = min(
|
|
169
169
|
mse, key=mse.get
|
|
170
170
|
) # get the regularisation parameter which leads to the minimal error
|
|
@@ -183,7 +183,7 @@ print("mse = " + str(mse_min))
|
|
|
183
183
|
y_eval_anova = a.evaluateANOVAterms(
|
|
184
184
|
X=X_test, lam=λ_min
|
|
185
185
|
) # evaluate all of the ANOVA terms
|
|
186
|
-
pos = a.U.index((3,)) # find the index for the subset u=[3]
|
|
186
|
+
pos = a.getSetting().U.index((3,)) # find the index for the subset u=[3]
|
|
187
187
|
y_eval_anova_3 = y_eval_anova.T[pos]
|
|
188
188
|
|
|
189
189
|
perm = np.argsort(X_test.T[3])
|
|
@@ -89,7 +89,7 @@ ads.approximate(lam=lambdas, max_iter=max_iter, solver="lsqr")
|
|
|
89
89
|
## get approximation accuracy ##
|
|
90
90
|
################################
|
|
91
91
|
|
|
92
|
-
# mse =
|
|
92
|
+
# mse = ads.get_mse() # get mse error at the given training points
|
|
93
93
|
mse = ads.get_mse(X=X_test, y=y_test) # get mse error at the test points
|
|
94
94
|
λ_min = min(
|
|
95
95
|
mse, key=mse.get
|
|
@@ -81,10 +81,10 @@ print("Total number of used parameters = " + str(len(anova_model.fc[lambdas[0]].
|
|
|
81
81
|
#######################
|
|
82
82
|
|
|
83
83
|
### Do sensitivity analysis ####
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
anova_model.get_GSI(
|
|
85
|
+
lam=0.0
|
|
86
86
|
) # calculates indices for importance of terms (gsis is vector, with indices belonging to terms in anova_model.U)
|
|
87
|
-
|
|
87
|
+
anova_model.get_GSI(lam=0.0, Dict=true)
|
|
88
88
|
|
|
89
89
|
y_min_calc = 10 ** (np.min(np.log10(gsis)) - 0.5)
|
|
90
90
|
label = list(anova_model.U[1:])
|
|
@@ -113,8 +113,8 @@ plt.show()
|
|
|
113
113
|
################################
|
|
114
114
|
|
|
115
115
|
### error analysis ###
|
|
116
|
-
mse_train =
|
|
117
|
-
mse_test =
|
|
116
|
+
mse_train = anova_model.get_mse(lam=0.0)
|
|
117
|
+
mse_test = anova_model.get_mse(X=X_test, y=y_test, lam=0.0)
|
|
118
118
|
|
|
119
119
|
print("MSE on test points: " + str(mse_test))
|
|
120
120
|
|
|
@@ -122,13 +122,13 @@ print("MSE on test points: " + str(mse_test))
|
|
|
122
122
|
## Approximation with better suited index set ##
|
|
123
123
|
################################################
|
|
124
124
|
|
|
125
|
-
U =
|
|
125
|
+
U = anova_model.get_ActiveSet(eps=[0.01, 0.01], lam=0.0)
|
|
126
126
|
print("Found index-set U: " + str(U))
|
|
127
|
-
anova_model =
|
|
128
|
-
X, y, U=U, N=[i + 2 for i in N], basis=basis
|
|
127
|
+
anova_model = anova_model.approx(
|
|
128
|
+
X=X, y=y, U=U, N=[i + 2 for i in N], basis=basis
|
|
129
129
|
) # increase number of paramers in N for the important terms
|
|
130
130
|
anova_model.approximate(lam=lambdas)
|
|
131
131
|
print("Total number of used parameters = " + str(len(anova_model.fc[lambdas[0]].vec())))
|
|
132
|
-
mse_train =
|
|
133
|
-
mse_test =
|
|
132
|
+
mse_train = anova_model.get_mse(lam=0.0)
|
|
133
|
+
mse_test = anova_model.get_mse(X=X_test, y=y_test, lam=0.0)
|
|
134
134
|
print("MSE on test points after ANOVA truncation: " + str(mse_test))
|
|
@@ -187,6 +187,9 @@ class approx:
|
|
|
187
187
|
):
|
|
188
188
|
|
|
189
189
|
self.X = X
|
|
190
|
+
|
|
191
|
+
if X.shape[0] != y.shape[0]:
|
|
192
|
+
raise ValueError("X and y have different lengths.")
|
|
190
193
|
|
|
191
194
|
setting = approx_setting(
|
|
192
195
|
parent=self,
|
|
@@ -246,8 +249,6 @@ class approx:
|
|
|
246
249
|
setting = self.getSetting(settingnr)
|
|
247
250
|
if settingnr is None:
|
|
248
251
|
settingnr = self.aktsetting
|
|
249
|
-
# print(setting.U)
|
|
250
|
-
# print(setting.N)
|
|
251
252
|
self.trafo[settingnr] = GroupedTransform(
|
|
252
253
|
system=gt_systems[setting.basis],
|
|
253
254
|
U=setting.U,
|
|
@@ -386,7 +387,7 @@ class approx:
|
|
|
386
387
|
B,
|
|
387
388
|
maxiter,
|
|
388
389
|
solver,
|
|
389
|
-
|
|
390
|
+
verbosity,
|
|
390
391
|
solver_max_iter,
|
|
391
392
|
solver_weights,
|
|
392
393
|
solver_verbose,
|
|
@@ -400,8 +401,16 @@ class approx:
|
|
|
400
401
|
|
|
401
402
|
D = dict([(u, tuple([1.0] * len(u))) for u in setting.U])
|
|
402
403
|
t = dict([(u, tuple([1.0] * len(u))) for u in setting.U])
|
|
404
|
+
|
|
405
|
+
if verbosity>3:
|
|
406
|
+
if not os.path.exists("log"):
|
|
407
|
+
os.mkdir("log")
|
|
408
|
+
with open('log/log.csv', 'w', newline='') as csvfile:
|
|
409
|
+
csv.writer(csvfile, delimiter=',').writerow(["it"] + setting.U)
|
|
403
410
|
|
|
404
411
|
for idx in range(maxiter):
|
|
412
|
+
if verbosity > 0:
|
|
413
|
+
print("===== Iteration ", str(idx + 1), " =====")
|
|
405
414
|
bw = compute_bandwidth(B, D, t)
|
|
406
415
|
if setting.N is not None:
|
|
407
416
|
self.addSetting(setting)
|
|
@@ -411,9 +420,14 @@ class approx:
|
|
|
411
420
|
setting.N = [bw[i] for i in setting.U]
|
|
412
421
|
self.addTrafo()
|
|
413
422
|
|
|
414
|
-
if
|
|
415
|
-
|
|
416
|
-
|
|
423
|
+
if verbosity > 0:
|
|
424
|
+
for i in setting.U:
|
|
425
|
+
print("bw in", str(i), ":", bw[i])
|
|
426
|
+
#print("bw in iteration", str(idx + 1), "are", str(bw))
|
|
427
|
+
print()
|
|
428
|
+
if verbosity > 3:
|
|
429
|
+
with open('log/log.csv', 'a', newline='') as csvfile:
|
|
430
|
+
csv.writer(csvfile, delimiter=',').writerow(["bw in it"+str(idx+1)] + [str(bw[i]) for i in setting.U])
|
|
417
431
|
self.approximate(
|
|
418
432
|
lam=lam,
|
|
419
433
|
solver=solver,
|
|
@@ -423,16 +437,25 @@ class approx:
|
|
|
423
437
|
tol=solver_tol,
|
|
424
438
|
)
|
|
425
439
|
|
|
426
|
-
D, t = self.estimate_rates(lam=lam,
|
|
427
|
-
if
|
|
428
|
-
|
|
429
|
-
"estimated rates
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
440
|
+
D, t = self.estimate_rates(lam=lam, verbosity=verbosity)
|
|
441
|
+
if verbosity > 1:
|
|
442
|
+
for i in setting.U:
|
|
443
|
+
print("estimated rates for", str(i), ": D = ", str(D[i]), "and t = ", str(t[i]) )
|
|
444
|
+
print()
|
|
445
|
+
|
|
446
|
+
#print(
|
|
447
|
+
# "estimated rates in iteration",
|
|
448
|
+
# str(idx + 1),
|
|
449
|
+
# "are D =",
|
|
450
|
+
# str(D),
|
|
451
|
+
# "and t =",
|
|
452
|
+
# str(t),
|
|
453
|
+
#)
|
|
454
|
+
if verbosity > 3:
|
|
455
|
+
with open('log/log.csv', 'a', newline='') as csvfile:
|
|
456
|
+
wr = csv.writer(csvfile, delimiter=',')
|
|
457
|
+
wr.writerow(["D in it"+str(idx+1)] + [str(D[i]) for i in setting.U])
|
|
458
|
+
wr.writerow(["t in it"+str(idx+1)] + [str(t[i]) for i in setting.U])
|
|
436
459
|
return D, t
|
|
437
460
|
|
|
438
461
|
def autoapproximate(
|
|
@@ -442,7 +465,7 @@ class approx:
|
|
|
442
465
|
B=None,
|
|
443
466
|
maxiter=2,
|
|
444
467
|
solver="lsqr",
|
|
445
|
-
|
|
468
|
+
verbosity=0,
|
|
446
469
|
solver_max_iter=50,
|
|
447
470
|
solver_weights=None,
|
|
448
471
|
solver_verbose=False,
|
|
@@ -464,7 +487,7 @@ class approx:
|
|
|
464
487
|
B=B,
|
|
465
488
|
maxiter=maxiter,
|
|
466
489
|
solver=solver,
|
|
467
|
-
|
|
490
|
+
verbosity=verbosity,
|
|
468
491
|
solver_max_iter=solver_max_iter,
|
|
469
492
|
solver_weights=solver_weights,
|
|
470
493
|
solver_verbose=solver_verbose,
|
|
@@ -478,7 +501,7 @@ class approx:
|
|
|
478
501
|
B=B,
|
|
479
502
|
maxiter=maxiter,
|
|
480
503
|
solver=solver,
|
|
481
|
-
|
|
504
|
+
verbosity=verbosity,
|
|
482
505
|
solver_max_iter=solver_max_iter,
|
|
483
506
|
solver_weights=solver_weights,
|
|
484
507
|
solver_verbose=solver_verbose,
|
|
@@ -543,7 +566,7 @@ class approx:
|
|
|
543
566
|
|
|
544
567
|
Xt = transformX(X, setting.basis)
|
|
545
568
|
|
|
546
|
-
if self.
|
|
569
|
+
if self.getSetting(settingnr).basis == "per":
|
|
547
570
|
values = np.zeros((Xt.shape[0], len(self.setting[settingnr].U)), "complex")
|
|
548
571
|
else:
|
|
549
572
|
values = np.zeros((Xt.shape[0], len(self.setting[settingnr].U)), "float")
|
|
@@ -5,23 +5,30 @@ def getfcu(ghat, u):
|
|
|
5
5
|
idx = [s.u for s in ghat.settings].index(u)
|
|
6
6
|
bws = ghat.settings[idx].bandwidths
|
|
7
7
|
|
|
8
|
-
fcu = ghat[u].reshape(bws[::-1] - 1)
|
|
9
|
-
fcu = np.permute_dims(fcu, range(len(bws))[::-1])
|
|
10
|
-
|
|
8
|
+
#fcu = ghat[u].reshape(bws[::-1] - 1)
|
|
9
|
+
#fcu = np.permute_dims(fcu, range(len(bws))[::-1])
|
|
10
|
+
fcu = ghat[u].reshape(bws - 1)
|
|
11
|
+
fcu = np.permute_dims(fcu, range(len(bws)))
|
|
12
|
+
|
|
11
13
|
return fcu
|
|
12
14
|
|
|
13
15
|
|
|
14
|
-
def getaxissum(ghat, u, j):
|
|
16
|
+
def getaxissum(ghat, u, j, system):
|
|
15
17
|
fcu = getfcu(ghat, u)
|
|
16
18
|
idx = [s.u for s in ghat.settings].index(u)
|
|
17
19
|
bws = ghat.settings[idx].bandwidths
|
|
18
20
|
|
|
19
21
|
fcuj = np.sum(abs(fcu) ** 2, axis=tuple([i for i in range(len(u)) if i != j]))
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
fcuj
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if system == "exp":
|
|
24
|
+
fcuj = (
|
|
25
|
+
fcuj[np.mod(range(int(bws[j] / 2), bws[j]), bws[j] - 1)]
|
|
26
|
+
+ fcuj[range(int(bws[j] / 2) - 1, -1, -1)]
|
|
27
|
+
)
|
|
28
|
+
elif system == "cos":
|
|
29
|
+
pass
|
|
30
|
+
else:
|
|
31
|
+
raise ValueError("For this basis is estimate rates not implemented")
|
|
25
32
|
# fcuj = np.concatenate(fcuj[math.ceil(bws[j]/2):] + [fcuj[0]]) + fcuj[math.ceil(bws[j]/2)-1::-1]
|
|
26
33
|
return fcuj
|
|
27
34
|
|
|
@@ -30,7 +37,7 @@ def compute_bandwidth(B, D, t):
|
|
|
30
37
|
us = set(D.keys()) - {()}
|
|
31
38
|
bw = {u: [6] * len(u) for u in us}
|
|
32
39
|
bw[()] = []
|
|
33
|
-
|
|
40
|
+
|
|
34
41
|
minfreqs = sum(math.prod((bw[u][j] - 1) for j in range(len(u))) for u in us)
|
|
35
42
|
if B < minfreqs:
|
|
36
43
|
raise ValueError(f"Budget too small: {B} < {minfreqs}")
|
|
@@ -104,7 +111,7 @@ def most_common_value(data):
|
|
|
104
111
|
return t[max_index]
|
|
105
112
|
|
|
106
113
|
|
|
107
|
-
def estimate_rates(self, lam, settingnr=None,
|
|
114
|
+
def estimate_rates(self, lam, settingnr=None, verbosity=0):
|
|
108
115
|
us = [s.u for s in self.getTrafo(settingnr).settings]
|
|
109
116
|
nhat = GroupedCoefficients(
|
|
110
117
|
self.getTrafo(settingnr).settings,
|
|
@@ -116,25 +123,28 @@ def estimate_rates(self, lam, settingnr=None, verbose=False):
|
|
|
116
123
|
|
|
117
124
|
mcl = np.exp(most_common_value(np.log(abs(self.getFc(settingnr)[lam].data))))
|
|
118
125
|
threshold = 100 * mcl**2
|
|
119
|
-
|
|
120
|
-
if
|
|
121
|
-
|
|
126
|
+
|
|
127
|
+
if verbosity>5:
|
|
128
|
+
if not os.path.exists(os.path.join("log","figures")):
|
|
129
|
+
os.mkdir(os.path.join("log","figures"))
|
|
130
|
+
num = 0
|
|
131
|
+
|
|
132
|
+
system = self.getTrafo(settingnr).system
|
|
122
133
|
|
|
123
134
|
for u in us:
|
|
124
135
|
if len(u) == 0:
|
|
125
136
|
continue
|
|
126
137
|
|
|
127
|
-
if
|
|
138
|
+
if verbosity>5:
|
|
128
139
|
fig, ax = plt.subplots()
|
|
129
140
|
ax.set_xscale("log")
|
|
130
141
|
ax.set_yscale("log")
|
|
131
142
|
ax.set_title(str(u))
|
|
132
|
-
ps.append(ax)
|
|
133
143
|
|
|
134
144
|
for j in range(len(u)):
|
|
135
|
-
axissum = getaxissum(self.getFc(settingnr)[lam], u, j)
|
|
145
|
+
axissum = getaxissum(self.getFc(settingnr)[lam], u, j, system)
|
|
136
146
|
|
|
137
|
-
axissumnum = getaxissum(nhat, u, j)
|
|
147
|
+
axissumnum = getaxissum(nhat, u, j, system)
|
|
138
148
|
idx = next(
|
|
139
149
|
(
|
|
140
150
|
i
|
|
@@ -144,7 +154,7 @@ def estimate_rates(self, lam, settingnr=None, verbose=False):
|
|
|
144
154
|
None,
|
|
145
155
|
)
|
|
146
156
|
|
|
147
|
-
if
|
|
157
|
+
if verbosity>5:
|
|
148
158
|
|
|
149
159
|
y = np.cumsum(axissum[::-1])[::-1]
|
|
150
160
|
ax.plot(
|
|
@@ -156,26 +166,28 @@ def estimate_rates(self, lam, settingnr=None, verbose=False):
|
|
|
156
166
|
)
|
|
157
167
|
|
|
158
168
|
if (idx is None) or idx >= len(axissum):
|
|
159
|
-
D[u][
|
|
160
|
-
t[u][
|
|
169
|
+
D[u][j] = math.nan
|
|
170
|
+
t[u][j] = math.nan
|
|
161
171
|
else:
|
|
162
172
|
idx = min(len(axissum), len(axissum) - idx + 2)
|
|
163
173
|
Duj, tuj = fitrate_log(np.cumsum((axissum[0:idx])[::-1])[::-1])
|
|
164
|
-
D[u][
|
|
165
|
-
t[u][
|
|
174
|
+
D[u][j] = Duj
|
|
175
|
+
t[u][j] = -tuj / 2
|
|
166
176
|
|
|
167
|
-
if
|
|
177
|
+
if verbosity>5:
|
|
168
178
|
x = np.arange(1, idx + 1)
|
|
169
179
|
ax.plot(
|
|
170
180
|
x,
|
|
171
|
-
D[u][
|
|
181
|
+
D[u][j] * x ** (-2 * t[u][j]),
|
|
172
182
|
linewidth=2,
|
|
173
183
|
# color=j
|
|
174
184
|
)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
plt.sca(ax)
|
|
179
|
-
|
|
185
|
+
if verbosity>5:
|
|
186
|
+
#plt.figure(figsize=(12, 9))
|
|
187
|
+
#for ax in ps:
|
|
188
|
+
# plt.sca(ax)
|
|
189
|
+
fig.savefig(os.path.join("log","figures", str(num).strip()+ "_rates_" + str(u).strip() + ".png"))
|
|
190
|
+
num = num + 1
|
|
191
|
+
plt.close(fig)
|
|
180
192
|
|
|
181
193
|
return D, t
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|