Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 3748 invoked from network); 30 Jan 2011 13:49:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 30 Jan 2011 13:49:54 -0000 Received: (qmail 4784 invoked by uid 500); 30 Jan 2011 13:49:54 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 3945 invoked by uid 500); 30 Jan 2011 13:49:51 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 3933 invoked by uid 99); 30 Jan 2011 13:49:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 30 Jan 2011 13:49:50 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,MIME_QP_LONG_LINE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of phil.steitz@gmail.com designates 209.85.214.171 as permitted sender) Received: from [209.85.214.171] (HELO mail-iw0-f171.google.com) (209.85.214.171) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 30 Jan 2011 13:49:44 +0000 Received: by iwn2 with SMTP id 2so4687425iwn.30 for ; Sun, 30 Jan 2011 05:49:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:content-type:mime-version:subject:from :in-reply-to:date:content-transfer-encoding:message-id:references:to :x-mailer; bh=fXcrnMKQ57Jrg2cmpSAM/dnhZ9fJpb9Yioy8UZpxecw=; b=l0+UBlajuaOa1+AQIkrakDwvXjWIL3jpCpznGQzTfrH7aa2XT63i7r6zVemsmRI5fH IJtocnWPRbX4WE6DDrLAblj/SrYfg3G6EODCX5RZRndwaiGq/ZSLGrisA8jbpSxb5Ib8 rJ65eOj4h3XbP+b3DG8zZh9X9kVYXNlDN32o8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; b=EpewzwNEHNTPC3H1XjsUgdaJti7ITzalfDg+zlnl9cWju9slAcDmqnofvkodvyWO4c EhdXxSFPEwEM1lMmOXAB6PfbfjQ6KSW4c1noC4xhjDLdHbg/PNLealjPbX8uNB4pbYac P2BJFULy3MAUDZ2mgpEEmSgeKRtfZmpR03rYw= Received: by 10.231.20.68 with SMTP id e4mr5269565ibb.194.1296395363886; Sun, 30 Jan 2011 05:49:23 -0800 (PST) Received: from [192.168.0.2] (97-124-83-150.phnx.qwest.net [97.124.83.150]) by mx.google.com with ESMTPS id d21sm16928195ibg.3.2011.01.30.05.49.20 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 30 Jan 2011 05:49:21 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1082) Subject: 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/ From: Phil Steitz In-Reply-To: <20110129233840.553E823889ED@eris.apache.org> Date: Sun, 30 Jan 2011 08:47:41 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20110129233840.553E823889ED@eris.apache.org> To: dev@commons.apache.org X-Mailer: Apple Mail (2.1082) 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 >=20 > URL: http://svn.apache.org/viewvc?rev=3D1065146&view=3Drev > Log: > MATH-503 > Added sigmoid and generalized logistic functions. >=20 > Added: > = commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/f= unction/Logistic.java (with props) > = commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/f= unction/Sigmoid.java (with props) > = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/ > = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/LogisticTest.java (with props) > = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/SigmoidTest.java (with props) >=20 > Added: = commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/f= unction/Logistic.java > URL: = http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/a= pache/commons/math/analysis/function/Logistic.java?rev=3D1065146&view=3Dau= to > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- = commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/f= unction/Logistic.java (added) > +++ = commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/f= unction/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; > + > +/** > + * > + * Generalised logistic 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 <=3D 0}.] Aren't there other constraints on the parameters? Like upper > lower, = growth rate >=3D 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 <=3D 0) { > + throw new NotStrictlyPositiveException(n); > + } > + > + this.k =3D k; > + this.m =3D m; > + this.b =3D b; > + this.q =3D q; > + this.a =3D a; > + this.n =3D n; > + } > + > + /** {@inheritDoc} */ > + public double value(double x) { > + return a + (k - a) / FastMath.pow((1 + q * FastMath.exp(b * = (m - x))), 1 / n); > + } > +} >=20 > Propchange: = commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/f= unction/Logistic.java > = --------------------------------------------------------------------------= ---- > svn:eol-style =3D native >=20 > Added: = commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/f= unction/Sigmoid.java > URL: = http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/a= pache/commons/math/analysis/function/Sigmoid.java?rev=3D1065146&view=3Daut= o > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- = commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/f= unction/Sigmoid.java (added) > +++ = commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/f= unction/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; > + > +/** > + * > + * Sigmoid 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)); > + } > +} >=20 > Propchange: = commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/f= unction/Sigmoid.java > = --------------------------------------------------------------------------= ---- > svn:eol-style =3D native >=20 > Added: = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/LogisticTest.java > URL: = http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/a= pache/commons/math/analysis/function/LogisticTest.java?rev=3D1065146&view=3D= auto > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/LogisticTest.java (added) > +++ = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/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 =3D Math.ulp(1d); > + > + @Test > + public void testPreconditions() { > + try { > + final UnivariateRealFunction f =3D new Logistic(1, 0, 1, = 1, 0, -1); > + } catch (NotStrictlyPositiveException e) { > + // Expected. > + } > + > + try { > + final UnivariateRealFunction f =3D new Logistic(1, 0, 1, = 1, 0, 0); > + } catch (NotStrictlyPositiveException e) { > + // Expected. > + } > + } > + > + @Test > + public void testCompareSigmoid() { > + final UnivariateRealFunction sig =3D new Sigmoid(); > + final UnivariateRealFunction sigL =3D new Logistic(1, 0, 1, = 1, 0, 1); > + > + final double min =3D -2; > + final double max =3D 2; > + final int n =3D 100; > + final double delta =3D (max - min) / n; > + for (int i =3D 0; i < n; i++) { > + final double x =3D min + i * delta; > + Assert.assertEquals("x=3D" + x, sig.value(x), = sigL.value(x), EPS); > + } > + } > + > + @Test > + public void testSomeValues() { > + final double k =3D 4; > + final double m =3D 5; > + final double b =3D 2; > + final double q =3D 3; > + final double a =3D -1; > + final double n =3D 2; > + > + final UnivariateRealFunction f =3D new Logistic(k, m, b, q, = a, n); > + > + double x; > + x =3D m; > + Assert.assertEquals("x=3D" + x, a + (k - a) / FastMath.sqrt(1 = + q), f.value(x), EPS); > + > + x =3D Double.NEGATIVE_INFINITY; > + Assert.assertEquals("x=3D" + x, a, f.value(x), EPS); > + > + x =3D Double.POSITIVE_INFINITY; > + Assert.assertEquals("x=3D" + x, k, f.value(x), EPS); > + } > +} >=20 > Propchange: = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/LogisticTest.java > = --------------------------------------------------------------------------= ---- > svn:eol-style =3D native >=20 > Added: = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/SigmoidTest.java > URL: = http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/a= pache/commons/math/analysis/function/SigmoidTest.java?rev=3D1065146&view=3D= auto > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/SigmoidTest.java (added) > +++ = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/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 =3D Math.ulp(1d); > + > + @Test > + public void testSomeValues() { > + final UnivariateRealFunction f =3D new Sigmoid(); > + > + double x; > + x =3D 0; > + Assert.assertEquals("x=3D" + x, 0.5, f.value(x), EPS); > + > + x =3D Double.NEGATIVE_INFINITY; > + Assert.assertEquals("x=3D" + x, 0, f.value(x), EPS); > + > + x =3D Double.POSITIVE_INFINITY; > + Assert.assertEquals("x=3D" + x, 1, f.value(x), EPS); > + } > +} >=20 > Propchange: = commons/proper/math/trunk/src/test/java/org/apache/commons/math/analysis/f= unction/SigmoidTest.java > = --------------------------------------------------------------------------= ---- > svn:eol-style =3D native >=20 >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org