Skip to content

Commit b1cf141

Browse files
committed
test computing BID passed
1 parent 6adb6f3 commit b1cf141

File tree

6 files changed

+1188
-12
lines changed

6 files changed

+1188
-12
lines changed

dadapy/_utils/stochastic_minimization_hamming.py

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

188-
189-
def test_initial_condition(Op, d0, d1):
190-
""" """
191-
Op.d0_r = jnp.double(d0)
192-
Op.d1_r = jnp.double(d1)
193-
Op = compute_Pmodel(Op)
194-
Op = compute_KLd(Op)
195-
return np.log(Op.KL)
196-
197-
198188
class BID:
199189
def __init__(
200190
self,
201191
H=None,
192+
Op=None,
202193
alphamin=0.0,
203194
alphamax=0.2,
204195
seed=1,
@@ -213,6 +204,7 @@ def __init__(
213204
L=0, # Number of bits / Ising spins
214205
):
215206
self.H = H
207+
self.Op = Op
216208
self.alphamin = alphamin
217209
self.alphamax = alphamax
218210
self.seed = seed
@@ -284,6 +276,13 @@ def truncate_hist(self):
284276
self.Pemp /= jnp.sum(self.Pemp)
285277
self.Pmodel = jnp.zeros(shape=self.Pemp.shape, dtype=jnp.float64)
286278

279+
def test_initial_condition(self, d0, d1):
280+
self.Op.d0_r = jnp.double(d0)
281+
self.Op.d1_r = jnp.double(d1)
282+
self.Op = compute_Pmodel(self.Op)
283+
self.Op = compute_KLd(self.Op)
284+
return np.log(self.Op.KL)
285+
287286
def set_initial_condition(self, d00min=0.05, d00max=0.95, d00step=0.05):
288287
# our home-made guess:
289288
d00_guess_list = jnp.array([jnp.double(self.Op.remp[-1])])
@@ -305,8 +304,7 @@ def set_initial_condition(self, d00min=0.05, d00max=0.95, d00step=0.05):
305304
logKLs0 = jnp.empty(shape=(len(d00_guess_list)), dtype=jnp.double)
306305
for i in range(len(d00_guess_list)):
307306
logKLs0 = logKLs0.at[i].set(
308-
test_initial_condition(
309-
self.Op,
307+
self.test_initial_condition(
310308
d00_guess_list[i],
311309
d10_guess_list[i],
312310
)

0 commit comments

Comments
 (0)