UditArora2000 commented on a change in pull request #8: Addition of Log Cauchy 
Distribution
URL: https://github.com/apache/commons-statistics/pull/8#discussion_r285259512
 
 

 ##########
 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");
+        }
+        return 0.5 + (Math.atan((Math.log(x) - location) / scale) / Math.PI);
+    }
+
+    /**
+     * Access the median.
+     *
+     * @return the median for this distribution.
+     */
+    public double getMedian() {
+        return Math.pow (Math.E,location);
+    }
+
+    /**
+     * Access the scale parameter.
+     *
+     * @return the scale parameter for this distribution.
+     */
+    public double getScale() {
+        return scale;
+    }
+
+    /**
+     * Access the location parameter.
+     *
+     * @return the location parameter for this distribution.
+     */
+    public double getLocation() {
+        return location;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double density(double x) {
+        if (x <= 0) {
+            throw new IllegalArgumentException("The argument cannot be less 
than or equal to 0");
+        }
+        final double dev = Math.log(x) - median;
+        return (1 / Math.PI) * (1 / Math.x) * (scale / (dev * dev + scale * 
scale));
 
 Review comment:
   Sir, median is not used in this method, it was my mistake. Instead of 
   final double dev = Math.log(x) - median; it should have been
   final double dev = Math.log(x) - location;
   So I don't think now we need to compute median in the constructor. 

----------------------------------------------------------------
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

Reply via email to