weakEigenPairs = new ArrayList<>();
// determine sum of eigenvalues
double totalSum = 0;
for(int i = 0; i < eigenPairs.size(); i++) {
EigenPair eigenPair = eigenPairs.getEigenPair(i);
totalSum += eigenPair.getEigenvalue();
}
if(LOG.isDebugging()) {
msg.append("\ntotalSum = ").append(totalSum);
}
// determine strong and weak eigenpairs
double currSum = 0;
boolean found = false;
for(int i = 0; i < eigenPairs.size(); i++) {
EigenPair eigenPair = eigenPairs.getEigenPair(i);
currSum += eigenPair.getEigenvalue();
if(currSum / totalSum >= alpha) {
if(!found) {
found = true;
strongEigenPairs.add(eigenPair);
}
else {
weakEigenPairs.add(eigenPair);
}
}
else {
strongEigenPairs.add(eigenPair);
}
}
if(LOG.isDebugging()) {
msg.append("\nstrong EigenPairs = ").append(strongEigenPairs);
msg.append("\nweak EigenPairs = ").append(weakEigenPairs);
LOG.debugFine(msg.toString());
}
return new FilteredEigenPairs(weakEigenPairs, strongEigenPairs);
}
/**
* Parameterization class.
*
* @author Erich Schubert
*
* @apiviz.exclude
*/
public static class Parameterizer extends AbstractParameterizer {
/**
* The threshold for 'strong' eigenvectors: the 'strong' eigenvectors explain
* a portion of at least alpha of the total variance.
*
* Default value: {@link #DEFAULT_ALPHA}
*
*
* Key: {@code -pca.filter.alpha}
*
*/
public static final OptionID ALPHA_ID = new OptionID("pca.filter.alpha", "The share (0.0 to 1.0) of variance that needs to be explained by the 'strong' eigenvectors." + "The filter class will choose the number of strong eigenvectors by this share.");
/**
* The threshold for strong eigenvectors: the strong eigenvectors explain a
* portion of at least alpha of the total variance.
*/
private double alpha;
@Override
protected void makeOptions(Parameterization config) {
super.makeOptions(config);
DoubleParameter alphaP = new DoubleParameter(ALPHA_ID, DEFAULT_ALPHA);
alphaP.addConstraint(CommonConstraints.GREATER_THAN_ZERO_DOUBLE);
alphaP.addConstraint(CommonConstraints.LESS_THAN_ONE_DOUBLE);
if(config.grab(alphaP)) {
alpha = alphaP.doubleValue();
}
}
@Override
protected PercentageEigenPairFilter makeInstance() {
return new PercentageEigenPairFilter(alpha);
}
}
}