[ https://issues.apache.org/jira/browse/MATH-1373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15336549#comment-15336549 ]
Karl D. Gierach commented on MATH-1373: --------------------------------------- The problem is that in the method shape & scale are simply reversed: @Override public double getNumericalMean() { double s = shape; return FastMath.exp(scale + (s * s / 2)); } It should be: FastMath.exp( shape + (scale * scale / 2 ) ); In any case here is a unit test code snippet that illustrates the problem: var defaultScale = 1.0; // aka variance var mean = 12.2; var meanSquared = mean * mean // compute sigma (log scale) parameter of the lognormal distribution. // according to formulas on Wikipedia var logScale = Math.sqrt( Math.log( 1.0 + (defaultScale / meanSquared) ) ) var logShape = Math.log( mean / Math.sqrt( 1.0 + ( defaultScale / meanSquared ) ) ) println( "verifyLogNormalParms(): initializing with: scale/shape=" + logScale + ", " + logShape ) // parameter order according to api docs: scale shape/location // here, parameters are reversed, and produce the correct result var dist = new LogNormalDistribution( logShape, logScale ); var numMean = dist.getNumericalMean() if( Math.abs( numMean - mean ) > 0.01 ) { println( "verifyLogNormalParms(): mean is NOT OK: " + numMean ) assertTrue( false ) } else { println( "verifyLogNormalParms(): mean is OK: " + numMean ) } > In LogNormalDistribution.java, it appears shape & scale are > reversed/mis-labelled. > ---------------------------------------------------------------------------------- > > Key: MATH-1373 > URL: https://issues.apache.org/jira/browse/MATH-1373 > Project: Commons Math > Issue Type: Bug > Affects Versions: 3.6.1 > Reporter: Karl D. Gierach > Priority: Minor > Original Estimate: 1h > Remaining Estimate: 1h > > When I compute the logshape and log scale based on the formulas on > wikipedia's lognormal distribution page that use empirical mean and variance, > I found that the getNumericalMean() method was not returning the empirical > mean. > However, upon just trying to reverse the shape and scale parameters in the > constructor proved to fix the problem, and the object then returns the > correct empirical mean. -- This message was sent by Atlassian JIRA (v6.3.4#6332)