Skip to content

Commit

Permalink
Added simple factory method to choose Linear System Solver
Browse files Browse the repository at this point in the history
  • Loading branch information
sidereus3 committed Jul 27, 2017
1 parent 48b7c6b commit 7dfa76d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
13 changes: 6 additions & 7 deletions src/main/java/krigingsPointCase/Krigings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.LinkedHashMap;
import java.util.Set;

import linearSistemSolver.SimpleLinearSystemSolverFactory;
import oms3.annotations.Author;
import oms3.annotations.Description;
import oms3.annotations.Documentation;
Expand All @@ -43,7 +44,6 @@
import org.jgrasstools.gears.libs.monitor.IJGTProgressMonitor;
import org.jgrasstools.gears.libs.monitor.LogProgressMonitor;
import org.jgrasstools.gears.utils.math.matrixes.ColumnVector;
import org.jgrasstools.gears.utils.math.matrixes.LinearSystem;
import org.jgrasstools.hortonmachine.i18n.HortonMessageHandler;
import org.opengis.feature.simple.SimpleFeature;

Expand All @@ -57,7 +57,7 @@

@Description("Ordinary kriging algorithm.")
@Documentation("Kriging.html")
@Author(name = "Giuseppe Formetta, Daniele Andreis, Silvia Franceschi, Andrea Antonello & Marialaura Bancheri")
@Author(name = "Giuseppe Formetta, Daniele Andreis, Silvia Franceschi, Andrea Antonello, Marialaura Bancheri & Francesco Serafin")
@Keywords("Kriging, Hydrology")
@Label("")
@Name("kriging")
Expand Down Expand Up @@ -161,6 +161,9 @@ public class Krigings extends JGTModel {
@In
public int regressionOrder=1;

@Description("Type of linear system solver")
@In
public String linearSystemSolverType = "default";


@Description("The hashmap withe the interpolated results")
Expand Down Expand Up @@ -294,11 +297,7 @@ public void executeKriging() throws Exception {
/*
* solve the linear system, where the result is the weight (moltiplicativeFactor).
*/
ColumnVector knownTermColumn = new ColumnVector(knownTerm);

LinearSystem linearSystem = new LinearSystem(covarianceMatrix);

ColumnVector solution = linearSystem.solve(knownTermColumn,true);
ColumnVector solution = SimpleLinearSystemSolverFactory.solve(knownTerm,covarianceMatrix, linearSystemSolverType);

double[] moltiplicativeFactor = solution.copyValues1D();

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/krigingsRasterCase/Krigings.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.media.jai.iterator.RandomIterFactory;
import javax.media.jai.iterator.WritableRandomIter;

import linearSistemSolver.SimpleLinearSystemSolverFactory;
import oms3.annotations.Author;
import oms3.annotations.Description;
import oms3.annotations.Documentation;
Expand All @@ -54,7 +55,6 @@
import org.jgrasstools.gears.utils.RegionMap;
import org.jgrasstools.gears.utils.coverage.CoverageUtilities;
import org.jgrasstools.gears.utils.math.matrixes.ColumnVector;
import org.jgrasstools.gears.utils.math.matrixes.LinearSystem;
import org.jgrasstools.hortonmachine.i18n.HortonMessageHandler;
import org.opengis.geometry.DirectPosition;
import org.opengis.geometry.MismatchedDimensionException;
Expand All @@ -70,7 +70,7 @@

@Description("Ordinary kriging algorithm.")
@Documentation("Kriging.html")
@Author(name = "Giuseppe Formetta, Daniele Andreis, Silvia Franceschi, Andrea Antonello & Marialaura Bancheri")
@Author(name = "Giuseppe Formetta, Daniele Andreis, Silvia Franceschi, Andrea Antonello, Marialaura Bancheri & Francesco Serafin")
@Keywords("Kriging, Hydrology")
@Label("")
@Name("kriging")
Expand Down Expand Up @@ -162,7 +162,11 @@ public class Krigings extends JGTModel {
@Description("Degree of polynomial regression, default is 1")
@In
public int regressionOrder=1;


@Description("Type of linear system solver")
@In
public String linearSystemSolverType = "default";


@Description("The interpolated gridded data ")
@Out
Expand Down Expand Up @@ -340,11 +344,7 @@ public void executeKriging() throws Exception {
/*
* solve the linear system, where the result is the weight (moltiplicativeFactor).
*/
ColumnVector knownTermColumn = new ColumnVector(knownTerm);

LinearSystem linearSystem = new LinearSystem(covarianceMatrix);

ColumnVector solution = linearSystem.solve(knownTermColumn,true);
ColumnVector solution = SimpleLinearSystemSolverFactory.solve(knownTerm, covarianceMatrix, linearSystemSolverType);

double[] moltiplicativeFactor = solution.copyValues1D();

Expand Down Expand Up @@ -461,7 +461,7 @@ public static double round(double value, int places) {
/**
* Gets the coordinate of each pixel of the given map.
*
* @param GridGeometry2D grid is the map
* @param grid is the map
* @return the coordinate of each point
*/
private LinkedHashMap<Integer, Coordinate> getCoordinate(GridGeometry2D grid) {
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/leaveOneOut/Krigings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@

import static org.jgrasstools.gears.libs.modules.JGTConstants.isNovalue;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

import linearSistemSolver.SimpleLinearSystemSolverFactory;
import oms3.annotations.Author;
import oms3.annotations.Description;
import oms3.annotations.Documentation;
Expand All @@ -45,7 +44,6 @@
import org.jgrasstools.gears.libs.monitor.IJGTProgressMonitor;
import org.jgrasstools.gears.libs.monitor.LogProgressMonitor;
import org.jgrasstools.gears.utils.math.matrixes.ColumnVector;
import org.jgrasstools.gears.utils.math.matrixes.LinearSystem;
import org.jgrasstools.hortonmachine.i18n.HortonMessageHandler;
import org.opengis.feature.simple.SimpleFeature;

Expand All @@ -59,7 +57,7 @@

@Description("Ordinary kriging algorithm.")
@Documentation("Kriging.html")
@Author(name = "Giuseppe Formetta, Daniele Andreis, Silvia Franceschi, Andrea Antonello & Marialaura Bancheri")
@Author(name = "Giuseppe Formetta, Daniele Andreis, Silvia Franceschi, Andrea Antonello, Marialaura Bancheri & Francesco Serafin")
@Keywords("Kriging, Hydrology")
@Label("")
@Name("kriging")
Expand Down Expand Up @@ -153,6 +151,10 @@ public class Krigings extends JGTModel {
@In
public double thresholdCorrelation;

@Description("Type of linear system solver")
@In
public String linearSystemSolverType = "default";



@Description("The hashmap withe the interpolated results")
Expand Down Expand Up @@ -298,11 +300,7 @@ public void executeKriging() throws Exception {
/*
* solve the linear system, where the result is the weight (moltiplicativeFactor).
*/
ColumnVector knownTermColumn = new ColumnVector(knownTerm);

LinearSystem linearSystem = new LinearSystem(covarianceMatrix);

ColumnVector solution = linearSystem.solve(knownTermColumn,true);
ColumnVector solution = SimpleLinearSystemSolverFactory.solve(knownTerm, covarianceMatrix, linearSystemSolverType);

double[] moltiplicativeFactor = solution.copyValues1D();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package linearSistemSolver;

import org.jgrasstools.gears.utils.math.matrixes.ColumnVector;
import org.jgrasstools.gears.utils.math.matrixes.LinearSystem;
import org.jgrasstools.gears.utils.math.matrixes.MatrixException;

public class SimpleLinearSystemSolverFactory {

public static ColumnVector solve(double[] knownTerm, double[][] covarianceMatrix, String type) throws MatrixException {

if (type.equals("default")) {
ColumnVector knownTermColumn = new ColumnVector(knownTerm);
return new LinearSystem(covarianceMatrix).solve(knownTermColumn, true);
}

return null;
}
}

0 comments on commit 7dfa76d

Please sign in to comment.