You are on page 1of 28

1

1819 P.S.delaplace

1969 J.M.Bates C.W.J.Granger


,,
,,
,,
,,,
,,
,,
,,,

1.

2.
3

4 C++

1.1

Rand
1964 Delphi

1.2

1.3


1954 Schmitt 1940 1950
37

Y 1 Y1 2 Y2 Y1 Y2
Y 1 2 Y1 Y2

Y = kY1 + H1 kL Y2

k=

H1L

cov He1, e2L var He2L


2 cov He1, e2L var He1L var He2L

e1 1 Y1 -Y e2 2 Y2 -Y
cov var Y *
Y * Y e0
var( e0 ) var( e1 )var( e2 )
var(e 0 ) min{var(e1 ), var(e 2 )}
13.1

n 2 f it
Yt t=1,2,,n;
f it i i=1nt=12N
eit = Yt f it i i=1nt=12N
K i i i=1n,

K
i =1

= 1;

f t = K i f it t=12N
i =1

et = Yt f t t=12N
n

et = Yt f t = K i f it
i =1

J = et2
t =1

iN

J = Aki kj eit ejt E


n

kt=1

i=1 j=1

T
K = @k1, k2, ..., knD I

T
Ei = @ei1, ei2, ..., eiND e = @ E1 E2... EnD
T
T
J J = e e = K EH nL K

E11
E
E (n) = 21
.....

E n1

..... E1n
..... E 2 n
..... ..... ....

E n 2 ..... E nn
E12
E 22

Eij = Eji = EiT EJ

Eii = EiT Ei = eit2


N

t=1

Eii i EHnL
T
Rn = @1, 1, ..., 1D = n 1
n

K i = 1 R n k = 1
T

i =1

Kn

J n = min
{J } = min
{K T E ( n ) K } K n
T
T
Rn

Rn

E1, E2, ..., En

EHnL1 Rn
Kn = T
Rn EHnL1 Rn
1

Jn =

EHnL1 Rn

E22 E12
k1 =
E11 + E22 2 E12
E11 E12
k2 =
E11 + E22 2 E12

J2 =

RnT

E11 E22 E122


E11 + E22 2 E12 .

Y1 Y2

Y1 Y2 Y

Y = k Y1 + H1 kL Y2

K 0<K<1

Y1 Y2
K

Yt Y1 t Y2 t

t et , e1t , e2t t Yt
t

e1 t = Y1 t Yt

e2 t = Y2 t Yt
et

Yt Yt = Ak Y1 t + H1 kL Y2 tE @kYt + H1 kL Yt D

= k I Y1 t YtM + H1 kL I Y2 t YtM
= k e1 t + H1 kL e2 t

E = et2 = @k e1 t + H1 kL e2 tD2
N

t=1

t=1

= k2 e1 t2 + H1 kL2 e2 t2 + 2 H1 kL e1 t e2 t
N

t=1

t=1

t=1

N
e2
t=1 t

= k2

N
e 2
t=1 1 t

+ H1 kL2

N
e 2
t=1 2 t

+ 2 H1 kL

tN=1 e1 t e2 t

2
2
2

Y
Y
Y
,
Y
1
2
1
t,
1
2

Y2

2 = k2 12 + H1 kL2 22 + 2 k H1 kL 1 2

F HkL =

E
= k2 12 + H1 kL2 22 + 2 k H1 kL 1 2
n

Fk = 2 k12 + 2 k22 + 2 H1 k kL 1 2

k=

22 1 2
12 + 22 2 1 2

Fk = 0

= 0 K

k=

22
12 + 22

13.2

KA
T
1 1
1 T 1
1
KA = A , , ..., E = @1, 1, ..., 1D = Rn
n n
n
n
n

J A J A =

1
n2

i =1

j =1

ij

EHnL
E (n ) hi =

E
j =1

ij

= h i=1,2,,n

1.4

1)

[01]
2)

3)

0
5

2.1
Y X

Y = + X

a b Y
X
Y=a+bX
ab

y Yi Yi

min HYi
yiL2 = min e12
ab

n
IXi XM HYi
yL
in=1 Xi Yi n XY
i=1
b=
=

n
in=1 X12 n X2
IXi XM2
i=1

a = Y b X
Xi X I Yi Y I n

X Y n

2.1.1
1
http://www.stats.gov.cn/ndsj/information/gj/gat/3003

1991
1992
1993
1994
1995
1996
1997
1998
1999
2000

49278
54598
60322
65710
71291
77876
84174
90066
93758
98203

10

10

6.0
1837
7.3
2170
6.7
2286
6.8
2483
6.3
2691
5.9
2836
6.3
2933
4.3
2692
5.6
2905
6.4
3144

240909
264338
264196
286191
308086
333948
357503
379202
390466
404763

8982
10506
10011
10812
11630
12161
12457
11333
12100
12961

X
Y

12500
12000
11500
11000
10500
10000
9500
2000

2200

2400

2600

2800

ab

n
IXi XM HYi
yL
in=1 Xi Yi n XY
i=1
b=
=

n
in=1 X12 n X2
IXi XM2
i=1

a=3527.01

b=2.9905

Y=3527.01+2.9905*X
2

a = Y b X

11

11

2.2

Y = b0 + b1 X + b2 X2 + ... ... + bk Xk + e

x1 = x

x2 = x2

... ... xk = xk

y = b0 + b1 X1 + b2 X2 + ... ... + bk XK + e

Y = b0 + b1 X1 b2 X2 + e

b0 = Y b1 x1 b2 x2

b1 =

b2 =

X1 i Yi X2 i2 X2 i Yi X1 i X2 i
X1 i2 X2 i2 H X1 i X1 iL2

X2 i Yi X1 i2 X1 i Yi X1 i X2 i
X1 i2 X2 i2 H X1 i X2 iL2

y = y

12

12

22.1
1
b0=2.9114

b1=5.8318

b2=-0.00056

Y=2.9114+5.8318*X-0.00056*X^2
2

1991
1992
1993
1994
1995
1996
1997
1998
1999
2000

8982
10506
10011
10812
11630
12161
12457
11333
12100
12961

9020.559
10016.395
10363.293
10952.42
11574.446
12008.058
12298.137
11577.436
12214.413
12929.132

38.559
-489.605
352.293
140.42
-55.554
-152.942
-158.863
244.436
114.413
-31.868

8827.789
10023.196
10410.473
11033.674
11644.540
12041.745
12294.327
11647.360
12222.498
12807.398

K1 =

K2 =

E 22 E12
E11 + E 22 2E12

E11 E12
E11 + E 22 2E12

T
i Ei = @ei1, ei2, ..., eiND

e = @ E1 E2... EnD
T
T
J J = e e = K EH nL K

-154.211
-482.804
399.473
221.674
14.540
-119.255
-162.673
314.360
122.498
-153.602

E11
E
E (n) = 21
.....

E n1

13

13

..... E1n
E 22 ..... E 2 n
..... ..... ....

E n 2 ..... E nn
E12

Eij = Eji = EiT EJ

Eii = EiT Ei = eit2


N

t=1

14

14

3.1

k=

22 1 2
12 + 22 2 1 2

0 Y1 Y2 0

= 0 k =

2
1

2
2

K=0.5 k =

2
1

2
2

A1 A2 Y1 , Y2

Y = K * Y1 + (1 K )Y2

0K1

Y1 = a1 + b1 X
Y2 = a 2 + b2 X + c 2 X 2

15

15

Y = K (a1 + b1 X ) + (1 K )(a 2 + b2 X + c 2 X 2 )

0K1

( xi , y i ) i=12,n a1

b1 a 2 b2 c 2 K
K=N*TT=0.05 N=01220

Yi = K (a1 + b1 X i ) + (1 k )(a 2 + b2 X i + c 2 X i2 )
= N * T (a1 + b1 X i ) + (1 N * T )(a 2 + b2 X i + c 2 X i2 )
= N * T * (a1 a 2 ) + a 2 + [ N * T * (a1 a 2 ) + a 2 ] * X + (1 N * T )c 2 X i2

N 0 20 Yi
N N
K=N*T
T
3.2
1 ---
2
c++
3 K=N*TT=0.05 N=01220
---
4 ----
5
---------

3
5
for(int i=0;i<20;i++)
for(int j=0;j<m;j++)
{
k=i*T; //*****
a=k*a11+a22-k*a22;
b=k*b11+b22-k*b22;
c=c22-k*c22;
w[j]=a+b*data[j][0]+c*data[j][0]*data[j][0];//
w1[j]=w[j]-data[j][1];
//
w2[i][j]=w1[j]*w1[j];
//
}
//*********************
double min=w2[0][0],temp20[MAX],temp21=0;

16

16

for(int ii=0;ii<20;ii++)
for(int jj=0;jj<m;jj++)
{
if(min>w2[ii][jj])
min=w2[ii][jj];
}
//********
int kk;
for(int j=0;j<20;j++)
for(int i=0;i<m;i++)
{
if(min==w2[j][i])
{ kk=j;
break;
}
}
//******************************
for(i=0;i<m;i++)
{
k=kk*T;
a=k*a11+a22-k*a22;
b=k*b11+b22-k*b22;
c=c22-k*c22;
temp10=a+b*data[i][0]+c*data[i][0]*data[i][0];
//temp10[i]=(kk+1)*T*(a11+b11*data[i][0])+(1-(kk+1)*T)*(a22+b22*d
ata[i][0]+c22*data[i][0]*data[i][0]);
temp11[i]=temp10-data[i][1];
temp20[i]=temp11[i]*temp11[i];
temp21+=temp20[i];
printf("%f
%f\n",data[i][1],temp10,temp11[i]);

%f

}
cout<<""<<temp21/m<<"\n";
cout<<""<<kk*T<<"\n";
printf("
Y=%f(%f+%f*x)+(1-%f)(%f+%f*x+%f*x^2)\n",kk*T,a11,b11,kk*T,a22,b22
,c22);
}
//********************************

17

17

18

18

3.3

0.8 1-0.8=0.2 52557.5

Y=0.8(3527.005700+2.990451*x)+(1-0.8)(2.911437+5.831794*x-0.000560*x^2)

19

19

1991
8982 38.559
-154.211
1992
10506 -489.605
-482.804
1993
10011 352.293
399.473
1994
10812 140.42
221.674
1995
11630 -55.554
14.540
1996
12161 -152.942
-119.255
1997
12457 -158.863
-162.673
1998
11333 244.436
314.360
1999
12100 114.413
122.498
2000
12961 -31.868
-153.602
SSE 54059.124
64391.509

-0.071
-488.333
361.635
156.571
-41.645
-146.311
-159.736
258.312
115.912
-56.334
52575.5

-57.873
-486.260
375.825
180.984
-20.575
-136.165
-160.837
279.330
118.382
-92.810
55928.3

Y=0.8(3527.005700+2.990451*x)+(1-0.8)(2.911437+5.831794*x-0.000560*x^2)
2001

3.4

1.
n

SSE = ( y t
t =1

2.

yt )

MAE =

20

20

^
1 n
|
y

y
t t|
n t =1

3.
^

1
MSE =
n

(y
t =1

yt )

4.
^

MAPE =

1
n

|
t =1

yt
yt

yt

5.
^

MSPE

1
n

( yt yt )
yt
n

t =1

21

21

22

22

23

23

[1] ()(Philip Hans Franses)


[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]

2002

1995.10
Forecasting and time series :an applied approach =

:China Machine Press,2003.

1997.3

Visual C++

2002
, ,
200115244-46
2002
109899
1997
, , ,1997,
21(1): 42-46

[10]

, , 20021137-39

[11] 1993

#include
#define
#include
#include

24

24

"stdio.h"
MAX 100
"stdlib.h"
<iostream.h>

double
a11,b11,a22,b22,c22,temp6[MAX],temp7[MAX],temp16[MAX],temp17[MAX],tem
p18[MAX];
int m,m1;

void nihe(float data[100][2],int pointnum,int nhnumber)


{
int i;
double a1,b1,temp18=0;
double averX=0,averY=0,temp1=0,temp2=0;

for(i=0;i<pointnum;i++)
{
averX+=data[i][0];
averY+=data[i][1];
temp1+=data[i][0]*data[i][1];
temp2+=data[i][0]*data[i][0];
}
averX=averX/pointnum;
averY=averY/pointnum;
b1=(temp1-pointnum*averX*averY)/(temp2-pointnum*averX*averX);
a1=averY-b1*averX;
a11=a1;b11=b1;
for(i=0;i<pointnum;i++)
{
temp16[i]=a1+b1*data[i][0];
temp17[i]=temp16[i]-data[i][1];
temp18+=temp17[i]*temp17[i];
printf(" %f
%f

%f\n",data[i][1],temp16[i],temp17[i]);
}
printf("%f\n",temp18/m);
printf(" Y = %f + %f X\n",a1,b1);

25

25

double
a2,b2,c2,averX1=0,averX2=0,averY2=0,temp11=0,temp22=0,temp3=0,temp4=0
,temp5=0,temp8=0;
for(i=0;i<pointnum;i++)
{
averX1+=data[i][0];
averX2+=data[i][0]*data[i][0];
averY2+=data[i][1];
temp11+=data[i][0]*data[i][0]*data[i][1];
temp22+=data[i][0]*data[i][1];
temp3+=data[i][0]*data[i][0];
temp4+=data[i][0]*data[i][0]*data[i][0]*data[i][0];
temp5+=data[i][0]*data[i][0]*data[i][0];
}
averX1=averX1/pointnum;
averX2=averX2/pointnum;
averY2=averY2/pointnum;
c2=(temp11*temp3-temp22*temp5)/(temp3*temp4-temp5*temp5);
b2=(temp22*temp4-temp11*temp5)/(temp3*temp4-temp5*temp5);
a2=averY2-b2*averX1-c2*averX2;
for(i=0;i<pointnum;i++)
{
temp6[i]=a2+b2*data[i][0]+c2*data[i][0]*data[i][0];
temp7[i]=temp6[i]-data[i][1];
temp8+=temp7[i]*temp7[i];
printf(" %f
%f

%f\n",data[i][1],temp6[i],temp7[i]);
}
printf("%f\n",temp8/m);
a22=a2;b22=b2;c22=c2;
printf(" Y = %f

+ %f X

+%f X^2\n",a2,b2,c2);

void qwx(float data[MAX][2])


{
double
a,b,c,k,T=0.05,w[MAX],w1[MAX],w2[20][MAX],temp10=0,temp11[MAX];

26

26

for(int i=0;i<20;i++)
for(int j=0;j<m;j++)
{
k=i*T;
a=k*a11+a22-k*a22;
b=k*b11+b22-k*b22;
c=c22-k*c22;
w[j]=a+b*data[j][0]+c*data[j][0]*data[j][0];//
w1[j]=w[j]-data[j][1];
//
w2[i][j]=w1[j]*w1[j];
//
}
double min=w2[0][0],temp20[MAX],temp21=0;
for(int ii=0;ii<20;ii++)
for(int jj=0;jj<m;jj++)
{
if(min>w2[ii][jj])
min=w2[ii][jj];
}
int kk;
for(int j=0;j<20;j++)
for(int i=0;i<m;i++)
{
if(min==w2[j][i])
{ kk=j;
break;
}
}
if(m1==1)
{
for(i=0;i<m;i++)
{
k=kk*T;
a=k*a11+a22-k*a22;
b=k*b11+b22-k*b22;
c=c22-k*c22;
temp10=a+b*data[i][0]+c*data[i][0]*data[i][0];

27

27

//temp10[i]=(kk+1)*T*(a11+b11*data[i][0])+(1-(kk+1)*T)*(a22+b22*d
ata[i][0]+c22*data[i][0]*data[i][0]);
temp11[i]=temp10-data[i][1];
temp20[i]=temp11[i]*temp11[i];
temp21+=temp20[i];
printf("%f
%f\n",data[i][1],temp10,temp11[i]);

%f

}
cout<<""<<temp21/m<<"\n";
cout<<""<<kk*T<<"\n";
printf("
Y=%f(%f+%f*x)+(1-%f)(%f+%f*x+%f*x^2)\n",kk*T,a11,b11,kk*T,a22,b22,c22
);
}
else
{
printf("\n");
for(i=0;i<m;i++)
{
k=0.5;
a=k*a11+a22-k*a22;
b=k*b11+b22-k*b22;
c=c22-k*c22;
temp10=a+b*data[i][0]+c*data[i][0]*data[i][0];
//temp10[i]=(kk+1)*T*(a11+b11*data[i][0])+(1-(kk+1)*T)*(a22+b22*d
ata[i][0]+c22*data[i][0]*data[i][0]);
temp11[i]=temp10-data[i][1];
temp20[i]=temp11[i]*temp11[i];
temp21+=temp20[i];
printf("%f
%f\n",data[i][1],temp10,temp11[i]);

%f

}
cout<<""<<temp21/m<<"\n";
printf("

28

28

Y=1/2(%f+%f*x)+1/2(%f+%f*x+%f*x^2)\n",a11,b11,a22,b22,c22);
}
}

void main()
{
int i,j,temp=0;
int nhnum;
float
data[MAX][2];
//
for(i=0;i<3;i++)
for(j=0;j<MAX;j++)
data[j][i]=-1000;
//***************************************
//
printf(" 1
2\n");
scanf("%1d",&nhnum);
printf("\n");
printf("( 100 ), 0 \n");

for(i=0;i<MAX;i++)
{
scanf("%f,%f",&data[i][0],&data[i][1]);
temp++;
if(data[i][0]==0&&data[i][1]==-1000)break;

}
m=temp-1;
m1=nhnum;
printf("%d\n",temp-1);
//***************************************
nihe(data,temp-1,nhnum);
qwx(data);
}