Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/update.stepsize' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
aoymt committed Sep 24, 2024
2 parents 8621d29 + ab9432b commit 90d42ed
Show file tree
Hide file tree
Showing 34 changed files with 83 additions and 68 deletions.
16 changes: 7 additions & 9 deletions doc/en/source/algorithm/exchange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ Otherwise, continuous space is used.
Description: Initial value of parameters.
If not defined, these will be initialize randomly.

- ``unit_list``

Format: List of float. Length should be equal to ``dimension``.

Description:
Unit length of each parameter.
``Algorithm`` makes parameters dimensionless and normalized by dividing these by ``unit_list``.
If not defined, each component will be 1.0.

- ``min_list``

Format: List of float. Length should be equal to ``dimension``.
Expand All @@ -61,6 +52,13 @@ Otherwise, continuous space is used.
When a parameter exceeds this value during the Monte Carlo search,
the solver is not evaluated and the value is considered infinite.

- ``step_list``

Format: List of float. Length should be equal to ``dimension``.

Description:
The step length in one Monte Carlo update (deviation of Gaussian distribution).

- Discrete space

- ``mesh_path``
Expand Down
16 changes: 7 additions & 9 deletions doc/en/source/algorithm/pamc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ Otherwise, continuous space is used.
Initial value of parameters.
If not defined, these will be initialize randomly.

- ``unit_list``

Format: List of float. Length should be equal to ``dimension``.

Description:
Unit length of each parameter.
``Algorithm`` makes parameters dimensionless and normalized by dividing these by ``unit_list``.
If not defined, each component will be 1.0.

- ``min_list``

Format: List of float. Length should be equal to ``dimension``.
Expand All @@ -61,6 +52,13 @@ Otherwise, continuous space is used.
When a parameter exceeds this value during the Monte Carlo search,
the solver is not evaluated and the value is considered infinite.

- ``step_list``

Format: List of float. Length should be equal to ``dimension``.

Description:
The step length in one Monte Carlo update (deviation of Gaussian distribution).

- Discrete space

- ``mesh_path``
Expand Down
7 changes: 2 additions & 5 deletions doc/en/source/tutorial/exchange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ For details, see the input file section of the manual.
[algorithm.param]
min_list = [3.0, 3.0]
max_list = [6.0, 6.0]
initial_list = [0.0, 0.0]
unit_list = [0.3, 0.3]
step_list = [0.3, 0.3]
[algorithm.exchange]
Tmin = 0.1
Expand All @@ -67,9 +66,7 @@ The contents of ``[base]``, ``[solver]``, and ``[runner]`` sections are the same

- ``min_list`` is a lower bound and ``max_list`` is an upper bound.

- ``initial_list`` is an initial value.

- ``unit_list`` is the unit of each parameter.
- ``unit_list`` is step length in one Monte Carlo update (deviation of Gaussian distribution).

``[algorithm.exchange]`` section sets the hyper parameters for RXMC.

Expand Down
4 changes: 2 additions & 2 deletions doc/en/source/tutorial/pamc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ For details, see the input file section of the manual.
[algorithm.param]
max_list = [6.0, 6.0]
min_list = [-6.0, -6.0]
unit_list = [0.3, 0.3]
step_list = [0.3, 0.3]
[algorithm.pamc]
bmin = 0.0
Expand All @@ -74,7 +74,7 @@ The contents of ``[base]``, ``[solver]``, and ``[runner]`` sections are the same

- ``min_list`` is a lower bound and ``max_list`` is an upper bound.

- ``unit_list`` is step length in one MC update (deviation of Gaussian distribution).
- ``unit_list`` is step length in one Monte Carlo update (deviation of Gaussian distribution).

``[algorithm.pamc]`` section sets the parameters for PAMC.

Expand Down
15 changes: 6 additions & 9 deletions doc/ja/source/algorithm/exchange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ MPI並列を利用する場合は、あらかじめ `mpi4py <https://mpi4py.read

説明: パラメータの初期値。 定義しなかった場合は一様ランダムに初期化されます。

- ``unit_list``

形式: 実数型のリスト。長さはdimensionの値と一致させます。

説明: 各パラメータの単位。
探索アルゴリズム中では、各パラメータをそれぞれこれらの値で割ることで、
簡易的な無次元化・正規化を行います。
定義しなかった場合にはすべての次元で 1.0 となります。

- ``min_list``

形式: 実数型のリスト。長さはdimensionの値と一致させます。
Expand All @@ -56,6 +47,12 @@ MPI並列を利用する場合は、あらかじめ `mpi4py <https://mpi4py.read
モンテカルロ探索中にこの値を上回るパラメータが出現した場合、
ソルバーは評価されずに、値が無限大だとみなされます。

- ``step_list``

形式: 実数型のリスト。長さはdimensionの値と一致させます。

説明: モンテカルロ更新の際の変化幅(ガウス分布の偏差)です。

- 離散空間

- ``mesh_path``
Expand Down
15 changes: 6 additions & 9 deletions doc/ja/source/algorithm/pamc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ MPI 並列をする場合にはあらかじめ `mpi4py <https://mpi4py.readthedo

説明: パラメータの初期値。 定義しなかった場合は一様ランダムに初期化されます。

- ``unit_list``

形式: 実数型のリスト。長さはdimensionの値と一致させます。

説明: 各パラメータの単位。
探索アルゴリズム中では、各パラメータをそれぞれこれらの値で割ることで、
簡易的な無次元化・正規化を行います。
定義しなかった場合にはすべての次元で 1.0 となります。

- ``min_list``

形式: 実数型のリスト。長さはdimensionの値と一致させます。
Expand All @@ -56,6 +47,12 @@ MPI 並列をする場合にはあらかじめ `mpi4py <https://mpi4py.readthedo
モンテカルロ探索中にこの値を上回るパラメータが出現した場合、
ソルバーは評価されずに、値が無限大だとみなされます。

- ``step_list``

形式: 実数型のリスト。長さはdimensionの値と一致させます。

説明: モンテカルロ更新の際の変化幅(ガウス分布の偏差)です。

- 離散空間

- ``mesh_path``
Expand Down
7 changes: 2 additions & 5 deletions doc/ja/source/tutorial/exchange.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
[algorithm.param]
min_list = [3.0, 3.0]
max_list = [6.0, 6.0]
initial_list = [0.0, 0.0]
unit_list = [0.3, 0.3]
step_list = [0.3, 0.3]
[algorithm.exchange]
Tmin = 0.1
Expand All @@ -66,9 +65,7 @@

- ``min_list`` と ``max_list`` はそれぞれ探索範囲の最小値と最大値を指定します。

- ``initial_list`` は初期値を指定します。

- ``unit_list`` は各パラメータの単位を指定します。
- ``step_list`` はモンテカルロ更新の際の変化幅(ガウス分布の偏差)です。

``[algorithm.exchange]`` サブセクションは、レプリカ交換モンテカルロ法のハイパーパラメータを指定します。

Expand Down
4 changes: 2 additions & 2 deletions doc/ja/source/tutorial/pamc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
[algorithm.param]
max_list = [6.0, 6.0]
min_list = [-6.0, -6.0]
unit_list = [0.3, 0.3]
step_list = [0.3, 0.3]
[algorithm.pamc]
bmin = 0.0
Expand All @@ -69,7 +69,7 @@

- ``min_list`` と ``max_list`` はそれぞれ探索範囲の最小値と最大値を指定します。

- ``unit_list`` はモンテカルロ更新の際の変化幅(ガウス分布の偏差)です。
- ``step_list`` はモンテカルロ更新の際の変化幅(ガウス分布の偏差)です。

``[algorithm.pamc]`` セクションは、ポピュレーションアニーリングのハイパーパラメータを指定します。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ seed = 12345
[algorithm.param]
min_list = [3.0, 3.0]
max_list = [6.0, 6.0]
step_list = [1.0, 1.0]

[algorithm.exchange]
numsteps = 1000
Expand Down
2 changes: 1 addition & 1 deletion extra/sim-trhepd-rheed/sample/single_beam/pamc/input.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ seed = 12345
[algorithm.param]
min_list = [3.0, 3.0]
max_list = [6.0, 6.0]
unit_list = [0.3, 0.3]
step_list = [0.3, 0.3]

[algorithm.pamc]
numsteps_annealing = 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ seed = 12345
[algorithm.param]
min_list = [3.0, 3.0]
max_list = [6.0, 6.0]
step_list = [1.0, 1.0]

[algorithm.exchange]
numsteps = 1000
Expand Down
2 changes: 1 addition & 1 deletion extra/sim-trhepd-rheed/tests/single_beam/pamc/input.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ seed = 12345
[algorithm.param]
min_list = [3.0, 3.0]
max_list = [6.0, 6.0]
unit_list = [0.3, 0.3]
step_list = [0.3, 0.3]

[algorithm.pamc]
numsteps_annealing = 5
Expand Down
3 changes: 1 addition & 2 deletions sample/analytical/exchange/input.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ seed = 12345
[algorithm.param]
max_list = [6.0, 6.0]
min_list = [-6.0, -6.0]
initial_list = [0.0, 0.0]
unit_list = [0.3, 0.3]
step_list = [0.3, 0.3]

[algorithm.exchange]
Tmin = 0.01
Expand Down
2 changes: 1 addition & 1 deletion sample/analytical/pamc/input.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ seed = 12345
[algorithm.param]
max_list = [6.0, 6.0]
min_list = [-6.0, -6.0]
unit_list = [0.3, 0.3]
step_list = [0.3, 0.3]

[algorithm.pamc]
bmin = 0.0
Expand Down
3 changes: 2 additions & 1 deletion src/py2dmat/algorithm/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class Algorithm(py2dmat.algorithm.montecarlo.AlgorithmBase):
x: np.ndarray
xmin: np.ndarray
xmax: np.ndarray
xunit: np.ndarray
#xunit: np.ndarray
xstep: np.ndarray

numsteps: int
numsteps_exchange: int
Expand Down
18 changes: 14 additions & 4 deletions src/py2dmat/algorithm/montecarlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AlgorithmBase(py2dmat.algorithm.AlgorithmBase):
x: np.ndarray
xmin: np.ndarray
xmax: np.ndarray
xunit: np.ndarray
xstep: np.ndarray

# discrete problem
inode: np.ndarray
Expand Down Expand Up @@ -115,16 +115,26 @@ def __init__(self, info: py2dmat.Info,
if "mesh_path" in info_param:
self.iscontinuous = False
self.domain = py2dmat.domain.MeshGrid(info)

else:
self.iscontinuous = True
self.domain = py2dmat.domain.Region(info)

if self.iscontinuous:
self.xmin = self.domain.min_list
self.xmax = self.domain.max_list
self.xunit = self.domain.unit_list

if "step_list" in info_param:
self.xstep = info_param.get("step_list")

elif "unit_list" in info_param:
# for compatibility, unit_list can also be accepted for step size.
if self.mpirank == 0:
print("WARNING: unit_list is obsolete. use step_list instead")
self.xstep = info_param.get("unit_list")
else:
# neither step_list nor unit_list is specified, report error.
# default value not assumed.
raise ValueError("ERROR: algorithm.param.step_list not specified")
else:
self.node_coordinates = np.array(self.domain.grid)[:, 1:]
self.nnodes = self.node_coordinates.shape[0]
Expand Down Expand Up @@ -213,7 +223,7 @@ def propose(self, current: np.ndarray) -> np.ndarray:
proposal
"""
if self.iscontinuous:
dx = self.rng.normal(size=(self.nwalkers, self.dimension)) * self.xunit
dx = self.rng.normal(size=(self.nwalkers, self.dimension)) * self.xstep
proposed = current + dx
else:
proposed_list = [self.rng.choice(self.neighbor_list[i]) for i in current]
Expand Down
3 changes: 2 additions & 1 deletion src/py2dmat/algorithm/pamc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class Algorithm(py2dmat.algorithm.montecarlo.AlgorithmBase):
x: np.ndarray
xmin: np.ndarray
xmax: np.ndarray
xunit: np.ndarray
#xunit: np.ndarray
xstep: np.ndarray

numsteps: int
numsteps_annealing: int
Expand Down
2 changes: 2 additions & 0 deletions tests/bayes/do.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

rm -rf output

time python3 ../../src/py2dmat_main.py input.toml
Expand Down
2 changes: 2 additions & 0 deletions tests/exchange/do.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

rm -rf output

time mpiexec --oversubscribe -np 4 python3 ../../src/py2dmat_main.py input.toml
Expand Down
1 change: 1 addition & 0 deletions tests/exchange/input.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ seed = 12345
[algorithm.param]
min_list = [-5.0, -5.0]
max_list = [5.0, 5.0]
step_list = [1.0, 1.0]

[algorithm.exchange]
numsteps = 10000
Expand Down
2 changes: 1 addition & 1 deletion tests/exchange_continue/do.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

CMD="mpiexec -np 4 python3 -u ../../src/py2dmat_main.py"
CMD="mpiexec --oversubscribe -np 4 python3 -u ../../src/py2dmat_main.py"

rm -rf output1

Expand Down
1 change: 1 addition & 0 deletions tests/exchange_continue/input1a.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ checkpoint_steps = 1000
[algorithm.param]
min_list = [-5.0, -5.0]
max_list = [5.0, 5.0]
step_list = [1.0, 1.0]

[algorithm.exchange]
numsteps = 10000
Expand Down
1 change: 1 addition & 0 deletions tests/exchange_continue/input1b.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ checkpoint_steps = 5000
[algorithm.param]
min_list = [-5.0, -5.0]
max_list = [5.0, 5.0]
step_list = [1.0, 1.0]

[algorithm.exchange]
numsteps = 20000
Expand Down
1 change: 1 addition & 0 deletions tests/exchange_continue/input2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ checkpoint_steps = 1000
[algorithm.param]
min_list = [-5.0, -5.0]
max_list = [5.0, 5.0]
step_list = [1.0, 1.0]

[algorithm.exchange]
numsteps = 20000
Expand Down
2 changes: 2 additions & 0 deletions tests/exchange_mesh/do.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

rm -rf output

echo generate MeshData.txt
Expand Down
4 changes: 3 additions & 1 deletion tests/mapper/do.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh

rm -rf output

time mpiexec -np 2 python3 ../../src/py2dmat_main.py input.toml
time mpiexec --oversubscribe -np 2 python3 ../../src/py2dmat_main.py input.toml

resfile=output/ColorMap.txt

Expand Down
2 changes: 2 additions & 0 deletions tests/minsearch/do.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

rm -rf output

time python3 ../../src/py2dmat_main.py input.toml
Expand Down
2 changes: 2 additions & 0 deletions tests/pamc/do.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

rm -rf output

time mpiexec --oversubscribe -np 2 python3 -m mpi4py ../../src/py2dmat_main.py input.toml
Expand Down
Loading

0 comments on commit 90d42ed

Please sign in to comment.