Revision 1096
branches/threaded2/examples/threaded/multisimple/msimple1.tpl (revision 1096)  

1 
//$Id: msimple1.tpl 742M 20130602 00:06:06Z (local) $ 

2  
3 
DATA_SECTION 

4 
!! ad_comm::change_datafile_name("msimple.dat"); 

5 
init_int nobs 

6 
init_int nrow 

7 
matrix Y(1,nrow,1,nobs) 

8 
matrix x(1,nrow,1,nobs) 

9 
number A 

10 
number B 

11  
12 
LOCAL_CALCS 

13 
A = 2.0; 

14 
B = 4.0; 

15 
random_number_generator rng(101); 

16 
dvector err(1,nobs); 

17 
for (int i = 1; i <= nrow; i++) 

18 
{ 

19 
x(i).fill_randu(rng); 

20 
x(i) *= 100.0; 

21 
Y(i) = A*x(i) + B; 

22 
err.fill_randn(rng); 

23 
Y(i) += 5.0*err; 

24 
} 

25  
26 
PARAMETER_SECTION 

27 
init_number a 

28 
init_number b 

29 
vector ff(1,nrow) 

30 
matrix pred_Y(1,nrow,1,nobs) 

31 
objective_function_value f 

32  
33 
PRELIMINARY_CALCS_SECTION 

34 
a = 1.0; 

35 
b = 2.0; 

36  
37 
PROCEDURE_SECTION 

38 
for (int i=1;i<=nrow;i++) 

39 
{ 

40 
pred_Y(i) = a * x(i) + b; 

41 
ff(i) = norm2(pred_Y(i)Y(i)); 

42 
} 

43 
f = sum(ff); 

44 
f = (nrow*nobs)/2.*log(f); // make it a likelihood function so that 

45 
// covariance matrix is correct 

46 
REPORT_SECTION 

47 
report << "A = " << A << "; B = " << B <<endl; 

48 
report << "a = " << a << "; b = " << b <<endl; 

49  
50 
branches/threaded2/examples/threaded/multisimple/simple.tpl (revision 1096)  

1 
// Copyright (c) 2008, 2009, 2010 Regents of the University of California. 

2 
// 

3 
// ADModelbuilder and associated libraries and documentations are 

4 
// provided under the general terms of the "BSD" license. 

5 
// 

6 
// Redistribution and use in source and binary forms, with or without 

7 
// modification, are permitted provided that the following conditions are 

8 
// met: 

9 
// 

10 
// 1. Redistributions of source code must retain the above copyright 

11 
// notice, this list of conditions and the following disclaimer. 

12 
// 

13 
// 2. Redistributions in binary form must reproduce the above copyright 

14 
// notice, this list of conditions and the following disclaimer in the 

15 
// documentation and/or other materials provided with the distribution. 

16 
// 

17 
// 3. Neither the name of the University of California, Otter Research, 

18 
// nor the ADMB Foundation nor the names of its contributors may be used 

19 
// to endorse or promote products derived from this software without 

20 
// specific prior written permission. 

21 
// 

22 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 

23 
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 

24 
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 

25 
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 

26 
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 

27 
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 

28 
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 

29 
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 

30 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 

31 
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 

32 
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

33  
34 
DATA_SECTION 

35 
init_int nobs 

36 
init_vector Y(1,nobs) 

37 
init_vector x(1,nobs) 

38 
PARAMETER_SECTION 

39 
init_number a 

40 
init_number b 

41 
vector pred_Y(1,nobs) 
Also available in: Unified diff