请求高手帮忙看看这个程序那里不对!

DECEL27 2012-01-09 10:15:35
/* Used for prediction from a time series based on the reconstruction of
phase space.(一阶局域法) */
#include<iostream.h>
#include<math.h>
#include<fstream.h>

#define N 8000
#define e 2.7182818281828
#define L 40 //代表需要寻找的邻域的点数,一般选取L>Dim+1即可。
#define Dim 5 //Dimention of the reconstructed phase space.

double y[N];
double Tau=5;
//*****************************************************************************************
double Cal_Lenth(int p1,int p2,int dim,int tau) //Calculate the distance between p1 and p2
{ //dim is the dimension of reconstruction,
double Lenth=0.0; //tau is the the time delay in the reconstruction.
for(int i=0;i<=dim-1;i++)
{
int t=i*tau;
Lenth=Lenth+(y[p1+t]-y[p2+t])*(y[p1+t]-y[p2+t]);
}
return Lenth=sqrt(Lenth);
}

//******************************************************************************************

void main()
{
int i=0;
ifstream fin; //Read from the data source file.
fin.open("the source.txt",ios::in|ios::nocreate);
while(!fin.eof())
{
fin>>y[i];
i++;
}
int n=i-1;
if (n>N) cout<<"Not enogh space for time series."<<endl;
cout<<"The totle number of data: N="<<n<<endl;
cout<<"There is ("<<n-(Dim-1)*Tau<<") points in the reconstructed phase space."<<endl;
cout<<"The last point(center point) is: (";
for(i=Dim;i=1;i--) {cout<<y[n-(i-1)*Tau];}
cout<<")."<<endl;
fin.close();

int Npoint[L],Cpoint=n-(Dim-1)*Tau;
double Nlenth[L],P[L]; //Nlenth[]为各近邻点到中心点的距离,P[]为各点的权值。
for(i=0;i<L;i++) {Nlenth[i]=1000;}
for(i=0;i<n-(Dim-1)*Tau;i++) //Find nearest neighbors (Npoint[Dim]) to the last data point.
{
double D=Cal_Lenth(Cpoint,i,Dim,Tau);
for(int j=0;j<L;j++)
{
int Flag=0;
if(D<=Nlenth[j])
{
for(k=L-1;k>j;k--) {Nlenth[k]=Nlenth[k-1];Npoint[k]=Npoint[k-1];}
Nlenth[j]=D;
Npoint[j]=i;
Flag=1;
}
if(Flag==1) break;
}
}
//******************the L nearest points have been found.************************

double Temp=0; //计算各点的权值,保存到P[]中。
for(i=0;i<L;i++)
{
P[i]=Nlenth[0]-Nlenth[i];
P[i]=pow(e,P[i]);
Temp=Temp+P[i];
}
for(i=0;i<L;i++) {P[i]=P[i]/Temp;}

}
...全文
33 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧