// Copyright 2015 Georg-August-Universität Göttingen, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package de.ugoe.cs.cpdp.wekaclassifier; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import de.ugoe.cs.util.console.Console; import weka.classifiers.AbstractClassifier; import weka.classifiers.Classifier; import weka.classifiers.bayes.BayesNet; import weka.classifiers.functions.Logistic; import weka.classifiers.functions.MultilayerPerceptron; import weka.classifiers.functions.RBFNetwork; import weka.classifiers.rules.DecisionTable; import weka.core.Attribute; import weka.core.DenseInstance; import weka.core.Instance; import weka.core.Instances; /** *
* Implements CODEP proposed by Panichella et al. (2014). *
* * @author Steffen Herbold */ public abstract class AbstractCODEP extends AbstractClassifier { /** * Default serialization ID. */ private static final long serialVersionUID = 1L; /** * List of classifiers that is internally used. */ private List* Creates a CODEP instance using the classications of the internal classifiers. *
* * @param instance * instance for which the CODEP instance is created * @return CODEP instance * @throws Exception * thrown if an exception occurs during classification with an internal classifer */ private Instance createInternalInstance(Instance instance) throws Exception { double[] values = new double[internalAttributes.size()]; for (int j = 0; j < internalClassifiers.size(); j++) { values[j] = internalClassifiers.get(j).classifyInstance(instance); } values[internalAttributes.size() - 1] = instance.classValue(); return new DenseInstance(1.0, values); } /** ** Sets up the attributes array. *
*/ private void setupInternalAttributes() { internalAttributes = new ArrayList<>(); for (Classifier classifier : internalClassifiers) { internalAttributes.add(new Attribute(classifier.getClass().getName())); } final ArrayList* Sets up the classifier array. *
*/ private void setupInternalClassifiers() { internalClassifiers = new ArrayList<>(6); // create training data with prediction labels // TODO ADTree missing?! internalClassifiers.add(new BayesNet()); internalClassifiers.add(new DecisionTable()); internalClassifiers.add(new Logistic()); internalClassifiers.add(new MultilayerPerceptron()); internalClassifiers.add(new RBFNetwork()); } /** ** Abstract method through which implementing classes define which classifier is used for the * CODEP. *
* * @return classifier for CODEP */ abstract protected Classifier getCodepClassifier(); }