Example usage for weka.core Instances add

List of usage examples for weka.core Instances add

Introduction

In this page you can find the example usage for weka.core Instances add.

Prototype

@Override
public boolean add(Instance instance) 

Source Link

Document

Adds one instance to the end of the set.

Usage

From source file:gnusmail.MainManager.java

License:Open Source License

/** Connects to URL
 * @throws Exception *//*from ww  w . j  a v  a 2 s. c om*/
//TODO no deberia estar aqui
/*private void connect(String url) throws MessagingException {
   if (url != null) {
 try {
    connection = new Connection(url);
    // connection.login(url);
    connection.login();
    System.out.println("Connected!");
 } catch (Exception e) {
    e.printStackTrace();
    System.out.println("Unable to connect to the requested host!");
 }
 if (connection.getFolder() != null) {
    connection.show_mens();
 }
   } else {
 if (connection == null) {
    connection = new Connection();
 }
   }
}*/

/*public void mailsInFolder() {
   try {
 connection.showMessages("INBOX");
   } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
   }
}*/

/*public void openMail(int mail_id) {
   try {
 connection.readMail(mail_id);
   } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
   }
}*/

public void extractAttributes(String datasetFileName) {
    System.out.println("Mainmanager.extract attributes");
    filterManager.extractAttributeHeaders(getDocumentReader());
    Instances instances = new Instances(filterManager.getDataset());
    DocumentReader reader = getDocumentReader();
    for (Document doc : reader) {
        Instance inst = doc.toWekaInstance(filterManager);
        instances.add(inst);
    }
    /*for (gnusmail.filters.Filter f : filterManager.filterList) {
       if (f instanceof MultilabelFolder) {
    ((MultilabelFolder)f).writeToHierarchicalFile();
       }
    }*/
    filterManager.writeToFile(instances, datasetFileName);
}

From source file:gov.va.chir.tagline.dao.DatasetUtil.java

License:Open Source License

public static Instances createDataset(final Collection<Document> documents) {

    // Key = feature name | Value = number representing NUMERIC, NOMINAL, etc.
    final Map<String, Integer> featureType = new TreeMap<String, Integer>();

    // Key = feature name | Values = distinct values for NOMINAL values
    final Map<String, Set<String>> nominalFeatureMap = new HashMap<String, Set<String>>();

    final Set<String> labels = new TreeSet<String>();
    final Set<String> docIds = new TreeSet<String>();

    // First scan -- determine attribute values
    for (Document document : documents) {
        processFeatures(document.getFeatures(), featureType, nominalFeatureMap);
        docIds.add(document.getName());//from  w ww .j  a va2  s . c  o  m

        for (Line line : document.getLines()) {
            processFeatures(line.getFeatures(), featureType, nominalFeatureMap);

            labels.add(line.getLabel());
        }
    }

    final ArrayList<Attribute> attributes = new ArrayList<Attribute>();

    // Add Document and Line IDs as first two attributes
    //final Attribute docId = new Attribute(DOC_ID, (ArrayList<String>) null);
    final Attribute docId = new Attribute(DOC_ID, new ArrayList<String>(docIds));
    final Attribute lineId = new Attribute(LINE_ID);

    attributes.add(docId);
    attributes.add(lineId);

    // Build attributes
    for (String feature : featureType.keySet()) {
        final int type = featureType.get(feature);

        if (type == Attribute.NUMERIC) {
            attributes.add(new Attribute(feature));
        } else {
            if (nominalFeatureMap.containsKey(feature)) {
                attributes.add(new Attribute(feature, new ArrayList<String>(nominalFeatureMap.get(feature))));
            }
        }
    }

    // Add class attribute
    Attribute classAttr = new Attribute(LABEL, new ArrayList<String>(labels));
    attributes.add(classAttr);

    final Instances instances = new Instances("train", attributes, documents.size());

    // Second scan -- add data
    for (Document document : documents) {
        final Map<String, Object> docFeatures = document.getFeatures();

        for (Line line : document.getLines()) {
            final Instance instance = new DenseInstance(attributes.size());

            final Map<String, Object> lineFeatures = line.getFeatures();
            lineFeatures.putAll(docFeatures);

            instance.setValue(docId, document.getName());
            instance.setValue(lineId, line.getLineId());
            instance.setValue(classAttr, line.getLabel());

            for (Attribute attribute : attributes) {
                if (!attribute.equals(docId) && !attribute.equals(lineId) && !attribute.equals(classAttr)) {
                    final String name = attribute.name();
                    final Object obj = lineFeatures.get(name);

                    if (obj instanceof Double) {
                        instance.setValue(attribute, ((Double) obj).doubleValue());
                    } else if (obj instanceof Integer) {
                        instance.setValue(attribute, ((Integer) obj).doubleValue());
                    } else {
                        instance.setValue(attribute, obj.toString());
                    }
                }
            }

            instances.add(instance);
        }
    }

    // Set last attribute as class
    instances.setClassIndex(attributes.size() - 1);

    return instances;
}

From source file:gov.va.chir.tagline.dao.DatasetUtil.java

License:Open Source License

@SuppressWarnings("unchecked")
public static Instances createDataset(final Instances header, final Collection<Document> documents)
        throws Exception {

    // Update header to include all docIDs from the passed in documents
    // (Weka requires all values for nominal features)
    final Set<String> docIds = new TreeSet<String>();

    for (Document document : documents) {
        docIds.add(document.getName());//from   ww w  . java2s.co  m
    }

    final AddValues avf = new AddValues();
    avf.setLabels(StringUtils.join(docIds, ","));

    // Have to add 1 because SingleIndex.setValue() has a bug, expecting
    // the passed in index to be 1-based rather than 0-based. Why? I have 
    // no idea.
    // Calling path: AddValues.setInputFormat() -->
    //               SingleIndex.setUpper() -->
    //               SingleIndex.setValue()
    avf.setAttributeIndex(String.valueOf(header.attribute(DOC_ID).index() + 1));

    avf.setInputFormat(header);
    final Instances newHeader = Filter.useFilter(header, avf);

    final Instances instances = new Instances(newHeader, documents.size());

    // Map attributes
    final Map<String, Attribute> attrMap = new HashMap<String, Attribute>();

    final Enumeration<Attribute> en = newHeader.enumerateAttributes();

    while (en.hasMoreElements()) {
        final Attribute attr = en.nextElement();

        attrMap.put(attr.name(), attr);
    }

    attrMap.put(newHeader.classAttribute().name(), newHeader.classAttribute());

    final Attribute docId = attrMap.get(DOC_ID);
    final Attribute lineId = attrMap.get(LINE_ID);
    final Attribute classAttr = attrMap.get(LABEL);

    // Add data
    for (Document document : documents) {
        final Map<String, Object> docFeatures = document.getFeatures();

        for (Line line : document.getLines()) {
            final Instance instance = new DenseInstance(attrMap.size());

            final Map<String, Object> lineFeatures = line.getFeatures();
            lineFeatures.putAll(docFeatures);

            instance.setValue(docId, document.getName());
            instance.setValue(lineId, line.getLineId());

            if (line.getLabel() == null) {
                instance.setMissing(classAttr);
            } else {
                instance.setValue(classAttr, line.getLabel());
            }

            for (Attribute attribute : attrMap.values()) {
                if (!attribute.equals(docId) && !attribute.equals(lineId) && !attribute.equals(classAttr)) {
                    final String name = attribute.name();
                    final Object obj = lineFeatures.get(name);

                    if (obj instanceof Double) {
                        instance.setValue(attribute, ((Double) obj).doubleValue());
                    } else if (obj instanceof Integer) {
                        instance.setValue(attribute, ((Integer) obj).doubleValue());
                    } else {
                        instance.setValue(attribute, obj.toString());
                    }
                }
            }

            instances.add(instance);
        }
    }

    // Set last attribute as class
    instances.setClassIndex(attrMap.size() - 1);

    return instances;
}

From source file:gr.auth.ee.lcs.utilities.InstancesUtility.java

License:Open Source License

/**
 * The number of instances are multiple of the number of folds.
 * From a se t of instances, it returns a chunk whose length is instances.numInstances / numberOfFolds
 * with index = index. Index starts at zero.
 * /*from  www. ja v  a  2s  . c o  m*/
 * In essencem this is used when splitting a partition of instances to a train and test set.
 * 
 * One chunk is the test set and the rest is the train set.
 * We provide the index for the test set and the rest will automatically become the train set
        
 * see splitPartitionIntoFolds
 * 
 * _____
 * |_6_| index = 0
 * |_6_|       1
 * |_6_|       2 
 * |_6_|       3
 * |_6_|       4   
 * |_6_|       5
 * |_6_|       6
 * |_6_|       7      
 * |_6_|       8
 * |_6_|       9
 * 
 * */
public static Instances getPartitionSegment(Instances instances, int index, int numberOfFolds) {

    if (instances.numInstances() % numberOfFolds != 0) {
        System.out.println("Number of instances not a multiple of " + numberOfFolds);
        return null;
    }

    int numberOfInstancesToGet = instances.numInstances() / numberOfFolds;
    Instances segment = new Instances(instances, numberOfInstancesToGet);

    for (int i = index * numberOfInstancesToGet; i < (index + 1) * numberOfInstancesToGet; i++) {
        segment.add(instances.instance(i));
    }
    return segment;
}

From source file:gr.auth.ee.lcs.utilities.InstancesUtility.java

License:Open Source License

public static void splitDatasetIntoFolds(final AbstractLearningClassifierSystem lcs, final Instances dataset,
        final int numberOfFolds) throws Exception {

    Instances[] partitions = InstancesUtility.partitionInstances(lcs, dataset);

    testInstances.setSize(partitions.length);
    trainInstances.setSize(partitions.length);

    int lowerBound = (int) Math.floor((double) dataset.numInstances() / (double) numberOfFolds);
    int upperBound = (int) Math.ceil((double) dataset.numInstances() / (double) numberOfFolds);

    // we demand lowerBound <= numberOfTestInstancesPerFold[i] <= upperBound
    int[] numberOfTestInstancesPerFold = new int[numberOfFolds];

    /*/*  w w w .  ja v a  2 s . co  m*/
     * let X partitions have partitions[i].numInstances() > numberOfFolds. 
     * Then, vectors testInstances and trainInstances, after the call of splitPartitionIntoFolds(), will hold X arrays 
      *   meaning X elements.  
     * */
    Vector<Integer> vectorOfPartitionIndices = new Vector<Integer>();

    for (int i = 0; i < partitions.length; i++) {

        if (partitions[i].numInstances() > numberOfFolds) {
            InstancesUtility.splitPartitionIntoFolds(partitions[i], numberOfFolds, i);
            vectorOfPartitionIndices.add(i);
        } else {

            Instances[] emptyArrayTest = new Instances[numberOfFolds];
            Instances[] emptyArrayTrain = new Instances[numberOfFolds];

            for (int j = 0; j < numberOfFolds; j++) {
                emptyArrayTest[j] = new Instances(partitions[0], partitions[i].numInstances());
                emptyArrayTrain[j] = new Instances(partitions[0], partitions[i].numInstances());

            }
            //placeholders
            InstancesUtility.testInstances.add(i, emptyArrayTest);
            InstancesUtility.trainInstances.add(i, emptyArrayTrain);
        }
    }

    /*
     * At this point all partitions with numInstances > numFolds have been successfully been split.
     * What is left is splitting the leftovers. 1st from the above partitions and 2nd from the ones that originally had numInstances < numFolds
     * */

    for (int i = 0; i < numberOfFolds; i++) {
        int instancesSum = 0;
        for (int j = 0; j < vectorOfPartitionIndices.size(); j++) {
            instancesSum += InstancesUtility.testInstances.elementAt(vectorOfPartitionIndices.elementAt(j))[i]
                    .numInstances();
        }

        // initial number of instances in test set per fold
        numberOfTestInstancesPerFold[i] = instancesSum;
    }

    /*
     * 
     *  i = 0 |_0|_0|_0|_0|_0|_0|_0|_0|_0|_0|
       i = 1 |_0|_0|_0|_0|_0|_0|_0|_0|_0|_0|
       i = 2 |_0|_0|_0|_0|_0|_0|_0|_0|_0|_0|
       i = 3 |_0|_0|_0|_0|_0|_0|_0|_0|_0|_0|
       i = 4 |_0|_0|_0|_0|_0|_0|_0|_0|_0|_0|
       i = 5 |_1|_1|_1|_1|_1|_1|_1|_1|_1|_1|
       i = 6 |_3|_3|_3|_3|_3|_3|_3|_3|_3|_3|
       i = 7 |_6|_6|_6|_6|_6|_6|_6|_6|_6|_6|
     * 
     * 
     * */

    for (int i = 0; i < partitions.length; i++) {

        int numberOfLeftoverInstances = partitions[i].numInstances() % numberOfFolds; // eg 64 % 10 = 4
        Instances leftoverInstances = new Instances(partitions[i], numberOfLeftoverInstances);

        if (numberOfLeftoverInstances > 0) {
            /*
             * Starting from the end. Anyhow they are the last {numberOfLeftoverInstances} instances in each partition
             * that splitPartitionIntoFolds() has been called on.
             * */
            for (int k = partitions[i].numInstances() - 1; k >= partitions[i].numInstances()
                    - numberOfLeftoverInstances; k--) {
                leftoverInstances.add(partitions[i].instance(k));
            }

            /*
             * For each partition, randomize the folds. Leftover instances will be placed in the first {numberOfLeftoverInstances} folds,
             * that are already randomly distributed. If the first folds were not randomly distributed, there would be an uneven distribution,
             * meaning that in the first ones there would be instances of the first partition and so on.
             * 
             * */

            ArrayList<Integer> folds = new ArrayList<Integer>();

            for (int k = 0; k < numberOfFolds; k++) {
                folds.add(k);
            }

            Collections.shuffle(folds);

            int j = 0;
            while (leftoverInstances.numInstances() > 0) {
                int foldIndex = folds.get(j);

                if (numberOfTestInstancesPerFold[foldIndex] < upperBound) {

                    Instance toBeAdded = leftoverInstances.instance(0);

                    // place the leftover first instance in a test set
                    testInstances.elementAt(i)[foldIndex].add(toBeAdded);

                    numberOfTestInstancesPerFold[foldIndex]++;

                    // the instance placed in a test set for the current fold, needs to be put in the train set for all the other folds,
                    // except for the current one of course
                    for (int k = 0; k < numberOfFolds; k++) {
                        if (k != foldIndex) {
                            trainInstances.elementAt(i)[k].add(toBeAdded);
                        }
                    }

                    // remove the instance placed in the test set
                    leftoverInstances.delete(0);

                }
                j++;
                // if j hits the roof reset it. 
                // there may exist folds that have not reached their upper limit and abandon them
                if (j == numberOfFolds)
                    j = 0;
            }
        }
    }
}

From source file:gr.auth.ee.lcs.utilities.InstancesUtility.java

License:Open Source License

/**
 * Splits a partition (collection of instances that belong to the same label combination) into train and test sets, leaving leftover instances.
 * It presupposes that partition.numInstances > numberOfFolds.
 * /* ww  w  .j a  v  a2s  .com*/
 * Leftover instances should be distributed in a way that each test set holds
 * 
 * floor(totalNumInstances / numberOfFolds) <= testSetNumInstances <= ceil(totalNumInstances / numberOfFolds)
 */
public static void splitPartitionIntoFolds(Instances partition, int numberOfFolds, int partitionIndex) {

    int numberOfTestInstancesPerFold = partition.numInstances() / numberOfFolds; // eg 64 / 10 = 6
    int numberOfLeftoverInstances = partition.numInstances() % numberOfFolds; // eg 64 % 10 = 4
    int numberOfTrainInstancesPerFold = partition.numInstances() - numberOfTestInstancesPerFold
            - numberOfLeftoverInstances; // eg 64 - 6 - 4 = 54

    Instances[] testArrayPerPartition = new Instances[numberOfFolds];
    Instances[] trainArrayPerPartition = new Instances[numberOfFolds];

    Instances bulk = new Instances(partition, partition.numInstances() - numberOfLeftoverInstances);

    /*
     * E.g. I will split 64 total instances into 6 for testing, 54 for training and the rest (4) will be leftovers.
     * 6 + 54 = 60 ~ 10
     * The first 60 instances will be temporarily placed in the roundArray array
     * */

    for (int i = 0; i < partition.numInstances() - numberOfLeftoverInstances; i++) {
        bulk.add(partition.instance(i));
    }

    for (int i = 0; i < numberOfFolds; i++) {
        testArrayPerPartition[i] = InstancesUtility.getPartitionSegment(bulk, i, numberOfFolds);
        trainArrayPerPartition[i] = new Instances(bulk, numberOfFolds);

        for (int j = 0; j < numberOfFolds; j++) {
            if (j != i) {
                for (int k = 0; k < numberOfTestInstancesPerFold; k++) {
                    Instance kthInstance = InstancesUtility.getPartitionSegment(bulk, j, numberOfFolds)
                            .instance(k);
                    trainArrayPerPartition[i].add(kthInstance);
                }
            }
        }
    }

    /*
     * In total, there will be partitions.length additions.
     * Place each array in its respective place, depending on the partition index.
     * */

    InstancesUtility.testInstances.add(partitionIndex, testArrayPerPartition);
    InstancesUtility.trainInstances.add(partitionIndex, trainArrayPerPartition);
}

From source file:gr.demokritos.iit.cpgislanddetection.io.FileCreatorARFF.java

public Instances createARFF(List<Vector<Integer>> listVector, String nameClass) throws ParseException {

    // Declare four numeric attributes
    Attribute Attribute1 = new Attribute("adenine");
    Attribute Attribute2 = new Attribute("thymine");
    Attribute Attribute3 = new Attribute("cytosine");
    Attribute Attribute4 = new Attribute("guanine");

    // Declare the class attribute along with its values
    FastVector fvClassVal = new FastVector(2);
    fvClassVal.addElement("yes");
    fvClassVal.addElement("no");
    Attribute ClassAttribute = new Attribute("theClass", fvClassVal);

    // Declare the feature vector
    FastVector fvWekaAttributes = new FastVector(5);
    fvWekaAttributes.addElement(Attribute1);
    fvWekaAttributes.addElement(Attribute2);
    fvWekaAttributes.addElement(Attribute3);
    fvWekaAttributes.addElement(Attribute4);
    fvWekaAttributes.addElement(ClassAttribute);

    // Create an empty training set
    int capacity = listVector.size() + 7;
    Instances isTrainingSet = new Instances("isCpG", fvWekaAttributes, capacity);

    // Set class index
    isTrainingSet.setClassIndex(4);//from   w  w  w .j  a v a  2  s . c  o  m

    // Create the instances from the file with vectors
    for (int i = 0; i < listVector.size(); i++) {
        Instance instance = new Instance(5);
        instance.setValue((Attribute) fvWekaAttributes.elementAt(0), listVector.get(i).get(0));
        instance.setValue((Attribute) fvWekaAttributes.elementAt(1), listVector.get(i).get(1));
        instance.setValue((Attribute) fvWekaAttributes.elementAt(2), listVector.get(i).get(2));
        instance.setValue((Attribute) fvWekaAttributes.elementAt(3), listVector.get(i).get(3));
        instance.setValue((Attribute) fvWekaAttributes.elementAt(4), nameClass);

        //add the instance in training set
        isTrainingSet.add(instance);

    }
    System.out.println(isTrainingSet);
    return isTrainingSet;
}

From source file:gr.ntua.ece.cslab.panic.core.models.AbstractWekaModel.java

License:Apache License

/**
 * Creates a new dataset out of a OutputSpacePoint list.
 * @param points/*from  ww w.  j a v a2 s. c om*/
 * @return 
 */
protected static Instances getInstances(List<OutputSpacePoint> points) {
    OutputSpacePoint first = points.get(0);
    FastVector att = new FastVector(first.getInputSpacePoint().numberDimensions() + first.numberDimensions());
    int index = 0;
    for (String s : first.getInputSpacePoint().getKeysAsCollection())
        att.addElement(new Attribute(s, index++));

    for (String s : first.getOutputPoints().keySet())
        att.addElement(new Attribute(s, index++));

    Instances instances = new Instances("instances", att,
            first.getInputSpacePoint().numberDimensions() + first.numberDimensions());
    for (OutputSpacePoint p : points) {
        Instance i = convertPointToInstance(p.getInputSpacePoint(), p);
        instances.add(i);
        //System.out.println(i);
    }
    instances.setClassIndex(first.getInputSpacePoint().numberDimensions());
    return instances;
}

From source file:graph.clustering.NodeClusterer.java

License:Apache License

private Instances convertNodesInfoToInstances(long[] ids) {
    GraphQuery graph = new GraphQuery(graphDb);
    Map<String, String[]> nodesInfo = graph.getNodesInfo(ids);

    String[] attributeNames = new String[nodesInfo.keySet().size()];

    // Declare the feature vector
    FastVector fvWekaAttributes = new FastVector(attributeNames.length);

    int attributeIndex = 0;
    for (String attributeName : nodesInfo.keySet()) {
        attributeNames[attributeIndex++] = attributeName;
        System.out.println("Attribute:\t" + attributeName);

        Set<String> valueSet = new HashSet<String>();

        boolean isStringAttribute = false;
        String[] attributes = nodesInfo.get(attributeName);
        for (int i = 0; i < ids.length; i++) {
            valueSet.add(attributes[i]);

            if (attributes[i].split("\\s").length > 1) {
                isStringAttribute = true;
            }/*from w ww .j a v a2 s .co  m*/
        }

        Attribute wekaAttribute = null;
        if (isStringAttribute) {
            wekaAttribute = new Attribute(attributeName, (FastVector) null);
        } else {
            // Declare a nominal attribute along with its values
            FastVector fvNominalVal = new FastVector(valueSet.size());
            for (String uniqueValue : valueSet) {
                fvNominalVal.addElement(uniqueValue.toLowerCase());
            }
            wekaAttribute = new Attribute(attributeName, fvNominalVal);
        }

        // add this new attribute type to the feature vector
        fvWekaAttributes.addElement(wekaAttribute);

    }

    // Create an empty training set
    Instances clusterTrainingSet = new Instances("Rel", fvWekaAttributes, ids.length);
    for (int i = 0; i < ids.length; i++) {
        // Create the instance
        Instance instance = new Instance(attributeNames.length);

        for (int j = 0; j < attributeNames.length; j++) {
            String attributeValue = nodesInfo.get(attributeNames[j])[i];
            if (attributeValue == null) {
                attributeValue = "none";
            } else {
                attributeValue = attributeValue.toLowerCase();
            }

            instance.setValue((Attribute) fvWekaAttributes.elementAt(j), attributeValue);
        }

        // add the instance to the data set
        clusterTrainingSet.add(instance);
    }

    return clusterTrainingSet;
}

From source file:Gui.NewClass.java

public static void main(String[] args) throws FileNotFoundException, IOException, Exception {
    Graph bestemodel = null;//from  ww  w  .  j a  v a 2  s. co  m
    int anz;
    int anziter;
    List<BayesNetz> results;
    results = new ArrayList<BayesNetz>();
    int[] tab;
    double maxFitness;
    String verfahren = null;
    ArrayList<ComplexClassifierZufall> Complexnetze = new ArrayList<>();
    Simpleclassifier Simplenetz = null;
    BayesNetz K2_Netz;
    System.out.println("Datei im ARFF-Format auswhlen");
    JFileChooser dialogue = new JFileChooser();

    dialogue.showOpenDialog(null);

    // selektierte File
    String Name = dialogue.getSelectedFile().getName();
    System.out.println("Ausgewhlte Datensatz:" + " " + Name);
    if (Name.contains(".arff") && (dialogue.getSelectedFile().isFile())) {
        BufferedReader reader = new BufferedReader(new FileReader(dialogue.getSelectedFile()));

        ArffReader arff = new ArffReader(reader, 1000);
        Instances data = arff.getStructure();
        data.setClassIndex(data.numAttributes() - 1);//
        Instance inst;
        while ((inst = arff.readInstance(data)) != null) {
            data.add(inst);
        }
        System.out.println(
                "bitte geben sie die  Groee der Startpopulation  ein (die Zahl muss groeer 1 sein!!)");

        Scanner s = new Scanner(System.in);
        if (s == null) {
            System.out.println("keine Zahl ausgewhlt");
            throw new Exception();
        }

        anziter = s.nextInt();
        if (anziter <= 1) {
            System.out.println(
                    "Sie haben eine Zahl eigegeben, die kleiner oder gleich 1 ist. Dies ist nicht zulaessig. Die Startpopulationsgroee muss>1 sein!");
            throw new Exception();

        }

        System.out.println("bitte geben sie die Anzahl Iterationen ein");
        Scanner sc = new Scanner(System.in);
        Collection<BayesNetz> dieNetze = new ArrayList<BayesNetz>();
        anz = sc.nextInt();
        System.out.println("ldt bitte warten...");
        /* BayesNetz struct=new BayesNetz(data,1);
                 
         struct.BerechneFitness();
                  
         struct.getGraph().ToString();
         ;
         tab = new int[anz];*/

        int i = 0;
        long anfangszeit_MTA = 0;

        while (i < anziter) {
            ComplexClassifierZufall cc = new ComplexClassifierZufall(data, anziter);
            Complexnetze.add(cc);

            dieNetze.add(new BayesNetz(cc.getinst(), cc.Model));

            i++;
        }

        for (ComplexClassifierZufall c : Complexnetze) {
            anfangszeit_MTA = System.currentTimeMillis();
            c.BauClassifier();
            // System.out.println("Ergebnisse mit Complexclassifier");
            //System.out.println("********************************");
            c.BewertunginProzent();
            // System.out.println("-----------------------------------------------------------------------------------------------------------------------------");
            // System.out.println("                                    ");

        }

        double max = Complexnetze.get(0).Mittlerevalidierungsquote;
        double zeitmin = Complexnetze.get(0).Mittlerezeit;
        int indexbeste = 0;

        long endzeit_MTA = 0;

        for (ComplexClassifierZufall c : Complexnetze) {

            if (max > c.Mittlerevalidierungsquote) {
                max = c.Mittlerevalidierungsquote;
                bestemodel = c.Model;
                indexbeste = Complexnetze.indexOf(c);
            } else {
                if (max == c.Mittlerevalidierungsquote) {
                    if (zeitmin >= c.Mittlerezeit) {
                        max = c.Mittlerevalidierungsquote;
                        zeitmin = c.Mittlerezeit;
                        bestemodel = c.Model;
                        indexbeste = Complexnetze.indexOf(c);
                    }
                }
            }

        }

        if (Complexnetze.get(indexbeste).Model.getAnzahlkanten() != 0) {
            System.out.println(
                    "-----------------------------------------------------------------------------------------------------");
            System.out.println();
            System.out.println("Ergebnisse mit MTA_learning ");
            System.out.println("Fitness:" + ""
                    + (double) (int) (Complexnetze.get(indexbeste).Mittlerevalidierungsquote * 100) / 100
                    + "("
                    + (double) (int) (Complexnetze.get(indexbeste).stadartdeviationvalidierung * 100) / 100
                    + ")" + "%" + " " + "Zeit:" + "" + (int) Complexnetze.get(indexbeste).Mittlerezeit + "("
                    + (int) Complexnetze.get(indexbeste).standartdeviationtime + ")" + "ms");
            System.out.println("Vernetzungsprozent:" + "" + Complexnetze.get(indexbeste).vernetzung + "("
                    + (Complexnetze.get(indexbeste).Model.getMoeglischeAnzahlKanten()
                            * Complexnetze.get(indexbeste).vernetzung)
                            / Complexnetze.get(indexbeste).Model.getAnzahlkanten()
                    + ")" + "%" + "    " + "max Anzahlkanten:"
                    + Complexnetze.get(indexbeste).Model.getAnzahlkanten() + "("
                    + Complexnetze.get(indexbeste).Model.getMoeglischeAnzahlKanten() + " )");
        } else {
            System.out.println(
                    "-----------------------------------------------------------------------------------------------------");
            System.out.println();
            System.out.println("Ergebnisse mit MTA_learning ");
            System.out.println("Fitness:" + ""
                    + (double) (int) (Complexnetze.get(indexbeste).Mittlerevalidierungsquote * 100) / 100
                    + "("
                    + (double) (int) (Complexnetze.get(indexbeste).stadartdeviationvalidierung * 100) / 100
                    + ")" + " " + "Zeit:" + "" + (int) Complexnetze.get(indexbeste).Mittlerezeit + "("
                    + (int) Complexnetze.get(indexbeste).standartdeviationtime + ")" + "ms");
            System.out.println("Vernetzungsprozent:" + "" + Complexnetze.get(indexbeste).vernetzung + "("
                    + (Complexnetze.get(indexbeste).Model.getMoeglischeAnzahlKanten()
                            * Complexnetze.get(indexbeste).vernetzung)
                    + ")" + "%" + "    " + "max Anzahlkanten:"
                    + Complexnetze.get(indexbeste).Model.getAnzahlkanten() + "("
                    + Complexnetze.get(indexbeste).Model.getMoeglischeAnzahlKanten() + " )");
        }

        Complexnetze.get(indexbeste).Model.ToString();
        endzeit_MTA = System.currentTimeMillis();
        System.out.println(
                "Gesamte Ausfhrungszet MTA_learning:" + (endzeit_MTA - anfangszeit_MTA) + " " + "ms");
        results.add(Complexnetze.get(indexbeste).getStruct());
        maxFitness = ((Complexnetze.get(indexbeste).Mittlerevalidierungsquote * 100) / 100);
        verfahren = "MTA_learning";

        System.out.println(
                "---------------------------------------------------------------------------------------------------------------------");

        System.out.println();
        long anfangszeit_NB = System.currentTimeMillis();
        long endzeit_NB = 0;

        Simplenetz = new Simpleclassifier(new BayesNetz(data, 0), anz);

        Simplenetz.BauClassifier();
        System.out.println("Ergebnisse mit NaiveBayes");

        System.out.println("Vernetzungsprozent:" + "" + (100 * (Simplenetz.getinst().numAttributes() - 1))
                / Complexnetze.get(indexbeste).Model.getMaxAnzahlkanten() + "%");
        Simplenetz.BewertunginProzent();

        System.out.println("Fitness NaiveBayes:" + ""
                + (double) (int) (Simplenetz.Mittlerevalidierungsquote * 100) / 100 + "("
                + (double) (int) (Simplenetz.stadartdeviationvalidierung * 100) / 100 + ")" + " " + "Zeit:" + ""
                + (int) Simplenetz.Mittlerezeit + "(" + (int) Simplenetz.standartdeviationtime + ")" + "ms");

        Simplenetz.Model.ToString();
        double[] er = new double[3];
        er = Simplenetz.getStruct().getErgebnisse();
        endzeit_NB = System.currentTimeMillis();
        System.out.println("Gesamte Ausfhrungszet NaiveBayes:" + (endzeit_NB - anfangszeit_NB) + " " + "ms");

        results.add(Simplenetz.getStruct());

        if (maxFitness > ((Simplenetz.Mittlerevalidierungsquote * 100) / 100)) {
            maxFitness = (Simplenetz.Mittlerevalidierungsquote * 100) / 100;
            verfahren = "NaiveBayes";
        }
        /* for(int l=0;l<er.length;l++)
         System.out.println(er[l]);
         /* Simpleclassifier c = new Simpleclassifier(data, 5);
         c.BauClassifier();
         c.BewertunginProzent();// Get a DescriptiveStatistics instance*/

        System.out.println(
                "---------------------------------------------------------------------------------------------------------------------");
        System.out.println();
        System.out.println("Ergebnisse mit K2:");
        System.out.println();
        long anfangszeit_K2 = System.currentTimeMillis();
        long endzeit_K2 = 0;
        K2_Netz = new BayesNetz(new BayesNetz(data, 1));
        er = K2_Netz.getErgebnisse();
        endzeit_K2 = System.currentTimeMillis();
        double f1 = K2_Netz.getFitness();
        System.out.println("Vernetzung:" + " " + K2_Netz.getVernetzung() + "%" + "    " + "Fitness :" + "" + f1
                + "(" + K2_Netz.geterb(3) + ")" + " " + "Zeit:" + (int) K2_Netz.getZeit() + "("
                + K2_Netz.geterb(4) + ")" + "" + "ms");
        K2_Netz.getGraph().ToString();
        System.out.println("Gesamte Ausfhrungszet K2:" + (endzeit_K2 - anfangszeit_K2) + " " + "ms");

        results.add(K2_Netz);
        if (maxFitness > f1) {
            maxFitness = f1;
            verfahren = "K2";
        }

        System.out.println(
                "---------------------------------------------------------------------------------------------------------------------");

        //  System.out.println();
        // System.out.println("Ergebnisse mit Ci:");
        // System.out.println();
        //BayesNetz Ci_Netz=new BayesNetz(new BayesNetz(data,2));
        //System.out.println("Vernetzung:"+Ci_Netz.getVernetzung()+"%"+"    "+"Fitness :" + ""+Ci_Netz.getFitness());
        //Ci_Netz.getGraph().ToString();
        //System.out.println("---------------------------------------------------------------------------------------------------------------------");
        Random r;
        r = new Random();
        long anfangszeit_SGA = System.currentTimeMillis();

        AbstractCandidateFactory Factory = new BayesFactory<BayesNetz>();

        List<EvolutionaryOperator<BayesNetz>> operators = new LinkedList<EvolutionaryOperator<BayesNetz>>();
        operators.add(new Bayescrossover());
        operators.add(new Mutation(new ConstantGenerator<Probability>(new Probability(0.02)),
                new ConstantGenerator(10)));
        EvolutionaryOperator<BayesNetz> pipeline = new EvolutionPipeline<BayesNetz>(operators);
        FitnessEvaluator<BayesNetz> fitness = new BayesFitnessEvaluator();
        SelectionStrategy<BayesNetz> select = new TunrnierSelektion(new Probability(0.6));
        System.out.println("please wait while simulating  evolution...");
        System.out.println();

        long endzeit_SGA = 0;

        EvolutionEngine<BayesNetz> engine = new Geneticsimulation((BayesFactory) Factory, pipeline, fitness,
                select, r);

        engine.addEvolutionObserver(new EvolutionObserver<BayesNetz>() {

            @Override
            public void populationUpdate(PopulationData<? extends BayesNetz> data) {
                System.out.println("Generation" + " " + (data.getGenerationNumber() + 1) + ":");
                System.out.println("Fitness:" + " " + data.getBestCandidate().getFitness() + "," + " "
                        + "Dauer:" + " " + data.getBestCandidate().geterb(3) + " " + "ms");
                ///System.out.println("Beste Netz:");

                //data.getBestCandidate().getGraph().ToString();
                System.out.println(
                        "-------------------------------------------------------------------------------");
            }

        });
        BayesNetz result = new BayesNetz(engine.evolve(dieNetze.size(), 1, dieNetze, new Terminason(anz)));
        endzeit_SGA = System.currentTimeMillis();
        System.out.println("Ergebnisse der Evolution:");
        double f = result.getFitness();
        if (maxFitness > f) {
            maxFitness = f;
            verfahren = "SGA";
        }

        er = result.getErgebnisse();

        System.out.println("Vernetzung:" + " " + result.getVernetzung() + "%" + "  " + "Fittness:" + " " + f
                + "(" + result.geterb(3) + ")" + " " + "Zeit:" + " " + (int) result.getZeit() + "("
                + result.geterb(4) + ")" + " " + "ms");
        result.getGraph().ToString();
        System.out.println("Gesamte Dauer von SGA:" + " " + (endzeit_SGA - anfangszeit_SGA) + " " + "ms");
        results.add(result);

        System.out.println(
                "---------------------------------------------------------------------------------------------------------------------");

    } else {
        System.out.println("ungltige Dateiformat");

    }

    switch (verfahren) {
    case "MTA_learning": {
        System.out.println("Bester Verfahren:" + " " + verfahren);
        System.out.println("gelernte Struktur: (" + results.get(0).getVernetzung() + "% Vernetzung)" + ":");
        results.get(0).getGraph().ToString();

        break;
    }
    case "NaiveBayes": {
        System.out.println("Bester Verfahren:" + " " + verfahren);
        System.out.println("gelernte Struktur: (" + results.get(1).getVernetzung() + "% Vernetzung)" + " "
                + verfahren + ":");
        results.get(1).getGraph().ToString();
        break;
    }

    case "K2": {
        System.out.println("Bester Verfahren:" + " " + verfahren);
        System.out.println("gelernte Struktur: (" + results.get(2).getVernetzung() + "% Vernetzung)" + " "
                + verfahren + ":");
        results.get(2).getGraph().ToString();
        break;
    }

    case "SGA": {
        System.out.println("Bester Verfahren:" + " " + verfahren);
        System.out.println("gelernte Struktur: (" + results.get(3).getVernetzung() + "% Vernetzung)" + " "
                + verfahren + ":");
        results.get(3).getGraph().ToString();
        break;
    }
    default:
        System.out.println("weiss nicht");
    }

}