pyANOVAapprox 0.2.3__tar.gz → 2.0.0__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-0.2.3 → pyanovaapprox-2.0.0}/.github/workflows/ci.yml +1 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/.gitignore +2 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/PKG-INFO +4 -2
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/README.md +1 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/pyproject.toml +3 -2
- pyanovaapprox-2.0.0/simpleTest/exampleAutoapproximate.py +66 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/simpleTest/exampleCheb.py +2 -2
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/simpleTest/exampleClassification.py +2 -2
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/simpleTest/exampleNonPeriodic.py +2 -2
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/simpleTest/examplePeriodic.py +6 -6
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/simpleTest/exampleWavelet.py +2 -2
- pyanovaapprox-2.0.0/src/pyANOVAapprox/__init__.py +165 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/src/pyANOVAapprox/analysis.py +82 -46
- pyanovaapprox-2.0.0/src/pyANOVAapprox/approx.py +647 -0
- pyanovaapprox-2.0.0/src/pyANOVAapprox/bandwidth.py +181 -0
- pyanovaapprox-2.0.0/src/pyANOVAapprox/errors.py +261 -0
- pyanovaapprox-2.0.0/tests/TestFunctionPeriodic.py +155 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/tests/cheb_fista.py +8 -12
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/tests/cheb_lsqr.py +15 -20
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/tests/per_fista.py +7 -7
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/tests/per_lsqr.py +7 -7
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/tests/wav_lsqr.py +6 -6
- pyanovaapprox-0.2.3/src/pyANOVAapprox/__init__.py +0 -69
- pyanovaapprox-0.2.3/src/pyANOVAapprox/approx.py +0 -469
- pyanovaapprox-0.2.3/src/pyANOVAapprox/errors.py +0 -191
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/.github/workflows/documentation.yml +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/.github/workflows/format.yml +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/.github/workflows/release.yml +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/LICENSE +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/docs/Makefile +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/docs/source/Analysis.rst +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/docs/source/Approximation.rst +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/docs/source/Errors.rst +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/docs/source/conf.py +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/docs/source/index.rst +0 -0
- {pyanovaapprox-0.2.3/tests → pyanovaapprox-2.0.0/simpleTest}/TestFunctionPeriodic.py +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/src/pyANOVAapprox/fista.py +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/src/pyANOVAapprox/trafos.py +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/tests/TestFunctionCheb.py +0 -0
- {pyanovaapprox-0.2.3 → pyanovaapprox-2.0.0}/tests/run_tests.py +0 -0
|
@@ -6,6 +6,7 @@ dist/
|
|
|
6
6
|
*.py[cod]
|
|
7
7
|
__pycache__/
|
|
8
8
|
venv/
|
|
9
|
+
venv2/
|
|
9
10
|
|
|
10
11
|
bin/
|
|
11
12
|
/lib64/
|
|
@@ -16,3 +17,4 @@ src/pyNFFT3/lib/AVX2/libgomp-1.dll
|
|
|
16
17
|
src/pyNFFT3/lib/AVX2/libgcc_s_seh-1.dll
|
|
17
18
|
src/pyNFFT3/lib/AVX2/libwinpthread-1.dll
|
|
18
19
|
simpleTest/venv/
|
|
20
|
+
bandwidth_detection.py
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyANOVAapprox
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 2.0.0
|
|
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>
|
|
7
7
|
Maintainer-email: Pascal Schröter <pascal.schroeter@mathematik.tu-chemnitz.de>
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
Requires-Python: >=3.9
|
|
10
|
+
Requires-Dist: matplotlib>=3.5
|
|
10
11
|
Requires-Dist: numpy>=2.0.0
|
|
11
|
-
Requires-Dist: pygroupedtransforms>=
|
|
12
|
+
Requires-Dist: pygroupedtransforms>=1.1.0
|
|
12
13
|
Requires-Dist: scipy>=1.16.0
|
|
13
14
|
Description-Content-Type: text/markdown
|
|
14
15
|
|
|
@@ -67,3 +68,4 @@ Requirements
|
|
|
67
68
|
- pyGroupedTransforms 0.1.0 or greater
|
|
68
69
|
- NumPy 2.0.0 or greater
|
|
69
70
|
- SciPy 1.16.0 or greater
|
|
71
|
+
- Matplotlib 3.5 or greater
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pyANOVAapprox"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "2.0.0"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Felix Wirth", email="fwi012001@gmail.com" },
|
|
10
10
|
]
|
|
@@ -15,9 +15,10 @@ description = "Approximation Package for High-Dimensional Functions"
|
|
|
15
15
|
readme = "README.md"
|
|
16
16
|
requires-python = ">=3.9"
|
|
17
17
|
dependencies = [
|
|
18
|
-
"pyGroupedTransforms>=
|
|
18
|
+
"pyGroupedTransforms>=1.1.0",
|
|
19
19
|
"numpy>=2.0.0",
|
|
20
20
|
"scipy>=1.16.0",
|
|
21
|
+
"matplotlib>=3.5"
|
|
21
22
|
]
|
|
22
23
|
|
|
23
24
|
[project.urls]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# pip install pyANOVAapprox
|
|
2
|
+
|
|
3
|
+
# Example for approximating an periodic function
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
|
|
7
|
+
import matplotlib.pyplot as plt
|
|
8
|
+
import numpy as np
|
|
9
|
+
from TestFunctionPeriodic import *
|
|
10
|
+
|
|
11
|
+
import pyANOVAapprox as ANOVAapprox
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def TestFunction(x):
|
|
15
|
+
return b_spline_2(x[0]) * b_spline_4(x[1]) * b_spline_6(x[2])
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
rng = np.random.default_rng(1234)
|
|
19
|
+
|
|
20
|
+
##################################
|
|
21
|
+
## Definition of the parameters ##
|
|
22
|
+
##################################
|
|
23
|
+
|
|
24
|
+
d = 3 # dimension
|
|
25
|
+
|
|
26
|
+
M = 100000 # number of used evaluation points to train the model
|
|
27
|
+
M_test = 100000 # number of used evaluation points to test the accuracity the model
|
|
28
|
+
|
|
29
|
+
U = [(), (0,), (1,), (2,), (0, 1), (0, 2), (1, 2), (0, 1, 2)]
|
|
30
|
+
|
|
31
|
+
lambdas = np.array([0.0]) # used regularisation parameters λ
|
|
32
|
+
|
|
33
|
+
############################
|
|
34
|
+
## Generation of the data ##
|
|
35
|
+
############################
|
|
36
|
+
|
|
37
|
+
X = rng.random((M, d)) # construct the evaluation points for training
|
|
38
|
+
y = np.array(
|
|
39
|
+
[TestFunction(X[i, :].T) for i in range(M)], dtype=complex
|
|
40
|
+
) # evaluate the function at these points
|
|
41
|
+
X = X - 0.5
|
|
42
|
+
X_test = rng.random((M_test, d))
|
|
43
|
+
y_test = np.array(
|
|
44
|
+
[TestFunction(X_test[i, :].T) for i in range(M_test)], dtype=complex
|
|
45
|
+
) # the same for the test points
|
|
46
|
+
X_test = X_test - 0.5
|
|
47
|
+
|
|
48
|
+
##########################
|
|
49
|
+
## Do the approximation ##
|
|
50
|
+
##########################
|
|
51
|
+
|
|
52
|
+
ads = ANOVAapprox.approx(X, y, U=U, basis="per")
|
|
53
|
+
ads.autoapproximate()
|
|
54
|
+
|
|
55
|
+
################################
|
|
56
|
+
## get approximation accuracy ##
|
|
57
|
+
################################
|
|
58
|
+
|
|
59
|
+
# mse = ANOVAapprox.get_mse(ads) # get mse error at the given training points
|
|
60
|
+
mse = ads.get_mse(X=X_test, y=y_test) # get mse error at the test points
|
|
61
|
+
λ_min = min(
|
|
62
|
+
mse, key=mse.get
|
|
63
|
+
) # get the regularisation parameter which leads to the minimal error
|
|
64
|
+
mse_min = mse[λ_min]
|
|
65
|
+
|
|
66
|
+
print("mse = " + str(mse_min))
|
|
@@ -103,7 +103,7 @@ print("mse = " + str(mse_min))
|
|
|
103
103
|
ar = ANOVAapprox.get_AttributeRanking(ads, λ_min) # get the attrbute ranking
|
|
104
104
|
|
|
105
105
|
plt.figure()
|
|
106
|
-
|
|
106
|
+
markers, stemlines, baseline = plt.stem(
|
|
107
107
|
np.arange(1, d + 1), # x-Werte (1:d)
|
|
108
108
|
ar, # y-Werte (ar)
|
|
109
109
|
linefmt="C0-", # Stil der Stiele
|
|
@@ -126,7 +126,7 @@ label = list(ads.U[1:])
|
|
|
126
126
|
l = len(label)
|
|
127
127
|
plt.figure()
|
|
128
128
|
x_values = np.arange(1, l + 1)
|
|
129
|
-
|
|
129
|
+
markers, stemlines, baseline = plt.stem(
|
|
130
130
|
x_values, # X-Werte: 1 bis l
|
|
131
131
|
gsis, # Y-Werte: gsis
|
|
132
132
|
linefmt="C0-", # Stil der Stiele
|
|
@@ -100,7 +100,7 @@ print("accuracity = " + str(acc))
|
|
|
100
100
|
ar = ANOVAapprox.get_AttributeRanking(ads, 0.0) # get the attrbute ranking
|
|
101
101
|
|
|
102
102
|
plt.figure()
|
|
103
|
-
|
|
103
|
+
markers, stemlines, baseline = plt.stem(
|
|
104
104
|
np.arange(1, d + 1), # x-Werte (1:d)
|
|
105
105
|
ar, # y-Werte (ar)
|
|
106
106
|
linefmt="C0-", # Stil der Stiele
|
|
@@ -123,7 +123,7 @@ label = list(ads.U[1:])
|
|
|
123
123
|
l = len(label)
|
|
124
124
|
plt.figure()
|
|
125
125
|
x_values = np.arange(1, l + 1)
|
|
126
|
-
|
|
126
|
+
markers, stemlines, baseline = plt.stem(
|
|
127
127
|
x_values, # X-Werte: 1 bis l
|
|
128
128
|
gsis, # Y-Werte: gsis
|
|
129
129
|
linefmt="C0-", # Stil der Stiele
|
|
@@ -101,7 +101,7 @@ print("mse = " + str(mse_min))
|
|
|
101
101
|
ar = ANOVAapprox.get_AttributeRanking(ads, λ_min) # get the attrbute ranking
|
|
102
102
|
|
|
103
103
|
plt.figure()
|
|
104
|
-
|
|
104
|
+
markers, stemlines, baseline = plt.stem(
|
|
105
105
|
np.arange(1, d + 1), # x-Werte (1:d)
|
|
106
106
|
ar, # y-Werte (ar)
|
|
107
107
|
linefmt="C0-", # Stil der Stiele
|
|
@@ -124,7 +124,7 @@ label = list(ads.U[1:])
|
|
|
124
124
|
l = len(label)
|
|
125
125
|
plt.figure()
|
|
126
126
|
x_values = np.arange(1, l + 1)
|
|
127
|
-
|
|
127
|
+
markers, stemlines, baseline = plt.stem(
|
|
128
128
|
x_values, # X-Werte: 1 bis l
|
|
129
129
|
gsis, # Y-Werte: gsis
|
|
130
130
|
linefmt="C0-", # Stil der Stiele
|
|
@@ -90,7 +90,7 @@ ads.approximate(lam=lambdas, max_iter=max_iter, solver="lsqr")
|
|
|
90
90
|
################################
|
|
91
91
|
|
|
92
92
|
# mse = ANOVAapprox.get_mse(ads) # get mse error at the given training points
|
|
93
|
-
mse =
|
|
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
|
|
96
96
|
) # get the regularisation parameter which leads to the minimal error
|
|
@@ -103,10 +103,10 @@ print("mse = " + str(mse_min))
|
|
|
103
103
|
###############################################
|
|
104
104
|
|
|
105
105
|
|
|
106
|
-
ar =
|
|
106
|
+
ar = ads.get_AttributeRanking(lam=λ_min) # get the attrbute ranking
|
|
107
107
|
|
|
108
108
|
plt.figure()
|
|
109
|
-
|
|
109
|
+
markers, stemlines, baseline = plt.stem(
|
|
110
110
|
np.arange(1, d + 1), # x-Werte (1:d)
|
|
111
111
|
ar, # y-Werte (ar)
|
|
112
112
|
linefmt="C0-", # Stil der Stiele
|
|
@@ -124,12 +124,12 @@ plt.grid(True, which="both", ls="--", linewidth=0.5)
|
|
|
124
124
|
plt.show() # plot the arrtibute ranking in an logplot
|
|
125
125
|
print("active dimensions: " + str(ar[ar > 1e-2]))
|
|
126
126
|
|
|
127
|
-
gsis =
|
|
127
|
+
gsis = ads.get_GSI(lam=λ_min)
|
|
128
128
|
label = list(ads.U[1:])
|
|
129
129
|
l = len(label)
|
|
130
130
|
plt.figure()
|
|
131
131
|
x_values = np.arange(1, l + 1)
|
|
132
|
-
|
|
132
|
+
markers, stemlines, baseline = plt.stem(
|
|
133
133
|
x_values, # X-Werte: 1 bis l
|
|
134
134
|
gsis, # Y-Werte: gsis
|
|
135
135
|
linefmt="C0-", # Stil der Stiele
|
|
@@ -169,7 +169,7 @@ a.approximate(
|
|
|
169
169
|
lam=lambdas, max_iter=max_iter, solver="lsqr"
|
|
170
170
|
) # do the approximation for all specified regularisation parameters
|
|
171
171
|
|
|
172
|
-
mse =
|
|
172
|
+
mse = a.get_mse(X=X_test, y=y_test) # get mse error at the test points
|
|
173
173
|
λ_min = min(
|
|
174
174
|
mse, key=mse.get
|
|
175
175
|
) # get the regularisation parameter which leads to the minimal error
|
|
@@ -84,14 +84,14 @@ print("Total number of used parameters = " + str(len(anova_model.fc[lambdas[0]].
|
|
|
84
84
|
gsis = ANOVAapprox.get_GSI(
|
|
85
85
|
anova_model, 0.0
|
|
86
86
|
) # calculates indices for importance of terms (gsis is vector, with indices belonging to terms in anova_model.U)
|
|
87
|
-
gsis_as_dict = ANOVAapprox.get_GSI(anova_model,0.0,dict=true)
|
|
87
|
+
gsis_as_dict = ANOVAapprox.get_GSI(anova_model, 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:])
|
|
91
91
|
l = len(label)
|
|
92
92
|
plt.figure()
|
|
93
93
|
x_values = np.arange(1, l + 1)
|
|
94
|
-
|
|
94
|
+
markers, stemlines, baseline = plt.stem(
|
|
95
95
|
x_values, # X-Werte: 1 bis l
|
|
96
96
|
gsis, # Y-Werte: gsis
|
|
97
97
|
linefmt="C0-", # Stil der Stiele
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import threading
|
|
3
|
+
from math import acos, isnan
|
|
4
|
+
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
import numpy as np
|
|
7
|
+
from pyGroupedTransforms import *
|
|
8
|
+
from scipy.optimize import bisect
|
|
9
|
+
from scipy.sparse.linalg import lsqr
|
|
10
|
+
from scipy.special import erf
|
|
11
|
+
|
|
12
|
+
# from sklearn.metrics import roc_auc_score
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def bisection(l, r, fun, maxiter=1000):
|
|
16
|
+
lval = fun(l)
|
|
17
|
+
rval = fun(r)
|
|
18
|
+
|
|
19
|
+
if np.sign(lval) * np.sign(rval) == 1:
|
|
20
|
+
raise ValueError("bisection: root is not between l and r")
|
|
21
|
+
|
|
22
|
+
if lval > 0:
|
|
23
|
+
gun = fun
|
|
24
|
+
fun = lambda t: -gun(t)
|
|
25
|
+
|
|
26
|
+
m = 0.0
|
|
27
|
+
for _ in range(maxiter):
|
|
28
|
+
m = (l + r) / 2
|
|
29
|
+
mval = fun(m)
|
|
30
|
+
if abs(mval) < 1e-16:
|
|
31
|
+
break
|
|
32
|
+
if mval < 0:
|
|
33
|
+
l = m
|
|
34
|
+
lval = mval
|
|
35
|
+
else:
|
|
36
|
+
r = m
|
|
37
|
+
rval = mval
|
|
38
|
+
|
|
39
|
+
return m
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# from .analysis import *
|
|
43
|
+
from .approx import *
|
|
44
|
+
# from .errors import *
|
|
45
|
+
# from .fista import *
|
|
46
|
+
from .trafos import *
|
|
47
|
+
|
|
48
|
+
# from .bandwidth import *
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def approximate(
|
|
52
|
+
a, lam=None, max_iter=50, weights=None, verbose=False, solver=None, tol=1e-8
|
|
53
|
+
):
|
|
54
|
+
a.approximate(lam, max_iter, weights, verbose, solver, tol)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def autoapproximate(
|
|
58
|
+
a,
|
|
59
|
+
settingnr=None,
|
|
60
|
+
B=None,
|
|
61
|
+
maxiter=2,
|
|
62
|
+
lmbda=0.0,
|
|
63
|
+
solver="lsqr",
|
|
64
|
+
verbose=False,
|
|
65
|
+
solver_max_iter=50,
|
|
66
|
+
solver_weights=None,
|
|
67
|
+
solver_verbose=False,
|
|
68
|
+
solver_tol=1e-8,
|
|
69
|
+
):
|
|
70
|
+
a.autoapproximate(settingnr, B, maxiter, lmbda, solver, verbose)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def evaluate(a, settingnr=None, lam=None, X=None):
|
|
74
|
+
return a.evaluate(settingnr, lam, X)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def evaluateANOVAterms(a, settingnr=None, X=None, lam=None):
|
|
78
|
+
return a.evaluateANOVAterms(settingnr, X, lam)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def evaluateSHAPterms(a, settingnr=None, X=None, lam=None):
|
|
82
|
+
return a.evaluateSHAPterms(settingnr, X, lam)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def get_l2_error(a, settingnr=None, X=None, y=None, lam=None):
|
|
86
|
+
return a.get_l2_error(settingnr, X, y, lam)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def get_mse(a, settingnr=None, X=None, y=None, lam=None):
|
|
90
|
+
return a.get_mse(settingnr, X, y, lam)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def get_mad(a, settingnr=None, X=None, y=None, lam=None):
|
|
94
|
+
return a.get_mad(settingnr, X, y, lam)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def get_L2_error(a, norm, bc_fun, settingnr=None, lam=None):
|
|
98
|
+
return a.get_L2_error(settingnr, norm, bc_fun, lam)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def get_acc(a, settingnr=None, X=None, y=None, lam=None):
|
|
102
|
+
return a.get_acc(settingnr, X, y, lam)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def get_auc(a, settingnr=None, X=None, y=None, lam=None):
|
|
106
|
+
return a.get_auc(settingnr, X, y, lam)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def estimate_rates(a, lam, settingnr=None, verbose=False):
|
|
110
|
+
return a.estimate_rates(lam, settingnr, verbose)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def get_variances(a, settingnr=None, lam=None, Dict=False):
|
|
114
|
+
return a.get_variances(settingnr, lam, Dict)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def get_GSI(a, settingnr=None, lam=None, Dict=False):
|
|
118
|
+
return a.get_GSI(settingnr, lam, Dict)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def get_AttributeRanking(a, settingnr=None, lam=None):
|
|
122
|
+
return a.get_AttributeRanking(settingnr, lam)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def get_ActiveSet(a, eps, settingnr=None, lam=None):
|
|
126
|
+
return a.get_ActiveSet(eps, settingnr, lam)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def get_ShapleyValues(a, settingnr=None, lam=None):
|
|
130
|
+
return a.get_ShapleyValues(settingnr, lam)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
# Export functions and classes:
|
|
134
|
+
__all__ = [
|
|
135
|
+
# from Analysis.py:
|
|
136
|
+
"get_variances",
|
|
137
|
+
"get_GSI",
|
|
138
|
+
"get_AttributeRanking",
|
|
139
|
+
"get_ActiveSet",
|
|
140
|
+
"get_ShapleyValues",
|
|
141
|
+
# from approx.py:
|
|
142
|
+
"approx",
|
|
143
|
+
"approximate",
|
|
144
|
+
"autoapproximate",
|
|
145
|
+
"evaluate",
|
|
146
|
+
"evaluateANOVAterms",
|
|
147
|
+
# from Errors.py:
|
|
148
|
+
"get_l2_error",
|
|
149
|
+
"get_mse",
|
|
150
|
+
"get_mad",
|
|
151
|
+
"get_L2_error",
|
|
152
|
+
"get_acc",
|
|
153
|
+
"get_auc",
|
|
154
|
+
# from trafo.py:
|
|
155
|
+
"transform_cube",
|
|
156
|
+
"transform_R",
|
|
157
|
+
# from fista.py:
|
|
158
|
+
# "bisection",
|
|
159
|
+
# "newton",
|
|
160
|
+
# "λ2ξ",
|
|
161
|
+
# "fista",
|
|
162
|
+
# from bandwidth.py:
|
|
163
|
+
"compute_bandwidth",
|
|
164
|
+
"estimate_rates",
|
|
165
|
+
]
|
|
@@ -1,62 +1,74 @@
|
|
|
1
|
-
from pyANOVAapprox import *
|
|
1
|
+
# from pyANOVAapprox import *
|
|
2
|
+
import numpy as np
|
|
2
3
|
|
|
3
4
|
|
|
4
|
-
def
|
|
5
|
-
|
|
6
|
-
if
|
|
7
|
-
variances =
|
|
5
|
+
def _variances(self, settingnr, lam, Dict): # helpfunction for get_variances
|
|
6
|
+
setting = self.getSetting(settingnr)
|
|
7
|
+
if setting.basis.startswith("chui"):
|
|
8
|
+
variances = self.getFc(settingnr)[lam].norms(
|
|
9
|
+
Dict=False, m=int(setting.basis[-1])
|
|
10
|
+
)
|
|
8
11
|
else:
|
|
9
|
-
variances =
|
|
12
|
+
variances = self.getFc(settingnr)[lam].norms()
|
|
10
13
|
|
|
11
14
|
variances = variances[1:]
|
|
12
15
|
if Dict:
|
|
13
16
|
if a.basis.startswith("chui"):
|
|
14
|
-
variances =
|
|
17
|
+
variances = self.getFc(settingnr)[lam].norms(
|
|
18
|
+
Dict=True, m=int(setting.basis[-1])
|
|
19
|
+
)
|
|
15
20
|
else:
|
|
16
|
-
variances =
|
|
21
|
+
variances = self.getFc(settingnr)[lam].norms(Dict=True)
|
|
17
22
|
|
|
18
23
|
return {u: variances[u] for u in list(variances)}
|
|
19
24
|
else:
|
|
20
25
|
return variances
|
|
21
26
|
|
|
22
27
|
|
|
23
|
-
def get_variances(
|
|
28
|
+
def get_variances(self, settingnr=None, lam=None, Dict=False):
|
|
24
29
|
"""
|
|
25
30
|
This function returns the variances of the approximated ANOVA terms for all ``\lambda``, if lam == None. Otherwise for the provided lam. Depending on Dict, it returns the approximated ANOVA terms as a vector or as a dict.
|
|
26
31
|
"""
|
|
27
32
|
if isinstance(lam, float):
|
|
28
|
-
return
|
|
29
|
-
|
|
33
|
+
return self._variances(
|
|
34
|
+
settingnr, lam, Dict
|
|
30
35
|
) # get_variances(a::approx, λ::Float64; dict::Bool=false,)::Union{Vector{Float64},Dict{Vector{Int},Float64}}
|
|
31
36
|
|
|
32
37
|
elif (
|
|
33
38
|
lam == None
|
|
34
39
|
): # get_variances( a::approx; dict::Bool = false )::Dict{Float64,Union{Vector{Float64},Dict{Vector{Int},Float64}}}
|
|
35
|
-
return {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
return {
|
|
41
|
+
l: self._variances(settingnr, l, Dict)
|
|
42
|
+
for l in self.getSetting(settingnr).lam
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _GSI(self, settingnr, lam, Dict): # helpfunction for get_GSI
|
|
47
|
+
setting = self.getSetting(settingnr)
|
|
48
|
+
if setting.basis.startswith("chui"):
|
|
49
|
+
variances = np.square(
|
|
50
|
+
self.getFc(settingnr)[lam].norms(Dict=False, m=int(setting.basis[-1]))
|
|
51
|
+
)
|
|
42
52
|
else:
|
|
43
|
-
variances = np.square(
|
|
53
|
+
variances = np.square(self.getFc(settingnr)[lam].norms())
|
|
44
54
|
|
|
45
55
|
variances = variances[1:]
|
|
46
56
|
variance_f = sum(variances)
|
|
47
57
|
|
|
48
58
|
if Dict:
|
|
49
|
-
if
|
|
50
|
-
variances =
|
|
59
|
+
if setting.basis.startswith("chui"):
|
|
60
|
+
variances = self.getFc(settingnr)[lam].norms(
|
|
61
|
+
Dict=True, m=int(setting.basis[-1])
|
|
62
|
+
)
|
|
51
63
|
else:
|
|
52
|
-
variances =
|
|
64
|
+
variances = self.getFc(settingnr)[lam].norms(Dict=True)
|
|
53
65
|
return {u: (variances[u] ** 2) / variance_f for u in list(variances)}
|
|
54
66
|
|
|
55
67
|
else:
|
|
56
68
|
return variances / variance_f
|
|
57
69
|
|
|
58
70
|
|
|
59
|
-
def get_GSI(
|
|
71
|
+
def get_GSI(self, settingnr=None, lam=None, Dict=False):
|
|
60
72
|
"""
|
|
61
73
|
This function returns the global sensitivity indices of the approximation for all ``\lambda``, if lam == None. Otherwise for the provided lam. Depending on Dict, it returns the approximated ANOVA terms as a vector or as a dict.
|
|
62
74
|
"""
|
|
@@ -64,15 +76,17 @@ def get_GSI(a, lam=None, Dict=False):
|
|
|
64
76
|
if (
|
|
65
77
|
lam is not None
|
|
66
78
|
): # get_GSI(a::approx, λ::Float64; dict::Bool = false,)::Union{Vector{Float64},Dict{Vector{Int},Float64}}
|
|
67
|
-
return _GSI(
|
|
79
|
+
return self._GSI(settingnr, lam, Dict)
|
|
68
80
|
else: # get_GSI( a::approx; dict::Bool = false )::Dict{Float64,Union{Vector{Float64},Dict{Vector{Int},Float64}}}
|
|
69
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
l: self._GSI(settingnr, l, Dict) for l in self.getSetting(settingnr).lam
|
|
83
|
+
}
|
|
70
84
|
|
|
71
85
|
|
|
72
|
-
def
|
|
86
|
+
def _AttributeRanking(self, settingnr, lam): # helpfunction for get_AttributeRanking
|
|
73
87
|
|
|
74
|
-
d =
|
|
75
|
-
gsis = get_GSI(
|
|
88
|
+
d = self.X.shape[1]
|
|
89
|
+
gsis = self.get_GSI(settingnr, lam, Dict=True)
|
|
76
90
|
U = list(gsis)
|
|
77
91
|
lengths = [len(u) for u in U]
|
|
78
92
|
ds = max(lengths)
|
|
@@ -99,28 +113,31 @@ def lam_AttributeRanking(a, lam): # helpfunction foor get_AttributeRanking
|
|
|
99
113
|
return r / nf
|
|
100
114
|
|
|
101
115
|
|
|
102
|
-
def get_AttributeRanking(
|
|
116
|
+
def get_AttributeRanking(self, settingnr=None, lam=None):
|
|
103
117
|
"""
|
|
104
118
|
This function returns the attribute ranking of the approximation for all reg. parameters ``\lambda``, if lam == None, as a dictionary of vectors of length `a.d`. Otherwise for the provided lam as a vector of length `a.d`.
|
|
105
119
|
"""
|
|
106
120
|
if (
|
|
107
|
-
lam
|
|
121
|
+
lam is None
|
|
108
122
|
): # get_AttributeRanking( a::approx, λ::Float64 )::Dict{Float64,Vector{Float64}}
|
|
109
|
-
return {
|
|
123
|
+
return {
|
|
124
|
+
l: self._AttributeRanking(settingnr, l)
|
|
125
|
+
for l in self.getSetting(settingnr).lam
|
|
126
|
+
}
|
|
110
127
|
else: # get_AttributeRanking( a::approx, λ::Float64 )::Vector{Float64}
|
|
111
|
-
return
|
|
128
|
+
return self._AttributeRanking(settingnr, lam)
|
|
112
129
|
|
|
113
130
|
|
|
114
|
-
def
|
|
131
|
+
def _ActiveSet(self, eps, settingnr, lam): # helpfunction for get_ActiveSet
|
|
115
132
|
|
|
116
|
-
U =
|
|
133
|
+
U = self.getSetting(settingnr).U[1:]
|
|
117
134
|
lengths = [len(u) for u in U]
|
|
118
135
|
ds = max(lengths)
|
|
119
136
|
|
|
120
137
|
if len(eps) != ds:
|
|
121
138
|
raise ValueError("Entries in vector eps have to be ds.")
|
|
122
139
|
|
|
123
|
-
gsi = get_GSI(
|
|
140
|
+
gsi = self.get_GSI(settingnr, lam)
|
|
124
141
|
|
|
125
142
|
n = 0
|
|
126
143
|
|
|
@@ -140,20 +157,23 @@ def lam_ActiveSet(a, eps, lam): # helpfunction for get_ActiveSet
|
|
|
140
157
|
return U_active
|
|
141
158
|
|
|
142
159
|
|
|
143
|
-
def get_ActiveSet(
|
|
160
|
+
def get_ActiveSet(self, eps, settingnr=None, lam=None):
|
|
144
161
|
|
|
145
162
|
if (
|
|
146
|
-
lam
|
|
163
|
+
lam is None
|
|
147
164
|
): # get_ActiveSet(a::approx, eps::Vector{Float64})::Dict{Float64,Vector{Vector{Int}}}
|
|
148
|
-
return {
|
|
165
|
+
return {
|
|
166
|
+
l: self._ActiveSet(eps, settingnr, l)
|
|
167
|
+
for l in self.getSetting(settingnr).lam
|
|
168
|
+
}
|
|
149
169
|
else: # get_ActiveSet(a::approx, eps::Vector{Float64}, λ::Float64)::Vector{Vector{Int}}
|
|
150
|
-
return
|
|
170
|
+
return self._ActiveSet(eps, settingnr, lam)
|
|
151
171
|
|
|
152
172
|
|
|
153
|
-
def
|
|
173
|
+
def _ShapleyValues(self, settingnr, lam): # helpfunction for get_ShapleyValues
|
|
154
174
|
|
|
155
|
-
d =
|
|
156
|
-
vars_dict = get_variances(
|
|
175
|
+
d = self.X.shape[1]
|
|
176
|
+
vars_dict = get_variances(self, settingnr, lam, Dict=True)
|
|
157
177
|
U = list(vars_dict)
|
|
158
178
|
r = np.zeros(d)
|
|
159
179
|
|
|
@@ -165,11 +185,27 @@ def lam_ShapleyValues(a, lam): # helpfunction for get_ShapleyValues
|
|
|
165
185
|
return r
|
|
166
186
|
|
|
167
187
|
|
|
168
|
-
def get_ShapleyValues(
|
|
188
|
+
def get_ShapleyValues(self, settingnr=None, lam=None):
|
|
169
189
|
"""
|
|
170
190
|
This function returns the Shapley values of the approximation for all reg. parameters ``\lambda``, if lam == None, as a dictionary of vectors of length `a.d`. Otherwise for the provided lam as a vector of length `a.d`.
|
|
171
191
|
"""
|
|
172
|
-
if lam
|
|
173
|
-
return {
|
|
192
|
+
if lam is None: # get_ShapleyValues(a::approx)::Dict{Float64,Vector{Float64}}
|
|
193
|
+
return {
|
|
194
|
+
l: self._ShapleyValues(settingnr, l) for l in self.getSetting(settingnr).lam
|
|
195
|
+
}
|
|
174
196
|
else: # get_ShapleyValues(a::approx, λ::Float64)::Vector{Float64}
|
|
175
|
-
return
|
|
197
|
+
return self._ShapleyValues(settingnr, lam)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
_all = [
|
|
201
|
+
"_variances",
|
|
202
|
+
"get_variances",
|
|
203
|
+
"_GSI",
|
|
204
|
+
"get_GSI",
|
|
205
|
+
"_AttributeRanking",
|
|
206
|
+
"get_AttributeRanking",
|
|
207
|
+
"_ActiveSet",
|
|
208
|
+
"get_ActiveSet",
|
|
209
|
+
"_ShapleyValues",
|
|
210
|
+
"get_ShapleyValues",
|
|
211
|
+
]
|