Skip to content

Commit 8c3ed9f

Browse files
committed
format again
1 parent b1cf141 commit 8c3ed9f

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

dadapy/_utils/stochastic_minimization_hamming.py

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def minimize_KL(Op):
185185
Op.acc_ratio = jnp.double(Op.accepted) / jnp.double(Op.Nsteps)
186186
return Op
187187

188+
188189
class BID:
189190
def __init__(
190191
self,

tests/test_hamming/test0.py

+32-30
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
""" Module for testing BID routines"""
1717

1818
import os
19-
os.environ['JAX_ENABLE_X64'] = 'True'
19+
20+
os.environ["JAX_ENABLE_X64"] = "True"
2021

2122
import pytest
2223

23-
from dadapy.hamming import Hamming
2424
from dadapy._utils.stochastic_minimization_hamming import *
25-
26-
25+
from dadapy.hamming import Hamming
2726

2827
# EXPECTED OUTPUT
2928
d_0 = 99.855
@@ -35,38 +34,41 @@
3534
np.random.seed(seed=seed)
3635

3736
# DATA
38-
L = 100 # number of bits
37+
L = 100 # number of bits
3938
Ns = 5000 # number of samples
40-
X = 2*np.random.randint(low=0,high=2,size=(Ns,L))-1 # spins must be normalized to +-1
39+
X = (
40+
2 * np.random.randint(low=0, high=2, size=(Ns, L)) - 1
41+
) # spins must be normalized to +-1
4142

42-
# DISTANCES
43-
histfolder = f'./tests/test_hamming/results/hist/'
43+
# DISTANCES
44+
histfolder = f"./tests/test_hamming/results/hist/"
4445
H = Hamming(coordinates=X)
4546
H.compute_distances()
46-
H.D_histogram(L=L,Ns=Ns,resultsfolder=histfolder)
47+
H.D_histogram(L=L, Ns=Ns, resultsfolder=histfolder)
4748

4849
# PARAMETER DEFINITIONS
49-
eps = 1E-5 # good-old small epsilon
50-
alphamin = 0 #+ eps # order of min_quantile, to remove poorly sampled parts of the histogram
51-
alphamax = 1 #- eps # order of max_quantile, to define r* (named rmax here)
52-
delta = 5E-4 # stochastic optimization step
53-
Nsteps = int(1E6) # number of optimization steps
54-
seed = 1 #
55-
optfolder0 = f'results/opt/' # folder where optimization results are saved
56-
export_logKLs = 1 # flag to export the logKLs during optimization
50+
eps = 1e-5 # good-old small epsilon
51+
alphamin = 0 # + eps # order of min_quantile, to remove poorly sampled parts of the histogram
52+
alphamax = 1 # - eps # order of max_quantile, to define r* (named rmax here)
53+
delta = 5e-4 # stochastic optimization step
54+
Nsteps = int(1e6) # number of optimization steps
55+
seed = 1 #
56+
optfolder0 = f"results/opt/" # folder where optimization results are saved
57+
export_logKLs = 1 # flag to export the logKLs during optimization
5758

58-
B = BID(H,
59-
alphamin=alphamin,
60-
alphamax=alphamax,
61-
seed=seed,
62-
delta=delta,
63-
Nsteps=Nsteps,
64-
export_logKLs=export_logKLs,
65-
optfolder0=optfolder0,
66-
L=L
67-
)
59+
B = BID(
60+
H,
61+
alphamin=alphamin,
62+
alphamax=alphamax,
63+
seed=seed,
64+
delta=delta,
65+
Nsteps=Nsteps,
66+
export_logKLs=export_logKLs,
67+
optfolder0=optfolder0,
68+
L=L,
69+
)
6870
B.computeBID()
6971

70-
assert pytest.approx(B.Op.d0,abs=1E-3) == d_0
71-
assert pytest.approx(B.Op.d1,abs=1E-3) == d_1
72-
assert pytest.approx(jnp.log(B.Op.KL),abs=1E-2) == logKL
72+
assert pytest.approx(B.Op.d0, abs=1e-3) == d_0
73+
assert pytest.approx(B.Op.d1, abs=1e-3) == d_1
74+
assert pytest.approx(jnp.log(B.Op.KL), abs=1e-2) == logKL

0 commit comments

Comments
 (0)