MainFrame.java Source code

Java tutorial

Introduction

Here is the source code for MainFrame.java

Source

import java.io.File;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import weka.attributeSelection.AttributeSelection;
import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.classifiers.lazy.IBk;
import weka.core.Debug;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.ConverterUtils;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author ferhat
 */
public class MainFrame extends javax.swing.JFrame {
    double[] food_source;
    File fileopen;
    String path;
    int[] sa_indexes_ig = null;
    int[] sa_indexes_gr = null;
    int[] sa_indexes_csq = null;
    String sf_indexes = "";

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        filechooser = new javax.swing.JFileChooser();
        buttongroup = new javax.swing.ButtonGroup();
        jButton1 = new javax.swing.JButton();
        fileopenButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        iterationnumber_cb = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        crossvalfold_cb = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        modificationrate_cb = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        selectedfeaturesindexes_tf = new javax.swing.JTextField();
        ChisquareButton = new javax.swing.JButton();
        infogainbutton = new javax.swing.JButton();
        gainratioButton = new javax.swing.JButton();
        selectedfeaturesindexes_tf_csq = new javax.swing.JTextField();
        selectedfeaturesindexes_tf_gr = new javax.swing.JTextField();
        selectedfeaturesindexes_tf_ig = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        numofattr_tf = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        svm_button = new javax.swing.JButton();
        knn_button = new javax.swing.JButton();
        naivebayesbutton = new javax.swing.JButton();
        c45button = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        classification_result_ta = new javax.swing.JTextArea();
        rb_abc = new javax.swing.JRadioButton();
        rb_csq = new javax.swing.JRadioButton();
        rb_ig = new javax.swing.JRadioButton();
        rb_gr = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Feature Selection With ABC");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        fileopenButton.setText("File ...");
        fileopenButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                fileopenButtonMouseClicked(evt);
            }
        });

        jLabel1.setText("Iteration Number:");

        iterationnumber_cb.setModel(
                new javax.swing.DefaultComboBoxModel(new String[] { "100", "150", "200", "250", "300", "350", "400",
                        "450", "500", "550", "600", "650", "700", "750", "800", "850", "900", "950", "1000" }));
        iterationnumber_cb.setSelectedIndex(10);

        jLabel2.setText("Cross Val. Fold Number:");

        crossvalfold_cb.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "3", "5", "10", "15", "20", "25", "30", "35", "40" }));

        jLabel3.setText("Modification Rate:");

        modificationrate_cb.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9" }));
        modificationrate_cb.setSelectedIndex(4);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("Selected Features' Indexes:");

        selectedfeaturesindexes_tf.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        ChisquareButton.setText("ChiSquare");
        ChisquareButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ChisquareButtonMouseClicked(evt);
            }
        });

        infogainbutton.setText("Info Gain");
        infogainbutton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                infogainbuttonMouseClicked(evt);
            }
        });

        gainratioButton.setText("Gain Ratio");
        gainratioButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gainratioButtonMouseClicked(evt);
            }
        });

        selectedfeaturesindexes_tf_csq.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        selectedfeaturesindexes_tf_gr.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        selectedfeaturesindexes_tf_ig.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel6.setText("Number of Attributes:");

        numofattr_tf.setFocusable(false);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setText("Classification Phase");

        svm_button.setText("SVM");
        svm_button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                svm_buttonMouseClicked(evt);
            }
        });

        knn_button.setText("KNN");
        knn_button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                knn_buttonMouseClicked(evt);
            }
        });

        naivebayesbutton.setText("Naive Bayes");
        naivebayesbutton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                naivebayesbuttonMouseClicked(evt);
            }
        });

        c45button.setText("C4.5");
        c45button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                c45buttonMouseClicked(evt);
            }
        });

        classification_result_ta.setColumns(20);
        classification_result_ta.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N
        classification_result_ta.setRows(5);
        jScrollPane1.setViewportView(classification_result_ta);

        buttongroup.add(rb_abc);
        rb_abc.setSelected(true);
        rb_abc.setText("ABC");

        buttongroup.add(rb_csq);
        rb_csq.setText("ChiSquare");

        buttongroup.add(rb_ig);
        rb_ig.setText("Info Gain");

        buttongroup.add(rb_gr);
        rb_gr.setText("Gain Ratio");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
                                .createSequentialGroup().addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(fileopenButton)
                                                .addGroup(layout.createSequentialGroup().addComponent(jLabel1)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(iterationnumber_cb,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(layout.createSequentialGroup().addComponent(jLabel2)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(crossvalfold_cb,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(layout.createSequentialGroup().addComponent(jLabel4)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(selectedfeaturesindexes_tf,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 111,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(layout.createSequentialGroup().addComponent(jLabel3)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(modificationrate_cb,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup().addGap(17, 17, 17)
                                                .addComponent(
                                                        ChisquareButton, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        137, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(22, 22, 22)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(selectedfeaturesindexes_tf_ig)
                                                        .addComponent(infogainbutton,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE, 143,
                                                                Short.MAX_VALUE))
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 37,
                                                        Short.MAX_VALUE)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(gainratioButton,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 115,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(selectedfeaturesindexes_tf_gr,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 119,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addContainerGap(47, Short.MAX_VALUE))
                                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup().addGap(25, 25, 25)
                                                        .addComponent(jLabel6).addGap(18, 18, 18)
                                                        .addComponent(numofattr_tf,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 61,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(layout.createSequentialGroup().addGap(18, 18, 18)
                                                        .addComponent(selectedfeaturesindexes_tf_csq,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 136,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        Short.MAX_VALUE))))
                        .addGroup(layout.createSequentialGroup().addComponent(jSeparator1).addContainerGap())
                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGap(122, 122, 122)
                                        .addComponent(jScrollPane1))
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(rb_abc).addComponent(rb_csq).addComponent(rb_ig)
                                        .addComponent(rb_gr).addComponent(jLabel5)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addComponent(c45button, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(knn_button, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(svm_button, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(naivebayesbutton,
                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                        .addGap(0, 0, Short.MAX_VALUE)))
                                .addGap(10, 10, 10)))));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(fileopenButton)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1)
                                .addComponent(iterationnumber_cb, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel6).addComponent(numofattr_tf,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2).addComponent(crossvalfold_cb,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3).addComponent(modificationrate_cb,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(17, 17, 17)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(ChisquareButton, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
                                .addComponent(infogainbutton, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(gainratioButton, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4)
                                .addComponent(selectedfeaturesindexes_tf, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(selectedfeaturesindexes_tf_csq,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 29,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(selectedfeaturesindexes_tf_ig, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(selectedfeaturesindexes_tf_gr, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        29, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGap(11, 11, 11).addComponent(svm_button)
                                        .addGap(18, 18, 18).addComponent(knn_button).addGap(18, 18, 18)
                                        .addComponent(naivebayesbutton).addGap(18, 18, 18).addComponent(c45button)
                                        .addGap(18, 18, 18).addComponent(rb_abc)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(rb_csq)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(rb_ig)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(rb_gr).addGap(0, 2, Short.MAX_VALUE))
                                .addComponent(jScrollPane1))
                        .addContainerGap()));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        double[][] food_sources = new double[0][0];
        Classifier classifier;
        Evaluation eval;
        int N;
        PreparingSteps pr = new PreparingSteps();
        int iterationnumber = Integer.parseInt(iterationnumber_cb.getSelectedItem().toString());
        double modificationRate = Double.parseDouble(modificationrate_cb.getSelectedItem().toString());
        int foldnumber = Integer.parseInt(crossvalfold_cb.getSelectedItem().toString());
        //statuslabel.setText("Calculating...");
        try {
            N = pr.getReadFileData(path).numAttributes();
            Instances data = pr.getReadFileData(path);

            food_sources = pr.createFoodSources(data.numAttributes(), food_sources); // food sources olusturuluyor

            //////////////////////////////////////////////////////// + 

            Debug.Random rand = new Debug.Random(1);

            classifier = new IBk(); // snflandrc olusturuldu
            eval = new Evaluation(data);

            for (int i = 0; i < N - 1; i++) {
                food_source = new double[N];

                for (int j = 0; j < N; j++) {
                    food_source[j] = food_sources[i][j];
                }
                Instances data1 = pr.getReadFileData(path);
                food_sources[i][N - 1] = pr.getSourceFitnessValue(foldnumber, N, rand, data1, food_source, eval,
                        classifier);

            }

            ////////////////// +++++

            BeesProcesses bees = new BeesProcesses();
            double[] neighbor;
            int e = 0;

            while (e < iterationnumber) {
                System.out.println("iter:" + e);
                for (int i = 0; i < N - 1; i++) {
                    neighbor = new double[N];
                    food_source = new double[N];

                    for (int j = 0; j < N; j++)
                        food_source[j] = food_sources[i][j];

                    Instances data2 = pr.getReadFileData(path);
                    neighbor = bees.employedBeeProcess(food_source, modificationRate, i); // komsu olusturuldu
                    neighbor[N - 1] = pr.getSourceFitnessValue(foldnumber, N, rand, data2, neighbor, eval,
                            classifier); // komsunun fitness degeri bulunuyor
                    double a = food_source[N - 1];
                    double b = neighbor[N - 1];
                    if (b > a) {
                        for (int j = 0; j < N; j++) {
                            food_sources[i][j] = neighbor[j];
                        }
                    }

                }

                e++;
            } // while sonu

            double[][] onlooker_foodsources = new double[N - 1][N];
            onlooker_foodsources = bees.onlookerBeeProcess(N, 0.5);
            for (int i = 0; i < N - 1; i++) {
                double[] onlooker_food_source = new double[N];

                for (int j = 0; j < N; j++) {
                    onlooker_food_source[j] = onlooker_foodsources[i][j];
                }

                Instances data3 = pr.getReadFileData(path);
                onlooker_foodsources[i][N - 1] = pr.getSourceFitnessValue(foldnumber, N, rand, data3,
                        onlooker_food_source, eval, classifier);

            }

            int m = 0;
            while (m < 20) {
                double[][] onlooker_foodsources2 = new double[N - 1][N];
                onlooker_foodsources2 = bees.onlookerBeeProcess(N, 0.5);

                for (int i = 0; i < N - 1; i++) {
                    double[] onlooker_food_source = new double[N];

                    for (int j = 0; j < N; j++) {
                        onlooker_food_source[j] = onlooker_foodsources2[i][j];
                    }

                    Instances data4 = pr.getReadFileData(path);
                    onlooker_food_source[N - 1] = pr.getSourceFitnessValue(foldnumber, N, rand, data4,
                            onlooker_food_source, eval, classifier);

                    for (int j = 0; j < N - 1; j++) {
                        if (onlooker_foodsources[j][N - 1] < onlooker_foodsources2[j][N - 1]) {
                            for (int k = 0; k < N; k++) {
                                onlooker_foodsources[j][k] = onlooker_foodsources[j][k];
                            }
                        }
                    }
                }
                m++;
            }

            /////// feature selection
            double[] selected_features = new double[N];

            double max_fit = 0.0;
            for (int i = 0; i < N - 1; i++) {
                if (food_sources[i][N - 1] > max_fit) {
                    max_fit = food_sources[i][N - 1];
                    for (int j = 0; j < N; j++) {
                        selected_features[j] = food_sources[i][j];
                    }
                }

            }

            for (int i = 0; i < N - 1; i++) {
                if (onlooker_foodsources[i][N - 1] > max_fit) {
                    max_fit = food_sources[i][N - 1];
                    for (int j = 0; j < N; j++) {
                        selected_features[j] = onlooker_foodsources[i][j];
                    }
                }

            }

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

            String sf_wfmeasure = "";
            for (int i = 0; i < N; i++) {
                System.out.print(selected_features[i] + " ");
                if (i == N - 1) {
                    sf_wfmeasure = Double.toString(selected_features[i]);
                } else {
                    if (selected_features[i] == 1.0)
                        sf_indexes = sf_indexes + Integer.toString(i) + ",";
                }
            }

            selectedfeaturesindexes_tf.setText(sf_indexes);
            //weightedfmeasure_tf.setText(sf_wfmeasure);
            //statuslabel.setText("Finished.");

        } catch (Exception ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1MouseClicked

    private void fileopenButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fileopenButtonMouseClicked
        int returnVal = filechooser.showOpenDialog(this);
        if (returnVal == filechooser.APPROVE_OPTION) {
            fileopen = filechooser.getSelectedFile();
            path = fileopen.getAbsolutePath();
            PreparingSteps pr = new PreparingSteps();
            String na = Integer.toString(pr.getReadFileData(path).numAttributes());
            numofattr_tf.setText(na);
        }
    }//GEN-LAST:event_fileopenButtonMouseClicked

    private void infogainbuttonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_infogainbuttonMouseClicked
        AttributeSelection as = null;
        try {
            FeatureSelectionClass fs = new FeatureSelectionClass();
            as = fs.withInfoGain(this.path);
            sa_indexes_ig = as.selectedAttributes();
        } catch (Exception ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        String results = "";
        for (int i = 0; i < sa_indexes_ig.length; i++) {
            results = results + sa_indexes_ig[i] + ",";
        }
        selectedfeaturesindexes_tf_ig.setText(results);
    }//GEN-LAST:event_infogainbuttonMouseClicked

    private void ChisquareButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ChisquareButtonMouseClicked
        AttributeSelection as = null;

        try {
            FeatureSelectionClass fs = new FeatureSelectionClass();
            as = fs.withChiSquare(this.path);
            sa_indexes_csq = as.selectedAttributes();
        } catch (Exception ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        String results = "";
        for (int i = 0; i < sa_indexes_csq.length; i++) {
            results = results + sa_indexes_csq[i] + ",";
        }
        selectedfeaturesindexes_tf_csq.setText(results);
    }//GEN-LAST:event_ChisquareButtonMouseClicked

    private void gainratioButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gainratioButtonMouseClicked
        FeatureSelectionClass fs = new FeatureSelectionClass();
        AttributeSelection as = null;
        try {
            as = fs.withGainRatio(this.path);
            sa_indexes_gr = as.selectedAttributes();
        } catch (Exception ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        String results = "";
        for (int i = 0; i < sa_indexes_gr.length; i++) {
            results = results + sa_indexes_gr[i] + ",";
        }
        selectedfeaturesindexes_tf_gr.setText(results);
    }//GEN-LAST:event_gainratioButtonMouseClicked

    private void svm_buttonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_svm_buttonMouseClicked
        ClassificationClass classificationClass = new ClassificationClass();
        PreparingSteps pr = new PreparingSteps();
        Instances data = pr.getReadFileData(path);
        data = pr.deleteattributefromData(data, this.getfsresults());
        Evaluation ev = null;
        ev = classificationClass.cls_svm(data);
        classification_result_ta.setText("SVM RESULTS:\n" + ev.toSummaryString());
    }//GEN-LAST:event_svm_buttonMouseClicked

    private void knn_buttonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_knn_buttonMouseClicked
        ClassificationClass classificationClass = new ClassificationClass();
        PreparingSteps pr = new PreparingSteps();
        Instances data = pr.getReadFileData(path);
        data = pr.deleteattributefromData(data, this.getfsresults());
        Evaluation ev = null;
        ev = classificationClass.cls_knn(data);
        classification_result_ta.setText("KNN RESULTS:\n" + ev.toSummaryString());
    }//GEN-LAST:event_knn_buttonMouseClicked

    private void naivebayesbuttonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_naivebayesbuttonMouseClicked
        ClassificationClass classificationClass = new ClassificationClass();
        PreparingSteps pr = new PreparingSteps();
        Instances data = pr.getReadFileData(path);
        data = pr.deleteattributefromData(data, this.getfsresults());
        Evaluation ev = null;
        ev = classificationClass.cls_naivebayes(data);
        classification_result_ta.setText("NAIVE BAYES RESULTS:\n" + ev.toSummaryString());
    }//GEN-LAST:event_naivebayesbuttonMouseClicked

    private void c45buttonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_c45buttonMouseClicked
        ClassificationClass classificationClass = new ClassificationClass();
        PreparingSteps pr = new PreparingSteps();
        Instances data = pr.getReadFileData(path);
        data = pr.deleteattributefromData(data, this.getfsresults());
        Evaluation ev = null;
        ev = classificationClass.cls_c4_5(data);
        classification_result_ta.setText("C4.5 RESULTS\n" + ev.toSummaryString());
    }//GEN-LAST:event_c45buttonMouseClicked

    public double[] getfsresults() {
        if (rb_abc.isSelected()) {

            String[] a = sf_indexes.split(",");
            double[] rs = new double[a.length];
            for (int i = 0; i < a.length; i++) {
                rs[i] = Double.parseDouble(a[i]);
            }
            return rs;
        } else if (rb_csq.isSelected()) {
            double[] rs = new double[sa_indexes_csq.length - 1];
            for (int i = 0; i < sa_indexes_csq.length - 1; i++) {
                rs[i] = sa_indexes_csq[i] * 1.0;
            }
            return rs;
        } else if (rb_gr.isSelected()) {
            double[] rs = new double[sa_indexes_gr.length - 1];
            for (int i = 0; i < sa_indexes_gr.length - 1; i++) {
                rs[i] = sa_indexes_gr[i] * 1.0;
            }
            return rs;
        } else {
            double[] rs = new double[sa_indexes_ig.length - 1];
            for (int i = 0; i < sa_indexes_ig.length - 1; i++) {
                rs[i] = sa_indexes_ig[i] * 1.0;
            }
            return rs;
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ChisquareButton;
    private javax.swing.ButtonGroup buttongroup;
    private javax.swing.JButton c45button;
    private javax.swing.JTextArea classification_result_ta;
    private javax.swing.JComboBox crossvalfold_cb;
    private javax.swing.JFileChooser filechooser;
    private javax.swing.JButton fileopenButton;
    private javax.swing.JButton gainratioButton;
    private javax.swing.JButton infogainbutton;
    private javax.swing.JComboBox iterationnumber_cb;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton knn_button;
    private javax.swing.JComboBox modificationrate_cb;
    private javax.swing.JButton naivebayesbutton;
    private javax.swing.JTextField numofattr_tf;
    private javax.swing.JRadioButton rb_abc;
    private javax.swing.JRadioButton rb_csq;
    private javax.swing.JRadioButton rb_gr;
    private javax.swing.JRadioButton rb_ig;
    private javax.swing.JTextField selectedfeaturesindexes_tf;
    private javax.swing.JTextField selectedfeaturesindexes_tf_csq;
    private javax.swing.JTextField selectedfeaturesindexes_tf_gr;
    private javax.swing.JTextField selectedfeaturesindexes_tf_ig;
    private javax.swing.JButton svm_button;
    // End of variables declaration//GEN-END:variables
}