搜索
人大经济论坛 标签 Direction 相关日志

tag 标签: Direction经管大学堂:名校名师名课

相关日志

分享 C++:变尺度法DFP求函数的最小值
accumulation 2015-4-24 16:53
#include "iostream.h" #include "math.h" #include "stdlib.h" double fun(double *x); double fcon(double *x); double funs(double *x,double M); void Grad(double (*pf)(double *x,double M),double m,int n,double *point,double *grad); double Search(double (*pf)(double *x,double M),double m,int n,double *start,double *direction); double DFP(double (*pf)(double *x,double M),double m,int n,double *min_point); double DFP(double (*pf)(double *x,double M),double m,int n,double *min_point) { int i,j,k; double e=1E-5,g_norm; double *g0=new double ; double *g1=new double ; double *dg=new double ; double *p=new double ; double t; double *x0=new double ; double *x1=new double ; double *dx=new double ; double **H=new double* ; for(i=0; in; i++) H = new double ; double **tempH=new double* ; for (i=0; in; i++) tempH = new double ; double *gH=new double ; double *Hg=new double ; double num1; double num2; for(i=0;in;i++) for(j=0;jn;j++) { if(i==j) H =1.0; else H =0.0; tempH =0.0; } for(i=0;in;i++) x0 =min_point ; Grad(pf,m,n,x0,g0); g_norm=0.0; for(i=0;in;i++) g_norm=g_norm+g0 *g0 ; g_norm=sqrt(g_norm); if(g_norme) { for(i=0;in;i++) min_point =x0 ; delete g1; delete p; delete x1; delete H ; delete tempH ; delete gH; delete =-g0 ; k=0; do { t=Search(pf,m,n,x0,p); for(i=0;in;i++) x1 =x0 +t*p ; Grad(pf,m,n,x1,g1); g_norm=0.0; for(i=0;in;i++) g_norm=g_norm+g1 *g1 ; g_norm=sqrt(g_norm); for(i=0;in;i++) { dx =x1 -x0 ; dg =g1 -g0 ; } for(i=0;in;i++) { gH =0.0; Hg =0.0; } for(i=0;in;i++) { for(j=0;jn;j++) { gH =gH +dg *H ; Hg =gH ; } } num1=0.0; num2=0.0; for(i=0;in;i++) { num1=num1+dx *dg ; num2=num2+gH *dg ; } for(i=0;in;i++) for(j=0;jn;j++) tempH =0.0; for(i=0;in;i++) { for(j=0;jn;j++) { tempH =tempH +H ; tempH =tempH +dx *dx /num1; tempH =tempH -Hg *gH /num2; } } for(i=0;in;i++) { for(j=0;jn;j++) { H =tempH ; } } for(i=0;in;i++) p =0.0; for(i=0;in;i++) { for(j=0;jn;j++) { p =p -H *g1 ; } } for(i=0;in;i++) { g0 =g1 ; x0 =x1 ; } k=k+1; }while(g_norme); for(i=0;in;i++) min_point =x1 ; delete g1; delete p; delete x1; delete H ; delete tempH ; delete gH; delete ; temp_point=new double ; Grad(pf,m,n,start,grad); diver_a=0; for(i=0;in;i++) diver_a=diver_a+grad *direction ; do { b=a+step; for(i=0;in;i++) temp_point =start +b*direction ; Grad(pf,m,n,temp_point,grad); diver_b=0; for(i=0;in;i++) diver_b=diver_b+grad *direction ; if( fabs(diver_b)1E-10 ) { delete temp_point; return b; } if( diver_b-1E-15 ) { a=b; diver_a=diver_b; step=2*step; } }while(diver_b=1E-15 ); for(i=0;in;i++) temp_point =start +a*direction ; value_a=pf(temp_point,m); for(i=0;in;i++) temp_point =start +b*direction ; value_b=pf(temp_point,m); do { s=3*(value_b-value_a)/(b-a); z=s-diver_a-diver_b; w=sqrt( fabs(z*z-diver_a*diver_b) ); t=a+(w-z-diver_a)*(b-a)/(diver_b-diver_a+2*w); value_b=pf(temp_point,m); for(i=0;in;i++) temp_point =start +t*direction ; value_t=pf(temp_point,m); Grad(pf,m,n,temp_point,grad); diver_t=0; for(i=1;i=n;i++) diver_t=diver_t+grad *direction ; if(diver_t1E-6) { b=t; value_b=value_t; diver_b=diver_t; } else if(diver_t-1E-6) { a=t; value_a=value_t; diver_a=diver_t; } else break; }while( (fabs(diver_t)=1E-6) (fabs(b-a)1E-6) ); delete temp_point; return t; } void Grad(double (*pf)(double *x,double M),double m,int n,double *point,double *grad) { double h=1E-3; int i; double *temp; temp = new double ; for(i=0;in;i++) { temp =point ; } for(i=0;in;i++) { temp +=0.5*h; grad =4*pf(temp,m)/(3*h); temp -=h; grad -=4*pf(temp,m)/(3*h); temp +=(3*h/2); grad -=(pf(temp,m)/(6*h)); temp -=(2*h); grad +=(pf(temp,m)/(6*h)); temp =point ; } delete ; double *x1=new double ; double e=1E-3,t; double M0,c; M0=1; c=2.5; for(i=0;in;i++) x0 =min_point ; k=0; do{ DFP(funs,M0,n,x0); for(i=0;in;i++) x1 =x0 ; t=fabs(fcon(x1)); if(te) { for(i=0;in;i++) min_point =x1 ; delete x1; return pf(min_point); } M0=c*M0; }while(k10); for(i=0;in;i++) min_point =x1 ; delete x1; return pf(min_point); } double fun(double *x) { //return -(0.5428-log(x )-((log(x )-5.9123)*(log(x )-5.9123))/0.0469-((x -127.2)*(x -127.2))/158.5624-0.1068*x -exp(-0.1068*(x -46.1355))); double a1=345,a2=181.52,b1=42.435,b2=10.70968; return log(2.51*b1*x )+0.5*((log(x )-a1)*(log(x )-a1))/(b1*b1)+log(2.51*b2)+0.5*((x -a2)*(x -a2)/(b2*b2)); } double fcon(double *x) { //return x -x -x ; return x -x ; } double funs(double *x,double M) { return fun(x)+M*fcon(x)*fcon(x); } void main() { int n=3; //double min_point ={201.15,201.15}; double mi ={5.836,181.52}; double min_value=Dev(fun,n,min_point); cout"本程序功能:使用变尺度法(DFP)求函数的最小值。"endl; cout"最小值点为:"endl; //cout"("min_point ","min_point ","min_point ")"endl; cout"("min_point ","min_point ")"endl; cout"最小值为:"endl; coutmin_valueendl; system("pause"); }
个人分类: 裂变模型|0 个评论
分享 The best trades
老渔夫 2014-7-13 08:24
The best trades are the ones in which you have all three things going for you: fundamentals, technicals, and market tone. 最好的交易就是有三件事情都对你有利:基本面,技术面和市场氛围。 First, the fundamentals should suggest that there is an imbalance of supply and demand, which could result in a major move. 首先基本面显示市场的供需关系不平衡,所以可能会有大的趋势产生。 Second, the chart must show that the market is moving in the direction that the fundamentals suggest. 其次图表显示价格走势和基本面符合。 Third, when news comes out, the market should act in a way that reflects the right psychological tone. 第三,当新闻公布后市场反应出的心态应该是准确的。
39 次阅读|0 个评论
分享 In the aftermath of the worst recession in decades, the richest Americans have b
insight 2013-10-12 21:01
http://www.huffingtonpost.com/2013/02/12/top-one-percent-income-gains_n_2670455.html In the aftermath of the worst recession in decades, the richest Americans have been getting richer -- a lot richer -- while most Americans have gone the other direction. Add it all together, and the top 1 percent of households by income captured 121 percent of all income gains between 2009 and 2011, during the first two years of the economic recovery, according to new research by Emmanuel Saez, an economics professor at the University of California at Berkeley. (Saez is a renowned income inequality expert and winner of the prestigious John Bates Clark Medal, an award that the American Economic Association gives every year to the top economist under age 40.) How was the top 1 percent able to capture more than all of the recovery's income gains? They became 11.2 percent richer while the bottom 99 percent got 0.4 percent poorer, when accounting for inflation, according to Saez. Saez released the updated figures in late January after finding last year that the top 1 percent had captured 93 percent of all income gains in 2010, the first full year of the economic recovery. Overall, between 1993 and 2011, the top 1 percent's incomes surged 57.5 percent, while the incomes of the bottom 99 percent grew just 5.8 percent, according to Saez. (Hat tip: The New Republic's Timothy Noah .)
个人分类: inequality|24 次阅读|0 个评论

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-12 11:34