Permalink
Browse files

remove indadvertant colt dependencies

  • Loading branch information...
1 parent 1334e6a commit 00e6e3cb3374e7f87623cddbc214e556ec1b9aeb @JohnMount JohnMount committed Feb 23, 2012
@@ -1,52 +0,0 @@
-package com.winvector.opt.impl;
-
-import cern.colt.matrix.DoubleMatrix2D;
-import cern.colt.matrix.impl.DenseDoubleMatrix2D;
-import cern.colt.matrix.linalg.Algebra;
-import cern.colt.matrix.linalg.CholeskyDecomposition;
-
-import com.winvector.opt.def.LinearSolver;
-
-/**
- * only applicable to symmetric positive definite matrices (or their negations)
- * @author johnmount
- *
- */
-public class CholeskySolver implements LinearSolver {
- @Override
- public double[] solve(final double[][] ain, final double[] b) {
- final int dim = b.length;
- double sign = 1.0;
- for(int i=0;i<dim;++i) {
- if(Math.abs(ain[i][i])>0.0) {
- if(ain[i][i]<0.0) {
- sign = -1.0;
- }
- break;
- }
- }
- final DoubleMatrix2D ma = new DenseDoubleMatrix2D(dim,dim);
- for(int i=0;i<dim;++i) {
- for(int j=0;j<dim;++j) {
- ma.set(i,j,sign*ain[i][j]);
- }
- }
- final DoubleMatrix2D mb = new DenseDoubleMatrix2D(dim,1);
- for(int i=0;i<dim;++i) {
- mb.set(i,0,sign*b[i]);
- }
- final CholeskyDecomposition decomp = new CholeskyDecomposition(ma);
- final DoubleMatrix2D mx;
- if(decomp.isSymmetricPositiveDefinite()) {
- mx = decomp.solve(mb);
- } else {
- // fall back to direct
- mx = Algebra.ZERO.solve(ma,mb);
- }
- final double[] x = new double[dim];
- for(int i=0;i<dim;++i) {
- x[i] = mx.get(i,0);
- }
- return x;
- }
-}
@@ -1,33 +0,0 @@
-package com.winvector.opt.impl;
-
-import cern.colt.matrix.DoubleMatrix2D;
-import cern.colt.matrix.impl.DenseDoubleMatrix2D;
-import cern.colt.matrix.linalg.Algebra;
-
-import com.winvector.opt.def.LinearSolver;
-
-/**
- * @author johnmount
- *
- */
-public class DirectSolver implements LinearSolver {
- private final Algebra algebra = Algebra.DEFAULT;
-
- @Override
- public double[] solve(final double[][] a, final double[] b) {
- final int dim = b.length;
- final DoubleMatrix2D mb = new DenseDoubleMatrix2D(dim,1);
- for(int i=0;i<dim;++i) {
- final double bi = b[i];
- mb.set(i,0,bi);
- }
- final DoubleMatrix2D ab = new DenseDoubleMatrix2D(a);
- final DoubleMatrix2D mx = algebra.solve(ab,mb);
- final double[] x = new double[dim];
- for(int i=0;i<dim;++i) {
- x[i] = mx.get(i,0);
- }
- return x;
- }
-
-}
@@ -10,15 +10,16 @@
import com.winvector.opt.def.VectorOptimizer;
+
+
/**
* Newton step optimizer (set up to maximize)
* @author johnmount
*
*/
public final class Newton implements VectorOptimizer {
private final Log log = LogFactory.getLog(Newton.class);
- //private final LinearSolver lSolver = new ConjugateGradient();
- private final LinearSolver lSolver = new DirectSolver();
+ private final LinearSolver lSolver = new ConjugateGradientSolver();
private final double ridgeTerm = 1.0e-8;
private final double minGNormSQ = 1.0e-12;
private final double boxBound = 10.0; // TODO: set this
@@ -4,11 +4,11 @@
import com.winvector.opt.def.LinUtil;
import com.winvector.opt.def.LinearSolver;
-import com.winvector.opt.impl.CholeskySolver;
import com.winvector.opt.impl.ConjugateGradientSolver;
-import com.winvector.opt.impl.DirectSolver;
import com.winvector.opt.impl.SOR;
+
+
public class TestLinearSolver extends TestCase {
public void checkSoln(final double[][] a, final double[] b, final double[] x, double tol) {
@@ -21,13 +21,6 @@ public void checkSoln(final double[][] a, final double[] b, final double[] x, do
}
}
- public void testDirectSolver() {
- final double[][] a = new double[][] { {4, 1}, {1, 3} };
- final double[] b = new double[] {1, 2};
- final LinearSolver solver = new DirectSolver();
- final double[] x = solver.solve(a, b);
- checkSoln(a,b,x, 1.0e-6);
- }
public void testCGSolver() {
final double[][] a = new double[][] { {4, 1}, {1, 3} };
@@ -46,12 +39,4 @@ public void testSORSolver() {
checkSoln(a,b,x, 1.0e-4);
}
- public void testCholeskySolver() {
- final double[][] a = new double[][] { {4, 1}, {1, 3} };
- final double[] b = new double[] {1, 2};
- final LinearSolver solver = new CholeskySolver();
- final double[] x = solver.solve(a, b);
- checkSoln(a,b,x, 1.0e-4);
- }
-
}

0 comments on commit 00e6e3c

Please sign in to comment.