commons-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r959801 [6/10] - in /websites/production/commons/content/proper/commons-math/apidocs: ./ org/apache/commons/math3/exception/class-use/ org/apache/commons/math3/fraction/ org/apache/commons/math3/geometry/euclidean/oned/class-use/ org/apache...
Date Mon, 27 Jul 2015 19:40:06 GMT
Modified: websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/geometry/euclidean/twod/Line.html
==============================================================================
--- websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/geometry/euclidean/twod/Line.html (original)
+++ websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/geometry/euclidean/twod/Line.html Mon Jul 27 19:40:06 2015
@@ -455,97 +455,130 @@
 <span class="sourceLineNo">447</span>     * org.apache.commons.math3.geometry.partitioning.SubHyperplane<a name="line.447"></a>
 <span class="sourceLineNo">448</span>     * SubHyperplane} instances<a name="line.448"></a>
 <span class="sourceLineNo">449</span>     * @exception MathIllegalArgumentException if the transform is non invertible<a name="line.449"></a>
-<span class="sourceLineNo">450</span>     */<a name="line.450"></a>
-<span class="sourceLineNo">451</span>    public static Transform&lt;Euclidean2D, Euclidean1D&gt; getTransform(final AffineTransform transform)<a name="line.451"></a>
-<span class="sourceLineNo">452</span>        throws MathIllegalArgumentException {<a name="line.452"></a>
-<span class="sourceLineNo">453</span>        return new LineTransform(transform);<a name="line.453"></a>
-<span class="sourceLineNo">454</span>    }<a name="line.454"></a>
-<span class="sourceLineNo">455</span><a name="line.455"></a>
-<span class="sourceLineNo">456</span>    /** Class embedding an affine transform.<a name="line.456"></a>
-<span class="sourceLineNo">457</span>     * &lt;p&gt;This class is used in order to apply an affine transform to a<a name="line.457"></a>
-<span class="sourceLineNo">458</span>     * line. Using a specific object allow to perform some computations<a name="line.458"></a>
-<span class="sourceLineNo">459</span>     * on the transform only once even if the same transform is to be<a name="line.459"></a>
-<span class="sourceLineNo">460</span>     * applied to a large number of lines (for example to a large<a name="line.460"></a>
-<span class="sourceLineNo">461</span>     * polygon)./&lt;p&gt;<a name="line.461"></a>
-<span class="sourceLineNo">462</span>     */<a name="line.462"></a>
-<span class="sourceLineNo">463</span>    private static class LineTransform implements Transform&lt;Euclidean2D, Euclidean1D&gt; {<a name="line.463"></a>
-<span class="sourceLineNo">464</span><a name="line.464"></a>
-<span class="sourceLineNo">465</span>        // CHECKSTYLE: stop JavadocVariable check<a name="line.465"></a>
-<span class="sourceLineNo">466</span>        private double cXX;<a name="line.466"></a>
-<span class="sourceLineNo">467</span>        private double cXY;<a name="line.467"></a>
-<span class="sourceLineNo">468</span>        private double cX1;<a name="line.468"></a>
-<span class="sourceLineNo">469</span>        private double cYX;<a name="line.469"></a>
-<span class="sourceLineNo">470</span>        private double cYY;<a name="line.470"></a>
-<span class="sourceLineNo">471</span>        private double cY1;<a name="line.471"></a>
-<span class="sourceLineNo">472</span><a name="line.472"></a>
-<span class="sourceLineNo">473</span>        private double c1Y;<a name="line.473"></a>
-<span class="sourceLineNo">474</span>        private double c1X;<a name="line.474"></a>
-<span class="sourceLineNo">475</span>        private double c11;<a name="line.475"></a>
-<span class="sourceLineNo">476</span>        // CHECKSTYLE: resume JavadocVariable check<a name="line.476"></a>
-<span class="sourceLineNo">477</span><a name="line.477"></a>
-<span class="sourceLineNo">478</span>        /** Build an affine line transform from a n {@code AffineTransform}.<a name="line.478"></a>
-<span class="sourceLineNo">479</span>         * @param transform transform to use (must be invertible otherwise<a name="line.479"></a>
-<span class="sourceLineNo">480</span>         * the {@link LineTransform#apply(Hyperplane)} method would work<a name="line.480"></a>
-<span class="sourceLineNo">481</span>         * only for some lines, and fail for other ones)<a name="line.481"></a>
-<span class="sourceLineNo">482</span>         * @exception MathIllegalArgumentException if the transform is non invertible<a name="line.482"></a>
-<span class="sourceLineNo">483</span>         */<a name="line.483"></a>
-<span class="sourceLineNo">484</span>        public LineTransform(final AffineTransform transform) throws MathIllegalArgumentException {<a name="line.484"></a>
-<span class="sourceLineNo">485</span><a name="line.485"></a>
-<span class="sourceLineNo">486</span>            final double[] m = new double[6];<a name="line.486"></a>
-<span class="sourceLineNo">487</span>            transform.getMatrix(m);<a name="line.487"></a>
-<span class="sourceLineNo">488</span>            cXX = m[0];<a name="line.488"></a>
-<span class="sourceLineNo">489</span>            cXY = m[2];<a name="line.489"></a>
-<span class="sourceLineNo">490</span>            cX1 = m[4];<a name="line.490"></a>
-<span class="sourceLineNo">491</span>            cYX = m[1];<a name="line.491"></a>
-<span class="sourceLineNo">492</span>            cYY = m[3];<a name="line.492"></a>
-<span class="sourceLineNo">493</span>            cY1 = m[5];<a name="line.493"></a>
-<span class="sourceLineNo">494</span><a name="line.494"></a>
-<span class="sourceLineNo">495</span>            c1Y = MathArrays.linearCombination(cXY, cY1, -cYY, cX1);<a name="line.495"></a>
-<span class="sourceLineNo">496</span>            c1X = MathArrays.linearCombination(cXX, cY1, -cYX, cX1);<a name="line.496"></a>
-<span class="sourceLineNo">497</span>            c11 = MathArrays.linearCombination(cXX, cYY, -cYX, cXY);<a name="line.497"></a>
-<span class="sourceLineNo">498</span><a name="line.498"></a>
-<span class="sourceLineNo">499</span>            if (FastMath.abs(c11) &lt; 1.0e-20) {<a name="line.499"></a>
-<span class="sourceLineNo">500</span>                throw new MathIllegalArgumentException(LocalizedFormats.NON_INVERTIBLE_TRANSFORM);<a name="line.500"></a>
-<span class="sourceLineNo">501</span>            }<a name="line.501"></a>
-<span class="sourceLineNo">502</span><a name="line.502"></a>
-<span class="sourceLineNo">503</span>        }<a name="line.503"></a>
-<span class="sourceLineNo">504</span><a name="line.504"></a>
-<span class="sourceLineNo">505</span>        /** {@inheritDoc} */<a name="line.505"></a>
-<span class="sourceLineNo">506</span>        public Vector2D apply(final Point&lt;Euclidean2D&gt; point) {<a name="line.506"></a>
-<span class="sourceLineNo">507</span>            final Vector2D p2D = (Vector2D) point;<a name="line.507"></a>
-<span class="sourceLineNo">508</span>            final double  x   = p2D.getX();<a name="line.508"></a>
-<span class="sourceLineNo">509</span>            final double  y   = p2D.getY();<a name="line.509"></a>
-<span class="sourceLineNo">510</span>            return new Vector2D(MathArrays.linearCombination(cXX, x, cXY, y, cX1, 1),<a name="line.510"></a>
-<span class="sourceLineNo">511</span>                                MathArrays.linearCombination(cYX, x, cYY, y, cY1, 1));<a name="line.511"></a>
-<span class="sourceLineNo">512</span>        }<a name="line.512"></a>
-<span class="sourceLineNo">513</span><a name="line.513"></a>
-<span class="sourceLineNo">514</span>        /** {@inheritDoc} */<a name="line.514"></a>
-<span class="sourceLineNo">515</span>        public Line apply(final Hyperplane&lt;Euclidean2D&gt; hyperplane) {<a name="line.515"></a>
-<span class="sourceLineNo">516</span>            final Line   line    = (Line) hyperplane;<a name="line.516"></a>
-<span class="sourceLineNo">517</span>            final double rOffset = MathArrays.linearCombination(c1X, line.cos, c1Y, line.sin, c11, line.originOffset);<a name="line.517"></a>
-<span class="sourceLineNo">518</span>            final double rCos    = MathArrays.linearCombination(cXX, line.cos, cXY, line.sin);<a name="line.518"></a>
-<span class="sourceLineNo">519</span>            final double rSin    = MathArrays.linearCombination(cYX, line.cos, cYY, line.sin);<a name="line.519"></a>
-<span class="sourceLineNo">520</span>            final double inv     = 1.0 / FastMath.sqrt(rSin * rSin + rCos * rCos);<a name="line.520"></a>
-<span class="sourceLineNo">521</span>            return new Line(FastMath.PI + FastMath.atan2(-rSin, -rCos),<a name="line.521"></a>
-<span class="sourceLineNo">522</span>                            inv * rCos, inv * rSin,<a name="line.522"></a>
-<span class="sourceLineNo">523</span>                            inv * rOffset, line.tolerance);<a name="line.523"></a>
-<span class="sourceLineNo">524</span>        }<a name="line.524"></a>
-<span class="sourceLineNo">525</span><a name="line.525"></a>
-<span class="sourceLineNo">526</span>        /** {@inheritDoc} */<a name="line.526"></a>
-<span class="sourceLineNo">527</span>        public SubHyperplane&lt;Euclidean1D&gt; apply(final SubHyperplane&lt;Euclidean1D&gt; sub,<a name="line.527"></a>
-<span class="sourceLineNo">528</span>                                                final Hyperplane&lt;Euclidean2D&gt; original,<a name="line.528"></a>
-<span class="sourceLineNo">529</span>                                                final Hyperplane&lt;Euclidean2D&gt; transformed) {<a name="line.529"></a>
-<span class="sourceLineNo">530</span>            final OrientedPoint op     = (OrientedPoint) sub.getHyperplane();<a name="line.530"></a>
-<span class="sourceLineNo">531</span>            final Line originalLine    = (Line) original;<a name="line.531"></a>
-<span class="sourceLineNo">532</span>            final Line transformedLine = (Line) transformed;<a name="line.532"></a>
-<span class="sourceLineNo">533</span>            final Vector1D newLoc =<a name="line.533"></a>
-<span class="sourceLineNo">534</span>                transformedLine.toSubSpace(apply(originalLine.toSpace(op.getLocation())));<a name="line.534"></a>
-<span class="sourceLineNo">535</span>            return new OrientedPoint(newLoc, op.isDirect(), originalLine.tolerance).wholeHyperplane();<a name="line.535"></a>
+<span class="sourceLineNo">450</span>     * @deprecated as of 3.6, replaced with {@link #getTransform(double, double, double, double, double, double)}<a name="line.450"></a>
+<span class="sourceLineNo">451</span>     */<a name="line.451"></a>
+<span class="sourceLineNo">452</span>    @Deprecated<a name="line.452"></a>
+<span class="sourceLineNo">453</span>    public static Transform&lt;Euclidean2D, Euclidean1D&gt; getTransform(final AffineTransform transform)<a name="line.453"></a>
+<span class="sourceLineNo">454</span>        throws MathIllegalArgumentException {<a name="line.454"></a>
+<span class="sourceLineNo">455</span>        final double[] m = new double[6];<a name="line.455"></a>
+<span class="sourceLineNo">456</span>        transform.getMatrix(m);<a name="line.456"></a>
+<span class="sourceLineNo">457</span>        return new LineTransform(m[0], m[1], m[2], m[3], m[4], m[5]);<a name="line.457"></a>
+<span class="sourceLineNo">458</span>    }<a name="line.458"></a>
+<span class="sourceLineNo">459</span><a name="line.459"></a>
+<span class="sourceLineNo">460</span>    /** Get a {@link org.apache.commons.math3.geometry.partitioning.Transform<a name="line.460"></a>
+<span class="sourceLineNo">461</span>     * Transform} embedding an affine transform.<a name="line.461"></a>
+<span class="sourceLineNo">462</span>     * @param cXX transform factor between input abscissa and output abscissa<a name="line.462"></a>
+<span class="sourceLineNo">463</span>     * @param cYX transform factor between input abscissa and output ordinate<a name="line.463"></a>
+<span class="sourceLineNo">464</span>     * @param cXY transform factor between input ordinate and output abscissa<a name="line.464"></a>
+<span class="sourceLineNo">465</span>     * @param cYY transform factor between input ordinate and output ordinate<a name="line.465"></a>
+<span class="sourceLineNo">466</span>     * @param cX1 transform addendum for output abscissa<a name="line.466"></a>
+<span class="sourceLineNo">467</span>     * @param cY1 transform addendum for output ordinate<a name="line.467"></a>
+<span class="sourceLineNo">468</span>     * @return a new transform that can be applied to either {@link<a name="line.468"></a>
+<span class="sourceLineNo">469</span>     * Vector2D Vector2D}, {@link Line Line} or {@link<a name="line.469"></a>
+<span class="sourceLineNo">470</span>     * org.apache.commons.math3.geometry.partitioning.SubHyperplane<a name="line.470"></a>
+<span class="sourceLineNo">471</span>     * SubHyperplane} instances<a name="line.471"></a>
+<span class="sourceLineNo">472</span>     * @exception MathIllegalArgumentException if the transform is non invertible<a name="line.472"></a>
+<span class="sourceLineNo">473</span>     * @since 3.6<a name="line.473"></a>
+<span class="sourceLineNo">474</span>     */<a name="line.474"></a>
+<span class="sourceLineNo">475</span>    public static Transform&lt;Euclidean2D, Euclidean1D&gt; getTransform(final double cXX,<a name="line.475"></a>
+<span class="sourceLineNo">476</span>                                                                   final double cYX,<a name="line.476"></a>
+<span class="sourceLineNo">477</span>                                                                   final double cXY,<a name="line.477"></a>
+<span class="sourceLineNo">478</span>                                                                   final double cYY,<a name="line.478"></a>
+<span class="sourceLineNo">479</span>                                                                   final double cX1,<a name="line.479"></a>
+<span class="sourceLineNo">480</span>                                                                   final double cY1)<a name="line.480"></a>
+<span class="sourceLineNo">481</span>        throws MathIllegalArgumentException {<a name="line.481"></a>
+<span class="sourceLineNo">482</span>        return new LineTransform(cXX, cYX, cXY, cYY, cX1, cY1);<a name="line.482"></a>
+<span class="sourceLineNo">483</span>    }<a name="line.483"></a>
+<span class="sourceLineNo">484</span><a name="line.484"></a>
+<span class="sourceLineNo">485</span>    /** Class embedding an affine transform.<a name="line.485"></a>
+<span class="sourceLineNo">486</span>     * &lt;p&gt;This class is used in order to apply an affine transform to a<a name="line.486"></a>
+<span class="sourceLineNo">487</span>     * line. Using a specific object allow to perform some computations<a name="line.487"></a>
+<span class="sourceLineNo">488</span>     * on the transform only once even if the same transform is to be<a name="line.488"></a>
+<span class="sourceLineNo">489</span>     * applied to a large number of lines (for example to a large<a name="line.489"></a>
+<span class="sourceLineNo">490</span>     * polygon)./&lt;p&gt;<a name="line.490"></a>
+<span class="sourceLineNo">491</span>     */<a name="line.491"></a>
+<span class="sourceLineNo">492</span>    private static class LineTransform implements Transform&lt;Euclidean2D, Euclidean1D&gt; {<a name="line.492"></a>
+<span class="sourceLineNo">493</span><a name="line.493"></a>
+<span class="sourceLineNo">494</span>        // CHECKSTYLE: stop JavadocVariable check<a name="line.494"></a>
+<span class="sourceLineNo">495</span>        private double cXX;<a name="line.495"></a>
+<span class="sourceLineNo">496</span>        private double cXY;<a name="line.496"></a>
+<span class="sourceLineNo">497</span>        private double cX1;<a name="line.497"></a>
+<span class="sourceLineNo">498</span>        private double cYX;<a name="line.498"></a>
+<span class="sourceLineNo">499</span>        private double cYY;<a name="line.499"></a>
+<span class="sourceLineNo">500</span>        private double cY1;<a name="line.500"></a>
+<span class="sourceLineNo">501</span><a name="line.501"></a>
+<span class="sourceLineNo">502</span>        private double c1Y;<a name="line.502"></a>
+<span class="sourceLineNo">503</span>        private double c1X;<a name="line.503"></a>
+<span class="sourceLineNo">504</span>        private double c11;<a name="line.504"></a>
+<span class="sourceLineNo">505</span>        // CHECKSTYLE: resume JavadocVariable check<a name="line.505"></a>
+<span class="sourceLineNo">506</span><a name="line.506"></a>
+<span class="sourceLineNo">507</span>        /** Build an affine line transform from a n {@code AffineTransform}.<a name="line.507"></a>
+<span class="sourceLineNo">508</span>         * @param cXX transform factor between input abscissa and output abscissa<a name="line.508"></a>
+<span class="sourceLineNo">509</span>         * @param cYX transform factor between input abscissa and output ordinate<a name="line.509"></a>
+<span class="sourceLineNo">510</span>         * @param cXY transform factor between input ordinate and output abscissa<a name="line.510"></a>
+<span class="sourceLineNo">511</span>         * @param cYY transform factor between input ordinate and output ordinate<a name="line.511"></a>
+<span class="sourceLineNo">512</span>         * @param cX1 transform addendum for output abscissa<a name="line.512"></a>
+<span class="sourceLineNo">513</span>         * @param cY1 transform addendum for output ordinate<a name="line.513"></a>
+<span class="sourceLineNo">514</span>         * @exception MathIllegalArgumentException if the transform is non invertible<a name="line.514"></a>
+<span class="sourceLineNo">515</span>         * @since 3.6<a name="line.515"></a>
+<span class="sourceLineNo">516</span>         */<a name="line.516"></a>
+<span class="sourceLineNo">517</span>        public LineTransform(final double cXX, final double cYX, final double cXY,<a name="line.517"></a>
+<span class="sourceLineNo">518</span>                             final double cYY, final double cX1, final double cY1)<a name="line.518"></a>
+<span class="sourceLineNo">519</span>            throws MathIllegalArgumentException {<a name="line.519"></a>
+<span class="sourceLineNo">520</span><a name="line.520"></a>
+<span class="sourceLineNo">521</span>            this.cXX = cXX;<a name="line.521"></a>
+<span class="sourceLineNo">522</span>            this.cYX = cYX;<a name="line.522"></a>
+<span class="sourceLineNo">523</span>            this.cXY = cXY;<a name="line.523"></a>
+<span class="sourceLineNo">524</span>            this.cYY = cYY;<a name="line.524"></a>
+<span class="sourceLineNo">525</span>            this.cX1 = cX1;<a name="line.525"></a>
+<span class="sourceLineNo">526</span>            this.cY1 = cY1;<a name="line.526"></a>
+<span class="sourceLineNo">527</span><a name="line.527"></a>
+<span class="sourceLineNo">528</span>            c1Y = MathArrays.linearCombination(cXY, cY1, -cYY, cX1);<a name="line.528"></a>
+<span class="sourceLineNo">529</span>            c1X = MathArrays.linearCombination(cXX, cY1, -cYX, cX1);<a name="line.529"></a>
+<span class="sourceLineNo">530</span>            c11 = MathArrays.linearCombination(cXX, cYY, -cYX, cXY);<a name="line.530"></a>
+<span class="sourceLineNo">531</span><a name="line.531"></a>
+<span class="sourceLineNo">532</span>            if (FastMath.abs(c11) &lt; 1.0e-20) {<a name="line.532"></a>
+<span class="sourceLineNo">533</span>                throw new MathIllegalArgumentException(LocalizedFormats.NON_INVERTIBLE_TRANSFORM);<a name="line.533"></a>
+<span class="sourceLineNo">534</span>            }<a name="line.534"></a>
+<span class="sourceLineNo">535</span><a name="line.535"></a>
 <span class="sourceLineNo">536</span>        }<a name="line.536"></a>
 <span class="sourceLineNo">537</span><a name="line.537"></a>
-<span class="sourceLineNo">538</span>    }<a name="line.538"></a>
-<span class="sourceLineNo">539</span><a name="line.539"></a>
-<span class="sourceLineNo">540</span>}<a name="line.540"></a>
+<span class="sourceLineNo">538</span>        /** {@inheritDoc} */<a name="line.538"></a>
+<span class="sourceLineNo">539</span>        public Vector2D apply(final Point&lt;Euclidean2D&gt; point) {<a name="line.539"></a>
+<span class="sourceLineNo">540</span>            final Vector2D p2D = (Vector2D) point;<a name="line.540"></a>
+<span class="sourceLineNo">541</span>            final double  x   = p2D.getX();<a name="line.541"></a>
+<span class="sourceLineNo">542</span>            final double  y   = p2D.getY();<a name="line.542"></a>
+<span class="sourceLineNo">543</span>            return new Vector2D(MathArrays.linearCombination(cXX, x, cXY, y, cX1, 1),<a name="line.543"></a>
+<span class="sourceLineNo">544</span>                                MathArrays.linearCombination(cYX, x, cYY, y, cY1, 1));<a name="line.544"></a>
+<span class="sourceLineNo">545</span>        }<a name="line.545"></a>
+<span class="sourceLineNo">546</span><a name="line.546"></a>
+<span class="sourceLineNo">547</span>        /** {@inheritDoc} */<a name="line.547"></a>
+<span class="sourceLineNo">548</span>        public Line apply(final Hyperplane&lt;Euclidean2D&gt; hyperplane) {<a name="line.548"></a>
+<span class="sourceLineNo">549</span>            final Line   line    = (Line) hyperplane;<a name="line.549"></a>
+<span class="sourceLineNo">550</span>            final double rOffset = MathArrays.linearCombination(c1X, line.cos, c1Y, line.sin, c11, line.originOffset);<a name="line.550"></a>
+<span class="sourceLineNo">551</span>            final double rCos    = MathArrays.linearCombination(cXX, line.cos, cXY, line.sin);<a name="line.551"></a>
+<span class="sourceLineNo">552</span>            final double rSin    = MathArrays.linearCombination(cYX, line.cos, cYY, line.sin);<a name="line.552"></a>
+<span class="sourceLineNo">553</span>            final double inv     = 1.0 / FastMath.sqrt(rSin * rSin + rCos * rCos);<a name="line.553"></a>
+<span class="sourceLineNo">554</span>            return new Line(FastMath.PI + FastMath.atan2(-rSin, -rCos),<a name="line.554"></a>
+<span class="sourceLineNo">555</span>                            inv * rCos, inv * rSin,<a name="line.555"></a>
+<span class="sourceLineNo">556</span>                            inv * rOffset, line.tolerance);<a name="line.556"></a>
+<span class="sourceLineNo">557</span>        }<a name="line.557"></a>
+<span class="sourceLineNo">558</span><a name="line.558"></a>
+<span class="sourceLineNo">559</span>        /** {@inheritDoc} */<a name="line.559"></a>
+<span class="sourceLineNo">560</span>        public SubHyperplane&lt;Euclidean1D&gt; apply(final SubHyperplane&lt;Euclidean1D&gt; sub,<a name="line.560"></a>
+<span class="sourceLineNo">561</span>                                                final Hyperplane&lt;Euclidean2D&gt; original,<a name="line.561"></a>
+<span class="sourceLineNo">562</span>                                                final Hyperplane&lt;Euclidean2D&gt; transformed) {<a name="line.562"></a>
+<span class="sourceLineNo">563</span>            final OrientedPoint op     = (OrientedPoint) sub.getHyperplane();<a name="line.563"></a>
+<span class="sourceLineNo">564</span>            final Line originalLine    = (Line) original;<a name="line.564"></a>
+<span class="sourceLineNo">565</span>            final Line transformedLine = (Line) transformed;<a name="line.565"></a>
+<span class="sourceLineNo">566</span>            final Vector1D newLoc =<a name="line.566"></a>
+<span class="sourceLineNo">567</span>                transformedLine.toSubSpace(apply(originalLine.toSpace(op.getLocation())));<a name="line.567"></a>
+<span class="sourceLineNo">568</span>            return new OrientedPoint(newLoc, op.isDirect(), originalLine.tolerance).wholeHyperplane();<a name="line.568"></a>
+<span class="sourceLineNo">569</span>        }<a name="line.569"></a>
+<span class="sourceLineNo">570</span><a name="line.570"></a>
+<span class="sourceLineNo">571</span>    }<a name="line.571"></a>
+<span class="sourceLineNo">572</span><a name="line.572"></a>
+<span class="sourceLineNo">573</span>}<a name="line.573"></a>
 
 
 

Modified: websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/ml/neuralnet/Neuron.html
==============================================================================
--- websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/ml/neuralnet/Neuron.html (original)
+++ websites/production/commons/content/proper/commons-math/apidocs/src-html/org/apache/commons/math3/ml/neuralnet/Neuron.html Mon Jul 27 19:40:06 2015
@@ -28,199 +28,237 @@
 <span class="sourceLineNo">020</span>import java.io.Serializable;<a name="line.20"></a>
 <span class="sourceLineNo">021</span>import java.io.ObjectInputStream;<a name="line.21"></a>
 <span class="sourceLineNo">022</span>import java.util.concurrent.atomic.AtomicReference;<a name="line.22"></a>
-<span class="sourceLineNo">023</span>import org.apache.commons.math3.util.Precision;<a name="line.23"></a>
-<span class="sourceLineNo">024</span>import org.apache.commons.math3.exception.DimensionMismatchException;<a name="line.24"></a>
-<span class="sourceLineNo">025</span><a name="line.25"></a>
-<span class="sourceLineNo">026</span><a name="line.26"></a>
-<span class="sourceLineNo">027</span>/**<a name="line.27"></a>
-<span class="sourceLineNo">028</span> * Describes a neuron element of a neural network.<a name="line.28"></a>
-<span class="sourceLineNo">029</span> *<a name="line.29"></a>
-<span class="sourceLineNo">030</span> * This class aims to be thread-safe.<a name="line.30"></a>
+<span class="sourceLineNo">023</span>import java.util.concurrent.atomic.AtomicLong;<a name="line.23"></a>
+<span class="sourceLineNo">024</span><a name="line.24"></a>
+<span class="sourceLineNo">025</span>import org.apache.commons.math3.exception.DimensionMismatchException;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import org.apache.commons.math3.util.Precision;<a name="line.26"></a>
+<span class="sourceLineNo">027</span><a name="line.27"></a>
+<span class="sourceLineNo">028</span><a name="line.28"></a>
+<span class="sourceLineNo">029</span>/**<a name="line.29"></a>
+<span class="sourceLineNo">030</span> * Describes a neuron element of a neural network.<a name="line.30"></a>
 <span class="sourceLineNo">031</span> *<a name="line.31"></a>
-<span class="sourceLineNo">032</span> * @since 3.3<a name="line.32"></a>
-<span class="sourceLineNo">033</span> */<a name="line.33"></a>
-<span class="sourceLineNo">034</span>public class Neuron implements Serializable {<a name="line.34"></a>
-<span class="sourceLineNo">035</span>    /** Serializable. */<a name="line.35"></a>
-<span class="sourceLineNo">036</span>    private static final long serialVersionUID = 20130207L;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>    /** Identifier. */<a name="line.37"></a>
-<span class="sourceLineNo">038</span>    private final long identifier;<a name="line.38"></a>
-<span class="sourceLineNo">039</span>    /** Length of the feature set. */<a name="line.39"></a>
-<span class="sourceLineNo">040</span>    private final int size;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>    /** Neuron data. */<a name="line.41"></a>
-<span class="sourceLineNo">042</span>    private final AtomicReference&lt;double[]&gt; features;<a name="line.42"></a>
-<span class="sourceLineNo">043</span><a name="line.43"></a>
-<span class="sourceLineNo">044</span>    /**<a name="line.44"></a>
-<span class="sourceLineNo">045</span>     * Creates a neuron.<a name="line.45"></a>
-<span class="sourceLineNo">046</span>     * The size of the feature set is fixed to the length of the given<a name="line.46"></a>
-<span class="sourceLineNo">047</span>     * argument.<a name="line.47"></a>
-<span class="sourceLineNo">048</span>     * &lt;br/&gt;<a name="line.48"></a>
-<span class="sourceLineNo">049</span>     * Constructor is package-private: Neurons must be<a name="line.49"></a>
-<span class="sourceLineNo">050</span>     * {@link Network#createNeuron(double[]) created} by the network<a name="line.50"></a>
-<span class="sourceLineNo">051</span>     * instance to which they will belong.<a name="line.51"></a>
-<span class="sourceLineNo">052</span>     *<a name="line.52"></a>
-<span class="sourceLineNo">053</span>     * @param identifier Identifier (assigned by the {@link Network}).<a name="line.53"></a>
-<span class="sourceLineNo">054</span>     * @param features Initial values of the feature set.<a name="line.54"></a>
-<span class="sourceLineNo">055</span>     */<a name="line.55"></a>
-<span class="sourceLineNo">056</span>    Neuron(long identifier,<a name="line.56"></a>
-<span class="sourceLineNo">057</span>           double[] features) {<a name="line.57"></a>
-<span class="sourceLineNo">058</span>        this.identifier = identifier;<a name="line.58"></a>
-<span class="sourceLineNo">059</span>        this.size = features.length;<a name="line.59"></a>
-<span class="sourceLineNo">060</span>        this.features = new AtomicReference&lt;double[]&gt;(features.clone());<a name="line.60"></a>
-<span class="sourceLineNo">061</span>    }<a name="line.61"></a>
-<span class="sourceLineNo">062</span><a name="line.62"></a>
-<span class="sourceLineNo">063</span>    /**<a name="line.63"></a>
-<span class="sourceLineNo">064</span>     * Gets the neuron's identifier.<a name="line.64"></a>
-<span class="sourceLineNo">065</span>     *<a name="line.65"></a>
-<span class="sourceLineNo">066</span>     * @return the identifier.<a name="line.66"></a>
-<span class="sourceLineNo">067</span>     */<a name="line.67"></a>
-<span class="sourceLineNo">068</span>    public long getIdentifier() {<a name="line.68"></a>
-<span class="sourceLineNo">069</span>        return identifier;<a name="line.69"></a>
-<span class="sourceLineNo">070</span>    }<a name="line.70"></a>
-<span class="sourceLineNo">071</span><a name="line.71"></a>
-<span class="sourceLineNo">072</span>    /**<a name="line.72"></a>
-<span class="sourceLineNo">073</span>     * Gets the length of the feature set.<a name="line.73"></a>
-<span class="sourceLineNo">074</span>     *<a name="line.74"></a>
-<span class="sourceLineNo">075</span>     * @return the number of features.<a name="line.75"></a>
-<span class="sourceLineNo">076</span>     */<a name="line.76"></a>
-<span class="sourceLineNo">077</span>    public int getSize() {<a name="line.77"></a>
-<span class="sourceLineNo">078</span>        return size;<a name="line.78"></a>
-<span class="sourceLineNo">079</span>    }<a name="line.79"></a>
-<span class="sourceLineNo">080</span><a name="line.80"></a>
-<span class="sourceLineNo">081</span>    /**<a name="line.81"></a>
-<span class="sourceLineNo">082</span>     * Gets the neuron's features.<a name="line.82"></a>
-<span class="sourceLineNo">083</span>     *<a name="line.83"></a>
-<span class="sourceLineNo">084</span>     * @return a copy of the neuron's features.<a name="line.84"></a>
-<span class="sourceLineNo">085</span>     */<a name="line.85"></a>
-<span class="sourceLineNo">086</span>    public double[] getFeatures() {<a name="line.86"></a>
-<span class="sourceLineNo">087</span>        return features.get().clone();<a name="line.87"></a>
-<span class="sourceLineNo">088</span>    }<a name="line.88"></a>
-<span class="sourceLineNo">089</span><a name="line.89"></a>
-<span class="sourceLineNo">090</span>    /**<a name="line.90"></a>
-<span class="sourceLineNo">091</span>     * Tries to atomically update the neuron's features.<a name="line.91"></a>
-<span class="sourceLineNo">092</span>     * Update will be performed only if the expected values match the<a name="line.92"></a>
-<span class="sourceLineNo">093</span>     * current values.&lt;br/&gt;<a name="line.93"></a>
-<span class="sourceLineNo">094</span>     * In effect, when concurrent threads call this method, the state<a name="line.94"></a>
-<span class="sourceLineNo">095</span>     * could be modified by one, so that it does not correspond to the<a name="line.95"></a>
-<span class="sourceLineNo">096</span>     * the state assumed by another.<a name="line.96"></a>
-<span class="sourceLineNo">097</span>     * Typically, a caller {@link #getFeatures() retrieves the current state},<a name="line.97"></a>
-<span class="sourceLineNo">098</span>     * and uses it to compute the new state.<a name="line.98"></a>
-<span class="sourceLineNo">099</span>     * During this computation, another thread might have done the same<a name="line.99"></a>
-<span class="sourceLineNo">100</span>     * thing, and updated the state: If the current thread were to proceed<a name="line.100"></a>
-<span class="sourceLineNo">101</span>     * with its own update, it would overwrite the new state (which might<a name="line.101"></a>
-<span class="sourceLineNo">102</span>     * already have been used by yet other threads).<a name="line.102"></a>
-<span class="sourceLineNo">103</span>     * To prevent this, the method does not perform the update when a<a name="line.103"></a>
-<span class="sourceLineNo">104</span>     * concurrent modification has been detected, and returns {@code false}.<a name="line.104"></a>
-<span class="sourceLineNo">105</span>     * When this happens, the caller should fetch the new current state,<a name="line.105"></a>
-<span class="sourceLineNo">106</span>     * redo its computation, and call this method again.<a name="line.106"></a>
-<span class="sourceLineNo">107</span>     *<a name="line.107"></a>
-<span class="sourceLineNo">108</span>     * @param expect Current values of the features, as assumed by the caller.<a name="line.108"></a>
-<span class="sourceLineNo">109</span>     * Update will never succeed if the contents of this array does not match<a name="line.109"></a>
-<span class="sourceLineNo">110</span>     * the values returned by {@link #getFeatures()}.<a name="line.110"></a>
-<span class="sourceLineNo">111</span>     * @param update Features's new values.<a name="line.111"></a>
-<span class="sourceLineNo">112</span>     * @return {@code true} if the update was successful, {@code false}<a name="line.112"></a>
-<span class="sourceLineNo">113</span>     * otherwise.<a name="line.113"></a>
-<span class="sourceLineNo">114</span>     * @throws DimensionMismatchException if the length of {@code update} is<a name="line.114"></a>
-<span class="sourceLineNo">115</span>     * not the same as specified in the {@link #Neuron(long,double[])<a name="line.115"></a>
-<span class="sourceLineNo">116</span>     * constructor}.<a name="line.116"></a>
-<span class="sourceLineNo">117</span>     */<a name="line.117"></a>
-<span class="sourceLineNo">118</span>    public boolean compareAndSetFeatures(double[] expect,<a name="line.118"></a>
-<span class="sourceLineNo">119</span>                                         double[] update) {<a name="line.119"></a>
-<span class="sourceLineNo">120</span>        if (update.length != size) {<a name="line.120"></a>
-<span class="sourceLineNo">121</span>            throw new DimensionMismatchException(update.length, size);<a name="line.121"></a>
-<span class="sourceLineNo">122</span>        }<a name="line.122"></a>
-<span class="sourceLineNo">123</span><a name="line.123"></a>
-<span class="sourceLineNo">124</span>        // Get the internal reference. Note that this must not be a copy;<a name="line.124"></a>
-<span class="sourceLineNo">125</span>        // otherwise the "compareAndSet" below will always fail.<a name="line.125"></a>
-<span class="sourceLineNo">126</span>        final double[] current = features.get();<a name="line.126"></a>
-<span class="sourceLineNo">127</span>        if (!containSameValues(current, expect)) {<a name="line.127"></a>
-<span class="sourceLineNo">128</span>            // Some other thread already modified the state.<a name="line.128"></a>
-<span class="sourceLineNo">129</span>            return false;<a name="line.129"></a>
-<span class="sourceLineNo">130</span>        }<a name="line.130"></a>
-<span class="sourceLineNo">131</span><a name="line.131"></a>
-<span class="sourceLineNo">132</span>        if (features.compareAndSet(current, update.clone())) {<a name="line.132"></a>
-<span class="sourceLineNo">133</span>            // The current thread could atomically update the state.<a name="line.133"></a>
-<span class="sourceLineNo">134</span>            return true;<a name="line.134"></a>
-<span class="sourceLineNo">135</span>        } else {<a name="line.135"></a>
-<span class="sourceLineNo">136</span>            // Some other thread came first.<a name="line.136"></a>
-<span class="sourceLineNo">137</span>            return false;<a name="line.137"></a>
-<span class="sourceLineNo">138</span>        }<a name="line.138"></a>
-<span class="sourceLineNo">139</span>    }<a name="line.139"></a>
+<span class="sourceLineNo">032</span> * This class aims to be thread-safe.<a name="line.32"></a>
+<span class="sourceLineNo">033</span> *<a name="line.33"></a>
+<span class="sourceLineNo">034</span> * @since 3.3<a name="line.34"></a>
+<span class="sourceLineNo">035</span> */<a name="line.35"></a>
+<span class="sourceLineNo">036</span>public class Neuron implements Serializable {<a name="line.36"></a>
+<span class="sourceLineNo">037</span>    /** Serializable. */<a name="line.37"></a>
+<span class="sourceLineNo">038</span>    private static final long serialVersionUID = 20130207L;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>    /** Identifier. */<a name="line.39"></a>
+<span class="sourceLineNo">040</span>    private final long identifier;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>    /** Length of the feature set. */<a name="line.41"></a>
+<span class="sourceLineNo">042</span>    private final int size;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>    /** Neuron data. */<a name="line.43"></a>
+<span class="sourceLineNo">044</span>    private final AtomicReference&lt;double[]&gt; features;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>    /** Number of attempts to update a neuron. */<a name="line.45"></a>
+<span class="sourceLineNo">046</span>    private final AtomicLong numberOfAttemptedUpdates = new AtomicLong(0);<a name="line.46"></a>
+<span class="sourceLineNo">047</span>    /** Number of successful updates  of a neuron. */<a name="line.47"></a>
+<span class="sourceLineNo">048</span>    private final AtomicLong numberOfSuccessfulUpdates = new AtomicLong(0);<a name="line.48"></a>
+<span class="sourceLineNo">049</span><a name="line.49"></a>
+<span class="sourceLineNo">050</span>    /**<a name="line.50"></a>
+<span class="sourceLineNo">051</span>     * Creates a neuron.<a name="line.51"></a>
+<span class="sourceLineNo">052</span>     * The size of the feature set is fixed to the length of the given<a name="line.52"></a>
+<span class="sourceLineNo">053</span>     * argument.<a name="line.53"></a>
+<span class="sourceLineNo">054</span>     * &lt;br/&gt;<a name="line.54"></a>
+<span class="sourceLineNo">055</span>     * Constructor is package-private: Neurons must be<a name="line.55"></a>
+<span class="sourceLineNo">056</span>     * {@link Network#createNeuron(double[]) created} by the network<a name="line.56"></a>
+<span class="sourceLineNo">057</span>     * instance to which they will belong.<a name="line.57"></a>
+<span class="sourceLineNo">058</span>     *<a name="line.58"></a>
+<span class="sourceLineNo">059</span>     * @param identifier Identifier (assigned by the {@link Network}).<a name="line.59"></a>
+<span class="sourceLineNo">060</span>     * @param features Initial values of the feature set.<a name="line.60"></a>
+<span class="sourceLineNo">061</span>     */<a name="line.61"></a>
+<span class="sourceLineNo">062</span>    Neuron(long identifier,<a name="line.62"></a>
+<span class="sourceLineNo">063</span>           double[] features) {<a name="line.63"></a>
+<span class="sourceLineNo">064</span>        this.identifier = identifier;<a name="line.64"></a>
+<span class="sourceLineNo">065</span>        this.size = features.length;<a name="line.65"></a>
+<span class="sourceLineNo">066</span>        this.features = new AtomicReference&lt;double[]&gt;(features.clone());<a name="line.66"></a>
+<span class="sourceLineNo">067</span>    }<a name="line.67"></a>
+<span class="sourceLineNo">068</span><a name="line.68"></a>
+<span class="sourceLineNo">069</span>    /**<a name="line.69"></a>
+<span class="sourceLineNo">070</span>     * Gets the neuron's identifier.<a name="line.70"></a>
+<span class="sourceLineNo">071</span>     *<a name="line.71"></a>
+<span class="sourceLineNo">072</span>     * @return the identifier.<a name="line.72"></a>
+<span class="sourceLineNo">073</span>     */<a name="line.73"></a>
+<span class="sourceLineNo">074</span>    public long getIdentifier() {<a name="line.74"></a>
+<span class="sourceLineNo">075</span>        return identifier;<a name="line.75"></a>
+<span class="sourceLineNo">076</span>    }<a name="line.76"></a>
+<span class="sourceLineNo">077</span><a name="line.77"></a>
+<span class="sourceLineNo">078</span>    /**<a name="line.78"></a>
+<span class="sourceLineNo">079</span>     * Gets the length of the feature set.<a name="line.79"></a>
+<span class="sourceLineNo">080</span>     *<a name="line.80"></a>
+<span class="sourceLineNo">081</span>     * @return the number of features.<a name="line.81"></a>
+<span class="sourceLineNo">082</span>     */<a name="line.82"></a>
+<span class="sourceLineNo">083</span>    public int getSize() {<a name="line.83"></a>
+<span class="sourceLineNo">084</span>        return size;<a name="line.84"></a>
+<span class="sourceLineNo">085</span>    }<a name="line.85"></a>
+<span class="sourceLineNo">086</span><a name="line.86"></a>
+<span class="sourceLineNo">087</span>    /**<a name="line.87"></a>
+<span class="sourceLineNo">088</span>     * Gets the neuron's features.<a name="line.88"></a>
+<span class="sourceLineNo">089</span>     *<a name="line.89"></a>
+<span class="sourceLineNo">090</span>     * @return a copy of the neuron's features.<a name="line.90"></a>
+<span class="sourceLineNo">091</span>     */<a name="line.91"></a>
+<span class="sourceLineNo">092</span>    public double[] getFeatures() {<a name="line.92"></a>
+<span class="sourceLineNo">093</span>        return features.get().clone();<a name="line.93"></a>
+<span class="sourceLineNo">094</span>    }<a name="line.94"></a>
+<span class="sourceLineNo">095</span><a name="line.95"></a>
+<span class="sourceLineNo">096</span>    /**<a name="line.96"></a>
+<span class="sourceLineNo">097</span>     * Tries to atomically update the neuron's features.<a name="line.97"></a>
+<span class="sourceLineNo">098</span>     * Update will be performed only if the expected values match the<a name="line.98"></a>
+<span class="sourceLineNo">099</span>     * current values.&lt;br/&gt;<a name="line.99"></a>
+<span class="sourceLineNo">100</span>     * In effect, when concurrent threads call this method, the state<a name="line.100"></a>
+<span class="sourceLineNo">101</span>     * could be modified by one, so that it does not correspond to the<a name="line.101"></a>
+<span class="sourceLineNo">102</span>     * the state assumed by another.<a name="line.102"></a>
+<span class="sourceLineNo">103</span>     * Typically, a caller {@link #getFeatures() retrieves the current state},<a name="line.103"></a>
+<span class="sourceLineNo">104</span>     * and uses it to compute the new state.<a name="line.104"></a>
+<span class="sourceLineNo">105</span>     * During this computation, another thread might have done the same<a name="line.105"></a>
+<span class="sourceLineNo">106</span>     * thing, and updated the state: If the current thread were to proceed<a name="line.106"></a>
+<span class="sourceLineNo">107</span>     * with its own update, it would overwrite the new state (which might<a name="line.107"></a>
+<span class="sourceLineNo">108</span>     * already have been used by yet other threads).<a name="line.108"></a>
+<span class="sourceLineNo">109</span>     * To prevent this, the method does not perform the update when a<a name="line.109"></a>
+<span class="sourceLineNo">110</span>     * concurrent modification has been detected, and returns {@code false}.<a name="line.110"></a>
+<span class="sourceLineNo">111</span>     * When this happens, the caller should fetch the new current state,<a name="line.111"></a>
+<span class="sourceLineNo">112</span>     * redo its computation, and call this method again.<a name="line.112"></a>
+<span class="sourceLineNo">113</span>     *<a name="line.113"></a>
+<span class="sourceLineNo">114</span>     * @param expect Current values of the features, as assumed by the caller.<a name="line.114"></a>
+<span class="sourceLineNo">115</span>     * Update will never succeed if the contents of this array does not match<a name="line.115"></a>
+<span class="sourceLineNo">116</span>     * the values returned by {@link #getFeatures()}.<a name="line.116"></a>
+<span class="sourceLineNo">117</span>     * @param update Features's new values.<a name="line.117"></a>
+<span class="sourceLineNo">118</span>     * @return {@code true} if the update was successful, {@code false}<a name="line.118"></a>
+<span class="sourceLineNo">119</span>     * otherwise.<a name="line.119"></a>
+<span class="sourceLineNo">120</span>     * @throws DimensionMismatchException if the length of {@code update} is<a name="line.120"></a>
+<span class="sourceLineNo">121</span>     * not the same as specified in the {@link #Neuron(long,double[])<a name="line.121"></a>
+<span class="sourceLineNo">122</span>     * constructor}.<a name="line.122"></a>
+<span class="sourceLineNo">123</span>     */<a name="line.123"></a>
+<span class="sourceLineNo">124</span>    public boolean compareAndSetFeatures(double[] expect,<a name="line.124"></a>
+<span class="sourceLineNo">125</span>                                         double[] update) {<a name="line.125"></a>
+<span class="sourceLineNo">126</span>        if (update.length != size) {<a name="line.126"></a>
+<span class="sourceLineNo">127</span>            throw new DimensionMismatchException(update.length, size);<a name="line.127"></a>
+<span class="sourceLineNo">128</span>        }<a name="line.128"></a>
+<span class="sourceLineNo">129</span><a name="line.129"></a>
+<span class="sourceLineNo">130</span>        // Get the internal reference. Note that this must not be a copy;<a name="line.130"></a>
+<span class="sourceLineNo">131</span>        // otherwise the "compareAndSet" below will always fail.<a name="line.131"></a>
+<span class="sourceLineNo">132</span>        final double[] current = features.get();<a name="line.132"></a>
+<span class="sourceLineNo">133</span>        if (!containSameValues(current, expect)) {<a name="line.133"></a>
+<span class="sourceLineNo">134</span>            // Some other thread already modified the state.<a name="line.134"></a>
+<span class="sourceLineNo">135</span>            return false;<a name="line.135"></a>
+<span class="sourceLineNo">136</span>        }<a name="line.136"></a>
+<span class="sourceLineNo">137</span><a name="line.137"></a>
+<span class="sourceLineNo">138</span>        // Increment attempt counter.<a name="line.138"></a>
+<span class="sourceLineNo">139</span>        numberOfAttemptedUpdates.incrementAndGet();<a name="line.139"></a>
 <span class="sourceLineNo">140</span><a name="line.140"></a>
-<span class="sourceLineNo">141</span>    /**<a name="line.141"></a>
-<span class="sourceLineNo">142</span>     * Checks whether the contents of both arrays is the same.<a name="line.142"></a>
-<span class="sourceLineNo">143</span>     *<a name="line.143"></a>
-<span class="sourceLineNo">144</span>     * @param current Current values.<a name="line.144"></a>
-<span class="sourceLineNo">145</span>     * @param expect Expected values.<a name="line.145"></a>
-<span class="sourceLineNo">146</span>     * @throws DimensionMismatchException if the length of {@code expected}<a name="line.146"></a>
-<span class="sourceLineNo">147</span>     * is not the same as specified in the {@link #Neuron(long,double[])<a name="line.147"></a>
-<span class="sourceLineNo">148</span>     * constructor}.<a name="line.148"></a>
-<span class="sourceLineNo">149</span>     * @return {@code true} if the arrays contain the same values.<a name="line.149"></a>
-<span class="sourceLineNo">150</span>     */<a name="line.150"></a>
-<span class="sourceLineNo">151</span>    private boolean containSameValues(double[] current,<a name="line.151"></a>
-<span class="sourceLineNo">152</span>                                      double[] expect) {<a name="line.152"></a>
-<span class="sourceLineNo">153</span>        if (expect.length != size) {<a name="line.153"></a>
-<span class="sourceLineNo">154</span>            throw new DimensionMismatchException(expect.length, size);<a name="line.154"></a>
-<span class="sourceLineNo">155</span>        }<a name="line.155"></a>
-<span class="sourceLineNo">156</span><a name="line.156"></a>
-<span class="sourceLineNo">157</span>        for (int i = 0; i &lt; size; i++) {<a name="line.157"></a>
-<span class="sourceLineNo">158</span>            if (!Precision.equals(current[i], expect[i])) {<a name="line.158"></a>
-<span class="sourceLineNo">159</span>                return false;<a name="line.159"></a>
-<span class="sourceLineNo">160</span>            }<a name="line.160"></a>
-<span class="sourceLineNo">161</span>        }<a name="line.161"></a>
-<span class="sourceLineNo">162</span>        return true;<a name="line.162"></a>
+<span class="sourceLineNo">141</span>        if (features.compareAndSet(current, update.clone())) {<a name="line.141"></a>
+<span class="sourceLineNo">142</span>            // The current thread could atomically update the state (attempt succeeded).<a name="line.142"></a>
+<span class="sourceLineNo">143</span>            numberOfSuccessfulUpdates.incrementAndGet();<a name="line.143"></a>
+<span class="sourceLineNo">144</span>            return true;<a name="line.144"></a>
+<span class="sourceLineNo">145</span>        } else {<a name="line.145"></a>
+<span class="sourceLineNo">146</span>            // Some other thread came first (attempt failed).<a name="line.146"></a>
+<span class="sourceLineNo">147</span>            return false;<a name="line.147"></a>
+<span class="sourceLineNo">148</span>        }<a name="line.148"></a>
+<span class="sourceLineNo">149</span>    }<a name="line.149"></a>
+<span class="sourceLineNo">150</span><a name="line.150"></a>
+<span class="sourceLineNo">151</span>    /**<a name="line.151"></a>
+<span class="sourceLineNo">152</span>     * Retrieves the number of calls to the<a name="line.152"></a>
+<span class="sourceLineNo">153</span>     * {@link #compareAndSetFeatures(double[],double[]) compareAndSetFeatures}<a name="line.153"></a>
+<span class="sourceLineNo">154</span>     * method.<a name="line.154"></a>
+<span class="sourceLineNo">155</span>     * Note that if the caller wants to use this method in combination with<a name="line.155"></a>
+<span class="sourceLineNo">156</span>     * {@link #getNumberOfSuccessfulUpdates()}, additional synchronization<a name="line.156"></a>
+<span class="sourceLineNo">157</span>     * may be required to ensure consistency.<a name="line.157"></a>
+<span class="sourceLineNo">158</span>     *<a name="line.158"></a>
+<span class="sourceLineNo">159</span>     * @return the number of update attempts.<a name="line.159"></a>
+<span class="sourceLineNo">160</span>     */<a name="line.160"></a>
+<span class="sourceLineNo">161</span>    public long getNumberOfAttemptedUpdates() {<a name="line.161"></a>
+<span class="sourceLineNo">162</span>        return numberOfAttemptedUpdates.get();<a name="line.162"></a>
 <span class="sourceLineNo">163</span>    }<a name="line.163"></a>
 <span class="sourceLineNo">164</span><a name="line.164"></a>
 <span class="sourceLineNo">165</span>    /**<a name="line.165"></a>
-<span class="sourceLineNo">166</span>     * Prevents proxy bypass.<a name="line.166"></a>
-<span class="sourceLineNo">167</span>     *<a name="line.167"></a>
-<span class="sourceLineNo">168</span>     * @param in Input stream.<a name="line.168"></a>
-<span class="sourceLineNo">169</span>     */<a name="line.169"></a>
-<span class="sourceLineNo">170</span>    private void readObject(ObjectInputStream in) {<a name="line.170"></a>
-<span class="sourceLineNo">171</span>        throw new IllegalStateException();<a name="line.171"></a>
-<span class="sourceLineNo">172</span>    }<a name="line.172"></a>
-<span class="sourceLineNo">173</span><a name="line.173"></a>
-<span class="sourceLineNo">174</span>    /**<a name="line.174"></a>
-<span class="sourceLineNo">175</span>     * Custom serialization.<a name="line.175"></a>
-<span class="sourceLineNo">176</span>     *<a name="line.176"></a>
-<span class="sourceLineNo">177</span>     * @return the proxy instance that will be actually serialized.<a name="line.177"></a>
-<span class="sourceLineNo">178</span>     */<a name="line.178"></a>
-<span class="sourceLineNo">179</span>    private Object writeReplace() {<a name="line.179"></a>
-<span class="sourceLineNo">180</span>        return new SerializationProxy(identifier,<a name="line.180"></a>
-<span class="sourceLineNo">181</span>                                      features.get());<a name="line.181"></a>
-<span class="sourceLineNo">182</span>    }<a name="line.182"></a>
-<span class="sourceLineNo">183</span><a name="line.183"></a>
-<span class="sourceLineNo">184</span>    /**<a name="line.184"></a>
-<span class="sourceLineNo">185</span>     * Serialization.<a name="line.185"></a>
-<span class="sourceLineNo">186</span>     */<a name="line.186"></a>
-<span class="sourceLineNo">187</span>    private static class SerializationProxy implements Serializable {<a name="line.187"></a>
-<span class="sourceLineNo">188</span>        /** Serializable. */<a name="line.188"></a>
-<span class="sourceLineNo">189</span>        private static final long serialVersionUID = 20130207L;<a name="line.189"></a>
-<span class="sourceLineNo">190</span>        /** Features. */<a name="line.190"></a>
-<span class="sourceLineNo">191</span>        private final double[] features;<a name="line.191"></a>
-<span class="sourceLineNo">192</span>        /** Identifier. */<a name="line.192"></a>
-<span class="sourceLineNo">193</span>        private final long identifier;<a name="line.193"></a>
+<span class="sourceLineNo">166</span>     * Retrieves the number of successful calls to the<a name="line.166"></a>
+<span class="sourceLineNo">167</span>     * {@link #compareAndSetFeatures(double[],double[]) compareAndSetFeatures}<a name="line.167"></a>
+<span class="sourceLineNo">168</span>     * method.<a name="line.168"></a>
+<span class="sourceLineNo">169</span>     * Note that if the caller wants to use this method in combination with<a name="line.169"></a>
+<span class="sourceLineNo">170</span>     * {@link #getNumberOfAttemptedUpdates()}, additional synchronization<a name="line.170"></a>
+<span class="sourceLineNo">171</span>     * may be required to ensure consistency.<a name="line.171"></a>
+<span class="sourceLineNo">172</span>     *<a name="line.172"></a>
+<span class="sourceLineNo">173</span>     * @return the number of successful updates.<a name="line.173"></a>
+<span class="sourceLineNo">174</span>     */<a name="line.174"></a>
+<span class="sourceLineNo">175</span>    public long getNumberOfSuccessfulUpdates() {<a name="line.175"></a>
+<span class="sourceLineNo">176</span>        return numberOfSuccessfulUpdates.get();<a name="line.176"></a>
+<span class="sourceLineNo">177</span>    }<a name="line.177"></a>
+<span class="sourceLineNo">178</span><a name="line.178"></a>
+<span class="sourceLineNo">179</span>    /**<a name="line.179"></a>
+<span class="sourceLineNo">180</span>     * Checks whether the contents of both arrays is the same.<a name="line.180"></a>
+<span class="sourceLineNo">181</span>     *<a name="line.181"></a>
+<span class="sourceLineNo">182</span>     * @param current Current values.<a name="line.182"></a>
+<span class="sourceLineNo">183</span>     * @param expect Expected values.<a name="line.183"></a>
+<span class="sourceLineNo">184</span>     * @throws DimensionMismatchException if the length of {@code expected}<a name="line.184"></a>
+<span class="sourceLineNo">185</span>     * is not the same as specified in the {@link #Neuron(long,double[])<a name="line.185"></a>
+<span class="sourceLineNo">186</span>     * constructor}.<a name="line.186"></a>
+<span class="sourceLineNo">187</span>     * @return {@code true} if the arrays contain the same values.<a name="line.187"></a>
+<span class="sourceLineNo">188</span>     */<a name="line.188"></a>
+<span class="sourceLineNo">189</span>    private boolean containSameValues(double[] current,<a name="line.189"></a>
+<span class="sourceLineNo">190</span>                                      double[] expect) {<a name="line.190"></a>
+<span class="sourceLineNo">191</span>        if (expect.length != size) {<a name="line.191"></a>
+<span class="sourceLineNo">192</span>            throw new DimensionMismatchException(expect.length, size);<a name="line.192"></a>
+<span class="sourceLineNo">193</span>        }<a name="line.193"></a>
 <span class="sourceLineNo">194</span><a name="line.194"></a>
-<span class="sourceLineNo">195</span>        /**<a name="line.195"></a>
-<span class="sourceLineNo">196</span>         * @param identifier Identifier.<a name="line.196"></a>
-<span class="sourceLineNo">197</span>         * @param features Features.<a name="line.197"></a>
-<span class="sourceLineNo">198</span>         */<a name="line.198"></a>
-<span class="sourceLineNo">199</span>        SerializationProxy(long identifier,<a name="line.199"></a>
-<span class="sourceLineNo">200</span>                           double[] features) {<a name="line.200"></a>
-<span class="sourceLineNo">201</span>            this.identifier = identifier;<a name="line.201"></a>
-<span class="sourceLineNo">202</span>            this.features = features;<a name="line.202"></a>
-<span class="sourceLineNo">203</span>        }<a name="line.203"></a>
-<span class="sourceLineNo">204</span><a name="line.204"></a>
-<span class="sourceLineNo">205</span>        /**<a name="line.205"></a>
-<span class="sourceLineNo">206</span>         * Custom serialization.<a name="line.206"></a>
-<span class="sourceLineNo">207</span>         *<a name="line.207"></a>
-<span class="sourceLineNo">208</span>         * @return the {@link Neuron} for which this instance is the proxy.<a name="line.208"></a>
-<span class="sourceLineNo">209</span>         */<a name="line.209"></a>
-<span class="sourceLineNo">210</span>        private Object readResolve() {<a name="line.210"></a>
-<span class="sourceLineNo">211</span>            return new Neuron(identifier,<a name="line.211"></a>
-<span class="sourceLineNo">212</span>                              features);<a name="line.212"></a>
-<span class="sourceLineNo">213</span>        }<a name="line.213"></a>
-<span class="sourceLineNo">214</span>    }<a name="line.214"></a>
-<span class="sourceLineNo">215</span>}<a name="line.215"></a>
+<span class="sourceLineNo">195</span>        for (int i = 0; i &lt; size; i++) {<a name="line.195"></a>
+<span class="sourceLineNo">196</span>            if (!Precision.equals(current[i], expect[i])) {<a name="line.196"></a>
+<span class="sourceLineNo">197</span>                return false;<a name="line.197"></a>
+<span class="sourceLineNo">198</span>            }<a name="line.198"></a>
+<span class="sourceLineNo">199</span>        }<a name="line.199"></a>
+<span class="sourceLineNo">200</span>        return true;<a name="line.200"></a>
+<span class="sourceLineNo">201</span>    }<a name="line.201"></a>
+<span class="sourceLineNo">202</span><a name="line.202"></a>
+<span class="sourceLineNo">203</span>    /**<a name="line.203"></a>
+<span class="sourceLineNo">204</span>     * Prevents proxy bypass.<a name="line.204"></a>
+<span class="sourceLineNo">205</span>     *<a name="line.205"></a>
+<span class="sourceLineNo">206</span>     * @param in Input stream.<a name="line.206"></a>
+<span class="sourceLineNo">207</span>     */<a name="line.207"></a>
+<span class="sourceLineNo">208</span>    private void readObject(ObjectInputStream in) {<a name="line.208"></a>
+<span class="sourceLineNo">209</span>        throw new IllegalStateException();<a name="line.209"></a>
+<span class="sourceLineNo">210</span>    }<a name="line.210"></a>
+<span class="sourceLineNo">211</span><a name="line.211"></a>
+<span class="sourceLineNo">212</span>    /**<a name="line.212"></a>
+<span class="sourceLineNo">213</span>     * Custom serialization.<a name="line.213"></a>
+<span class="sourceLineNo">214</span>     *<a name="line.214"></a>
+<span class="sourceLineNo">215</span>     * @return the proxy instance that will be actually serialized.<a name="line.215"></a>
+<span class="sourceLineNo">216</span>     */<a name="line.216"></a>
+<span class="sourceLineNo">217</span>    private Object writeReplace() {<a name="line.217"></a>
+<span class="sourceLineNo">218</span>        return new SerializationProxy(identifier,<a name="line.218"></a>
+<span class="sourceLineNo">219</span>                                      features.get());<a name="line.219"></a>
+<span class="sourceLineNo">220</span>    }<a name="line.220"></a>
+<span class="sourceLineNo">221</span><a name="line.221"></a>
+<span class="sourceLineNo">222</span>    /**<a name="line.222"></a>
+<span class="sourceLineNo">223</span>     * Serialization.<a name="line.223"></a>
+<span class="sourceLineNo">224</span>     */<a name="line.224"></a>
+<span class="sourceLineNo">225</span>    private static class SerializationProxy implements Serializable {<a name="line.225"></a>
+<span class="sourceLineNo">226</span>        /** Serializable. */<a name="line.226"></a>
+<span class="sourceLineNo">227</span>        private static final long serialVersionUID = 20130207L;<a name="line.227"></a>
+<span class="sourceLineNo">228</span>        /** Features. */<a name="line.228"></a>
+<span class="sourceLineNo">229</span>        private final double[] features;<a name="line.229"></a>
+<span class="sourceLineNo">230</span>        /** Identifier. */<a name="line.230"></a>
+<span class="sourceLineNo">231</span>        private final long identifier;<a name="line.231"></a>
+<span class="sourceLineNo">232</span><a name="line.232"></a>
+<span class="sourceLineNo">233</span>        /**<a name="line.233"></a>
+<span class="sourceLineNo">234</span>         * @param identifier Identifier.<a name="line.234"></a>
+<span class="sourceLineNo">235</span>         * @param features Features.<a name="line.235"></a>
+<span class="sourceLineNo">236</span>         */<a name="line.236"></a>
+<span class="sourceLineNo">237</span>        SerializationProxy(long identifier,<a name="line.237"></a>
+<span class="sourceLineNo">238</span>                           double[] features) {<a name="line.238"></a>
+<span class="sourceLineNo">239</span>            this.identifier = identifier;<a name="line.239"></a>
+<span class="sourceLineNo">240</span>            this.features = features;<a name="line.240"></a>
+<span class="sourceLineNo">241</span>        }<a name="line.241"></a>
+<span class="sourceLineNo">242</span><a name="line.242"></a>
+<span class="sourceLineNo">243</span>        /**<a name="line.243"></a>
+<span class="sourceLineNo">244</span>         * Custom serialization.<a name="line.244"></a>
+<span class="sourceLineNo">245</span>         *<a name="line.245"></a>
+<span class="sourceLineNo">246</span>         * @return the {@link Neuron} for which this instance is the proxy.<a name="line.246"></a>
+<span class="sourceLineNo">247</span>         */<a name="line.247"></a>
+<span class="sourceLineNo">248</span>        private Object readResolve() {<a name="line.248"></a>
+<span class="sourceLineNo">249</span>            return new Neuron(identifier,<a name="line.249"></a>
+<span class="sourceLineNo">250</span>                              features);<a name="line.250"></a>
+<span class="sourceLineNo">251</span>        }<a name="line.251"></a>
+<span class="sourceLineNo">252</span>    }<a name="line.252"></a>
+<span class="sourceLineNo">253</span>}<a name="line.253"></a>
 
 
 



Mime
View raw message