@@ -14,13 +14,13 @@ class AMH(InferenceABC):
1414
1515 name = "Adaptive Metropolis-Hastings"
1616
17- def __init__ (self , nChain : int = 1 , warmUp : int = 1000 , maxIterTimes : int = 1000 ,
17+ def __init__ (self , nChains : int = 1 , warmUp : int = 1000 , maxIterTimes : int = 1000 ,
1818 propDist : Literal ['gauss' , 'uniform' ] = 'gauss' ,
1919 verboseFlag : bool = True , verboseFreq : int = 10 ,
2020 logFlag : bool = False , saveFlag : bool = True ):
2121 super ().__init__ (maxIterTimes , verboseFlag , verboseFreq , logFlag , saveFlag )
2222
23- self .setParaVal ('nChain ' , nChain )
23+ self .setParaVal ('nChains ' , nChains )
2424 self .setParaVal ('warmUp' , warmUp )
2525 self .setParaVal ('propDist' , propDist )
2626
@@ -35,27 +35,27 @@ def run(self, problem: ProblemABC, gamma: Union[float, np.ndarray] = 0.1, seed:
3535
3636 self .setup (problem , seed )
3737
38- nChain = self .getParaVal ('nChain ' )
38+ nChains = self .getParaVal ('nChains ' )
3939 warmUp = self .getParaVal ('warmUp' )
4040 propDist = self .getParaVal ('propDist' )
4141 self .setParaVal ('gamma' , gamma )
4242
4343 gamma = self ._check_gamma_ (gamma )
4444 sd = 2.38 ** 2 / problem .nInput
4545
46- X_init , Objs_init , Cons_init = self .initialSampling (problem , nChain )
46+ X_init , Objs_init , Cons_init = self .initialSampling (problem , nChains )
4747
48- chains = self .initChains (nChain , X_init , Objs_init , Cons_init )
48+ chains = self .initChains (nChains , X_init , Objs_init , Cons_init )
4949
5050 # calculate proposal covariance matrix
5151 gamma = self ._check_gamma_ (gamma )
5252 propCovs = []
5353
54- for i in range (nChain ):
54+ for i in range (nChains ):
5555 cov = (gamma [i ] * (problem .ub - problem .lb ))** 2
5656 propCovs .append (np .diag (cov .ravel ()))
5757
58- ac_rate = np .zeros (nChain )
58+ ac_rate = np .zeros (nChains )
5959
6060 X_cur = X_init ; Objs_cur = Objs_init ; Cons_cur = Cons_init
6161
@@ -65,7 +65,7 @@ def run(self, problem: ProblemABC, gamma: Union[float, np.ndarray] = 0.1, seed:
6565
6666 Objs_star , Cons_star = self .evaluate (X_star )
6767
68- for i in range (nChain ):
68+ for i in range (nChains ):
6969
7070 if np .log (np .random .rand ()) < (self .log_prob (Objs_star [i ]) - self .log_prob (Objs_cur [i ])) \
7171 and (problem .nCons == 0 or (problem .nCons > 0 and all (Cons_star [i ] <= 0 ))):
@@ -86,7 +86,7 @@ def run(self, problem: ProblemABC, gamma: Union[float, np.ndarray] = 0.1, seed:
8686 if np .log (np .random .rand ()) < (self .log_prob (Objs_star [i ]) - self .log_prob (Objs_cur [i ])) \
8787 and (problem .nCons == 0 or (problem .nCons > 0 and all (Cons_star [i ] <= 0 ))):
8888
89- ac_rate [i ] += 1 / self .maxIter
89+ ac_rate [i ] += 1 / self .maxIters
9090
9191 X_cur [i ] = X_star [i ]; Objs_cur [i ] = Objs_star [i ]
9292
@@ -110,7 +110,7 @@ def run(self, problem: ProblemABC, gamma: Union[float, np.ndarray] = 0.1, seed:
110110 "acceptanceRate_mean" : ((), mean_ac_rate , {"long_name" : "mean of acceptance rate for all chains" , "description" : "mean of acceptance rate for all chains" })
111111 },
112112 coords = {
113- "chain" : np .arange (nChain ),
113+ "chain" : np .arange (nChains ),
114114 },
115115 )
116116
@@ -121,7 +121,7 @@ def run(self, problem: ProblemABC, gamma: Union[float, np.ndarray] = 0.1, seed:
121121 "lg" : (("chain" , "draw" , "objsDim" ), lg , {"long_name" : "log probability" , "description" : "log probability for each sample" }),
122122 },
123123 coords = {
124- "chain" : np .arange (nChain ),
124+ "chain" : np .arange (nChains ),
125125 "draw" : np .arange (self .iter ),
126126 "objsDim" : np .arange (self .problem .nOutput ),
127127 },
@@ -144,21 +144,21 @@ def updateCovs(self, chains, sd):
144144
145145 def _check_alpha (self , gamma ):
146146
147- nChain = self .getParaVal ('nChain ' )
147+ nChains = self .getParaVal ('nChains ' )
148148 nInput = self .problem .nInput
149149
150150 if isinstance (gamma , float ):
151- gamma = np .full ((nChain , nInput ), gamma )
151+ gamma = np .full ((nChains , nInput ), gamma )
152152
153153 elif isinstance (gamma , np .ndarray ):
154154 gamma = np .atleast_2d (gamma )
155155 n , _ = gamma .shape
156156 if n == 1 :
157- gamma = np .tile (gamma , (nChain , 1 ))
158- elif n == nChain :
157+ gamma = np .tile (gamma , (nChains , 1 ))
158+ elif n == nChains :
159159 gamma = gamma
160160 else :
161- raise ValueError ("The shape of gamma must be (nChain , nInput) or (1, nInput)" )
161+ raise ValueError ("The shape of gamma must be (nChains , nInput) or (1, nInput)" )
162162 else :
163163 raise ValueError ("gamma must be a float or a numpy array" )
164164
0 commit comments