Description
When FD gradient is enabled for posterior, UQ method in Bayesian problem is not able to detect that in some cases because it checks for the likelihood and the prior gradients that might not be available
Example to reproduce
Provide a code example to reproduce the bug
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
Cell In [1], [line 14](vscode-notebook-cell:?execution_count=1&line=14)
[12](vscode-notebook-cell:?execution_count=1&line=12) BP_test.set_data(y_test=y_test_data)
[13](vscode-notebook-cell:?execution_count=1&line=13) BP_test.posterior.enable_FD()
---> [14](vscode-notebook-cell:?execution_count=1&line=14) BP_test.UQ()
File ~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:411, in BayesianProblem.UQ(self, Ns, Nb, percent, exact)
[388](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:388) """ Run an Uncertainty Quantification (UQ) analysis on the Bayesian problem and provide a summary of the results.
[389](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:389)
[390](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:390) Parameters
(...)
[408](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:408) Samples from the posterior. The samples can be used to compute further statistics and plots.
[409](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:409) """
[410](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:410) print(f"Computing {Ns} samples")
--> [411](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:411) samples = self.sample_posterior(Ns, Nb)
[413](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:413) print("Plotting results")
[414](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:414) # Gibbs case
File ~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:357, in BayesianProblem.sample_posterior(self, Ns, Nb, callback)
[354](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:354) return self._sampleRegularizedLinearRTO(Ns, Nb, callback)
[356](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:356) else:
--> [357](https://file+.vscode-resource.vscode-cdn.net/Users/amal/Documents/research_code/CUQI-DTU/Collab-BrainEfflux/code/ear_aqueducts/~/Documents/research_code/CUQI-DTU/CUQIpy/cuqi/problem/_problem.py:357) raise NotImplementedError(f"Automatic sampler choice is not implemented for model: {type(self.model)}, likelihood: {type(self.likelihood.distribution)} and prior: {type(self.prior)} and dim {self.prior.dim}. Manual sampler choice can be done via the 'sampler' module. Posterior distribution can be extracted via '.posterior' of any testproblem (BayesianProblem).")
NotImplementedError: Automatic sampler choice is not implemented for model: <class 'cuqi.model._model.Model'>, likelihood: <class 'cuqi.distribution._gaussian.Gaussian'> and prior: <class 'cuqi.distribution._custom.UserDefinedDistribution'> and dim 2. Manual sampler choice can be done via the 'sampler' module. Posterior distribution can be extracted via '.posterior' of any testproblem (BayesianProblem).
Description When FD gradient is enabled for posterior, UQ method in Bayesian problem is not able to detect that in some cases because it checks for the likelihood and the prior gradients that might not be available
Example to reproduce Provide a code example to reproduce the bug
Output