Login
Login

Re: Digamma function’s exception, why?

Home 21090308 Forums Re: Digamma function’s exception, why?

#2051
haksunli
Keymaster

Hello Isaac,

I took a look at your code. There is no a problem with the

function.
However, I found a problem with your following code:

I am not exactly sure what you try to do here. The problem is that it changes the input value [tt:3566cwt1]double[] x[/tt:3566cwt1].

When you call this function with [tt:3566cwt1]y[/tt:3566cwt1], you are changing the values of [tt:3566cwt1]y[/tt:3566cwt1] (the observations)!!!

It happens when you call

in:

The first time you call

on, e.g., [tt:3566cwt1]0.52392859[/tt:3566cwt1], it will becomes -ve. When you call

again, it will become [tt:3566cwt1]NaN[/tt:3566cwt1].

Then, when you pass [tt:3566cwt1]NaN[/tt:3566cwt1] to the [tt:3566cwt1]Digamma[/tt:3566cwt1] function, it will throw an exception.

I suggest you modify your code to avoid changing the input values:

Alternatively, you can use the SuanShu functions:
DoubleUtils.sum
DoubleUtils.foreach
ref: http://www.numericalmethod.com/javadoc/suanshu/com/numericalmethod/suanshu/number/DoubleUtils.html

Lastly, you should be able to debug this by walking thru you code in a debugger.

Hope this helps.