bs-python-utils 0.4.1__tar.gz → 0.4.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.
Files changed (30) hide show
  1. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/PKG-INFO +3 -2
  2. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/README.md +2 -1
  3. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bivariate_quantiles.py +4 -2
  4. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bs_sparse_gaussian.py +19 -4
  5. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bsstats.py +0 -35
  6. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/pyproject.toml +1 -1
  7. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/LICENSE +0 -0
  8. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/Timer.py +0 -0
  9. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/__init__.py +0 -0
  10. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bs_altair.py +0 -0
  11. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bs_logging.py +0 -0
  12. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bs_mathstr.py +0 -0
  13. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bs_mem.py +0 -0
  14. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bs_opt.py +0 -0
  15. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bs_plots.py +0 -0
  16. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bs_seaborn.py +0 -0
  17. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bsmplutils.py +0 -0
  18. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bsnputils.py +0 -0
  19. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bssputils.py +0 -0
  20. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/bsutils.py +0 -0
  21. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/chebyshev.py +0 -0
  22. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/distance_covariances.py +0 -0
  23. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/example_opt.py +0 -0
  24. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/examples_altair.py +0 -0
  25. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/examples_distance_covariances.py +0 -0
  26. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/examples_mem.py +0 -0
  27. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/examples_seaborn.py +0 -0
  28. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/examples_sklearn.py +0 -0
  29. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/pandas_utils.py +0 -0
  30. {bs_python_utils-0.4.1 → bs_python_utils-0.4.2}/bs_python_utils/sklearn_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bs-python-utils
3
- Version: 0.4.1
3
+ Version: 0.4.2
4
4
  Summary: my Python utilities
5
5
  Home-page: https://github.com/bsalanie/bs-python-utils
6
6
  Author: Bernard Salanie
@@ -37,7 +37,8 @@ My Python utilities.
37
37
  - **Documentation** <https://bsalanie.github.io/bs-python-utils/>
38
38
 
39
39
  ### Release notes
40
-
40
+ #### 0.4.2 (August 2, 2023)
41
+ Updated the docs.
41
42
  #### 0.4.1 (July 23, 2023)
42
43
  Only print if verbose in bivariate quantiles.
43
44
  #### 0.4 (July 22, 2023)
@@ -12,7 +12,8 @@ My Python utilities.
12
12
  - **Documentation** <https://bsalanie.github.io/bs-python-utils/>
13
13
 
14
14
  ### Release notes
15
-
15
+ #### 0.4.2 (August 2, 2023)
16
+ Updated the docs.
16
17
  #### 0.4.1 (July 23, 2023)
17
18
  Only print if verbose in bivariate quantiles.
18
19
  #### 0.4 (July 22, 2023)
@@ -254,7 +254,7 @@ def solve_for_v_(y: np.ndarray, n_nodes: int = 32, verbose: bool = False) -> np.
254
254
 
255
255
  def bivariate_quantiles(
256
256
  y: np.ndarray, u: np.ndarray, n_nodes: int = 32, verbose: bool = False
257
- ):
257
+ ) -> np.ndarray:
258
258
  """computes the bivariate quantiles of `y` at the quantiles `u`
259
259
 
260
260
  Args:
@@ -271,7 +271,9 @@ def bivariate_quantiles(
271
271
  return bivariate_quantiles_v(y, u, v)
272
272
 
273
273
 
274
- def bivariate_ranks(y: np.ndarray, n_nodes: int = 32, verbose: bool = False):
274
+ def bivariate_ranks(
275
+ y: np.ndarray, n_nodes: int = 32, verbose: bool = False
276
+ ) -> np.ndarray:
275
277
  """computes the bivariate ranks of `y`
276
278
 
277
279
  Args:
@@ -1,5 +1,11 @@
1
1
  """
2
- sets up sparse integration over a Gaussian
2
+ Sets up sparse integration over a Gaussian, given text files that contain rescaled Gauss-Hermite nodes and weights.
3
+
4
+ These files must be named `GHsparseGrid{ndims}prec{iprec}.txt`, where `ndims` is the number of dimensions of integration
5
+ and `iprec` is a precision level that must be 9, 13, or (most precise) 17. The file must have `(ndims+1) columns,
6
+ with the weights in the first column.
7
+
8
+ The nodes and weights are rescaled so that `f(nodes) @ weights` approximates `Ef(X)` for `X` an `N(0,I)` variable.
3
9
  """
4
10
  from pathlib import Path
5
11
 
@@ -15,11 +21,12 @@ def setup_sparse_gaussian(
15
21
  """
16
22
  get nodes and weights for sparse integration Ef(X) with X = N(0,1) in `ndims` dimensions
17
23
 
18
- usage: nodes, weights = setup_sparse_gaussian(mdims, iprec); intf = f(nodes) @ weights
24
+ usage: nodes, weights = setup_sparse_gaussian(mdims, iprec); integral_f = f(nodes) @ weights
19
25
 
20
26
  Args:
21
27
  ndims: number of dimensions (1 to 5)
22
28
  iprec: precision (must be 9, 13, or 17)
29
+ GHsparsedir: the name of a directory that contains nodes and weights
23
30
 
24
31
  Returns:
25
32
  a pair of arrays `nodes` and `weights`;
@@ -36,9 +43,17 @@ def setup_sparse_gaussian(
36
43
  )
37
44
 
38
45
  if ndims in [1, 2, 3, 4, 5]:
46
+ if not GHdir.exists():
47
+ bs_error_abort("I did not find the directory with the nodes/weights files.")
39
48
  grid = np.loadtxt(GHdir / f"GHsparseGrid{ndims}prec{iprec}.txt")
40
- weights = grid[:, 0]
41
- nodes = grid[:, 1:]
49
+
50
+ print(f"{grid.shape=}")
51
+ if ndims == 1:
52
+ weights = grid[:, 0]
53
+ nodes = grid[:, 1]
54
+ else:
55
+ weights = grid[:, 0]
56
+ nodes = grid[:, 1:]
42
57
  return nodes, weights
43
58
  else:
44
59
  bs_error_abort(
@@ -16,7 +16,6 @@ from bs_python_utils.bsnputils import (
16
16
  check_matrix,
17
17
  check_vector,
18
18
  check_vector_or_matrix,
19
- make_lexico_grid,
20
19
  )
21
20
  from bs_python_utils.bssputils import spline_reg
22
21
  from bs_python_utils.bsutils import bs_error_abort
@@ -416,37 +415,3 @@ def estimate_pdf(
416
415
  if weights is not None:
417
416
  f_x *= weights / np.mean(weights)
418
417
  return cast(np.ndarray, f_x)
419
-
420
-
421
- def estimate_densities_at_quantiles(
422
- X: np.ndarray, qtiles: np.ndarray
423
- ) -> tuple[np.ndarray, np.ndarray] | tuple[np.ndarray, np.ndarray, np.ndarray]:
424
- """estimate densities of margins at prespecified quantiles (Silverman rule)
425
- and the joint density at each vector of these quantiles
426
-
427
- Args:
428
- X: `n`-vector or `(n, nx)`-matrix
429
- qtiles: vector of `nq` numbers between 0 and 1
430
-
431
- Returns:
432
- if `X` is a matrix, the `({nq}^{nx}, {nx})` matrices of estimated margin densities \
433
- and the `{nq}^{nx}` vector of the joint density on the lexicographic grid of quantiles;
434
- if `X` is a vector, the `nq`-vector of the density at the quantiles, twice
435
- """
436
- ndims_X = check_vector_or_matrix(X, "estimate_densities_")
437
- if ndims_X == 1:
438
- f_X = estimate_pdf(X, np.quantile(X, qtiles))
439
- return f_X, f_X
440
- else:
441
- nx = X.shape[1]
442
- nq = qtiles.size
443
- f_X_k = np.zeros((nq, nx))
444
- nodes_mat = np.zeros((nq, nx))
445
- for i_x in range(nx):
446
- X_ix = X[:, i_x]
447
- nodes_mat[:, i_x] = np.quantile(X_ix, qtiles)
448
- f_X_k[:, i_x] = estimate_pdf(X_ix, nodes_mat[:, i_x])
449
- f_margins = make_lexico_grid(f_X_k)
450
- values_X = make_lexico_grid(nodes_mat)
451
- f_X = estimate_pdf(X, values_X) # joint density
452
- return f_margins, f_X, values_X
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "bs_python_utils"
3
- version = "0.4.1"
3
+ version = "0.4.2"
4
4
  description = "my Python utilities"
5
5
  authors = ["Bernard Salanie <bsalanie@columbia.edu>"]
6
6
  repository = "https://github.com/bsalanie/bs-python-utils"
File without changes