Machine Learning-based Framework for Optimally Solving the Analytical Inverse Kinematics for Redundant Manipulators