001    /*
002     * Copyright (C) 2008-2009 Holger Arndt, A. Naegele and M. Bundschus
003     *
004     * This file is part of the Java Data Mining Package (JDMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * JDMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * JDMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with JDMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.jdmp.core.dataset.wrappers;
025    
026    import org.jdmp.core.dataset.RegressionDataSet;
027    import org.jdmp.core.sample.Sample;
028    import org.ujmp.core.Matrix;
029    import org.ujmp.core.coordinates.Coordinates;
030    import org.ujmp.core.doublematrix.stub.AbstractDenseDoubleMatrix2D;
031    import org.ujmp.core.exceptions.MatrixException;
032    import org.ujmp.core.interfaces.Wrapper;
033    
034    public class DataSetPredictedMatrixWrapper extends AbstractDenseDoubleMatrix2D implements
035                    Wrapper<RegressionDataSet> {
036            private static final long serialVersionUID = 5197402551973462998L;
037    
038            private RegressionDataSet dataSet = null;
039    
040            public DataSetPredictedMatrixWrapper(RegressionDataSet ds) {
041                    this.dataSet = ds;
042            }
043    
044            public long[] getSize() {
045                    if (dataSet.getSamples().isEmpty()) {
046                            return Coordinates.ZERO2D;
047                    }
048                    Sample p = dataSet.getSamples().getElementAt(0);
049                    if (p == null) {
050                            return Coordinates.ZERO2D;
051                    }
052                    Matrix output = p.getMatrix(Sample.PREDICTED);
053                    if (output != null) {
054                            return new long[] { dataSet.getSamples().getSize(), output.getValueCount() };
055                    } else {
056                            return Coordinates.ZERO2D;
057                    }
058    
059            }
060    
061            public double getDouble(long row, long column) throws MatrixException {
062                    return getDouble((int) row, (int) column);
063            }
064    
065            public void setDouble(double value, long row, long column) throws MatrixException {
066                    setDouble(value, (int) row, (int) column);
067            }
068    
069            public double getDouble(int row, int column) throws MatrixException {
070                    Sample p = dataSet.getSamples().getElementAt(row);
071                    if (p != null) {
072                            if (p.getMatrix(Sample.PREDICTED) != null) {
073                                    long r = column / p.getMatrix(Sample.PREDICTED).getColumnCount();
074                                    long c = column % p.getMatrix(Sample.PREDICTED).getColumnCount();
075                                    return p.getMatrix(Sample.PREDICTED).getAsDouble(r, c);
076                            }
077                    }
078                    return 0.0;
079            }
080    
081            public void setDouble(double value, int row, int column) throws MatrixException {
082                    Sample p = dataSet.getSamples().getElementAt(row);
083                    if (p != null) {
084                            if (p.getMatrix(Sample.PREDICTED) != null) {
085                                    long r = column / p.getMatrix(Sample.PREDICTED).getColumnCount();
086                                    long c = column % p.getMatrix(Sample.PREDICTED).getColumnCount();
087                                    p.getMatrix(Sample.PREDICTED).setAsDouble(value, r, c);
088                            }
089                    }
090            }
091    
092            public RegressionDataSet getWrappedObject() {
093                    return dataSet;
094            }
095    
096            public void setWrappedObject(RegressionDataSet object) {
097                    this.dataSet = object;
098            }
099    
100    }