Package weka.filters

Examples of weka.filters.Filter


   
    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_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

   * @return the filter string.
   */
  /* Taken from FilteredClassifier */
  protected String getProjectionFilterSpec() {
   
    Filter c = getProjectionFilter();
    if (c instanceof OptionHandler) {
      return c.getClass().getName() + " "
  + Utils.joinOptions(((OptionHandler)c).getOptions());
    }
    return c.getClass().getName();
  }
View Full Code Here

    else
      m_Filter = null;


    Instances transformedInsts;
    Filter convertToProp = new MultiInstanceToPropositional();
    Filter convertToMI = new PropositionalToMultiInstance();

    //transform the data into single-instance format
    if (m_minimax){
      /* using SimpleMI class minimax transform method.
         this method transforms the multi-instance dataset into minmax feature space (single-instance) */
      SimpleMI transMinimax = new SimpleMI();
      transMinimax.setTransformMethod(
          new SelectedTag(
            SimpleMI.TRANSFORMMETHOD_MINIMAX, SimpleMI.TAGS_TRANSFORMMETHOD));
      transformedInsts = transMinimax.transform(insts);
    }
    else {
      convertToProp.setInputFormat(insts);
      transformedInsts=Filter.useFilter(insts, convertToProp);
    }

    if (m_Missing != null) {
      m_Missing.setInputFormat(transformedInsts);
      transformedInsts = Filter.useFilter(transformedInsts, m_Missing);
    }

    if (m_NominalToBinary != null) {
      m_NominalToBinary.setInputFormat(transformedInsts);
      transformedInsts = Filter.useFilter(transformedInsts, m_NominalToBinary);
    }

    if (m_Filter != null) {
      m_Filter.setInputFormat(transformedInsts);
      transformedInsts = Filter.useFilter(transformedInsts, m_Filter);
    }

    // convert the single-instance format to multi-instance format
    convertToMI.setInputFormat(transformedInsts);
    insts = Filter.useFilter( transformedInsts, convertToMI);

    m_classIndex = insts.classIndex();
    m_classAttribute = insts.classAttribute();

View Full Code Here

    //convert instance into instances
    Instances insts = new Instances(inst.dataset(), 0);
    insts.add(inst);

    //transform the data into single-instance format
    Filter convertToProp = new MultiInstanceToPropositional();
    Filter convertToMI = new PropositionalToMultiInstance();

    if (m_minimax){ // using minimax feature space
      SimpleMI transMinimax = new SimpleMI();
      transMinimax.setTransformMethod(
          new SelectedTag(
            SimpleMI.TRANSFORMMETHOD_MINIMAX, SimpleMI.TAGS_TRANSFORMMETHOD));
      insts = transMinimax.transform (insts);
    }
    else{
      convertToProp.setInputFormat(insts);
      insts=Filter.useFilter( insts, convertToProp);
    }

    // Filter instances
    if (m_Missing!=null)
      insts = Filter.useFilter(insts, m_Missing);
   
    if (m_NominalToBinary != null) {
      insts = Filter.useFilter(insts, m_NominalToBinary);
    }

    if (m_Filter!=null)
      insts = Filter.useFilter(insts, m_Filter);    

    // convert the single-instance format to multi-instance format
    convertToMI.setInputFormat(insts);
    insts=Filter.useFilter( insts, convertToMI);

    inst = insts.instance(0)

    if (!m_fitLogisticModels) {
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

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

   * 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

   * @throws Exception  if the option setting fails
   */
  public void setOptions(String[] options) throws Exception {
    String  tmpStr;
    String[]  tmpOptions;
    Filter  filter;

    super.setOptions(options);

    tmpStr = Utils.getOption("A", options);
    if (tmpStr.length() != 0)
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(Messages.getInstance().getString("PreprocessPanel_OpenFileBut_SetToolTipText_Text"));
    m_OpenURLBut.setToolTipText(Messages.getInstance().getString("PreprocessPanel_OpenURLBut_SetToolTipText_Text"));
    m_OpenDBBut.setToolTipText(Messages.getInstance().getString("PreprocessPanel_OpenDBBut_SetToolTipText_Text"));
    m_GenerateBut.setToolTipText(Messages.getInstance().getString("PreprocessPanel_GenerateBut_SetToolTipText_Text"));
    m_UndoBut.setToolTipText(Messages.getInstance().getString("PreprocessPanel_UndoBut_SetToolTipText_Text"));
    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(Messages.getInstance().getString("PreprocessPanel_EditBut_SetToolTipText_Text"));
    m_SaveBut.setToolTipText(Messages.getInstance().getString("PreprocessPanel_SaveBut_SetToolTipText_Text"));
    m_ApplyFilterBut.setToolTipText(Messages.getInstance().getString("PreprocessPanel_ApplyFilterBut_SetToolTipText_Text"));

    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());
      }
    });
    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(Messages.getInstance().getString("PreprocessPanel_InstSummaryPanel_BorderFactoryCreateTitledBorder_Text")));
    JPanel attStuffHolderPanel = new JPanel();
    attStuffHolderPanel.setBorder(BorderFactory
          .createTitledBorder(Messages.getInstance().getString("PreprocessPanel_AttStuffHolderPanel_BorderFactoryCreateTitledBorder_Text")));
    attStuffHolderPanel.setLayout(new BorderLayout());
    attStuffHolderPanel.add(m_AttPanel, BorderLayout.CENTER);
    m_RemoveButton.setEnabled(false);
    m_RemoveButton.setToolTipText(Messages.getInstance().getString("PreprocessPanel_RemoveButton_SetToolTipText_Text"));
    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,
            Messages.getInstance().getString("PreprocessPanel_JOptionPaneShowMessageDialog_Text_First"),
            Messages.getInstance().getString("PreprocessPanel_JOptionPaneShowMessageDialog_Text_Second"),
              JOptionPane.ERROR_MESSAGE);
        m_Log.logMessage(Messages.getInstance().getString("PreprocessPanel_Log_LogMessage_Text_First"));
        m_Log.statusMessage(Messages.getInstance().getString("PreprocessPanel_Log_StatusMessage_Text_First"));
        return;
      }
      r.setAttributeIndicesArray(selected);
      applyFilter(r);
    } catch (Exception ex) {
      if (m_Log instanceof TaskLogger) {
        ((TaskLogger)m_Log).taskFinished();
      }
      // Pop up an error optionpane
      JOptionPane.showMessageDialog(PreprocessPanel.this,
          Messages.getInstance().getString("PreprocessPanel_JOptionPaneShowMessageDialog_Text_Third")
            + ex.getMessage(),
            Messages.getInstance().getString("PreprocessPanel_JOptionPaneShowMessageDialog_Text_Fourth"),
            JOptionPane.ERROR_MESSAGE);
      m_Log.logMessage(Messages.getInstance().getString("PreprocessPanel_Log_LogMessage_Text_Second") + ex.getMessage());
      m_Log.statusMessage(Messages.getInstance().getString("PreprocessPanel_Log_StatusMessage_Text_Second"));
    }
  }
      });

    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(Messages.getInstance().getString("PreprocessPanel_AttSummaryPanel_BorderFactoryCreateTitledBorder_Text")));
    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(Messages.getInstance().getString("PreprocessPanel_Filter_BorderFactoryCreateTitledBorder_Text")));
    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

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.