Machine learning successive descent method (machine learning algorithm principle and practice) Zheng Jie

Source: Internet
Author: User

Definition of successive descent method:

    1. For a given set of equations, use the formula:

      where k is the number of iterations (k=0,1,2,... )
      The method of finding approximate solution by stepwise generation is called iterative method
    2. If it exists (recorded as), it is said that this iterative method converges, obviously is the solution of the equations, otherwise called this iterative method divergence.
    3. Study the convergence of {}. Introducing Error Vectors:

      Get:

      Recursion gets:

      To investigate the convergence of {}, we should study the conditions of B.
The following gives the Python implementation

#-*-Coding:utf-8-*-
Import NumPy as NP
From numpy Import *
From common_libs Import *
Import Matplotlib.pyplot as Plt

#消元发求解方程组的解
#求解元方程
Def method_nomal ():
A=mat ([[8,-3,2],
[4,11,-1],
[6,3,12]])
B=mat ([20,33,36])

Result=linalg.solve (A,B.T)
Print result

#迭代法进行计算
def interationmethod (n,b0,f):
Error = 1.0e-6 # iteration Threshold
steps = 100 # Number of iterations
Xk=zeros ((n,1))
Errorlist=[]
For I in range (steps):
Xk_1=xk
Xk=b0*xk+f
Errorlist.append (Linalg.norm (XK_1-XK))
If Errorlist[-1]<error:
Print i+1
Break
Print XK
Return i,errorlist

Method_nomal ()
B0=mat ([[0.0,3.0/8,-2.0/8],
[ -4.0/11,0.0,1.0/11],
[ -6.0/12,-3.0/12,0.0]])
Print (B0)
F=mat ([20.0/8,33.0/11,36.0/12])
[K,errorlist]=interationmethod (3,b0,f)


# Plot Scatter plots
matpts= Zeros ((2,k+1))
Matpts[0]=linspace (1,k+1,k+1)
Print Matpts[0]
Matpts[1]=array (errorlist)
Drawscatter (plt,matpts)
Plt.show ()

Machine learning successive descent method (machine learning algorithm principle and practice) Zheng Jie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.