1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.math3.optimization.general; 19 20 import java.io.IOException; 21 22 import org.apache.commons.math3.exception.ConvergenceException; 23 import org.apache.commons.math3.exception.TooManyEvaluationsException; 24 import org.apache.commons.math3.optimization.SimpleVectorValueChecker; 25 import org.junit.Test; 26 27 /** 28 * <p>Some of the unit tests are re-implementations of the MINPACK <a 29 * href="http://www.netlib.org/minpack/ex/file17">file17</a> and <a 30 * href="http://www.netlib.org/minpack/ex/file22">file22</a> test files. 31 * The redistribution policy for MINPACK is available <a 32 * href="http://www.netlib.org/minpack/disclaimer">here</a>, for 33 * convenience, it is reproduced below.</p> 34 35 * <table border="0" width="80%" cellpadding="10" align="center" bgcolor="#E0E0E0"> 36 * <tr><td> 37 * Minpack Copyright Notice (1999) University of Chicago. 38 * All rights reserved 39 * </td></tr> 40 * <tr><td> 41 * Redistribution and use in source and binary forms, with or without 42 * modification, are permitted provided that the following conditions 43 * are met: 44 * <ol> 45 * <li>Redistributions of source code must retain the above copyright 46 * notice, this list of conditions and the following disclaimer.</li> 47 * <li>Redistributions in binary form must reproduce the above 48 * copyright notice, this list of conditions and the following 49 * disclaimer in the documentation and/or other materials provided 50 * with the distribution.</li> 51 * <li>The end-user documentation included with the redistribution, if any, 52 * must include the following acknowledgment: 53 * <code>This product includes software developed by the University of 54 * Chicago, as Operator of Argonne National Laboratory.</code> 55 * Alternately, this acknowledgment may appear in the software itself, 56 * if and wherever such third-party acknowledgments normally appear.</li> 57 * <li><strong>WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" 58 * WITHOUT WARRANTY OF ANY KIND. THE COPYRIGHT HOLDER, THE 59 * UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND 60 * THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR 61 * IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES 62 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE 63 * OR NON-INFRINGEMENT, (2) DO NOT ASSUME ANY LEGAL LIABILITY 64 * OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR 65 * USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF 66 * THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4) 67 * DO NOT WARRANT THAT THE SOFTWARE WILL FUNCTION 68 * UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT ANY ERRORS WILL 69 * BE CORRECTED.</strong></li> 70 * <li><strong>LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT 71 * HOLDER, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF 72 * ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT, 73 * INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF 74 * ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF 75 * PROFITS OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER 76 * SUCH LIABILITY IS ASSERTED ON THE BASIS OF CONTRACT, TORT 77 * (INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE, 78 * EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE 79 * POSSIBILITY OF SUCH LOSS OR DAMAGES.</strong></li> 80 * <ol></td></tr> 81 * </table> 82 83 * @author Argonne National Laboratory. MINPACK project. March 1980 (original fortran minpack tests) 84 * @author Burton S. Garbow (original fortran minpack tests) 85 * @author Kenneth E. Hillstrom (original fortran minpack tests) 86 * @author Jorge J. More (original fortran minpack tests) 87 * @author Luc Maisonobe (non-minpack tests and minpack tests Java translation) 88 */ 89 @Deprecated 90 public class GaussNewtonOptimizerTest 91 extends AbstractLeastSquaresOptimizerAbstractTest { 92 93 @Override createOptimizer()94 public AbstractLeastSquaresOptimizer createOptimizer() { 95 return new GaussNewtonOptimizer(new SimpleVectorValueChecker(1.0e-6, 1.0e-6)); 96 } 97 98 @Override 99 @Test(expected = ConvergenceException.class) testMoreEstimatedParametersSimple()100 public void testMoreEstimatedParametersSimple() { 101 /* 102 * Exception is expected with this optimizer 103 */ 104 super.testMoreEstimatedParametersSimple(); 105 } 106 107 @Override 108 @Test(expected=ConvergenceException.class) testMoreEstimatedParametersUnsorted()109 public void testMoreEstimatedParametersUnsorted() { 110 /* 111 * Exception is expected with this optimizer 112 */ 113 super.testMoreEstimatedParametersUnsorted(); 114 } 115 116 @Test(expected=TooManyEvaluationsException.class) testMaxEvaluations()117 public void testMaxEvaluations() throws Exception { 118 CircleVectorial circle = new CircleVectorial(); 119 circle.addPoint( 30.0, 68.0); 120 circle.addPoint( 50.0, -6.0); 121 circle.addPoint(110.0, -20.0); 122 circle.addPoint( 35.0, 15.0); 123 circle.addPoint( 45.0, 97.0); 124 125 GaussNewtonOptimizer optimizer 126 = new GaussNewtonOptimizer(new SimpleVectorValueChecker(1.0e-30, 1.0e-30)); 127 128 optimizer.optimize(100, circle, new double[] { 0, 0, 0, 0, 0 }, 129 new double[] { 1, 1, 1, 1, 1 }, 130 new double[] { 98.680, 47.345 }); 131 } 132 133 @Override 134 @Test(expected=ConvergenceException.class) testCircleFittingBadInit()135 public void testCircleFittingBadInit() { 136 /* 137 * This test does not converge with this optimizer. 138 */ 139 super.testCircleFittingBadInit(); 140 } 141 142 @Override 143 @Test(expected = ConvergenceException.class) testHahn1()144 public void testHahn1() 145 throws IOException { 146 /* 147 * TODO This test leads to a singular problem with the Gauss-Newton 148 * optimizer. This should be inquired. 149 */ 150 super.testHahn1(); 151 } 152 } 153