In this example a data set with 7 observations and 3 classes is filtered.
import com.imsl.stat.*;
import com.imsl.math.*;
import com.imsl.datamining.neural.*;
public class UnsupervisedNominalFilterEx1 {
public static void main(String args[]) throws Exception {
int nClasses = 3;
UnsupervisedNominalFilter filter = new UnsupervisedNominalFilter(nClasses);
int nObs = 7;
int[] x = {3, 3, 1, 2, 2, 1, 2};
int[] xBack = new int[nObs];
int[][] z;
/* Perform Binary Filtering. */
z = filter.encode(x);
PrintMatrix pm = new PrintMatrix();
pm.setTitle("Filtered x");
pm.print(z);
/* Perform Binary Un-filtering. */
for (int i=0;i<nObs;i++) {
xBack[i] = filter.decode(z[i]);
}
pm.setTitle("Result of inverse filtering");
pm.print(xBack);
}
}
Filtered x 0 1 2 0 0 0 1 1 0 0 1 2 1 0 0 3 0 1 0 4 0 1 0 5 1 0 0 6 0 1 0 Result of inverse filtering 0 0 3 1 3 2 1 3 2 4 2 5 1 6 2Link to Java source.