sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1654665 - in /sis/branches/JDK7: ./ core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ core/sis-utility/src/main/java/org/apache/sis/math/ core/sis-utility/src/main/java/org/apache/sis/util/resources/
Date Sun, 25 Jan 2015 15:41:38 GMT
Author: desruisseaux
Date: Sun Jan 25 15:41:38 2015
New Revision: 1654665

URL: http://svn.apache.org/r1654665
Log:
Merge from the JDK8 branch.

Modified:
    sis/branches/JDK7/   (props changed)
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/Line.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/Plane.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties

Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Jan 25 15:41:38 2015
@@ -1,4 +1,4 @@
 /sis/branches/Android:1430670-1480699
 /sis/branches/JDK6:1394913-1508480
-/sis/branches/JDK8:1584960-1654423
+/sis/branches/JDK8:1584960-1654664
 /sis/trunk:1394364-1508466,1519089-1519674

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java?rev=1654665&r1=1654664&r2=1654665&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
[UTF-8] Sun Jan 25 15:41:38 2015
@@ -16,14 +16,17 @@
  */
 package org.apache.sis.referencing.operation.builder;
 
+import java.io.IOException;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.geometry.MismatchedDimensionException;
+import org.apache.sis.io.TableAppender;
 import org.apache.sis.math.Line;
 import org.apache.sis.math.Plane;
 import org.apache.sis.referencing.operation.matrix.Matrices;
 import org.apache.sis.referencing.operation.matrix.MatrixSIS;
 import org.apache.sis.referencing.operation.transform.LinearTransform;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
+import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Classes;
@@ -66,6 +69,11 @@ public class LinearTransformBuilder {
     private double[][] targets;
 
     /**
+     * The transform created by the last call to {@link #create()}.
+     */
+    private LinearTransform transform;
+
+    /**
      * An estimation of the Pearson correlation coefficient for each target dimension.
      * This is {@code null} if not yet specified.
      */
@@ -116,6 +124,7 @@ public class LinearTransformBuilder {
         } else {
             sources = null;
         }
+        transform   = null;
         correlation = null;
     }
 
@@ -134,6 +143,7 @@ public class LinearTransformBuilder {
         } else {
             targets = null;
         }
+        transform   = null;
         correlation = null;
     }
 
@@ -149,40 +159,43 @@ public class LinearTransformBuilder {
      * @return The fitted linear transform.
      */
     public LinearTransform create() {
-        final double[][] sources = this.sources;  // Protect from changes.
-        final double[][] targets = this.targets;
-        if (sources == null || targets == null) {
-            throw new IllegalStateException(Errors.format(
-                    Errors.Keys.MissingValueForProperty_1, (sources == null) ? "sources"
: "targets"));
-        }
-        final int sourceDim = sources.length;
-        final int targetDim = targets.length;
-        correlation = new double[targetDim];
-        final MatrixSIS matrix = Matrices.createZero(targetDim + 1, sourceDim + 1);
-        matrix.setElement(targetDim, sourceDim, 1);
-        switch (sourceDim) {
-            case 1: {
-                final Line line = new Line();
-                for (int j=0; j<targets.length; j++) {
-                    correlation[j] = line.fit(sources[0], targets[j]);
-                    matrix.setElement(j, 0, line.slope());
-                    matrix.setElement(j, 1, line.y0());
-                }
-                break;
+        if (transform == null) {
+            final double[][] sources = this.sources;  // Protect from changes.
+            final double[][] targets = this.targets;
+            if (sources == null || targets == null) {
+                throw new IllegalStateException(Errors.format(
+                        Errors.Keys.MissingValueForProperty_1, (sources == null) ? "sources"
: "targets"));
             }
-            case 2: {
-                final Plane plan = new Plane();
-                for (int j=0; j<targets.length; j++) {
-                    correlation[j] = plan.fit(sources[0], sources[1], targets[j]);
-                    matrix.setElement(j, 0, plan.slopeX());
-                    matrix.setElement(j, 1, plan.slopeY());
-                    matrix.setElement(j, 2, plan.z0());
+            final int sourceDim = sources.length;
+            final int targetDim = targets.length;
+            correlation = new double[targetDim];
+            final MatrixSIS matrix = Matrices.createZero(targetDim + 1, sourceDim + 1);
+            matrix.setElement(targetDim, sourceDim, 1);
+            switch (sourceDim) {
+                case 1: {
+                    final Line line = new Line();
+                    for (int j=0; j<targets.length; j++) {
+                        correlation[j] = line.fit(sources[0], targets[j]);
+                        matrix.setElement(j, 0, line.slope());
+                        matrix.setElement(j, 1, line.y0());
+                    }
+                    break;
                 }
-                break;
+                case 2: {
+                    final Plane plan = new Plane();
+                    for (int j=0; j<targets.length; j++) {
+                        correlation[j] = plan.fit(sources[0], sources[1], targets[j]);
+                        matrix.setElement(j, 0, plan.slopeX());
+                        matrix.setElement(j, 1, plan.slopeY());
+                        matrix.setElement(j, 2, plan.z0());
+                    }
+                    break;
+                }
+                default: throw new AssertionError(sourceDim); // Should have been verified
by setSourcePoints(…) method.
             }
-            default: throw new AssertionError(sourceDim); // Should have been verified by
setSourcePoints(…) method.
+            transform = MathTransforms.linear(matrix);
         }
-        return MathTransforms.linear(matrix);
+        return transform;
     }
 
     /**
@@ -207,14 +220,27 @@ public class LinearTransformBuilder {
         final StringBuilder buffer = new StringBuilder(Classes.getShortClassName(this)).append('[');
         if (sources != null) {
             buffer.append(sources[0].length).append(" points");
-            if (correlation != null) {
-                String separator = ", correlation is ";
-                for (final double c : correlation) {
-                    buffer.append(separator).append((float) c);
-                    separator = ", ";
-                }
+        }
+        buffer.append(']');
+        if (transform != null) {
+            final String lineSeparator = System.lineSeparator();
+            buffer.append(':').append(lineSeparator);
+            final TableAppender table = new TableAppender(buffer, " ");
+            table.setMultiLinesCells(true);
+            table.append(Matrices.toString(transform.getMatrix()));
+            table.nextColumn();
+            table.append(lineSeparator);
+            table.append("  ");
+            table.append(Vocabulary.format(Vocabulary.Keys.Correlation));
+            table.append(" =");
+            table.nextColumn();
+            table.append(Matrices.create(correlation.length, 1, correlation).toString());
+            try {
+                table.flush();
+            } catch (IOException e) {
+                throw new AssertionError(e); // Should never happen since we wrote into a
StringBuilder.
             }
         }
-        return buffer.append(']').toString();
+        return buffer.toString();
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/Line.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/Line.java?rev=1654665&r1=1654664&r2=1654665&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/Line.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/Line.java [UTF-8]
Sun Jan 25 15:41:38 2015
@@ -224,7 +224,7 @@ public class Line implements Cloneable,
      *
      * @param x Vector of <var>x</var> values (independent variable).
      * @param y Vector of <var>y</var> values (dependent variable).
-     * @return Estimation of the correlation coefficient. The closer this coefficient is
to 1, the better the fit.
+     * @return Estimation of the correlation coefficient. The closer this coefficient is
to +1 or -1, the better the fit.
      *
      * @throws IllegalArgumentException if <var>x</var> and <var>y</var>
do not have the same length.
      */
@@ -242,7 +242,7 @@ public class Line implements Cloneable,
      * {@link Double#NaN} ordinate values are ignored.</p>
      *
      * @param  points The two-dimensional points.
-     * @return Estimation of the correlation coefficient. The closer this coefficient is
to 1, the better the fit.
+     * @return Estimation of the correlation coefficient. The closer this coefficient is
to +1 or -1, the better the fit.
      * @throws MismatchedDimensionException if a point is not two-dimensional.
      */
     public double fit(final Iterable<? extends DirectPosition> points) {

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/Plane.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/Plane.java?rev=1654665&r1=1654664&r2=1654665&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/Plane.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/math/Plane.java [UTF-8]
Sun Jan 25 15:41:38 2015
@@ -185,7 +185,7 @@ public class Plane implements Cloneable,
      * Computes the <var>z</var> value for the specified (<var>x</var>,<var>y</var>)
point.
      * The <var>z</var> value is computed using the following equation:
      *
-     * <blockquote>z(x,y) = {@linkplain #z0() z₀} + {@linkplain #slopeX() sx}⋅x
+ {@linkplain #slopeY() sy}⋅y</blockquote>
+     * <blockquote>z(x,y) = {@linkplain #slopeX() sx}⋅x + {@linkplain #slopeY() sy}⋅y
+ {@linkplain #z0() z₀}</blockquote>
      *
      * @param x The <var>x</var> value where to compute <var>z</var>.
      * @param y The <var>y</var> value where to compute <var>z</var>.
@@ -373,7 +373,7 @@ public class Plane implements Cloneable,
         setEquation(detectZeroSx ? 0 : sx.value,
                     detectZeroSy ? 0 : sy.value,
                     detectZeroZ0 ? 0 : z0.value);
-        return sum_dsz / sqrt(sum_ds2 * sum_dz2);
+        return Math.min(sum_dsz / sqrt(sum_ds2 * sum_dz2), 1);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java?rev=1654665&r1=1654664&r2=1654665&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
[UTF-8] Sun Jan 25 15:41:38 2015
@@ -121,6 +121,11 @@ public final class Vocabulary extends In
         public static final short ConstantPressureSurface = 19;
 
         /**
+         * Correlation
+         */
+        public static final short Correlation = 83;
+
+        /**
          * Current date and time
          */
         public static final short CurrentDateTime = 10;

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties?rev=1654665&r1=1654664&r2=1654665&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
[ISO-8859-1] Sun Jan 25 15:41:38 2015
@@ -27,6 +27,7 @@ Classpath               = Classpath
 Code_1                  = {0} code
 Commands                = Commands
 ConstantPressureSurface = Constant pressure surface
+Correlation             = Correlation
 CurrentDateTime         = Current date and time
 CurrentDirectory        = Current directory
 CycleOmitted            = Cycle omitted

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties?rev=1654665&r1=1654664&r2=1654665&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
[ISO-8859-1] Sun Jan 25 15:41:38 2015
@@ -27,6 +27,7 @@ Classpath               = Chemin de clas
 Code_1                  = Code {0}
 Commands                = Commandes
 ConstantPressureSurface = Surface \u00e0 pression constante
+Correlation             = Corr\u00e9lation
 CurrentDateTime         = Date et heure courantes
 CurrentDirectory        = R\u00e9pertoire courant
 CycleOmitted            = Cycle omit



Mime
View raw message