  This paper proposes a novel approach to generate samples from target
distributions that are difficult to sample from using Markov Chain Monte Carlo
(MCMC) methods. Traditional MCMC algorithms often face slow convergence due to
the difficulty in finding proposals that suit the problem at hand. To address
this issue, the paper introduces the Approximate Posterior Ensemble Sampler
(APES) algorithm, which employs kernel density estimation and radial basis
interpolation to create an adaptive proposal, leading to fast convergence of
the chains. The APES algorithm's scalability to higher dimensions makes it a
practical solution for complex problems. The proposed method generates an
approximate posterior probability that closely approximates the desired
distribution and is easy to sample from, resulting in smaller autocorrelation
times and a higher probability of acceptance by the chain. We compare the
performance of the APES algorithm with the affine invariance ensemble sampler
with the stretch move in various contexts, demonstrating the efficiency of the
proposed method. For instance, on the Rosenbrock function, the APES presented
an autocorrelation time 140 times smaller than the affine invariance ensemble
sampler. The comparison showcases the effectiveness of the APES algorithm in
generating samples from challenging distributions. This paper presents a
practical solution to generating samples from complex distributions while
addressing the challenge of finding suitable proposals. With new cosmological
surveys set to deal with many new systematics, this method offers a practical
solution for the upcoming era of cosmological analyses. The algorithms
presented in this paper are available at https://github.com/NumCosmo/NumCosmo.
