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 DataSetTargetMatrixWrapper extends AbstractDenseDoubleMatrix2D implements
035 Wrapper<RegressionDataSet> {
036 private static final long serialVersionUID = 5906451226992160036L;
037
038 private RegressionDataSet dataSet = null;
039
040 public DataSetTargetMatrixWrapper(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 m = p.getMatrix(Sample.TARGET);
053 if (m == null) {
054 return Coordinates.ZERO2D;
055 }
056 return new long[] { dataSet.getSamples().getSize(), m.getColumnCount() };
057 }
058
059 public double getDouble(long row, long column) throws MatrixException {
060 return getDouble((int) row, (int) column);
061 }
062
063 public void setDouble(double value, long row, long column) throws MatrixException {
064 setDouble(value, (int) row, (int) column);
065 }
066
067 public double getDouble(int row, int column) throws MatrixException {
068 Sample p = dataSet.getSamples().getElementAt(row);
069 if (p != null) {
070 return p.getMatrix(Sample.TARGET).getAsDouble(0, column);
071 } else {
072 return 0.0;
073 }
074 }
075
076 public void setDouble(double value, int row, int column) throws MatrixException {
077 Sample p = dataSet.getSamples().getElementAt(row);
078 if (p != null) {
079 p.getMatrix(Sample.TARGET).setAsDouble(value, 0, column);
080 }
081 }
082
083 public RegressionDataSet getWrappedObject() {
084 return dataSet;
085 }
086
087 public void setWrappedObject(RegressionDataSet object) {
088 this.dataSet = object;
089 }
090
091 }