bs-python-utils 0.0.1__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.
- bs_python_utils/Timer.py +76 -0
- bs_python_utils/__init__.py +0 -0
- bs_python_utils/bs_altair.py +927 -0
- bs_python_utils/bs_logging.py +100 -0
- bs_python_utils/bs_mathstr.py +130 -0
- bs_python_utils/bs_mem.py +148 -0
- bs_python_utils/bs_opt.py +518 -0
- bs_python_utils/bs_plots.py +2 -0
- bs_python_utils/bs_seaborn.py +174 -0
- bs_python_utils/bs_sparse_gaussian.py +46 -0
- bs_python_utils/bsmplutils.py +34 -0
- bs_python_utils/bsnputils.py +957 -0
- bs_python_utils/bssputils.py +79 -0
- bs_python_utils/bsstats.py +463 -0
- bs_python_utils/bsutils.py +363 -0
- bs_python_utils/distance_covariances.py +258 -0
- bs_python_utils/example_opt.py +71 -0
- bs_python_utils/examples_altair.py +195 -0
- bs_python_utils/examples_distance_covariances.py +32 -0
- bs_python_utils/examples_mem.py +25 -0
- bs_python_utils/examples_seaborn.py +37 -0
- bs_python_utils/examples_sklearn.py +33 -0
- bs_python_utils/pandas_utils.py +239 -0
- bs_python_utils/sklearn_utils.py +74 -0
- bs_python_utils-0.0.1.dist-info/LICENSE +21 -0
- bs_python_utils-0.0.1.dist-info/METADATA +71 -0
- bs_python_utils-0.0.1.dist-info/RECORD +28 -0
- bs_python_utils-0.0.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""
|
|
2
|
+
sets up sparse integration over a Gaussian
|
|
3
|
+
"""
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from bs_python_utils.bsnputils import TwoArrays
|
|
9
|
+
from bs_python_utils.bsutils import bs_error_abort
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def setup_sparse_gaussian(
|
|
13
|
+
ndims: int, iprec: int, GHsparsedir: str | None = None
|
|
14
|
+
) -> TwoArrays:
|
|
15
|
+
"""
|
|
16
|
+
get nodes and weights for sparse integration Ef(X) with X = N(0,1) in `ndims` dimensions
|
|
17
|
+
|
|
18
|
+
usage: nodes, weights = setup_sparse_gaussian(mdims, iprec); intf = f(nodes) @ weights
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
ndims: number of dimensions (1 to 5)
|
|
22
|
+
iprec: precision (must be 9, 13, or 17)
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
a pair of arrays `nodes` and `weights`;
|
|
26
|
+
`nodes` has `ndims`-1 columns and weights is a vector
|
|
27
|
+
"""
|
|
28
|
+
GHdir = (
|
|
29
|
+
Path.home() / "Dropbox" / "GHsparseGrids"
|
|
30
|
+
if GHsparsedir is None
|
|
31
|
+
else Path(GHsparsedir)
|
|
32
|
+
)
|
|
33
|
+
if iprec not in [9, 13, 17]:
|
|
34
|
+
bs_error_abort(
|
|
35
|
+
f"We only do sparse integration with precision 9, 13, or 17, not {iprec}"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
if ndims in [1, 2, 3, 4, 5]:
|
|
39
|
+
grid = np.loadtxt(GHdir / f"GHsparseGrid{ndims}prec{iprec}.txt")
|
|
40
|
+
weights = grid[:, 0]
|
|
41
|
+
nodes = grid[:, 1:]
|
|
42
|
+
return nodes, weights
|
|
43
|
+
else:
|
|
44
|
+
bs_error_abort(
|
|
45
|
+
f"We only do sparse integration in one to five dimensions, not {ndims}"
|
|
46
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""
|
|
2
|
+
personal library of Matplotlib utility programs.
|
|
3
|
+
"""
|
|
4
|
+
import matplotlib.axes as axes
|
|
5
|
+
|
|
6
|
+
from bs_python_utils.bsutils import bs_error_abort
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def ax_text(ax: axes.Axes, str_txt: str, x: float, y: float) -> axes.Axes:
|
|
10
|
+
"""
|
|
11
|
+
annotate an ax with text in Matplotlib
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
ax: axis we want to annotate
|
|
15
|
+
str_txt: string of text
|
|
16
|
+
x: position in fraction of horizontal axis
|
|
17
|
+
y: position in fraction of vertical axis
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
annotated ax
|
|
21
|
+
"""
|
|
22
|
+
if not (isinstance(x, float) and 0 <= x <= 1):
|
|
23
|
+
bs_error_abort("x should be a number between 0.0 and 1.0")
|
|
24
|
+
if not (isinstance(y, float) and 0 <= y <= 1):
|
|
25
|
+
bs_error_abort("y should be a number between 0.0 and 1.0")
|
|
26
|
+
ax.text(
|
|
27
|
+
x,
|
|
28
|
+
y,
|
|
29
|
+
str_txt,
|
|
30
|
+
horizontalalignment="center",
|
|
31
|
+
verticalalignment="center",
|
|
32
|
+
transform=ax.transAxes,
|
|
33
|
+
)
|
|
34
|
+
return ax
|