The Math Principle and Implementation of Machine Learning Algorithms