@@ -32,25 +32,46 @@ class Transformation():
3232 """
3333 def convert_log_pdf (self , log_pdf ):
3434 """
35- Returns a transformed log-PDF class.
35+ Returns a transformed :class:`pints.LogPDF`.
36+
37+ If `log_pdf` is a :class:`LogPrior`, a :class:`TransformedLogPrior`
38+ will be returned, which also transforms the output of the
39+ :meth:`sample` method.
40+
41+ If `log_pdf` is a :class:`LogLikelihood`, a
42+ :class:`TransformedLogLikelihood` is returned, which is assumed to be
43+ invariant with respect to the transform (because it is a probability of
44+ the data, not the parameters). For all other types (including
45+ ``LogPrior``) a non-invariant transform is used, see
46+ :class:`TransformedLogPDF` for details.
3647 """
48+ if isinstance (log_pdf , pints .LogLikelihood ):
49+ return TransformedLogLikelihood (log_pdf , self )
50+ if isinstance (log_pdf , pints .LogPrior ):
51+ return TransformedLogPrior (log_pdf , self )
3752 return TransformedLogPDF (log_pdf , self )
3853
3954 def convert_log_prior (self , log_prior ):
4055 """
41- Returns a transformed log-prior class .
56+ Deprecated function: Use :meth:`convert_log_pdf` instead .
4257 """
58+ # Deprecated on 2026-02-06
59+ import warnings
60+ warnings .warn (
61+ 'The method `convert_log_prior` is deprecated. Please use'
62+ ' `convert_log_pdf` instead (which will automatically detect'
63+ ' detect LogPDF subtypes).' )
4364 return TransformedLogPrior (log_prior , self )
4465
4566 def convert_error_measure (self , error_measure ):
4667 """
47- Returns a transformed error measure class.
68+ Returns a transformed : class:`pints.ErrorMeasure` .
4869 """
4970 return TransformedErrorMeasure (error_measure , self )
5071
5172 def convert_boundaries (self , boundaries ):
5273 """
53- Returns a transformed boundaries class.
74+ Returns a transformed : class:`pints.Boundaries` object .
5475 """
5576 if isinstance (boundaries , pints .RectangularBoundaries ):
5677 if self .elementwise ():
@@ -1212,6 +1233,62 @@ def sample(self, n):
12121233 return qs
12131234
12141235
1236+ class TransformedLogLikelihood (pints .LogLikelihood ):
1237+ r"""
1238+ A :class:`pints.LogLikelihood` that accepts parameters in a transformed
1239+ search space.
1240+
1241+ Unlike a :class:`TransformedLogPDF`, a likelihood (a probability of the
1242+ data, given fixed parameters) is invariant to a parameter transform (but
1243+ not to a data transform), and so no Jacobian term appears. Instead
1244+
1245+ .. math::
1246+ ???
1247+
1248+
1249+ For the first order sensitivity, the transformation is done using
1250+
1251+ .. math::
1252+ ???
1253+
1254+ Extends :class:`pints.LogLikelihood`.
1255+
1256+ Parameters
1257+ ----------
1258+ log_likelihood
1259+ A :class:`pints.LogLikelihood`.
1260+ transformation
1261+ A :class:`pints.Transformation`.
1262+ """
1263+ def __init__ (self , log_likelihood , transformation ):
1264+ self ._log_likelihood = log_likelihood
1265+ self ._transform = transformation
1266+ self ._n_parameters = self ._log_pdf .n_parameters ()
1267+ if self ._transform .n_parameters () != self ._n_parameters :
1268+ raise ValueError ('Number of parameters for log_likelihood and '
1269+ 'transformation must match.' )
1270+
1271+ def __call__ (self , q ):
1272+ # Compute LogLikelihood in the model space
1273+ return self ._log_likelihood (self ._transform .to_model (q ))
1274+
1275+ def evaluateS1 (self , q ):
1276+ """ See :meth:`LogPDF.evaluateS1()`. """
1277+
1278+ # Call evaluateS1 of LogLikelihood in the model space
1279+ logl , dlogl_nojac = self ._error .evaluateS1 (self ._transform .to_model (q ))
1280+
1281+ # Calculate the S1 using change of variable (see ErrorMeasure above)
1282+ jacobian = self ._transform .jacobian (q )
1283+ dlogl = np .matmul (dlogl_nojac , jacobian ) # Jacobian must be 2nd term
1284+
1285+ return logl , dlogl
1286+
1287+ def n_parameters (self ):
1288+ """ See :meth:`LogPDF.n_parameters()`. """
1289+ return self ._n_parameters
1290+
1291+
12151292class UnitCubeTransformation (ScalingTransformation ):
12161293 """
12171294 Maps a parameter space onto the unit (hyper)cube.
0 commit comments