@@ -68,6 +68,7 @@ def noise(self, sigma, values):
6868 pybop .SumofPower ,
6969 pybop .Minkowski ,
7070 pybop .LogPosterior ,
71+ pybop .LogPosterior , # Second for GaussianLogLikelihood
7172 ]
7273 )
7374 def cost_cls (self , request ):
@@ -90,13 +91,19 @@ def cost(self, model, parameters, init_soc, cost_cls):
9091 problem = pybop .FittingProblem (model , parameters , dataset )
9192
9293 # Construct the cost
94+ first_map = True
9395 if cost_cls is pybop .GaussianLogLikelihoodKnownSigma :
9496 return cost_cls (problem , sigma0 = self .sigma0 )
9597 elif cost_cls is pybop .GaussianLogLikelihood :
9698 return cost_cls (problem )
99+ elif cost_cls is pybop .LogPosterior and first_map :
100+ first_map = False
101+ return cost_cls (log_likelihood = pybop .GaussianLogLikelihood (problem ))
97102 elif cost_cls is pybop .LogPosterior :
98103 return cost_cls (
99- pybop .GaussianLogLikelihoodKnownSigma (problem , sigma0 = self .sigma0 )
104+ log_likelihood = pybop .GaussianLogLikelihoodKnownSigma (
105+ problem , sigma0 = self .sigma0
106+ )
100107 )
101108 else :
102109 return cost_cls (problem )
@@ -114,7 +121,7 @@ def test_thevenin_transformation(self, optimiser, cost):
114121 optim = optimiser (
115122 cost = cost ,
116123 sigma0 = [0.03 , 0.03 , 1e-3 ]
117- if isinstance (cost , pybop .GaussianLogLikelihood )
124+ if isinstance (cost , ( pybop .GaussianLogLikelihood , pybop . LogPosterior ) )
118125 else [0.03 , 0.03 ],
119126 max_unchanged_iterations = 35 ,
120127 absolute_tolerance = 1e-6 ,
@@ -125,7 +132,7 @@ def test_thevenin_transformation(self, optimiser, cost):
125132 x , final_cost = optim .run ()
126133
127134 # Add sigma0 to ground truth for GaussianLogLikelihood
128- if isinstance (optim .cost , pybop .GaussianLogLikelihood ):
135+ if isinstance (optim .cost , ( pybop .GaussianLogLikelihood , pybop . LogPosterior ) ):
129136 self .ground_truth = np .concatenate (
130137 (self .ground_truth , np .asarray ([self .sigma0 ]))
131138 )
0 commit comments