Package weka.filters

Examples of weka.filters.Filter


   * the filter and any options to the filter
   *
   * @return     the filter string.
   */
  protected String getFilterSpec() {
    Filter c = getFilter();
   
    if (c instanceof OptionHandler)
      return   c.getClass().getName() + " "
             + Utils.joinOptions(((OptionHandler)c).getOptions());
    else
      return c.getClass().getName();
  }
View Full Code Here


   *
   * @return     the filter string.
   */
  protected String getFilterSpec() {
    String  result;
    Filter   filter;
   
    filter = getFilter();
    result = filter.getClass().getName();
   
    if (filter instanceof OptionHandler)
      result += " " + Utils.joinOptions(((OptionHandler) filter).getOptions());
   
    return result;
View Full Code Here

   
    m_FilterEditor.addPropertyChangeListener(new PropertyChangeListener() {
      public void propertyChange(PropertyChangeEvent e) {
        m_ApplyFilterBut.setEnabled(getInstances() != null);
        Capabilities currentCapabilitiesFilter = m_FilterEditor.getCapabilitiesFilter();
        Filter filter = (Filter) m_FilterEditor.getValue();
        Capabilities currentFilterCapabilities = null;
        if (filter != null && currentCapabilitiesFilter != null &&
            (filter instanceof CapabilitiesHandler)) {
          currentFilterCapabilities = ((CapabilitiesHandler)filter).getCapabilities();
         
          if (!currentFilterCapabilities.supportsMaybe(currentCapabilitiesFilter) &&
              !currentFilterCapabilities.supports(currentCapabilitiesFilter)) {
            m_ApplyFilterBut.setEnabled(false);
          }
        }
      }
    });
    m_OpenFileBut.setToolTipText("Open a set of instances from a file");
    m_OpenURLBut.setToolTipText("Open a set of instances from a URL");
    m_OpenDBBut.setToolTipText("Open a set of instances from a database");
    m_GenerateBut.setToolTipText("Generates artificial data");
    m_UndoBut.setToolTipText("Undo the last change to the dataset");
    m_UndoBut.setEnabled(ExplorerDefaults.get("enableUndo", "true").equalsIgnoreCase("true"));
    if (!m_UndoBut.isEnabled()) {
      m_UndoBut.setToolTipText("Undo is disabled - " +
          "see weka.gui.explorer.Explorer.props to enable");
    }
    m_EditBut.setToolTipText("Open the current dataset in a Viewer for editing");
    m_SaveBut.setToolTipText("Save the working relation to a file");
    m_ApplyFilterBut.setToolTipText("Apply the current filter to the data");

    m_FileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    m_OpenURLBut.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
  setInstancesFromURLQ();
      }
    });
    m_OpenDBBut.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SqlViewerDialog dialog = new SqlViewerDialog(null);
        dialog.setVisible(true);
        if (dialog.getReturnValue() == JOptionPane.OK_OPTION)
          setInstancesFromDBQ(dialog.getURL(), dialog.getUser(),
                              dialog.getPassword(), dialog.getQuery(),
                              dialog.getGenerateSparseData());
      }
    });
    m_OpenFileBut.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
  setInstancesFromFileQ();
      }
    });
    m_GenerateBut.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
  generateInstances();
      }
    });
    m_UndoBut.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
  undo();
      }
    });
    m_EditBut.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        edit();
      }
    });
    m_SaveBut.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
  saveWorkingInstancesToFileQ();
      }
    });
    m_ApplyFilterBut.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    applyFilter((Filter) m_FilterEditor.getValue());
  }
      });
    m_AttPanel.getSelectionModel()
      .addListSelectionListener(new ListSelectionListener() {
  public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {   
      ListSelectionModel lm = (ListSelectionModel) e.getSource();
      for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) {
        if (lm.isSelectedIndex(i)) {
    m_AttSummaryPanel.setAttribute(i);
    m_AttVisualizePanel.setAttribute(i);
    break;
        }
      }
    }
  }
    });


    m_InstSummaryPanel.setBorder(BorderFactory
         .createTitledBorder("Current relation"));
    JPanel attStuffHolderPanel = new JPanel();
    attStuffHolderPanel.setBorder(BorderFactory
          .createTitledBorder("Attributes"));
    attStuffHolderPanel.setLayout(new BorderLayout());
    attStuffHolderPanel.add(m_AttPanel, BorderLayout.CENTER);
    m_RemoveButton.setEnabled(false);
    m_RemoveButton.setToolTipText("Remove selected attributes.");
    m_RemoveButton.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    try {
      Remove r = new Remove();
      int [] selected = m_AttPanel.getSelectedAttributes();
      if (selected.length == 0) {
        return;
      }
      if (selected.length == m_Instances.numAttributes()) {
        // Pop up an error optionpane
        JOptionPane.showMessageDialog(PreprocessPanel.this,
              "Can't remove all attributes from data!\n",
              "Remove Attributes",
              JOptionPane.ERROR_MESSAGE);
        m_Log.logMessage("Can't remove all attributes from data!");
        m_Log.statusMessage("Problem removing attributes");
        return;
      }
      r.setAttributeIndicesArray(selected);
      applyFilter(r);
      m_RemoveButton.setEnabled(false);
    } catch (Exception ex) {
      if (m_Log instanceof TaskLogger) {
        ((TaskLogger)m_Log).taskFinished();
      }
      // Pop up an error optionpane
      JOptionPane.showMessageDialog(PreprocessPanel.this,
            "Problem filtering instances:\n"
            + ex.getMessage(),
            "Remove Attributes",
            JOptionPane.ERROR_MESSAGE);
      m_Log.logMessage("Problem removing attributes: " + ex.getMessage());
      m_Log.statusMessage("Problem removing attributes");
    }
  }
      });

    JPanel p1 = new JPanel();
    p1.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
    p1.setLayout(new BorderLayout());
    p1.add(m_RemoveButton, BorderLayout.CENTER);
    attStuffHolderPanel.add(p1, BorderLayout.SOUTH);
    m_AttSummaryPanel.setBorder(BorderFactory
        .createTitledBorder("Selected attribute"));
    m_UndoBut.setEnabled(false);
    m_EditBut.setEnabled(false);
    m_SaveBut.setEnabled(false);
    m_ApplyFilterBut.setEnabled(false);
   
    // Set up the GUI layout
    JPanel buttons = new JPanel();
    buttons.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
    buttons.setLayout(new GridLayout(1, 6, 5, 5));
    buttons.add(m_OpenFileBut);
    buttons.add(m_OpenURLBut);
    buttons.add(m_OpenDBBut);
    buttons.add(m_GenerateBut);
    buttons.add(m_UndoBut);
    buttons.add(m_EditBut);
    buttons.add(m_SaveBut);

    JPanel attInfo = new JPanel();

    attInfo.setLayout(new BorderLayout());
    attInfo.add(attStuffHolderPanel, BorderLayout.CENTER);

    JPanel filter = new JPanel();
    filter.setBorder(BorderFactory
        .createTitledBorder("Filter"));
    filter.setLayout(new BorderLayout());
    filter.add(m_FilterPanel, BorderLayout.CENTER);
    filter.add(m_ApplyFilterBut, BorderLayout.EAST);

    JPanel attVis = new JPanel();
    attVis.setLayout( new GridLayout(2,1) );
    attVis.add(m_AttSummaryPanel);
View Full Code Here

    m_FilterEditor.setCapabilitiesFilter(filterClass);
   
    // check capabilities
    m_ApplyFilterBut.setEnabled(true);
    Capabilities currentCapabilitiesFilter = m_FilterEditor.getCapabilitiesFilter();
    Filter currentFilter = (Filter) m_FilterEditor.getValue();
    Capabilities currentFilterCapabilities = null;
    if (currentFilter != null && currentCapabilitiesFilter != null &&
        (currentFilter instanceof CapabilitiesHandler)) {
      currentFilterCapabilities = ((CapabilitiesHandler)currentFilter).getCapabilities();
     
View Full Code Here

    double[] instanceStats = new double[cc];
    Instances testRaw = null;
    boolean hasClass = (test.classIndex() >= 0);
    int unclusteredInstances = 0;
    Vector<Double> clusterAssignments = new Vector<Double>();
    Filter filter = null;
    DataSource source = null;
    Instance inst;

    if (testFileName == null)
      testFileName = "";
   
    // load data
    if (testFileName.length() != 0)
      source = new DataSource(testFileName);
    else
      source = new DataSource(test);
    testRaw = source.getStructure(test.classIndex());
   
    // If class is set then do class based evaluation as well
    if (hasClass) {
      if (testRaw.classAttribute().isNumeric())
  throw new Exception("ClusterEvaluation: Class must be nominal!");

      filter = new Remove();
      ((Remove) filter).setAttributeIndices("" + (testRaw.classIndex() + 1));
      ((Remove) filter).setInvertSelection(false);
      filter.setInputFormat(testRaw);
    }
   
    i = 0;
    while (source.hasMoreElements(testRaw)) {
      // next instance
      inst = source.nextElement(testRaw);
      if (filter != null) {
  filter.input(inst);
  filter.batchFinished();
  inst = filter.output();
      }
     
      cnum = -1;
      try {
  if (m_Clusterer instanceof DensityBasedClusterer) {
View Full Code Here

  public String[] getFilterSet(){
      String[] fset = new String[m_filter_set.size()];
      Iterator itrr = m_filter_set.iterator();
      int fset_counter=0;
      while (itrr.hasNext()){
          Filter aFeF = (Filter) itrr.next();
          if (aFeF instanceof OptionHandler)
          {fset[fset_counter] = m_filter_set.indexOf(aFeF) + " " + aFeF.toString() + arrayToString(((OptionHandler) aFeF).getOptions(), " ");}
          else
          {fset[fset_counter] = m_filter_set.indexOf(aFeF) + " " + aFeF.toString();}
          fset_counter++;
      }return fset;
  }
View Full Code Here

//            }
        }
        } catch (Exception e) {System.out.println(e.toString()); return;}

        ArrayList factorialOut = new ArrayList();
        Filter allF = new AllFilter();
        allF = null;
        Filter genericFilter = null;
        ArrayList factorialInB = null;
        try {
        for (Integer count_removes = 0; count_removes<aRemoves.size(); count_removes++){
           for (Integer count_discrete = 0; count_discrete<aDiscrete.size(); count_discrete++) {
                for (Integer count_CVFolds = 0; count_CVFolds<aCVFolds.length; count_CVFolds++){
View Full Code Here

            while (outsideFilterLoop.hasNext()) {                                         /////////// For each Arraylist of GROUPS of Filters
                current_Filter_ArrayList = (ArrayList) outsideFilterLoop.next();
                Iterator insideFilterLoop = current_Filter_ArrayList.iterator();
                filteredInstances = new Instances(allInstances);
                while (insideFilterLoop.hasNext()) {                                      /////////// For each GROUP of Filters
                    Filter insideFilter = (Filter) insideFilterLoop.next();
                    insideFilter.setInputFormat(filteredInstances);
                    filteredInstances = Filter.useFilter(filteredInstances, insideFilter);
                    validationSet = Filter.useFilter(validationSet, insideFilter);
                    filtersApplied.append(insideFilter.getClass().toString()).append(";");
                        if (insideFilter instanceof OptionHandler){
                            for (int i = 0 ;i<((OptionHandler) insideFilter).getOptions().length-1;i++){
                                filtersApplied.append(((OptionHandler) insideFilter).getOptions()[i]).append(" ");
                            }
                            filtersApplied.append(((OptionHandler) insideFilter).getOptions()[((OptionHandler) insideFilter).getOptions().length-1]).append(";");
                        }
                }   //InsideFilterLoop
                Iterator insideFactorialDesign = insideFact.iterator();
                while (insideFactorialDesign.hasNext()){
                    try {
                        Filter insideFilter = (Filter) insideFactorialDesign.next();
                        insideFilter.setInputFormat(filteredInstances);
                        filteredInstances = Filter.useFilter(filteredInstances, insideFilter);
                        validationSet = Filter.useFilter(validationSet, insideFilter);
                        filtersApplied.append(insideFilter.getClass().toString()).append(";");
                        if (insideFilter instanceof OptionHandler){
                            for (int i = 0 ;i<((OptionHandler) insideFilter).getOptions().length-1;i++){
                                filtersApplied.append(((OptionHandler) insideFilter).getOptions()[i]).append(" ");
                            }
                            filtersApplied.append(((OptionHandler) insideFilter).getOptions()[((OptionHandler) insideFilter).getOptions().length-1]).append(";");
View Full Code Here

    // Get all instances
    Instances train = getTrainInstances(trainArff)
    test = getTestInstances(testArff);
   
    // Apply log filter
      Filter logFilter = new LogFilter();
        logFilter.setInputFormat(train);
        train = Filter.useFilter(train, logFilter);       
        logFilter.setInputFormat(test);
        test = Filter.useFilter(test, logFilter);            
       
        Classifier clsCopy;
    try {
      // Copy the classifier
View Full Code Here

    test = getTestInstances(testArff);
   
    // Apply log filter
    if (useLogFilter)
    {
      Filter logFilter = new LogFilter();
      logFilter.setInputFormat(train);
      train = Filter.useFilter(train, logFilter);       
      logFilter.setInputFormat(test);
      test = Filter.useFilter(test, logFilter);
    }
       
        Classifier clsCopy;
    try {
View Full Code Here

TOP

Related Classes of weka.filters.Filter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.