/** * ReorderLabels - swap values of y[1] to y[L] according to s[]. * @param s new indices order (supposing that it contains the first s.length indices) */ public static void reorderLabels(Instances D, int s[]) throws Exception { int L = s.length; Reorder f = new Reorder(); String range = ""; for(int j = 0; j < L; j++) { range += String.valueOf(s[0]) + ","; } range = range + (L+1) + "-last"; f.setAttributeIndices(range); f.setInputFormat(D); D = Filter.useFilter(D, f); //return D; }
/** * processes the given instance (may change the provided instance) and * returns the modified version. * * @param instance the instance to process * @return the modified data * @throws Exception in case the processing goes wrong */ protected Instance process(Instance instance) throws Exception { m_Reorder.input(instance); m_Reorder.batchFinished(); return m_Reorder.output(); }
Reorder reorderFilter = new Reorder(); reorderFilter.setAttributeIndicesArray(order); reorderFilter.setInputFormat(instances); instances = Filter.useFilter(instances, reorderFilter);
order.append("" + (i+1)); m_Reorder.setAttributeIndices(order.toString()); m_Reorder.setInputFormat(inputFormat); output = m_Reorder.getOutputFormat(); output.setClassIndex(indices.length); output.setRelationName("-C " + indices.length);
m_ReorderOriginal = new Reorder(); m_ReorderOriginal.setAttributeIndicesArray(al.stream().mapToInt(j -> j).toArray()); m_ReorderOriginal.setAllAttributeWeightsToOne(true); m_ReorderOriginal.setInputFormat(data); return Filter.useFilter(data, m_ReorderOriginal); } else { m_ReorderFiltered = new Reorder(); m_ReorderFiltered.setAttributeIndicesArray(al.stream().mapToInt(j -> j).toArray()); m_ReorderFiltered.setAllAttributeWeightsToOne(true); m_ReorderFiltered.setInputFormat(data); return Filter.useFilter(data, m_ReorderFiltered);
/** * Parses a given list of options. * <p/> * * <!-- options-start --> Valid options are: * <p/> * * <pre> * -R <index1,index2-index4,...> * Specifies the order of the attributes (default first-last). * </pre> * * <!-- options-end --> * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ @Override public void setOptions(String[] options) throws Exception { String orderList = Utils.getOption('R', options); if (orderList.length() != 0) { setAttributeIndices(orderList); } if (getInputFormat() != null) { setInputFormat(getInputFormat()); } Utils.checkForRemainingOptions(options); }
/** Creates a specialized Reorder */ public Filter getFilter(String rangelist) { try { Reorder af = new Reorder(); af.setAttributeIndices(rangelist); return af; } catch (Exception ex) { ex.printStackTrace(); fail("Exception setting attribute range: " + rangelist + "\n" + ex.getMessage()); } return null; }
/** * Computes an array that has a value for each element in the partition. (If * the base classifier supports this.) */ public double[] getMembershipValues(Instance inst) throws Exception { if (m_Classifier instanceof PartitionGenerator) { if (m_ReorderOriginal != null) { m_ReorderOriginal.input(inst); inst = m_ReorderOriginal.output(); } Instance newInstance = filterInstance(inst); if (newInstance == null) { double[] unclassified = new double[numElements()]; for (int i = 0; i < unclassified.length; i++) { unclassified[i] = Utils.missingValue(); } return unclassified; } else { if (m_ReorderFiltered != null) { m_ReorderFiltered.input(newInstance); newInstance = m_ReorderFiltered.output(); } return ((PartitionGenerator) m_Classifier).getMembershipValues(newInstance); } } else throw new Exception( "Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); resetQueue(); m_NewBatch = false; double[] vals = new double[outputFormatPeek().numAttributes()]; for (int i = 0; i < m_SelectedAttributes.length; i++) { int current = m_SelectedAttributes[i]; copyValues(inst, false, instance.dataset(), outputFormatPeek()); push(inst); // No need to copy
/** * Set which attributes are to be copied (or kept if invert is true) * * @param attributes an array containing indexes of attributes to select. * Since the array will typically come from a program, attributes are * indexed from 0.<br> * Note: use this method before you call * <code>setInputFormat(Instances)</code>, since the output format is * determined in that method. * @throws Exception if an invalid set of ranges is supplied */ public void setAttributeIndicesArray(int[] attributes) throws Exception { setAttributeIndices(Range.indicesToRangeList(attributes)); }
Reorder reorderFilter = new Reorder(); reorderFilter.setAttributeIndicesArray(order); reorderFilter.setInputFormat(instances); instances = Filter.useFilter(instances, reorderFilter);
order.append("" + (i+1)); m_Reorder.setAttributeIndices(order.toString()); m_Reorder.setInputFormat(inputFormat); output = m_Reorder.getOutputFormat(); output.setClassIndex(indices.length); output.setRelationName("-C " + indices.length);
m_ReorderOriginal = new Reorder(); m_ReorderOriginal.setAttributeIndicesArray(al.stream().mapToInt(j -> j).toArray()); m_ReorderOriginal.setAllAttributeWeightsToOne(true); m_ReorderOriginal.setInputFormat(data); return Filter.useFilter(data, m_ReorderOriginal); } else { m_ReorderFiltered = new Reorder(); m_ReorderFiltered.setAttributeIndicesArray(al.stream().mapToInt(j -> j).toArray()); m_ReorderFiltered.setAllAttributeWeightsToOne(true); m_ReorderFiltered.setInputFormat(data); return Filter.useFilter(data, m_ReorderFiltered);
/** * Parses a given list of options. * <p/> * * <!-- options-start --> Valid options are: * <p/> * * <pre> * -R <index1,index2-index4,...> * Specifies the order of the attributes (default first-last). * </pre> * * <!-- options-end --> * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ @Override public void setOptions(String[] options) throws Exception { String orderList = Utils.getOption('R', options); if (orderList.length() != 0) { setAttributeIndices(orderList); } if (getInputFormat() != null) { setInputFormat(getInputFormat()); } Utils.checkForRemainingOptions(options); }
/** Creates a specialized Reorder */ public Filter getFilter(String rangelist) { try { Reorder af = new Reorder(); af.setAttributeIndices(rangelist); return af; } catch (Exception ex) { ex.printStackTrace(); fail("Exception setting attribute range: " + rangelist + "\n" + ex.getMessage()); } return null; }
/** * Computes an array that has a value for each element in the partition. (If * the base classifier supports this.) */ public double[] getMembershipValues(Instance inst) throws Exception { if (m_Classifier instanceof PartitionGenerator) { if (m_ReorderOriginal != null) { m_ReorderOriginal.input(inst); inst = m_ReorderOriginal.output(); } Instance newInstance = filterInstance(inst); if (newInstance == null) { double[] unclassified = new double[numElements()]; for (int i = 0; i < unclassified.length; i++) { unclassified[i] = Utils.missingValue(); } return unclassified; } else { if (m_ReorderFiltered != null) { m_ReorderFiltered.input(newInstance); newInstance = m_ReorderFiltered.output(); } return ((PartitionGenerator) m_Classifier).getMembershipValues(newInstance); } } else throw new Exception( "Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); resetQueue(); m_NewBatch = false; double[] vals = new double[outputFormatPeek().numAttributes()]; for (int i = 0; i < m_SelectedAttributes.length; i++) { int current = m_SelectedAttributes[i]; copyValues(inst, false, instance.dataset(), outputFormatPeek()); push(inst); // No need to copy
/** * Set which attributes are to be copied (or kept if invert is true) * * @param attributes an array containing indexes of attributes to select. * Since the array will typically come from a program, attributes are * indexed from 0.<br> * Note: use this method before you call * <code>setInputFormat(Instances)</code>, since the output format is * determined in that method. * @throws Exception if an invalid set of ranges is supplied */ public void setAttributeIndicesArray(int[] attributes) throws Exception { setAttributeIndices(Range.indicesToRangeList(attributes)); }