Finding the extremum of convex function by three-part method

Source: Internet
Author: User

Jostree Reprint Please specify the source http://www.cnblogs.com/jostree/p/4397990.html

In machine learning, it is a common problem to find the extremum of convex function, such as gradient descent method, Newton method, and so on, today we introduce a three-way method to find the extremum problem of a convex function.

For a convex function such as $f (x), x\in [left,right]$, where LM and RM are divided by interval [left,right], we find that if f (LM) <f (RM), then the horizontal axis x of the point with the lowest function value must be in [LEFT,RM] Between. If x is between [Rm,right], it appears that there is a lower point around RM, which is obviously impossible. Similarly, when F (LM) >f (RM), the maximum horizontal x must be within the range of [Lm,right].

By using this property, we can approximate the target point at the same time as we reduce the interval, and get the extremum.


As an example, the title derives from HTTP://HIHOCODER.COM/CONTEST/HIHO40/PROBLEM/1, such as a parabolic y=ax^2+bx+c and a point P (x, y) in a Cartesian coordinate system, and a point p to the shortest distance d of the parabola, Which -200≤a,b,c,x,y≤200. Our other pivot represents the parabolic symmetry pumping, which can be found when x>pivot, we can take left = Pivot,right = inf, and vice versa =-inf, right = pivot, whose distance exactly satisfies the convex function. the shortest distance we ask for D is exactly the extremum of this convex function.

The code is as follows:

#include <stdlib.h>#include<stdio.h>#include<string.h>#include<limits.h>#include<iostream>#include<cmath>using namespacestd;DoubleA, B, C, x, y;Const DoubleMAX =100000;DoubleDisDoubleX) {    DoubleY = a*x*x+b*x+C; returnsqrt ((x-x) * (x-x) + (y-y) * (yY));}DoubleSolveDoubleLDoubleR) {    DoubleLM = L + (r-l)/3; DoubleRM = R-(r-l)/3; DoubleLMD =dis (LM); DoubleRMD =Dis (RM); if(Fabs (LMD-RMD) <0.0001 )    {        returnLMD; }    if(LMD >RMD) {        returnSolve (LM, R); }    Else    {        returnsolve (l, RM); }}intMainintargcChar*argv[]) {     while(cin>>a>>b>>c>>x>>y) {DoublePivot =-b/(2*a); DoubleL =0, r =0; if(Pivot <x) {L= pivot +0.0001; R=MAX; }        Else{L= -MAX; R= Pivot-0.0001; }        Doubleres =Solve (L, R); printf ("%.3lf\n", RES); }}

Finding the extremum of convex function by three-part method

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.