Skip to content

Commit 289b2f2

Browse files
authored
Merge pull request #129 from sylvainczx/main
Minor fix in seqsampling
2 parents 5bca2e6 + 4bb8dea commit 289b2f2

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

mpisppy/confidence_intervals/seqsampling.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ def gap_estimators(xhat,solvername, scenario_names, scenario_creator, ArRP=1,
170170
scenario_creator_kwargs=scenario_creator_kwargs)
171171
#Evaluating xhat and xstar and getting the value of the objective function
172172
#for every (local) scenario
173-
173+
global_toc(f"xhat={xhat}")
174+
global_toc(f"xstar={xstar}")
174175
ev.evaluate(xhat)
175176
objs_at_xhat = ev.objs_dict
176177
ev.evaluate(xstar)
@@ -328,7 +329,7 @@ def bm_sampsize(self,k,G,s,nk_m1, r=2):
328329
raise RuntimeError("We need the confidence level to compute the constant cp")
329330
j = np.arange(1,1000)
330331
s = sum(np.power(j,-p*np.log(j)))
331-
c = max(1,2*np.log(s/(np.sqrt(2*np.pi)*confidence_level)))
332+
c = max(1,2*np.log(s/(np.sqrt(2*np.pi)*(1-confidence_level))))
332333

333334
lower_bound = (c+2*p* np.log(k)**2)/((h-hprime)**2)
334335
else :
@@ -340,9 +341,10 @@ def bm_sampsize(self,k,G,s,nk_m1, r=2):
340341
RuntimeError("We need the confidence level to compute the constant c_pq")
341342
j = np.arange(1,1000)
342343
s = sum(np.exp(-p*np.power(j,2*q/r)))
343-
c = max(1,2*np.log(s/(np.sqrt(2*np.pi)*confidence_level)))
344+
c = max(1,2*np.log(s/(np.sqrt(2*np.pi)*(1-confidence_level))))
344345

345-
lower_bound = (c+2*p*np.power(k,2*q/r))/((h-hprime)**2)
346+
lower_bound = (c+2*p*np.power(k,2*q/r))/((h-hprime)**2)
347+
#print(f"nk={lower_bound}")
346348
return int(np.ceil(lower_bound))
347349

348350
def bpl_fsp_sampsize(self,k,G,s,nk_m1):
@@ -399,12 +401,13 @@ def run(self,maxit=200):
399401
r = 2 #TODO : we could add flexibility here
400402
j = np.arange(1,1000)
401403
if self.q is None:
402-
s = sum(np.power(j,-self.p*np.log(j)))
404+
s = sum(np.power(j,-self.p*np.log(j)))
403405
else:
404406
if self.q<1:
405407
raise RuntimeError("Parameter q should be greater than 1.")
406408
s = sum(np.exp(-self.p*np.power(j,2*self.q/r)))
407-
self.c = max(1,2*np.log(s/(np.sqrt(2*np.pi)*self.confidence_level)))
409+
self.c = max(1,2*np.log(s/(np.sqrt(2*np.pi)*(1-self.confidence_level))))
410+
408411

409412
nk = self.ArRP *int(np.ceil(self.sample_size(k, None, None, None)/self.ArRP))
410413

mpisppy/tests/test_conf_int.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_seqsampling_running(self):
240240
x = seq_pb.run(maxit=50)
241241
T = x['T']
242242
ub = round_pos_sig(x['CI'][1],2)
243-
self.assertEqual((T,ub), (5,14000.0))
243+
self.assertEqual((T,ub), (1,7400.0))
244244

245245
if __name__ == '__main__':
246246
unittest.main()

0 commit comments

Comments
 (0)