16
16
""" Module for testing BID routines"""
17
17
18
18
import os
19
- os .environ ['JAX_ENABLE_X64' ] = 'True'
19
+
20
+ os .environ ["JAX_ENABLE_X64" ] = "True"
20
21
21
22
import pytest
22
23
23
- from dadapy .hamming import Hamming
24
24
from dadapy ._utils .stochastic_minimization_hamming import *
25
-
26
-
25
+ from dadapy .hamming import Hamming
27
26
28
27
# EXPECTED OUTPUT
29
28
d_0 = 99.855
35
34
np .random .seed (seed = seed )
36
35
37
36
# DATA
38
- L = 100 # number of bits
37
+ L = 100 # number of bits
39
38
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
41
42
42
- # DISTANCES
43
- histfolder = f' ./tests/test_hamming/results/hist/'
43
+ # DISTANCES
44
+ histfolder = f" ./tests/test_hamming/results/hist/"
44
45
H = Hamming (coordinates = X )
45
46
H .compute_distances ()
46
- H .D_histogram (L = L ,Ns = Ns ,resultsfolder = histfolder )
47
+ H .D_histogram (L = L , Ns = Ns , resultsfolder = histfolder )
47
48
48
49
# 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
57
58
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
+ )
68
70
B .computeBID ()
69
71
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