2
* Copyright (C) 2004-2007 The Chemistry Development Kit (CDK) project
4
* Contact: cdk-devel@lists.sourceforge.net
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public License
8
* as published by the Free Software Foundation; either version 2.1
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
package org.openscience.cdk.qsar.model.R;
24
* A class that wraps the return value from the R function, predict.cnn.
26
* This is an internal class used by R to return the result of
27
* the call to <a href="http://stat.ethz.ch/R-manual/R-patched/library/nnet/html/predict.nnet.html">predict.nnet</a>.
28
* As a result it should not be instantiated by the user. The actual modeling
29
* class, <code>CNNRegressionModel</code>, provides acess to the various
30
* fields of this object.
33
* @author Rajarshi Guha
34
* @cdk.require r-project
38
public class CNNRegressionModelPredict {
40
private double[][] predval;
42
private double[][] vectorToMatrix(double[] v, int nrow, int ncol) {
43
double[][] m = new double[nrow][ncol];
44
for (int i = 0; i < ncol; i++) {
45
for (int j = 0; j < nrow; j++) {
46
m[j][i] = v[j + i*nrow];
53
* Create an object to hold predictions from a previously built CNN model.
55
* This class should not be accessed directly
57
* @param noutput The number of predicted variables
58
* @param values The predicted values
60
public CNNRegressionModelPredict(int noutput, double[] values) {
61
this.noutput = noutput;
62
int nrow = values.length / noutput;
63
setPredicted(vectorToMatrix(values,nrow,noutput));
66
* Create an object to hold predictions from a previously built CNN model.
68
* This class should not be accessed directly. Required for the case
69
* of a single predicted value.
71
* @param noutput The number of predicted variables
72
* @param values The predicted value
74
public CNNRegressionModelPredict(int noutput, double values) {
75
this.noutput = noutput;
76
setPredicted(new double[][] { {values} });
80
* Get the predicted values.
82
* @return A 2-dimensional array containing the predicted values. The rows
83
* contain the observations and the columns contain the predicted variables
86
public double[][] getPredicted() { return(this.predval); }
88
* Set the predicted values.
90
* @param predicted A 2-dimensional array containing the predicted values. The rows
91
* contain the observations and the columns contain the predicted variables
94
public void setPredicted(double[][] predicted) {
95
this.predval = new double[predicted.length][this.noutput];
96
for (int i = 0; i < predicted.length; i++) {
97
for (int j = 0; j < this.noutput; j++) {
98
this.predval[i][j] = predicted[i][j];