Example: UnsupervisedOrdinalFilter

In this example a data set with 10 observations and 4 classes is filtered.

import com.imsl.stat.*;
import com.imsl.math.*;
import com.imsl.datamining.neural.*;

public class UnsupervisedOrdinalFilterEx1 {
    public static void main(String args[]) throws Exception {
        int nClasses = 4;
        UnsupervisedOrdinalFilter filter =
        new UnsupervisedOrdinalFilter(nClasses,
        UnsupervisedOrdinalFilter.TRANSFORM_ASIN_SQRT);
        int[] x = {2,1,3,4,2,4,1,1,3,3};
        int nObs = x.length;
        int[] xBack;
        double[] z;
        /* Ordinal Filtering. */
        z = filter.encode(x);
        // Print result without row/column labels.
        PrintMatrix pm = new PrintMatrix();
        PrintMatrixFormat mf;
        mf = new PrintMatrixFormat();
        mf.setNoRowLabels();
        mf.setNoColumnLabels();
        pm.setTitle("Filtered data");
        pm.print(mf, z);
        
        /* Ordinal Un-filtering. */
        pm.setTitle("Un-filtered data");
        xBack = filter.decode(z);
        
        // Print results of Un-filtering.
        pm.print(mf, xBack);
    }
}

Output

Filtered data
         
0.785  
0.58   
1.107  
1.571  
0.785  
1.571  
0.58   
0.58   
1.107  
1.107  

Un-filtered data
     
2  
1  
3  
4  
2  
4  
1  
1  
3  
3  

Link to Java source.