/// /// <summary> * Signify that this batch of input to the filter is finished. If /// * the filter requires all instances prior to filtering, output() /// * may now be called to retrieve the filtered instances. Any /// * subsequent instances filtered should be filtered based on setting /// * obtained from the first batch (unless the inputFormat has been /// * re-assigned or new options have been set). This default /// * implementation assumes all instance processing occurs during /// * inputFormat() and input(). /// * </summary> /// * <returns> true if there are instances pending output </returns> /// * <exception cref="NullPointerException"> if no input structure has been defined, </exception> /// * <exception cref="Exception"> if there was a problem finishing the batch. </exception> /// public override bool batchFinished() { if (getInputFormat() == null) { throw new java.lang.IllegalStateException("No input instance format defined"); } // throw if all attributes are not numeric Instances instances = getInputFormat(); if (instances.numInstances() < getNumCoeffs()) { throw new java.lang.IllegalStateException("Number of coeffs cannot be greater " + "than the total number of instances"); } m_attsFT = new AttFTHolder [instances.numAttributes()]; int nearestPower2; for (int attr = 0; attr < instances.numAttributes(); ++attr) { m_attsFT[attr] = new AttFTHolder(); double[] array = instances.attributeToDoubleArray(attr); // get the nearest power of 2 for the FT for (nearestPower2 = 1; array.Length > nearestPower2; nearestPower2 <<= 1) { ; } // initialize the complex numbers m_attsFT[attr].re = new double[nearestPower2]; m_attsFT[attr].im = new double[nearestPower2]; int j = 0; for (int i=0; i<nearestPower2; ++i, ++j) { m_attsFT[attr].re[i] = (j < array.Length) ? array[i] : 0; m_attsFT[attr].im[i] = 0; } // inplace FT if (m_useFFT) { computeFFT(m_attsFT[attr].re, m_attsFT[attr].im); } else { computeDFT(m_attsFT[attr].re, m_attsFT[attr].im); } } // set instances of the new dataset for (int i=0; i<getNumCoeffs(); ++i) { double[] vals = new double[instances.numAttributes() * 2]; for (int j=0; j<instances.numAttributes(); ++j) { vals[2*j] = m_attsFT[j].re[i]; vals[2*j+1] = m_attsFT[j].im[i]; } Instance inst = new weka.core.DenseInstance(instances.instance(i).weight(), vals); // Modified //inst.setDataset(instances.instance(i).dataset()); push(inst); } flushInput(); m_NewBatch = true; return (numPendingOutput() != 0); }
/// /// <summary> * Signify that this batch of input to the filter is finished. If /// * the filter requires all instances prior to filtering, output() /// * may now be called to retrieve the filtered instances. Any /// * subsequent instances filtered should be filtered based on setting /// * obtained from the first batch (unless the inputFormat has been /// * re-assigned or new options have been set). This default /// * implementation assumes all instance processing occurs during /// * inputFormat() and input(). /// * </summary> /// * <returns> true if there are instances pending output </returns> /// * <exception cref="NullPointerException"> if no input structure has been defined, </exception> /// * <exception cref="Exception"> if there was a problem finishing the batch. </exception> /// public override bool batchFinished() { if (getInputFormat() == null) { throw new java.lang.IllegalStateException("No input instance format defined"); } // throw if all attributes are not numeric Instances instances = getInputFormat(); if (instances.numInstances() < getNumCoeffs()) { throw new java.lang.IllegalStateException("Number of coeffs cannot be greater " + "than the total number of instances"); } m_attsFT = new AttFTHolder [instances.numAttributes()]; int nearestPower2; for (int attr = 0; attr < instances.numAttributes(); ++attr) { m_attsFT[attr] = new AttFTHolder(); double[] array = instances.attributeToDoubleArray(attr); // get the nearest power of 2 for the FT for (nearestPower2 = 1; array.Length > nearestPower2; nearestPower2 <<= 1) { ; } // initialize the complex numbers m_attsFT[attr].re = new double[nearestPower2]; m_attsFT[attr].im = new double[nearestPower2]; int j = 0; for (int i = 0; i < nearestPower2; ++i, ++j) { m_attsFT[attr].re[i] = (j < array.Length) ? array[i] : 0; m_attsFT[attr].im[i] = 0; } // inplace FT if (m_useFFT) { computeFFT(m_attsFT[attr].re, m_attsFT[attr].im); } else { computeDFT(m_attsFT[attr].re, m_attsFT[attr].im); } } // set instances of the new dataset for (int i = 0; i < getNumCoeffs(); ++i) { double[] vals = new double[instances.numAttributes() * 2]; for (int j = 0; j < instances.numAttributes(); ++j) { vals[2 * j] = m_attsFT[j].re[i]; vals[2 * j + 1] = m_attsFT[j].im[i]; } Instance inst = new weka.core.DenseInstance(instances.instance(i).weight(), vals); // Modified //inst.setDataset(instances.instance(i).dataset()); push(inst); } flushInput(); m_NewBatch = true; return(numPendingOutput() != 0); }