/** * Default projection method. */ protected Filter defaultFilter() { PrincipalComponents filter = new PrincipalComponents(); // filter.setNormalize(false); filter.setVarianceCovered(1.0); return filter; }
/** * Input an instance for filtering. Filter requires all training instances be * read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws IllegalStateException if no input format has been set * @throws Exception if conversion fails */ @Override public boolean input(Instance instance) throws Exception { Instance inst; if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (isNewBatch()) { resetQueue(); m_NewBatch = false; } if (isFirstBatchDone()) { inst = convertInstance(instance); inst.setDataset(getOutputFormat()); push(inst, false); // No need to copy return true; } else { bufferInput(instance); return false; } }
/** * Signify that this batch of input to the filter is finished. * * @return true if there are instances pending output * @throws NullPointerException if no input structure has been defined, * @throws Exception if there was a problem finishing the batch. */ @Override public boolean batchFinished() throws Exception { int i; Instances insts; Instance inst; if (getInputFormat() == null) { throw new NullPointerException("No input instance format defined"); } insts = getInputFormat(); if (!isFirstBatchDone()) { setup(insts); } for (i = 0; i < insts.numInstances(); i++) { inst = convertInstance(insts.instance(i)); inst.setDataset(getOutputFormat()); push(inst, false); // No need to copy } flushInput(); m_NewBatch = true; m_FirstBatchDone = true; return (numPendingOutput() != 0); }
/** * Main method for running this filter. * * @param args should contain arguments to the filter: use -h for help */ public static void main(String[] args) { runFilter(new PrincipalComponents(), args); } }
PrincipalComponents pca = new PrincipalComponents(); pca.buildEvaluator(dataSet);
setVarianceCovered(Double.parseDouble(tmpStr)); } else { setVarianceCovered(0.95); setMaximumAttributeNames(Integer.parseInt(tmpStr)); } else { setMaximumAttributeNames(5); setMaximumAttributes(Integer.parseInt(tmpStr)); } else { setMaximumAttributes(-1); setCenterData(Utils.getFlag('C', options));
getCapabilities().testWithFail(m_TrainInstances); fillCovariance(); m_SumOfEigenValues = Utils.sum(m_Eigenvalues); m_TransformedFormat = determineOutputFormat(m_TrainInstances); setOutputFormat(m_TransformedFormat);
/** * Creates a default PrincipalComponents filter. * * @return the default filter */ public Filter getFilter() { return new PrincipalComponents(); }
/** * Runs filter with different variance. */ public void testVariance() { m_Filter = getFilter(); ((PrincipalComponents) m_Filter).setVarianceCovered(0.8); performTest(); }
/** * Runs filter with a maximum number of attributes. */ public void testMaxAttributes() { m_Filter = getFilter(); ((PrincipalComponents) m_Filter).setMaximumAttributeNames(2); performTest(); }
/** * Runs filter with covariance matrix + centering rather than correlation * + standardizing. */ public void testCovariance() { m_Filter = getFilter(); ((PrincipalComponents) m_Filter).setCenterData(true); performTest(); }
setVarianceCovered(Double.parseDouble(tmpStr)); } else { setVarianceCovered(0.95); setMaximumAttributeNames(Integer.parseInt(tmpStr)); } else { setMaximumAttributeNames(5); setMaximumAttributes(Integer.parseInt(tmpStr)); } else { setMaximumAttributes(-1); setCenterData(Utils.getFlag('C', options));
/** * Main method for running this filter. * * @param args should contain arguments to the filter: use -h for help */ public static void main(String[] args) { runFilter(new PrincipalComponents(), args); } }
getCapabilities().testWithFail(m_TrainInstances); fillCovariance(); m_SumOfEigenValues = Utils.sum(m_Eigenvalues); m_TransformedFormat = determineOutputFormat(m_TrainInstances); setOutputFormat(m_TransformedFormat);
/** * Creates a default PrincipalComponents filter. * * @return the default filter */ public Filter getFilter() { return new PrincipalComponents(); }
/** * Runs filter with different variance. */ public void testVariance() { m_Filter = getFilter(); ((PrincipalComponents) m_Filter).setVarianceCovered(0.8); performTest(); }
/** * Runs filter with a maximum number of attributes. */ public void testMaxAttributes() { m_Filter = getFilter(); ((PrincipalComponents) m_Filter).setMaximumAttributeNames(2); performTest(); }
/** * Runs filter with covariance matrix + centering rather than correlation * + standardizing. */ public void testCovariance() { m_Filter = getFilter(); ((PrincipalComponents) m_Filter).setCenterData(true); performTest(); }
/** * Signify that this batch of input to the filter is finished. * * @return true if there are instances pending output * @throws NullPointerException if no input structure has been defined, * @throws Exception if there was a problem finishing the batch. */ @Override public boolean batchFinished() throws Exception { int i; Instances insts; Instance inst; if (getInputFormat() == null) { throw new NullPointerException("No input instance format defined"); } insts = getInputFormat(); if (!isFirstBatchDone()) { setup(insts); } for (i = 0; i < insts.numInstances(); i++) { inst = convertInstance(insts.instance(i)); inst.setDataset(getOutputFormat()); push(inst, false); // No need to copy } flushInput(); m_NewBatch = true; m_FirstBatchDone = true; return (numPendingOutput() != 0); }
/** * Input an instance for filtering. Filter requires all training instances be * read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws IllegalStateException if no input format has been set * @throws Exception if conversion fails */ @Override public boolean input(Instance instance) throws Exception { Instance inst; if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (isNewBatch()) { resetQueue(); m_NewBatch = false; } if (isFirstBatchDone()) { inst = convertInstance(instance); inst.setDataset(getOutputFormat()); push(inst, false); // No need to copy return true; } else { bufferInput(instance); return false; } }