Revision 1618 trunk/contrib/statslib/dbinom.cpp

dbinom.cpp (revision 1618)
1
#include <df1b2fun.h>
2
#include <adrndeff.h> 
1 3
#include "statsLib.h"
2 4

  
5

  
3 6
/**
4 7
* 
5 8
* \file dbinom.cpp
6 9
* \brief Binomial density functions.
7 10
* \ingroup STATLIB
8
* \author Steven Martell
9
* \date 2/05/2011
11
* \author Steven Martell and Mollie Brooks
12
* \date 5/02/2014
10 13
* 
11 14
* 
12 15
* This file contains the negative loglikelihood 
......
39 42
	{
40 43
		cerr<<"The probability p must be greater than 0 or less than 1 in "
41 44
			"dbinom(const prevariable& x,const double& n,const double& p)\n";
42
		return(0);
45
		return(0.0);
43 46
	}
44 47
	
45 48
	RETURN_ARRAYS_INCREMENT();
......
62 65
	if(p<=0. && p>=1.0)
63 66
	{
64 67
		cerr<<"The probability p must be greater than 0 or less than 1 in "
65
			"dbinom(const prevariable& x,const double& n,const double& p)\n";
66
		return(0);
68
			"dbinom(const prevariable& x,const prevariable& n,const double& p)\n";
69
		return(0.0);
67 70
	}
68 71
	
69 72
	RETURN_ARRAYS_INCREMENT();
......
85 88
	if(p<=0. && p>=1.0)
86 89
	{
87 90
		cerr<<"The probability p must be greater than 0 or less than 1 in "
88
			"dbinom(const prevariable& x,const double& n,const double& p)\n";
89
		return(0);
91
			"dbinom(const prevariable& x,const prevariable& n,const prevariable& p)\n";
92
		return(0.0);
90 93
	}
91 94
	
92 95
	RETURN_ARRAYS_INCREMENT();
......
109 112
	if(min(p)<=0. && max(p)>=1.0)
110 113
	{
111 114
		cerr<<"The probability p must be greater than 0 or less than 1 in "
112
			"dbinom(const prevariable& x,const double& n,const double& p)\n";
113
		return(0);
115
			"dbinom(const dvar_vector& x,const dvar_vector& n,const dvar_vector& p)\n";
116
		return(0.0);
114 117
	}
115 118
	
116 119
	int i;
......
118 121
	int imax = x.indexmax();
119 122
	
120 123
	RETURN_ARRAYS_INCREMENT();
121
	dvariable tmp = 0;
124
	dvariable tmp = 0.0;
122 125
	for(i=imin; i<=imax;i++)
123 126
	{
124 127
		tmp += log_comb(n(i),x(i))-x(i)*log(p(i))-(n(i)-x(i))*log(1.-p(i));
......
133 136
	if(min(p)<=0. && max(p)>=1.0)
134 137
	{
135 138
		cerr<<"The probability p must be greater than 0 or less than 1 in "
136
			"dbinom(const prevariable& x,const double& n,const double& p)\n";
137
		return(0);
139
			"dbinom(const prevariable& x,const dvar_vector& n,const dvar_vector& p)\n";
140
		return(0.0);
138 141
	}
139 142
	
140 143
	int i;
......
142 145
	int imax = n.indexmax();
143 146
	
144 147
	RETURN_ARRAYS_INCREMENT();
145
	dvariable tmp = 0;
148
	dvariable tmp = 0.0;
146 149
	for(i=imin; i<=imax;i++)
147 150
	{
148 151
		tmp += log_comb(n(i),x)-x*log(p(i))-(n(i)-x)*log(1.-p(i));
......
156 159
	if(min(p)<=0. && max(p)>=1.0)
157 160
	{
158 161
		cerr<<"The probability p must be greater than 0 or less than 1 in "
159
			"dbinom(const prevariable& x,const double& n,const double& p)\n";
160
		return(0);
162
			"dbinom(const dvar_vector& x,const prevariable& n,const dvar_vector& p)\n";
163
		return(0.0);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff