All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weka.classifiers.immune.clonalg.CSCA Maven / Gradle / Ivy

Go to download

Fork of the following defunct sourceforge.net project: https://sourceforge.net/projects/wekaclassalgos/

There is a newer version: 2023.2.8
Show newest version
/*
 *   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 3 of the License, or
 *   (at your option) any later version.
 *
 *   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.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see .
 */

package weka.classifiers.immune.clonalg;

import weka.classifiers.AbstractClassifier;
import weka.core.Capabilities;
import weka.core.Capabilities.Capability;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.Option;
import weka.core.Utils;

import java.util.Enumeration;
import java.util.LinkedList;
import java.util.Vector;

/**
 * Type: CLONALG 
* Date: 19/01/2005
*
*

* Description: * * @author Jason Brownlee */ public class CSCA extends AbstractClassifier { // user paramters protected int initialPopulationSize; // S protected int totalGenerations; // G protected long seed; // r protected double clonalScaleFactor; // a protected double minimumFitnessThreshold; // E protected int kNN; // k protected int numPartitions; // p protected CSCAAlgorithm algorithm; protected String trainingSummary; private final static String[] PARAMETERS = { "S", "G", "r", "a", "E", "k", "p" }; private final static String[] DESCRIPTIONS = { "Initial population size (S).", "Total generations (G).", "Random number generator seed (r).", "Clonal scale factor (Alpha).", "Minimum fitness threshold (Eta).", "k-Nearest Neighbours (k).", "Total Partitions (p)." }; public CSCA() { // set defaults initialPopulationSize = 50; totalGenerations = 5; seed = 1; clonalScaleFactor = 1.0; minimumFitnessThreshold = 1.0; kNN = 1; numPartitions = 1; // TODO: should not be true by default m_Debug = true; } /** * Returns the Capabilities of this classifier. * * @return the capabilities of this object * @see Capabilities */ @Override public Capabilities getCapabilities() { Capabilities result = super.getCapabilities(); result.disableAll(); // attributes result.enable(Capability.NUMERIC_ATTRIBUTES); result.enable(Capability.DATE_ATTRIBUTES); result.enable(Capability.NOMINAL_ATTRIBUTES); // class result.enable(Capability.NOMINAL_CLASS); result.enable(Capability.MISSING_CLASS_VALUES); result.setMinimumNumberInstances(1); return result; } public void buildClassifier(Instances data) throws Exception { Instances trainingInstances = new Instances(data); trainingInstances.deleteWithMissingClass(); getCapabilities().testWithFail(trainingInstances); // validation performParameterValidation(trainingInstances); // construct trainer algorithm = new CSCAAlgorithm( initialPopulationSize, totalGenerations, seed, clonalScaleFactor, minimumFitnessThreshold, kNN, numPartitions, m_Debug ); // train algorithm.train(trainingInstances); // training summary trainingSummary = algorithm.getTrainingSummary(trainingInstances); } protected void performParameterValidation(Instances trainingInstances) throws Exception { if (numPartitions >= trainingInstances.numInstances()) { throw new Exception("Total partitions is more than or equal to the number of training instances."); } if (numPartitions <= 0) { throw new Exception("Total partitions must be > 0 and < total training instances."); } if (initialPopulationSize > trainingInstances.numInstances()) { throw new Exception("The initial population size is larger than the number of training instances."); } if (initialPopulationSize <= 0) { throw new Exception("Initial population size must be > 0 and <= total training instances."); } } public double classifyInstance(Instance instance) throws Exception { if (algorithm == null) { throw new Exception("Algorithm has not been prepared."); } return algorithm.classify(instance); } public String toString() { StringBuffer buffer = new StringBuffer(1000); buffer.append("Clonal Selection Classification Algorithm (CSCA) v1.0.\n"); if (trainingSummary != null) { buffer.append("\n"); buffer.append(trainingSummary); } return buffer.toString(); } public String globalInfo() { StringBuffer buffer = new StringBuffer(1000); buffer.append(toString()); buffer.append("\n\n"); buffer.append("Jason Brownlee. " + "[Technical Report]. " + "Clonal Selection Theory & CLONAG - The Clonal Selection Classification Algorithm (CSCA). " + "Victoria, Australia: Centre for Intelligent Systems and Complex Processes (CISCP), " + "Faculty of Information and Communication Technologies (ICT), " + "Swinburne University of Technology; " + "2005 Jan; " + "Technical Report ID: 2-01.\n"); buffer.append("\\n"); buffer.append("http://www.it.swin.edu.au/centres/ciscp/ais/\n"); return buffer.toString(); } public Enumeration listOptions() { Vector





© 2015 - 2024 Weber Informatics LLC | Privacy Policy