package ac.essex.ooechs.ecj.jasmine.nodes.classification;

import ac.essex.ooechs.ecj.jasmine.problems.JasmineClassificationProblemDRS;

/**
 * <p/>
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version,
 * provided that any use properly credits the author.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details at http://www.gnu.org
 * </p>
 *
 * @author Olly Oechsle, University of Essex, Date: 14-Jun-2007
 * @version 1.0
 */
public class TrainingData {

    protected double[] features;

    protected int classID;

    public TrainingData(String CSV, Normaliser n) {

        features = new double[FeatureERC.NUM_FEATURES];

        String[] data = CSV.split(JasmineClassificationProblemDRS.SEPARATOR);

        if (data.length != FeatureERC.NUM_FEATURES + 1)  {
            throw new RuntimeException("Number of features is incorrect. Should be: " + (data.length - 1));
        }

        for (int i = 0; i < FeatureERC.NUM_FEATURES; i++) {
            features[i] = Double.parseDouble(data[i]);
            if (n != null) n.addData(i, features[i]);
        }

        classID = Integer.parseInt(data[data.length - 1]);

    }

    public void normalise(Normaliser n) {
        for (int i = 0; i < FeatureERC.NUM_FEATURES; i++) {
            features[i] = features[i] / n.getNormalisationFactor(i);
        }
    }

    public int getClassID() {
        return classID;
    }

    public double[] getFeatures() {
        return features;
    }

}
