Adaptive importance sampling algorithm for Probabilistic Graphical Models