ADMB Documentation  11.1.2491
 All Classes Files Functions Variables Typedefs Friends Defines
histgram.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: histgram.cpp 1112 2013-07-12 21:41:41Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <fvar.hpp>
00012 
00017 ivector histogram(double min, double max, int nbin, const dvector& v)
00018 {
00019   ivector tmp(1,nbin);
00020   int mmin=v.indexmin();
00021   int mmax=v.indexmax();
00022   tmp.initialize();
00023   double delta=double(max-min)/nbin;
00024   for (int i=mmin;i<=mmax;i++)
00025   {
00026     int j= int((v(i)-min)/delta)+1;
00027     if (j<1) j=1;
00028     if (j>nbin) j=nbin;
00029     tmp(j)+=1;
00030   }
00031   return tmp;
00032 }