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;
025
026 import org.jdmp.core.dataset.wrappers.DataSetInputMatrixWrapper;
027 import org.jdmp.core.sample.Sample;
028 import org.jdmp.core.variable.Variable;
029 import org.jdmp.core.variable.VariableFactory;
030 import org.ujmp.core.Matrix;
031 import org.ujmp.core.calculation.Calculation.Ret;
032 import org.ujmp.core.exceptions.MatrixException;
033
034 public class DefaultDataSet extends AbstractDataSet {
035 private static final long serialVersionUID = -2887879051530049677L;
036
037 public static final String INPUT = "Input";
038
039 public DefaultDataSet() {
040 super();
041 Matrix inputMatrix = new DataSetInputMatrixWrapper(this);
042 Variable input = VariableFactory.labeledVariable("Input");
043 input.addMatrix(inputMatrix);
044 getVariables().put(INPUT, input);
045 }
046
047 public final Variable getInputVariable() {
048 return getVariables().get(INPUT);
049 }
050
051 public final void standardize(int dimension) throws MatrixException {
052 getInputVariable().getMatrix().standardize(Ret.ORIG, dimension, true);
053 }
054
055 public final void center(int dimension) throws MatrixException {
056 getInputVariable().getMatrix().center(Ret.ORIG, dimension, true);
057 }
058
059 public void addMissingValues(int dimension, double percentMissing) throws MatrixException {
060 getInputVariable().getMatrix().addMissing(Ret.ORIG, dimension, percentMissing);
061 }
062
063 public Matrix getInputMatrix() {
064 return getInputVariable().getMatrix();
065 }
066
067 public int getFeatureCount() {
068 Matrix m = getInputVariable().getMatrix();
069 if (m == null) {
070 return 0;
071 } else {
072 return (int) m.getColumnCount();
073 }
074 }
075
076 @Override
077 public DefaultDataSet clone() {
078 DefaultDataSet ds = null;
079 try {
080 ds = this.getClass().newInstance();
081 } catch (Exception e) {
082 e.printStackTrace();
083 }
084 for (Sample s : getSamples()) {
085 ds.getSamples().add(s.clone());
086 }
087 return ds;
088 }
089
090 }