ADMB Documentation  11.1.2192
 All Classes Files Functions Variables Typedefs Friends Defines
alk.cpp
Go to the documentation of this file.
00001 #include "statsLib.h"
00002 
00041 dvar_matrix ageLengthKey(const dvar_vector& mu, const dvar_vector& sig, const dvector& x)
00042 {
00043   RETURN_ARRAYS_INCREMENT();
00044   int i, j;
00045   dvariable z1;
00046   dvariable z2;
00047   int si,ni; si=mu.indexmin(); ni=mu.indexmax();
00048   int sj,nj; sj=x.indexmin(); nj=x.indexmax()-1;
00049   dvar_matrix pdf(si,ni,sj,nj);
00050   pdf.initialize();
00051   //double xs=0.5*(x[sj+1]-x[sj]);
00052   for(i=si;i<=ni;i++) //loop over ages
00053   {
00054      for(j=sj;j<=nj;j++) //loop over length bins
00055     {
00056       z1=(x(j)-mu(i))/sig(i);
00057       z2=(x(j+1)-mu(i))/sig(i);
00058       pdf(i,j)=cumd_norm(z2)-cumd_norm(z1);
00059     }//end nbins
00060     pdf(i)/=sum(pdf(i));
00061   }//end nage
00062   
00063   RETURN_ARRAYS_DECREMENT();
00064   return(pdf);
00065 }
00066 
00067 
00079 dmatrix ageLengthKey(const dvector& mu, const dvector& sig, const dvector& x)
00080 {
00081   RETURN_ARRAYS_INCREMENT();
00082   int i, j;
00083   double z1;
00084   double z2;
00085   int si,ni; si=mu.indexmin(); ni=mu.indexmax();
00086   int sj,nj; sj=x.indexmin(); nj=x.indexmax()-1;
00087   dmatrix pdf(si,ni,sj,nj);
00088   pdf.initialize();
00089   //double xs=0.5*(x[sj+1]-x[sj]);
00090   for(i=si;i<=ni;i++) //loop over ages
00091   {
00092      for(j=sj;j<=nj;j++) //loop over length bins
00093     {
00094       z1=(x(j)-mu(i))/sig(i);
00095       z2=(x(j+1)-mu(i))/sig(i);
00096       pdf(i,j)=cumd_norm(z2)-cumd_norm(z1);
00097     }//end nbins
00098     pdf(i)/=sum(pdf(i));
00099   }//end nage
00100   
00101   RETURN_ARRAYS_DECREMENT();
00102   return(pdf);
00103 }
00104 
00105 dvar_matrix ALK(dvar_vector mu, dvar_vector sig, dvector x)
00106 {
00107   RETURN_ARRAYS_INCREMENT();
00108   int i, j;
00109   dvariable z1;
00110   dvariable z2;
00111   int si,ni; si=mu.indexmin(); ni=mu.indexmax();
00112   int sj,nj; sj=x.indexmin(); nj=x.indexmax();
00113   dvar_matrix pdf(si,ni,sj,nj);
00114   pdf.initialize();
00115   double xs=0.5*(x[sj+1]-x[sj]);
00116   for(i=si;i<=ni;i++) //loop over ages
00117   {
00118      for(j=sj;j<=nj;j++) //loop over length bins
00119     {
00120       z1=((x(j)-xs)-mu(i))/sig(i);
00121       z2=((x(j)+xs)-mu(i))/sig(i);
00122       pdf(i,j)=cumd_norm(z2)-cumd_norm(z1);
00123     }//end nbins
00124     pdf(i)/=sum(pdf(i));
00125   }//end nage
00126   //pdf/=sum(pdf);
00127   RETURN_ARRAYS_DECREMENT();
00128   return(pdf);
00129 }
00130