~ubuntu-branches/ubuntu/trusty/cdk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/qsar/model/R/CNNRegressionModelPredict.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2004-2007  The Chemistry Development Kit (CDK) project
 
3
 *
 
4
 *  Contact: cdk-devel@lists.sourceforge.net
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 */
 
20
 
 
21
package org.openscience.cdk.qsar.model.R;
 
22
 
 
23
/**
 
24
 * A class that wraps the return value from the R function, predict.cnn.
 
25
 *
 
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.
 
31
 * 
 
32
 *
 
33
 * @author Rajarshi Guha
 
34
 * @cdk.require r-project
 
35
 * @cdk.module qsar
 
36
 * @deprecated 
 
37
 */
 
38
public class CNNRegressionModelPredict {
 
39
    private int noutput;
 
40
    private double[][] predval;
 
41
 
 
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];
 
47
            }
 
48
        }
 
49
        return(m);
 
50
    }
 
51
 
 
52
    /**
 
53
     * Create an object to hold predictions from a previously built CNN model.
 
54
     *
 
55
     * This class should not be accessed directly
 
56
     *
 
57
     * @param noutput The number of predicted variables
 
58
     * @param values The predicted values
 
59
     */
 
60
    public CNNRegressionModelPredict(int noutput, double[] values) { 
 
61
        this.noutput = noutput;
 
62
        int nrow = values.length / noutput;
 
63
        setPredicted(vectorToMatrix(values,nrow,noutput));
 
64
    }
 
65
    /**
 
66
     * Create an object to hold predictions from a previously built CNN model.
 
67
     *
 
68
     * This class should not be accessed directly. Required for the case
 
69
     * of a single predicted value.
 
70
     *
 
71
     * @param noutput The number of predicted variables
 
72
     * @param values The predicted value
 
73
     */
 
74
    public CNNRegressionModelPredict(int noutput, double values) { 
 
75
        this.noutput = noutput;
 
76
        setPredicted(new double[][] { {values} });
 
77
    }
 
78
 
 
79
    /**
 
80
     * Get the predicted values.
 
81
     *
 
82
     * @return A 2-dimensional array containing the predicted values. The rows
 
83
     * contain the observations and the columns contain the predicted variables
 
84
     * @see #setPredicted
 
85
     */
 
86
    public double[][] getPredicted() { return(this.predval); }
 
87
    /**
 
88
     * Set the predicted values.
 
89
     *
 
90
     * @param predicted A 2-dimensional array containing the predicted values. The rows
 
91
     * contain the observations and the columns contain the predicted variables
 
92
     * @see #getPredicted
 
93
     */    
 
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];
 
99
            }
 
100
        }
 
101
    }
 
102
}
 
103
 
 
104