Пример #1
0
/**
 * Description not yet available.
 * \param
 */
dvar_vector posfun(const dvar_vector&x,double eps,const prevariable& _pen)
{
  int mmin=x.indexmin();
  int mmax=x.indexmax();
  dvar_vector tmp(mmin,mmax);
  for (int i=mmin;i<=mmax;i++)
  {
    tmp(i)=posfun(x(i),eps,_pen);
  }
  return tmp;
}
Пример #2
0
Type objective_function<Type>::operator() ()
{
	DATA_VECTOR(times);
	DATA_VECTOR(obs);
	
	PARAMETER(log_R0);
	PARAMETER(log_a);
	PARAMETER(log_theta);
	PARAMETER(log_sigma);
	Type sigma=exp(log_sigma);
	Type theta=exp(log_theta);
	Type R0=exp(log_R0);
	Type a=exp(log_a)+Type(1e-4);
	int n1=times.size();
	int n2=2;//mean and variance
	matrix<Type> xdist(n1,n2); //Ex and Vx
	Type m=(a-Type(1))*R0/times(n1-1);
	Type pen; 

	xdist(0,0)=obs[0];
	xdist(0,1)=Type(0);
	
	Type nll=0;       
	Fun<Type> F;
	F.setpars(R0, m, theta, sigma);

    CppAD::vector<Type> xi(n2);
	xi[1]=Type(0); //Bottinger's code started variance at 0 for all lsoda calls
	Type ti;
	Type tf;
	for(int i=0; i<n1-1; i++)
	{
		xi[0] = Type(obs[i]);
		ti=times[i];
		tf=times[i+1];
		xdist.row(i+1) = vector<Type>(CppAD::Runge45(F, 1, ti, tf, xi));
		xdist(i+1,1)=posfun(xdist(i+1,1), Type(1e-3), pen);//to keep the variance positive
		nll-= dnorm(obs[i+1], xdist(i+1,0), sqrt(xdist(i+1,1)), true);
	}
	nll+=pen; //penalty if the variance is near eps
	return nll;
}	
Пример #3
0
void LRGS::population_dynamics()
{
	// cout<<"In population dynamics"<<endl;
	int i;
	dvariable btmp;
	m_fpen.initialize();
	for(i=m_syr;i<=m_nyr;i++)
	{
		// m_ft(i) = -log((-m_ct(i)+m_bt(i))/m_bt(i));
		m_ft(i) = m_ct(i) / m_bt(i);
		if(i-m_syr > m_agek)
		{
			m_rt(i) = m_a*m_bt(i-m_agek)/(1.+m_b*m_bt(i-m_agek)) * exp(m_wt(i));	
		}
		
		btmp    = m_s*m_bt(i) + m_rt(i) - m_ct(i);
		m_bt(i+1) = posfun(btmp,0.1,m_fpen);
		// m_ft(i) = -log( (m_bt(i)*(1.-m_s) + m_bt(i+1) - m_rt(i))/m_bt(i) );
	}
	// sd_dep = m_bt(nyr)/m_bo;
}