## root / branches / pthreads-737 / examples / admb-re / weights / binomial_w2.tpl @ 765

History | View | Annotate | Download (953 Bytes)

1 |
// Example to illustrate the use of weights: Biomial with random effects |
---|---|

2 | |

3 |
DATA_SECTION |

4 | |

5 |
init_vector w(1,3) |

6 | |

7 |
PARAMETER_SECTION |

8 |
init_bounded_number mu(-5.0,5.0) |

9 |
init_bounded_number sigma(.001,5,2) |

10 | |

11 |
random_effects_vector u(0,2,2) |

12 | |

13 |
objective_function_value g |

14 |
!! set_multinomial_weights(w); |

15 | |

16 |
PROCEDURE_SECTION |

17 | |

18 |
int y; |

19 | |

20 |
for (y=0;y<=2;y++) |

21 |
f1(y,mu, sigma,u(y)); |

22 | |

23 |
SEPARABLE_FUNCTION void f1(const int& y, const prevariable & mu, const prevariable & sigma, const prevariable& ui) |

24 | |

25 |
dvariable f; |

26 | |

27 |
f = -0.5*log(2*PI) - 0.5*square(ui); |

28 | |

29 |
dvariable eta = mu + sigma*ui; |

30 |
dvariable p = mfexp(eta)/(1.0 + mfexp(eta)); |

31 | |

32 |
f += y*eta + 2.0*log(1.0 - p + .0000001); |

33 | |

34 |
g -= w(y+1)*f; // Where the weights are applied. |

35 | |

36 | |

37 |
TOP_OF_MAIN_SECTION |

38 |
arrmblsize = 4000000L; |

39 |
gradient_structure::set_GRADSTACK_BUFFER_SIZE(300000); |

40 |
gradient_structure::set_CMPDIF_BUFFER_SIZE(20000); |

41 |
gradient_structure::set_MAX_NVAR_OFFSET(100000); |

42 | |

43 |