Cycle-Based Cluster Variational Method for Direct and Inverse Inference