Comments (5)
Thanks for reporting.
Looks like we should go logarithmic on large DoF. In the meantime, a quick workaround would be to use Math.Exp(dist.DensityLn(0))
instead of dist.Density(0)
.
from mathnet-numerics.
I changed the computation for the ratios of the Gamma functions. This should fix the problem. (Problem arises because Gamma(339)=infinity and so the output becomes infinity). Try
int dof=1;
for(;dof<10000;dof++)
{
var dist = new MathNet.Numerics.Distributions.StudentT(0, 1, dof);
if (dist.Density(0)==Double.PositiveInfinity||dist.Density(0)==Double.NaN)
break;
}
var distr = new MathNet.Numerics.Distributions.StudentT(0, 1, dof);
Console.WriteLine("{0} {1}",distr,distr.Density(0));
Console.WriteLine(dof);
from mathnet-numerics.
Thanks a lot for the quick fix. I wonder, how does this compare numeric stability and accuracy-wise with just computing the gamma ratio in logarithmic space, i.e. replace
SpecialFunctions.Gamma((_dof + 1.0) / 2.0) / SpecialFunctions.Gamma(_dof / 2.0)
with
Math.Exp(SpecialFunctions.GammaLn((_dof + 1.0) / 2.0) - SpecialFunctions.GammaLn(_dof / 2.0))
?
Also note that DoF > 0.0, so the special casing for zero-division and zero-gamma in the fix should not actually be needed.
from mathnet-numerics.
Thanks for pointing out. I have looked at it again and the recurrence implementation is not as good as the logarithmic space one, so please ignore it and sorry about that.
I have looked at the values of the density for the above parameters (Location=1 and Scale=1). At Dof=10000, they differ at an order of 1e-13, and at Dof=100000, they differ at about 1e-11. I was thinking about the differences of large numbers when using
Math.Exp(SpecialFunctions.GammaLn((_dof + 1.0) / 2.0) - SpecialFunctions.GammaLn(_dof / 2.0))
Looking at the logarithm of Gamma functions, at 1e10, it is about 220258509288.811, so at this level, you still retain accuracy up to 1e-3 and the value of the density differs from the Gaussian density at the order of 1e-7. So this does not seem to be too much of an issue.
On the other hand, the recurrence implementation has accumulative error and is slower than the computation of gamma ration in logarithmic space. So please ignore the recurrence implementation.
The logarithmic space implementation do start to differ from the Gaussian limit at about Dof=1e11 and at Dof=1e15 gives a result that is rather wrong. While it is rather unlikely that such large Dof will be encountered, it may be a good idea to use a cutoff that is smaller than positive infinity (e.g. 1e10?) where the Gaussian density will be used when Dof is greater than the cut off?
from mathnet-numerics.
Thanks for the thorough analysis! Yes, switching to Gaussian density for large DoF would be very reasonable.
from mathnet-numerics.
Related Issues (20)
- How do I fit the gamma distribution, please? I didn't find it when I checked the documentation, am I missing something?
- Cholesky does not throw error on asymmetric matrix
- Power return NaN
- Adler32 checksum no work
- Using the Levenberg-Marquardt to solve a set of non-linear equations
- Beta distribution Sample method can return NaN HOT 1
- Is mono still required on Linux?
- Is it still impossible to read a 10 x 1 cell array of 3D arrays?
- Sparse MapIndexedInplace starts with incorrect indices
- Question: Building mathnet-numerics
- Marcum Q Function not implemented correctly. HOT 1
- Question: scipy splprep and splev
- DenseMatrix.OfRowArrays().LU() Memory Leak HOT 1
- I want use MKL under AOT publish,But cant HOT 2
- Polynomial fit returns infinity and NaN as parameters
- Incorrect condition for stopping the LevenbergMarquardtMinimizer's Minimum() by parameter tolerance. HOT 1
- Feature Request: Support for `ReadOnlyMemory<T>` and `ReadOnlySpan<T>` in Vector Creation HOT 2
- Modify NewtonMinimizer so that it forces Hessian to be positive definite HOT 1
- MKL_CBWR environment variable does not seem to be respected when running?
- Bug in SpecialFunctions.Hypotenuse HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mathnet-numerics.