root / trunk / tests / changepoint / changepoint.tpl @ 2018
History  View  Annotate  Download (882 Bytes)
1 
DATA_SECTION 

2 
init_int nobs 
3 
init_vector y(1,nobs) 
4 
vector predm(1,nobs) 
5 
PARAMETER_SECTION 
6 
init_number m1 
7 
init_number m2 
8 
init_number cp 
9 
objective_function_value f 
10 
PROCEDURE_SECTION 
11  
12 
double s=1; 
13 
switch (current_phase()) 
14 
{ 
15 
case 1: 
16 
s=1.0; 
17 
break; 
18 
case 2: 
19 
s=10.0; 
20 
break; 
21 
case 3: 
22 
s=100.0; 
23 
break; 
24 
default: 
25 
s=1000.0; 
26 
break; 
27 
} 
28  
29 
for (int i=1;i<=nobs;i++) 
30 
{ 
31 
dvariable p=f1(i,cp,s); 
32 
dvariable m=p*m1+(1.0p)*m2; 
33 
predm(i)=value(m); 
34 
f+=square(y(i)m); 
35 
} 
36 

37 
REPORT_SECTION 
38  
39 
report << predm << endl; 
40  
41 
GLOBALS_SECTION 
42  
43 
#include <admodel.h> 
44  
45 
dvariable f1(int i,const prevariable& cp,double s) 
46 
{ 
47 
dvariable z=s*(cpdouble(i)); 
48 
if (value(z)<20.) 
49 
{ 
50 
return 1.0/(1+exp(z)); 
51 
} 
52 
else 
53 
{ 
54 
return exp(z)/(1.0+exp(z)); 
55 
} 
56 
} 
57 