physbo 3.0.0__tar.gz → 3.1.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.
- {physbo-3.0.0 → physbo-3.1.0}/PKG-INFO +3 -14
- {physbo-3.0.0 → physbo-3.1.0}/README.md +0 -13
- {physbo-3.0.0 → physbo-3.1.0}/pyproject.toml +4 -1
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/__init__.py +1 -1
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/cov/_gauss.py +31 -2
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/misc/__init__.py +5 -8
- physbo-3.1.0/src/physbo/misc/_cholesky.py +59 -0
- physbo-3.1.0/src/physbo/misc/_matrix.py +74 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo.egg-info/PKG-INFO +3 -14
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo.egg-info/SOURCES.txt +2 -5
- physbo-3.1.0/src/physbo.egg-info/requires.txt +5 -0
- physbo-3.0.0/src/physbo/gp/cov/_src/__init__.py +0 -15
- physbo-3.0.0/src/physbo/gp/cov/_src/pure.py +0 -72
- physbo-3.0.0/src/physbo/misc/_src/__init__.py +0 -27
- physbo-3.0.0/src/physbo/misc/_src/pure.py +0 -159
- physbo-3.0.0/src/physbo/misc/_use_cython.py +0 -33
- physbo-3.0.0/src/physbo.egg-info/requires.txt +0 -2
- {physbo-3.0.0 → physbo-3.1.0}/setup.cfg +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/_variable.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/_predictor.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/basis/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/basis/_fourier.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/core/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/core/_model.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/inf/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/inf/exact.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/lik/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/lik/_cov.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/lik/_gauss.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/lik/_linear.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/prior/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/blm/prior/_gauss.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/_predictor.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/core/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/core/_model.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/core/_prior.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/core/learning.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/cov/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/inf/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/inf/exact.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/lik/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/lik/_gauss.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/mean/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/mean/_const.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/gp/mean/_zero.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/misc/_centering.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/misc/_gauss_elim.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/misc/_set_config.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/misc/permutation_importance.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/opt/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/opt/_adam.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/predictor.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/discrete/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/discrete/_history.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/discrete/_policy.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/discrete_multi/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/discrete_multi/_history.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/discrete_multi/_policy.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/optimize/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/optimize/odatse.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/optimize/random.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/pareto.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/range/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/range/_history.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/range/_policy.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/range_multi/__init__.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/range_multi/_history.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/range_multi/_policy.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/score.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/score_multi.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo/search/utility.py +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo.egg-info/dependency_links.txt +0 -0
- {physbo-3.0.0 → physbo-3.1.0}/src/physbo.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: physbo
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.1.0
|
|
4
4
|
Summary: optimization tool for PHYSics based on Bayesian Optimization
|
|
5
5
|
Author-email: PHYSBO developers <physbo-dev@issp.u-tokyo.ac.jp>
|
|
6
6
|
License-Expression: MPL-2.0
|
|
@@ -12,6 +12,8 @@ Requires-Python: >=3.9
|
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
Requires-Dist: numpy
|
|
14
14
|
Requires-Dist: scipy
|
|
15
|
+
Provides-Extra: odat-se
|
|
16
|
+
Requires-Dist: odat-se; extra == "odat-se"
|
|
15
17
|
|
|
16
18
|
# optimization tools for PHYsics based on Bayesian Optimization ( PHYSBO )
|
|
17
19
|
|
|
@@ -35,13 +37,6 @@ PHYSBO was developed based on [COMBO](https://github.com/tsudalab/combo) for aca
|
|
|
35
37
|
- NumPy
|
|
36
38
|
- SciPy
|
|
37
39
|
|
|
38
|
-
### About Cython
|
|
39
|
-
|
|
40
|
-
From v3.0.0, PHYSBO no longer uses Cython in order to simplify installation process particularly on Windows.
|
|
41
|
-
This means that the performance of PHYSBO is slightly degraded from older versions.
|
|
42
|
-
If you need more performance, you can install ``physbo-core-cython`` additionally.
|
|
43
|
-
This package offers Cythonized version of some functions of PHYSBO.
|
|
44
|
-
|
|
45
40
|
## Install
|
|
46
41
|
|
|
47
42
|
- From PyPI (recommended)
|
|
@@ -67,12 +62,6 @@ python3 -m pip install physbo
|
|
|
67
62
|
python3 -m pip install ./PHYSBO
|
|
68
63
|
```
|
|
69
64
|
|
|
70
|
-
- To install ``physbo-core-cython`` ::
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
python3 -m pip install physbo-core-cython
|
|
74
|
-
```
|
|
75
|
-
|
|
76
65
|
## Uninstall
|
|
77
66
|
|
|
78
67
|
```bash
|
|
@@ -20,13 +20,6 @@ PHYSBO was developed based on [COMBO](https://github.com/tsudalab/combo) for aca
|
|
|
20
20
|
- NumPy
|
|
21
21
|
- SciPy
|
|
22
22
|
|
|
23
|
-
### About Cython
|
|
24
|
-
|
|
25
|
-
From v3.0.0, PHYSBO no longer uses Cython in order to simplify installation process particularly on Windows.
|
|
26
|
-
This means that the performance of PHYSBO is slightly degraded from older versions.
|
|
27
|
-
If you need more performance, you can install ``physbo-core-cython`` additionally.
|
|
28
|
-
This package offers Cythonized version of some functions of PHYSBO.
|
|
29
|
-
|
|
30
23
|
## Install
|
|
31
24
|
|
|
32
25
|
- From PyPI (recommended)
|
|
@@ -52,12 +45,6 @@ python3 -m pip install physbo
|
|
|
52
45
|
python3 -m pip install ./PHYSBO
|
|
53
46
|
```
|
|
54
47
|
|
|
55
|
-
- To install ``physbo-core-cython`` ::
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
python3 -m pip install physbo-core-cython
|
|
59
|
-
```
|
|
60
|
-
|
|
61
48
|
## Uninstall
|
|
62
49
|
|
|
63
50
|
```bash
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "physbo"
|
|
7
|
-
version = "3.
|
|
7
|
+
version = "3.1.0"
|
|
8
8
|
description = "optimization tool for PHYSics based on Bayesian Optimization"
|
|
9
9
|
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
10
|
license = "MPL-2.0"
|
|
@@ -16,6 +16,9 @@ dependencies = [
|
|
|
16
16
|
"scipy",
|
|
17
17
|
]
|
|
18
18
|
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
odat-se = [ "odat-se" ]
|
|
21
|
+
|
|
19
22
|
[project.urls]
|
|
20
23
|
homepage = "https://www.pasums.issp.u-tokyo.ac.jp/physbo/en"
|
|
21
24
|
source = "https://github.com/issp-center-dev/PHYSBO"
|
|
@@ -8,9 +8,38 @@
|
|
|
8
8
|
# -*- coding:utf-8 -*-
|
|
9
9
|
import numpy as np
|
|
10
10
|
from scipy import spatial
|
|
11
|
-
from ._src import grad_width64
|
|
12
11
|
|
|
13
12
|
|
|
13
|
+
def grad_width(X, width, G):
|
|
14
|
+
"""
|
|
15
|
+
Gradiant along width direction.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
X: numpy.ndarray[numpy.float64_t, ndim = 2]
|
|
20
|
+
|
|
21
|
+
width: numpy.ndarray[numpy.float64_t, ndim = 1]
|
|
22
|
+
The grid width
|
|
23
|
+
G: numpy.ndarray[numpy.float64_t, ndim = 2]
|
|
24
|
+
The gram matrix
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
numpy.ndarray
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
## The meaning of the following einsum is:
|
|
31
|
+
# N = X.shape[0]
|
|
32
|
+
# D = X.shape[1]
|
|
33
|
+
# gradG = np.zeros([D, N, N], dtype=DTYPE64)
|
|
34
|
+
# for d in range(D):
|
|
35
|
+
# for i in range(N):
|
|
36
|
+
# for j in range(i + 1, N):
|
|
37
|
+
# gradG[d, i, j] = (X[i, d] - X[j, d]) / width[d]
|
|
38
|
+
# gradG[d, i, j] = gradG[d, i, j] ** 2 * G[i, j]
|
|
39
|
+
# gradG[d, j, i] = gradG[d, i, j]
|
|
40
|
+
gradG = np.einsum("ijd,ij->dij", ((X[:, None, :] - X) / width)**2, G)
|
|
41
|
+
return gradG
|
|
42
|
+
|
|
14
43
|
class Gauss:
|
|
15
44
|
"""gaussian kernel"""
|
|
16
45
|
|
|
@@ -126,7 +155,7 @@ class Gauss:
|
|
|
126
155
|
|
|
127
156
|
grad = np.zeros((self.num_params, num_data, num_data))
|
|
128
157
|
if self.ard:
|
|
129
|
-
grad[0 : self.num_params - 1, :, :] =
|
|
158
|
+
grad[0 : self.num_params - 1, :, :] = grad_width(X, width, G)
|
|
130
159
|
else:
|
|
131
160
|
pairwise_dists = spatial.distance.pdist(X / width, "euclidean")
|
|
132
161
|
grad[0, :, :] = G * spatial.distance.squareform(pairwise_dists**2)
|
|
@@ -8,18 +8,15 @@
|
|
|
8
8
|
from ._centering import centering as centering
|
|
9
9
|
from ._gauss_elim import gauss_elim as gauss_elim
|
|
10
10
|
from ._set_config import SetConfig as SetConfig
|
|
11
|
-
from ._use_cython import use_cython as use_cython
|
|
12
|
-
|
|
13
|
-
from ._src import cholupdate as cholupdate
|
|
14
|
-
from ._src import diagAB as diagAB
|
|
15
|
-
from ._src import logsumexp64 as logsumexp64
|
|
16
|
-
from ._src import traceAB2 as traceAB2
|
|
17
|
-
from ._src import traceAB3 as traceAB3
|
|
18
11
|
|
|
12
|
+
from ._cholesky import cholupdate as cholupdate
|
|
13
|
+
from ._matrix import diagAB as diagAB
|
|
14
|
+
from ._matrix import logsumexp as logsumexp
|
|
15
|
+
from ._matrix import traceAB2 as traceAB2
|
|
16
|
+
from ._matrix import traceAB3 as traceAB3
|
|
19
17
|
|
|
20
18
|
__warned_names = set()
|
|
21
19
|
|
|
22
|
-
|
|
23
20
|
def deprecated_warning(old: str, new: str):
|
|
24
21
|
"""
|
|
25
22
|
Print a warning message when a deprecated name is used.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
+
#
|
|
4
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
import scipy
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _cholupdate_fastupdate(U, x):
|
|
13
|
+
"""Cholesky update using fast update method."""
|
|
14
|
+
|
|
15
|
+
N = x.shape[0]
|
|
16
|
+
x2 = x.copy()
|
|
17
|
+
|
|
18
|
+
for k in range(N):
|
|
19
|
+
r = np.hypot(U[k, k], x2[k])
|
|
20
|
+
c = r / U[k, k]
|
|
21
|
+
s = x2[k] / U[k, k]
|
|
22
|
+
U[k, k] = r
|
|
23
|
+
|
|
24
|
+
U[k, k + 1 :] += s * x2[k + 1 :]
|
|
25
|
+
U[k, k + 1 :] /= c
|
|
26
|
+
x2[k + 1 :] *= c
|
|
27
|
+
x2[k + 1 :] -= s * U[k, k + 1 :]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _cholupdate_direct(U, x):
|
|
31
|
+
"""Cholesky update just by calling scipy.linalg.cholesky directly."""
|
|
32
|
+
|
|
33
|
+
A = np.dot(U.T, U) + np.outer(x, x)
|
|
34
|
+
U[:] = scipy.linalg.cholesky(A, check_finite=False)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def cholupdate(U, x, matrix_size_threshold=500):
|
|
38
|
+
"""Cholesky update
|
|
39
|
+
|
|
40
|
+
This calculates the Cholesky decomposition of A = U.T @ U + x @ x.T.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
U: numpy.ndarray
|
|
45
|
+
Upper triangular matrix of the Cholesky decomposition of the original matrix.
|
|
46
|
+
U is updated to U' of A in place.
|
|
47
|
+
x: numpy.ndarray
|
|
48
|
+
Vector to be added to the original matrix.
|
|
49
|
+
matrix_size_threshold: int
|
|
50
|
+
If the size of the matrix is larger than this threshold, the fast update method is used.
|
|
51
|
+
Otherwise, the direct method is used.
|
|
52
|
+
Default is 500.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
N = U.shape[0]
|
|
56
|
+
if N > matrix_size_threshold:
|
|
57
|
+
_cholupdate_fastupdate(U, x)
|
|
58
|
+
else:
|
|
59
|
+
_cholupdate_direct(U, x)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
+
#
|
|
4
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
def diagAB(A, B):
|
|
11
|
+
"""Return diagonal part of AB
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
==========
|
|
15
|
+
A: np.ndarray
|
|
16
|
+
NxM matrix
|
|
17
|
+
B: np.ndarray
|
|
18
|
+
MxN matrix
|
|
19
|
+
|
|
20
|
+
Returns
|
|
21
|
+
=======
|
|
22
|
+
d: np.ndarray
|
|
23
|
+
Diagonal part of the matrix AB
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
return np.einsum("ij,ji->i", A, B)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def logsumexp(x):
|
|
30
|
+
"""Calculate log(sum(exp(x)))
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
==========
|
|
34
|
+
x: np.ndarray
|
|
35
|
+
"""
|
|
36
|
+
xmax = np.max(x)
|
|
37
|
+
return np.log(np.sum(np.exp(x - xmax))) + xmax
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def traceAB3(A, B):
|
|
41
|
+
"""Calculates vector of trace of AB[i], where i is the first axis of 3-rank tensor B
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
==========
|
|
45
|
+
A: np.ndarray
|
|
46
|
+
NxM matrix
|
|
47
|
+
B: np.ndarray
|
|
48
|
+
dxMxN tensor
|
|
49
|
+
|
|
50
|
+
Returns
|
|
51
|
+
=======
|
|
52
|
+
traceAB: np.ndarray
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
return np.einsum("ij,kji->k", A, B)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def traceAB2(A, B):
|
|
59
|
+
"""Calculates trace of AB
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
==========
|
|
63
|
+
A: np.ndarray
|
|
64
|
+
NxM matrix
|
|
65
|
+
B: np.ndarray
|
|
66
|
+
MxN matrix
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
=======
|
|
70
|
+
traceAB: float
|
|
71
|
+
trace of the matrix AB
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
return np.einsum("ij,ji->", A, B)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: physbo
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.1.0
|
|
4
4
|
Summary: optimization tool for PHYSics based on Bayesian Optimization
|
|
5
5
|
Author-email: PHYSBO developers <physbo-dev@issp.u-tokyo.ac.jp>
|
|
6
6
|
License-Expression: MPL-2.0
|
|
@@ -12,6 +12,8 @@ Requires-Python: >=3.9
|
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
Requires-Dist: numpy
|
|
14
14
|
Requires-Dist: scipy
|
|
15
|
+
Provides-Extra: odat-se
|
|
16
|
+
Requires-Dist: odat-se; extra == "odat-se"
|
|
15
17
|
|
|
16
18
|
# optimization tools for PHYsics based on Bayesian Optimization ( PHYSBO )
|
|
17
19
|
|
|
@@ -35,13 +37,6 @@ PHYSBO was developed based on [COMBO](https://github.com/tsudalab/combo) for aca
|
|
|
35
37
|
- NumPy
|
|
36
38
|
- SciPy
|
|
37
39
|
|
|
38
|
-
### About Cython
|
|
39
|
-
|
|
40
|
-
From v3.0.0, PHYSBO no longer uses Cython in order to simplify installation process particularly on Windows.
|
|
41
|
-
This means that the performance of PHYSBO is slightly degraded from older versions.
|
|
42
|
-
If you need more performance, you can install ``physbo-core-cython`` additionally.
|
|
43
|
-
This package offers Cythonized version of some functions of PHYSBO.
|
|
44
|
-
|
|
45
40
|
## Install
|
|
46
41
|
|
|
47
42
|
- From PyPI (recommended)
|
|
@@ -67,12 +62,6 @@ python3 -m pip install physbo
|
|
|
67
62
|
python3 -m pip install ./PHYSBO
|
|
68
63
|
```
|
|
69
64
|
|
|
70
|
-
- To install ``physbo-core-cython`` ::
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
python3 -m pip install physbo-core-cython
|
|
74
|
-
```
|
|
75
|
-
|
|
76
65
|
## Uninstall
|
|
77
66
|
|
|
78
67
|
```bash
|
|
@@ -30,8 +30,6 @@ src/physbo/gp/core/_prior.py
|
|
|
30
30
|
src/physbo/gp/core/learning.py
|
|
31
31
|
src/physbo/gp/cov/__init__.py
|
|
32
32
|
src/physbo/gp/cov/_gauss.py
|
|
33
|
-
src/physbo/gp/cov/_src/__init__.py
|
|
34
|
-
src/physbo/gp/cov/_src/pure.py
|
|
35
33
|
src/physbo/gp/inf/__init__.py
|
|
36
34
|
src/physbo/gp/inf/exact.py
|
|
37
35
|
src/physbo/gp/lik/__init__.py
|
|
@@ -41,12 +39,11 @@ src/physbo/gp/mean/_const.py
|
|
|
41
39
|
src/physbo/gp/mean/_zero.py
|
|
42
40
|
src/physbo/misc/__init__.py
|
|
43
41
|
src/physbo/misc/_centering.py
|
|
42
|
+
src/physbo/misc/_cholesky.py
|
|
44
43
|
src/physbo/misc/_gauss_elim.py
|
|
44
|
+
src/physbo/misc/_matrix.py
|
|
45
45
|
src/physbo/misc/_set_config.py
|
|
46
|
-
src/physbo/misc/_use_cython.py
|
|
47
46
|
src/physbo/misc/permutation_importance.py
|
|
48
|
-
src/physbo/misc/_src/__init__.py
|
|
49
|
-
src/physbo/misc/_src/pure.py
|
|
50
47
|
src/physbo/opt/__init__.py
|
|
51
48
|
src/physbo/opt/_adam.py
|
|
52
49
|
src/physbo/search/__init__.py
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
-
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
-
#
|
|
4
|
-
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
-
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
-
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
-
|
|
8
|
-
from ....misc import use_cython
|
|
9
|
-
|
|
10
|
-
if use_cython():
|
|
11
|
-
from physbo_core_cython.gp.cov._src.enhance_gauss import grad_width64, grad_width32
|
|
12
|
-
else:
|
|
13
|
-
from .pure import grad_width64, grad_width32
|
|
14
|
-
|
|
15
|
-
__all__ = ["grad_width64", "grad_width32"]
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
-
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
-
#
|
|
4
|
-
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
-
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
-
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
-
|
|
8
|
-
import numpy as np
|
|
9
|
-
|
|
10
|
-
DTYPE64 = np.float64
|
|
11
|
-
DTYPE32 = np.float32
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def grad_width64(X, width, G):
|
|
15
|
-
"""
|
|
16
|
-
Gradiant along width direction (64bit).
|
|
17
|
-
|
|
18
|
-
Parameters
|
|
19
|
-
----------
|
|
20
|
-
X: numpy.ndarray[numpy.float64_t, ndim = 2]
|
|
21
|
-
|
|
22
|
-
width: numpy.ndarray[numpy.float64_t, ndim = 1]
|
|
23
|
-
The grid width
|
|
24
|
-
G: numpy.ndarray[numpy.float64_t, ndim = 2]
|
|
25
|
-
The gram matrix
|
|
26
|
-
Returns
|
|
27
|
-
-------
|
|
28
|
-
numpy.ndarray
|
|
29
|
-
"""
|
|
30
|
-
N = X.shape[0]
|
|
31
|
-
D = X.shape[1]
|
|
32
|
-
|
|
33
|
-
gradG = np.zeros([D, N, N], dtype=DTYPE64)
|
|
34
|
-
|
|
35
|
-
for d in range(D):
|
|
36
|
-
for i in range(N):
|
|
37
|
-
for j in range(i + 1, N):
|
|
38
|
-
gradG[d, i, j] = (X[i, d] - X[j, d]) / width[d]
|
|
39
|
-
gradG[d, i, j] = gradG[d, i, j] ** 2 * G[i, j]
|
|
40
|
-
gradG[d, j, i] = gradG[d, i, j]
|
|
41
|
-
return gradG
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def grad_width32(X, width, G):
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
Gradiant along width direction (32bit).
|
|
48
|
-
|
|
49
|
-
Parameters
|
|
50
|
-
----------
|
|
51
|
-
X: numpy.ndarray[numpy.float32_t, ndim = 2]
|
|
52
|
-
|
|
53
|
-
width: numpy.ndarray[numpy.float32_t, ndim = 1]
|
|
54
|
-
The grid width
|
|
55
|
-
G: numpy.ndarray[numpy.float32_t, ndim = 2]
|
|
56
|
-
The gram matrix
|
|
57
|
-
Returns
|
|
58
|
-
-------
|
|
59
|
-
numpy.ndarray
|
|
60
|
-
"""
|
|
61
|
-
N = X.shape[0]
|
|
62
|
-
D = X.shape[1]
|
|
63
|
-
|
|
64
|
-
gradG = np.zeros([D, N, N], dtype=DTYPE32)
|
|
65
|
-
|
|
66
|
-
for d in range(D):
|
|
67
|
-
for i in range(N):
|
|
68
|
-
for j in range(i + 1, N):
|
|
69
|
-
gradG[d, i, j] = (X[i, d] - X[j, d]) / width[d]
|
|
70
|
-
gradG[d, i, j] = gradG[d, i, j] ** 2 * G[i, j]
|
|
71
|
-
gradG[d, j, i] = gradG[d, i, j]
|
|
72
|
-
return gradG
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
-
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
-
#
|
|
4
|
-
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
-
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
-
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
-
|
|
8
|
-
from .. import use_cython
|
|
9
|
-
|
|
10
|
-
if use_cython():
|
|
11
|
-
from physbo_core_cython.misc._src import (
|
|
12
|
-
cholupdate64 as cholupdate,
|
|
13
|
-
diagAB_64 as diagAB,
|
|
14
|
-
logsumexp64 as logsumexp64,
|
|
15
|
-
traceAB2_64 as traceAB2,
|
|
16
|
-
traceAB3_64 as traceAB3,
|
|
17
|
-
)
|
|
18
|
-
else:
|
|
19
|
-
from .pure import (
|
|
20
|
-
cholupdate64 as cholupdate,
|
|
21
|
-
diagAB_64 as diagAB,
|
|
22
|
-
logsumexp64 as logsumexp64,
|
|
23
|
-
traceAB2_64 as traceAB2,
|
|
24
|
-
traceAB3_64 as traceAB3,
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
__all__ = ["cholupdate", "diagAB", "logsumexp64", "traceAB2", "traceAB3"]
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
-
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
-
#
|
|
4
|
-
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
-
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
-
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
-
|
|
8
|
-
# Pure Python version of merged Cython functions
|
|
9
|
-
# Converted from traceAB.pyx, cholupdate.pyx, diagAB.pyx, and logsumexp.pyx
|
|
10
|
-
|
|
11
|
-
import math
|
|
12
|
-
import numpy as np
|
|
13
|
-
|
|
14
|
-
DTYPE = np.float64
|
|
15
|
-
|
|
16
|
-
# ==============================================================================
|
|
17
|
-
# Functions from cholupdate.pyx
|
|
18
|
-
# ==============================================================================
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def hypot(x, y):
|
|
22
|
-
"""Pure Python version of hypot function"""
|
|
23
|
-
x = abs(x)
|
|
24
|
-
y = abs(y)
|
|
25
|
-
t = min(x, y)
|
|
26
|
-
x = max(x, y)
|
|
27
|
-
if x == 0:
|
|
28
|
-
return 0
|
|
29
|
-
t = t / x
|
|
30
|
-
return x * math.sqrt(1 + t * t)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def cholupdate64(L, x):
|
|
34
|
-
"""Pure Python version of Cholesky update"""
|
|
35
|
-
N = x.shape[0]
|
|
36
|
-
x2 = x.copy()
|
|
37
|
-
|
|
38
|
-
for k in range(N):
|
|
39
|
-
r = hypot(L[k, k], x2[k])
|
|
40
|
-
c = r / L[k, k]
|
|
41
|
-
s = x2[k] / L[k, k]
|
|
42
|
-
L[k, k] = r
|
|
43
|
-
|
|
44
|
-
for i in range(k + 1, N):
|
|
45
|
-
L[k, i] = (L[k, i] + s * x2[i]) / c
|
|
46
|
-
x2[i] = c * x2[i] - s * L[k, i]
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# ==============================================================================
|
|
50
|
-
# Functions from diagAB.pyx
|
|
51
|
-
# ==============================================================================
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def diagAB_64(A, B):
|
|
55
|
-
"""Return diagonal part of AB
|
|
56
|
-
|
|
57
|
-
Parameters
|
|
58
|
-
==========
|
|
59
|
-
A: np.ndarray
|
|
60
|
-
NxM matrix
|
|
61
|
-
B: np.ndarray
|
|
62
|
-
MxN matrix
|
|
63
|
-
|
|
64
|
-
Returns
|
|
65
|
-
=======
|
|
66
|
-
d: np.ndarray
|
|
67
|
-
Diagonal part of the matrix AB
|
|
68
|
-
"""
|
|
69
|
-
N = A.shape[0]
|
|
70
|
-
M = A.shape[1]
|
|
71
|
-
|
|
72
|
-
diagAB = np.zeros(N, dtype=DTYPE)
|
|
73
|
-
|
|
74
|
-
for i in range(N):
|
|
75
|
-
for j in range(M):
|
|
76
|
-
diagAB[i] += A[i, j] * B[j, i]
|
|
77
|
-
|
|
78
|
-
return diagAB
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
# ==============================================================================
|
|
82
|
-
# Functions from logsumexp.pyx
|
|
83
|
-
# ==============================================================================
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def logsumexp64(x):
|
|
87
|
-
"""Calculate log(sum(exp(x)))
|
|
88
|
-
|
|
89
|
-
Parameters
|
|
90
|
-
==========
|
|
91
|
-
x: np.ndarray
|
|
92
|
-
"""
|
|
93
|
-
N = x.shape[0]
|
|
94
|
-
tmp = 0.0
|
|
95
|
-
|
|
96
|
-
xmax = np.max(x)
|
|
97
|
-
|
|
98
|
-
for i in range(N):
|
|
99
|
-
tmp += math.exp(x[i] - xmax)
|
|
100
|
-
|
|
101
|
-
return math.log(tmp) + xmax
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
# ==============================================================================
|
|
105
|
-
# Functions from traceAB.pyx
|
|
106
|
-
# ==============================================================================
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def traceAB3_64(A, B):
|
|
110
|
-
"""Calculates vector of trace of AB[i], where i is the first axis of 3-rank tensor B
|
|
111
|
-
|
|
112
|
-
Parameters
|
|
113
|
-
==========
|
|
114
|
-
A: np.ndarray
|
|
115
|
-
NxM matrix
|
|
116
|
-
B: np.ndarray
|
|
117
|
-
dxMxN tensor
|
|
118
|
-
|
|
119
|
-
Returns
|
|
120
|
-
=======
|
|
121
|
-
traceAB: np.ndarray
|
|
122
|
-
"""
|
|
123
|
-
N = A.shape[0]
|
|
124
|
-
M = A.shape[1]
|
|
125
|
-
D = B.shape[0]
|
|
126
|
-
|
|
127
|
-
traceAB = np.zeros(D, dtype=DTYPE)
|
|
128
|
-
|
|
129
|
-
for d in range(D):
|
|
130
|
-
for i in range(N):
|
|
131
|
-
for j in range(M):
|
|
132
|
-
traceAB[d] += A[i, j] * B[d, j, i]
|
|
133
|
-
return traceAB
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def traceAB2_64(A, B):
|
|
137
|
-
"""Calculates trace of AB
|
|
138
|
-
|
|
139
|
-
Parameters
|
|
140
|
-
==========
|
|
141
|
-
A: np.ndarray
|
|
142
|
-
NxM matrix
|
|
143
|
-
B: np.ndarray
|
|
144
|
-
MxN matrix
|
|
145
|
-
|
|
146
|
-
Returns
|
|
147
|
-
=======
|
|
148
|
-
traceAB: float
|
|
149
|
-
trace of the matrix AB
|
|
150
|
-
"""
|
|
151
|
-
N = A.shape[0]
|
|
152
|
-
M = A.shape[1]
|
|
153
|
-
|
|
154
|
-
traceAB = 0.0
|
|
155
|
-
|
|
156
|
-
for i in range(N):
|
|
157
|
-
for j in range(M):
|
|
158
|
-
traceAB += A[i, j] * B[j, i]
|
|
159
|
-
return traceAB
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
-
# Copyright (C) 2020- The University of Tokyo
|
|
3
|
-
#
|
|
4
|
-
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
5
|
-
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
6
|
-
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
7
|
-
|
|
8
|
-
import os
|
|
9
|
-
from importlib.util import find_spec
|
|
10
|
-
|
|
11
|
-
if find_spec("physbo_core_cython"):
|
|
12
|
-
CYTHON_AVAILABLE = True
|
|
13
|
-
else:
|
|
14
|
-
CYTHON_AVAILABLE = False
|
|
15
|
-
|
|
16
|
-
PHYSBO_USE_CYTHON = os.environ.get("PHYSBO_USE_CYTHON", "auto")
|
|
17
|
-
if PHYSBO_USE_CYTHON == "0":
|
|
18
|
-
USING_CYTHON = False
|
|
19
|
-
elif PHYSBO_USE_CYTHON == "1":
|
|
20
|
-
if not CYTHON_AVAILABLE:
|
|
21
|
-
raise ImportError(
|
|
22
|
-
"PHYSBO_USE_CYTHON is set to 1, but physbo_core_cython is not installed"
|
|
23
|
-
)
|
|
24
|
-
USING_CYTHON = True
|
|
25
|
-
else: # PHYSBO_USE_CYTHON == "auto"
|
|
26
|
-
USING_CYTHON = CYTHON_AVAILABLE
|
|
27
|
-
|
|
28
|
-
if USING_CYTHON:
|
|
29
|
-
print("Cythonized version of physbo is used")
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def use_cython():
|
|
33
|
-
return USING_CYTHON
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|