You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2011/01/30 00:38:40 UTC

svn commit: r1065146 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/function/ test/java/org/apache/commons/math/analysis/function/

Author: erans
Date: Sat Jan 29 23:38:39 2011
New Revision: 1065146

URL: http://svn.apache.org/viewvc?rev=1065146&view=rev
Log:
MATH-503
Added sigmoid and generalized logistic functions.

Added:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java   (with props)
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java   (with props)
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java   (with props)
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java   (with props)

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java?rev=1065146&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java Sat Jan 29 23:38:39 2011
@@ -0,0 +1,78 @@
+/*
+ * 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.math.analysis.function;
+
+import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
+import org.apache.commons.math.util.FastMath;
+
+/**
+ * <a href="http://en.wikipedia.org/wiki/Generalised_logistic_function">
+ *  Generalised logistic</a> function.
+ *
+ * @version $Revision$ $Date$
+ * @since 3.0
+ */
+public class Logistic implements UnivariateRealFunction {
+    /** Lower asymptote. */
+    private final double a;
+    /** Upper asymptote. */
+    private final double k;
+    /** Growth rate. */
+    private final double b;
+    /** Parameter that affects near which asymptote maximum growth occurs. */
+    private final double n;
+    /** Parameter that affects the position of the curve along the ordinate axis. */
+    private final double q;
+    /** Abscissa of maximum growth. */
+    private final double m;
+
+    /**
+     * @param k Upper asymptote.
+     * @param m Abscissa of maximum growth.
+     * @param b Growth rate.
+     * @param q Parameter that affects the position of the curve along the
+     * ordinate axis.
+     * @param a Lower asymptote.
+     * @param n Parameter that affects near which asymptote the maximum
+     * growth occurs.
+     * @throws NotStrictlyPositiveException if {@code n <= 0}.
+     */
+    public Logistic(double k,
+                    double m,
+                    double b,
+                    double q,
+                    double a,
+                    double n) {
+        if (n <= 0) {
+            throw new NotStrictlyPositiveException(n);
+        }
+
+        this.k = k;
+        this.m = m;
+        this.b = b;
+        this.q = q;
+        this.a = a;
+        this.n = n;
+    }
+
+    /** {@inheritDoc} */
+    public double value(double x) {
+        return a + (k - a) / FastMath.pow((1 + q * FastMath.exp(b * (m - x))), 1 / n);
+    }
+}

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java?rev=1065146&view=auto
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java (added)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java Sat Jan 29 23:38:39 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.math.analysis.function;
+
+import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
+import org.apache.commons.math.util.FastMath;
+
+/**
+ * <a href="http://en.wikipedia.org/wiki/Sigmoid_function">
+ *  Sigmoid</a> function.
+ * A more flexible version, the generalised logistic, is implemented
+ * by the {@link Logistic} class.
+ *
+ * @version $Revision$ $Date$
+ * @since 3.0
+ */
+public class Sigmoid implements UnivariateRealFunction {
+    /** {@inheritDoc} */
+    public double value(double x) {
+        return 1 / (1 + FastMath.exp(-x));
+    }
+}

Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java?rev=1065146&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java Sat Jan 29 23:38:39 2011
@@ -0,0 +1,84 @@
+/*
+ * 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.math.analysis.function;
+
+import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
+import org.apache.commons.math.util.FastMath;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for class {@link Logistic}.
+ */
+public class LogisticTest {
+    private final double EPS = Math.ulp(1d);
+
+    @Test
+    public void testPreconditions() {
+        try {
+            final UnivariateRealFunction f = new Logistic(1, 0, 1, 1, 0, -1);
+        } catch (NotStrictlyPositiveException e) {
+            // Expected.
+        }
+
+        try {
+            final UnivariateRealFunction f = new Logistic(1, 0, 1, 1, 0, 0);
+        } catch (NotStrictlyPositiveException e) {
+            // Expected.
+        }
+    }
+
+    @Test
+    public void testCompareSigmoid() {
+        final UnivariateRealFunction sig = new Sigmoid();
+        final UnivariateRealFunction sigL = new Logistic(1, 0, 1, 1, 0, 1);
+
+        final double min = -2;
+        final double max = 2;
+        final int n = 100;
+        final double delta = (max - min) / n;
+        for (int i = 0; i < n; i++) {
+            final double x = min + i * delta;
+            Assert.assertEquals("x=" + x, sig.value(x), sigL.value(x), EPS);
+        }
+    }
+
+    @Test
+    public void testSomeValues() {
+        final double k = 4;
+        final double m = 5;
+        final double b = 2;
+        final double q = 3;
+        final double a = -1;
+        final double n = 2;
+
+        final UnivariateRealFunction f = new Logistic(k, m, b, q, a, n);
+
+        double x;
+        x = m;
+        Assert.assertEquals("x=" + x, a + (k - a) / FastMath.sqrt(1 + q), f.value(x), EPS);
+
+        x = Double.NEGATIVE_INFINITY;
+        Assert.assertEquals("x=" + x, a, f.value(x), EPS);
+
+        x = Double.POSITIVE_INFINITY;
+        Assert.assertEquals("x=" + x, k, f.value(x), EPS);
+    }
+}

Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java?rev=1065146&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java Sat Jan 29 23:38:39 2011
@@ -0,0 +1,47 @@
+/*
+ * 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.math.analysis.function;
+
+import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.exception.NotStrictlyPositiveException;
+import org.apache.commons.math.util.FastMath;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for class {@link Sigmoid}.
+ */
+public class SigmoidTest {
+    private final double EPS = Math.ulp(1d);
+
+    @Test
+    public void testSomeValues() {
+        final UnivariateRealFunction f = new Sigmoid();
+
+        double x;
+        x = 0;
+        Assert.assertEquals("x=" + x, 0.5, f.value(x), EPS);
+
+        x = Double.NEGATIVE_INFINITY;
+        Assert.assertEquals("x=" + x, 0, f.value(x), EPS);
+
+        x = Double.POSITIVE_INFINITY;
+        Assert.assertEquals("x=" + x, 1, f.value(x), EPS);
+    }
+}

Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Re: svn commit: r1065146 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/function/ test/java/org/apache/commons/math/analysis/function/

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
On Sun, Jan 30, 2011 at 08:47:41AM -0500, Phil Steitz wrote:
> > [...]
> > +     * @throws NotStrictlyPositiveException if {@code n <= 0}.]
> 
> Aren't there other constraints on the parameters?
> Like upper > lower,
> growth rate >= 0?

I don't think so, but I have clarified the meaning of parameters "a" and "k"
(cf. revision 1065614).

> Also, why not use meaningful names for the parameters?

I should now give very long names to "a" and "k". I have no idea for names
that would be mid-size and meaningful at the same time.


Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1065146 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/function/ test/java/org/apache/commons/math/analysis/function/

Posted by Phil Steitz <ph...@gmail.com>.
On Jan 29, 2011, at 6:38 PM, erans@apache.org wrote:

> Author: erans
> Date: Sat Jan 29 23:38:39 2011
> New Revision: 1065146
> 
> URL: http://svn.apache.org/viewvc?rev=1065146&view=rev
> Log:
> MATH-503
> Added sigmoid and generalized logistic functions.
> 
> Added:
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java   (with props)
> commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java   (with props)
> commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/
> commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java   (with props)
> commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java   (with props)
> 
> Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java?rev=1065146&view=auto
> ==============================================================================
> --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java (added)
> +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java Sat Jan 29 23:38:39 2011
> @@ -0,0 +1,78 @@
> +/*
> + * 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.math.analysis.function;
> +
> +import org.apache.commons.math.analysis.UnivariateRealFunction;
> +import org.apache.commons.math.exception.NotStrictlyPositiveException;
> +import org.apache.commons.math.util.FastMath;
> +
> +/**
> + * <a href="http://en.wikipedia.org/wiki/Generalised_logistic_function">
> + *  Generalised logistic</a> function.
> + *
> + * @version $Revision$ $Date$
> + * @since 3.0
> + */
> +public class Logistic implements UnivariateRealFunction {
> +    /** Lower asymptote. */
> +    private final double a;
> +    /** Upper asymptote. */
> +    private final double k;
> +    /** Growth rate. */
> +    private final double b;
> +    /** Parameter that affects near which asymptote maximum growth occurs. */
> +    private final double n;
> +    /** Parameter that affects the position of the curve along the ordinate axis. */
> +    private final double q;
> +    /** Abscissa of maximum growth. */
> +    private final double m;
> +
> +    /**
> +     * @param k Upper asymptote.
> +     * @param m Abscissa of maximum growth.
> +     * @param b Growth rate.
> +     * @param q Parameter that affects the position of the curve along the
> +     * ordinate axis.
> +     * @param a Lower asymptote.
> +     * @param n Parameter that affects near which asymptote the maximum
> +     * growth occurs.
> +     * @throws NotStrictlyPositiveException if {@code n <= 0}.]

Aren't there other constraints on the parameters?  Like upper > lower, growth rate >= 0?  Also, why not use meaningful names for the parameters?

Phil
> +     */
> +    public Logistic(double k,
> +                    double m,
> +                    double b,
> +                    double q,
> +                    double a,
> +                    double n) {
> +        if (n <= 0) {
> +            throw new NotStrictlyPositiveException(n);
> +        }
> +
> +        this.k = k;
> +        this.m = m;
> +        this.b = b;
> +        this.q = q;
> +        this.a = a;
> +        this.n = n;
> +    }
> +
> +    /** {@inheritDoc} */
> +    public double value(double x) {
> +        return a + (k - a) / FastMath.pow((1 + q * FastMath.exp(b * (m - x))), 1 / n);
> +    }
> +}
> 
> Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
> 
> Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java?rev=1065146&view=auto
> ==============================================================================
> --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java (added)
> +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java Sat Jan 29 23:38:39 2011
> @@ -0,0 +1,38 @@
> +/*
> + * 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.math.analysis.function;
> +
> +import org.apache.commons.math.analysis.UnivariateRealFunction;
> +import org.apache.commons.math.exception.NotStrictlyPositiveException;
> +import org.apache.commons.math.util.FastMath;
> +
> +/**
> + * <a href="http://en.wikipedia.org/wiki/Sigmoid_function">
> + *  Sigmoid</a> function.
> + * A more flexible version, the generalised logistic, is implemented
> + * by the {@link Logistic} class.
> + *
> + * @version $Revision$ $Date$
> + * @since 3.0
> + */
> +public class Sigmoid implements UnivariateRealFunction {
> +    /** {@inheritDoc} */
> +    public double value(double x) {
> +        return 1 / (1 + FastMath.exp(-x));
> +    }
> +}
> 
> Propchange: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
> 
> Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java?rev=1065146&view=auto
> ==============================================================================
> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java (added)
> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java Sat Jan 29 23:38:39 2011
> @@ -0,0 +1,84 @@
> +/*
> + * 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.math.analysis.function;
> +
> +import org.apache.commons.math.analysis.UnivariateRealFunction;
> +import org.apache.commons.math.exception.NotStrictlyPositiveException;
> +import org.apache.commons.math.util.FastMath;
> +
> +import org.junit.Assert;
> +import org.junit.Test;
> +
> +/**
> + * Test for class {@link Logistic}.
> + */
> +public class LogisticTest {
> +    private final double EPS = Math.ulp(1d);
> +
> +    @Test
> +    public void testPreconditions() {
> +        try {
> +            final UnivariateRealFunction f = new Logistic(1, 0, 1, 1, 0, -1);
> +        } catch (NotStrictlyPositiveException e) {
> +            // Expected.
> +        }
> +
> +        try {
> +            final UnivariateRealFunction f = new Logistic(1, 0, 1, 1, 0, 0);
> +        } catch (NotStrictlyPositiveException e) {
> +            // Expected.
> +        }
> +    }
> +
> +    @Test
> +    public void testCompareSigmoid() {
> +        final UnivariateRealFunction sig = new Sigmoid();
> +        final UnivariateRealFunction sigL = new Logistic(1, 0, 1, 1, 0, 1);
> +
> +        final double min = -2;
> +        final double max = 2;
> +        final int n = 100;
> +        final double delta = (max - min) / n;
> +        for (int i = 0; i < n; i++) {
> +            final double x = min + i * delta;
> +            Assert.assertEquals("x=" + x, sig.value(x), sigL.value(x), EPS);
> +        }
> +    }
> +
> +    @Test
> +    public void testSomeValues() {
> +        final double k = 4;
> +        final double m = 5;
> +        final double b = 2;
> +        final double q = 3;
> +        final double a = -1;
> +        final double n = 2;
> +
> +        final UnivariateRealFunction f = new Logistic(k, m, b, q, a, n);
> +
> +        double x;
> +        x = m;
> +        Assert.assertEquals("x=" + x, a + (k - a) / FastMath.sqrt(1 + q), f.value(x), EPS);
> +
> +        x = Double.NEGATIVE_INFINITY;
> +        Assert.assertEquals("x=" + x, a, f.value(x), EPS);
> +
> +        x = Double.POSITIVE_INFINITY;
> +        Assert.assertEquals("x=" + x, k, f.value(x), EPS);
> +    }
> +}
> 
> Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
> 
> Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java?rev=1065146&view=auto
> ==============================================================================
> --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java (added)
> +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java Sat Jan 29 23:38:39 2011
> @@ -0,0 +1,47 @@
> +/*
> + * 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.math.analysis.function;
> +
> +import org.apache.commons.math.analysis.UnivariateRealFunction;
> +import org.apache.commons.math.exception.NotStrictlyPositiveException;
> +import org.apache.commons.math.util.FastMath;
> +
> +import org.junit.Assert;
> +import org.junit.Test;
> +
> +/**
> + * Test for class {@link Sigmoid}.
> + */
> +public class SigmoidTest {
> +    private final double EPS = Math.ulp(1d);
> +
> +    @Test
> +    public void testSomeValues() {
> +        final UnivariateRealFunction f = new Sigmoid();
> +
> +        double x;
> +        x = 0;
> +        Assert.assertEquals("x=" + x, 0.5, f.value(x), EPS);
> +
> +        x = Double.NEGATIVE_INFINITY;
> +        Assert.assertEquals("x=" + x, 0, f.value(x), EPS);
> +
> +        x = Double.POSITIVE_INFINITY;
> +        Assert.assertEquals("x=" + x, 1, f.value(x), EPS);
> +    }
> +}
> 
> Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1065146 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/function/ test/java/org/apache/commons/math/analysis/function/

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
> > +/**
> > + * <a href="http://en.wikipedia.org/wiki/Generalised_logistic_function">
> > + *  Generalised logistic</a> function.
> > + *
> > + * @version $Revision$ $Date$
> 
> $Date$ is Locale-specific, so causes problems when comparing source
> code with SVN.
> 
> $Id$ is OK because it uses UTC, but it also includes the file name and
> last user id, so is fairly long.
> 
> $Revision$ should be sufficient in general.

Is this a general suggestion for changing those tags in all of CM?

Since I started committing, I've always tagged every new file with
  $Revision$ $Date$
as was being done in all of CM.

See, for example,
  src/main/java/org/apache/commons/math/ode/nonstiff/AdaptiveStepsizeIntegrator.java
  src/main/java/org/apache/commons/math/geometry/Rotation.java
I think that the list is quite long...


Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1065146 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/function/ test/java/org/apache/commons/math/analysis/function/

Posted by sebb <se...@gmail.com>.
On 29 January 2011 23:38,  <er...@apache.org> wrote:
> Author: erans
> Date: Sat Jan 29 23:38:39 2011
> New Revision: 1065146
>
> URL: http://svn.apache.org/viewvc?rev=1065146&view=rev
> Log:
> MATH-503
> Added sigmoid and generalized logistic functions.
>
> Added:
>    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java   (with props)
>    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Sigmoid.java   (with props)
>    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/
>    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/LogisticTest.java   (with props)
>    commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/function/SigmoidTest.java   (with props)
>
> Added: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java
> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java?rev=1065146&view=auto
> ==============================================================================
> --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java (added)
> +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/function/Logistic.java Sat Jan 29 23:38:39 2011
> @@ -0,0 +1,78 @@
> +/*
> + * 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.math.analysis.function;
> +
> +import org.apache.commons.math.analysis.UnivariateRealFunction;
> +import org.apache.commons.math.exception.NotStrictlyPositiveException;
> +import org.apache.commons.math.util.FastMath;
> +
> +/**
> + * <a href="http://en.wikipedia.org/wiki/Generalised_logistic_function">
> + *  Generalised logistic</a> function.
> + *
> + * @version $Revision$ $Date$

$Date$ is Locale-specific, so causes problems when comparing source
code with SVN.

$Id$ is OK because it uses UTC, but it also includes the file name and
last user id, so is fairly long.

$Revision$ should be sufficient in general.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org