aherbert commented on a change in pull request #8: Addition of Log Cauchy Distribution URL: https://github.com/apache/commons-statistics/pull/8#discussion_r285201899
########## File path: commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LogCauchyDistribution.java ########## @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.statistics.distribution; + +/** + * Implementation of the <a href="http://en.wikipedia.org/wiki/Log-Cauchy_distribution">Log Cauchy distribution</a>. + */ +public class LogCauchyDistribution extends AbstractContinuousDistribution { + /** The location of this distribution. */ + private final double location; + /** The scale of this distribution. */ + private final double scale; + + /** + * Creates a distribution. + * + * @param location Median for this distribution. + * @param scale Scale parameter for this distribution. + * @throws IllegalArgumentException if {@code scale <= 0}. + */ + public LogCauchyDistribution(double location, + double scale) { + if (scale <= 0) { + throw new DistributionException(DistributionException.NEGATIVE, scale); + } + this.scale = scale; + this.location = location; + } + + /** {@inheritDoc} */ + @Override + public double cumulativeProbability(double x) { + if (x <= 0) { + throw new IllegalArgumentException("The argument cannot be less than or equal to 0"); + } Review comment: I don't think you need to throw an exception here. Looking at the other continuous distributions in the package you can do this: ``` double ret; if (x <= 0) { ret = 0; } else { ret = 0.5 + (Math.atan((Math.log(x) - location) / scale) / Math.PI); } return ret; ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
