📄 linearregressionwmodeltest.java
字号:
/* $RCSfile$
* $Author: miguelrojasch $
* $Date: 2006-05-11 14:25:07 +0200 (Do, 11 Mai 2006) $
* $Revision: 6221 $
*
* Copyright (C) 2004-2007 Miguel Rojas <miguel.rojas@uni-koeln.de>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.test.qsar.model.weka;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.qsar.model.QSARModelException;
import org.openscience.cdk.qsar.model.weka.LinearRegressionWModel;
import org.openscience.cdk.test.CDKTestCase;
/**
* TestSuite that runs a test for the LinearRegressionWModel
*
* @author Miguel Rojas
* @cdk.module test-qsar
*/
public class LinearRegressionWModelTest extends CDKTestCase {
/**
* Constructor of the LinearRegressionModelTest object
*/
public LinearRegressionWModelTest() {
}
/**
* A unit test suite for JUnit
*
* @return The test suite
*/
public static Test suite() {
return new TestSuite(LinearRegressionWModelTest.class);
}
/**
* @throws CDKException
* @throws Exception
* @throws QSARModelException
*/
public void testLinearRegressionWModel1() throws CDKException, java.lang.Exception, QSARModelException {
double[][] x = {{1, 1}, {3, 3}, {4, 4}, {6, 6}};
Double[][] xD = new Double[x.length][x[0].length];
for (int i = 0; i < xD.length; i++)
for (int j = 0; j < xD[i].length; j++)
xD[i][j] = new Double(x[i][j]);
double[] y = {0, 2, 3, 5};
Double[] yD = new Double[y.length];
for (int i = 0; i < yD.length; i++)
yD[i] = new Double(y[i]);
LinearRegressionWModel lrm = new LinearRegressionWModel(yD, xD);
String[] options = new String[4];
options[0] = "-U";
options[1] = "0";
options[2] = "-R";
options[3] = "0.0001";
lrm.setOptions(options);
lrm.build();
/* Test predictions */
Double[][] newx = {
{new Double(2), new Double(2)},
{new Double(5), new Double(5)},
};
lrm.setParameters(newx);
lrm.predict();
Double[] preds = (Double[]) lrm.getPredictPredicted();
assertEquals(1.0, (preds[0]).doubleValue(), 0.001);
assertEquals(4.0, (preds[1]).doubleValue(), 0.001);
}
/**
* @throws CDKException
* @throws Exception
* @throws QSARModelException
*/
public void testLinearRegressionWModel2() throws CDKException, java.lang.Exception, QSARModelException {
LinearRegressionWModel lrm = new LinearRegressionWModel("data/arff/Table1.arff");
String[] options = new String[4];
options[0] = "-U";
options[1] = "0";
options[2] = "-R";
options[3] = "0.00000008";
lrm.setOptions(options);
lrm.build();
lrm.setParametersCDK("data/arff/Table2.arff");
lrm.predict();
Double[] result = (Double[]) lrm.getPredictPredicted();
assertNotNull(result);
assertEquals(1.0, (result[0]).doubleValue(), 0.001);
assertEquals(4.0, (result[1]).doubleValue(), 0.001);
}
// /**
// *
// * @throws CDKException
// * @throws java.lang.Exception
// * @throws QSARModelException
// */
// public void testLinearRegressionWModel3() throws CDKException, java.lang.Exception, QSARModelException {
//
// double[][] x = {{ 5.33029143313, 8.13257437501, 2.66720308462 },
// { 3.29906147519, 5.06835102093, 6.47319431067 },
// { 5.69553153292, 5.88043843898, 9.73312992111 },
// { 5.29194559083, 6.78243188133, 3.2602449344 },
// { 6.18105762768, 3.36588488672, 3.94539328809 },
// { 1.32223357975, 8.78797039033, 7.77485740688 },
// { 0.391740629966, 5.08060997023, 8.28722389016 },
// { 4.27475126706, 8.52015977633, 7.21468545649 },
// { 7.14131409262, 8.67086866827, 7.64228671009 },
// { 8.55502719447, 5.25013245421, 5.73240025988 },
// { 5.31791067667, 7.99313789208, 1.64835209014 },
// { 9.03149835466, 1.94042287241, 9.28020345543 },
// { 0.925468187342, 4.97155215507, 7.69457858258 },
// { 9.16182426614, 4.74534182996, 6.58111071706 },
// { 1.15220637861, 1.78078924823, 2.24407287943 },
// { 9.24209878847, 7.87658524713, 2.38732162601 },
// { 8.50715035908, 9.16453417058, 0.618727514944 },
// { 5.84019865932, 5.20208546615, 6.61838858253 },
// { 3.76256505014, 0.329738943471, 0.874419640166 },
// { 9.96004184517, 9.14019090437, 4.90929645109 },
// { 4.44743194213, 3.95642974577, 7.62629150218 },
// { 1.24177865105, 1.48660423923, 1.20830798956 },
// { 8.35590316383, 1.14743031542, 6.29868134513 },
// { 6.12876561357, 4.63929392357, 5.87722199543 },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -