Class UnsupervisedOrdinalFilter
- All Implemented Interfaces:
Serializable
Class UnsupervisedOrdinalFilter is designed to either encode or decode
ordinal variables. Encoding consists of transforming the ordinal classes
into percentages, with each percentage being equal to the percentage of the
data at or below this class.
Ordinal Encoding
In this case, x is input to the
method encode and is filtered by
converting each ordinal class value into a cumulative percentage.
For example, if x[]={2, 1, 3, 4, 2, 4, 1, 1, 3, 3} then
nClasses=4, and encode returns
the ordinal class designation with the cumulative
percentages displayed in the following table. Cumulative percentages are
equal to the percent of the data in this class or a lower class.
| Ordinal Class | Frequency | Cumulative Percentage |
1 | 3 | 30% |
2 | 2 | 50% |
3 | 3 | 80% |
4 | 2 | 100% |
Classes in x must be numbered from 1 to nClasses.
The values returned from encoding or decoding depend upon the setting of
transform. In this example, if the filter was constructed
with transform = TRANSFORM_NONE, then
the method encode will return
$$z[] = \{50, 30, 80, 100, 50, 100, 30, 30, 80, 80\}.$$
If the filter was constructed with transform = TRANSFORM_SQRT,
then the square root of these values is returned, i.e.,
$$z[i] = \sqrt{\frac{z[i]}{100}}$$
$$z[] = \{0.71, 0.55, 0.89, 1.0, 0.71, 1.0, 0.55, 0.55, 0.89, 0.89\};$$
If the filter was constructed with transform = TRANSFORM_ASIN_SQRT,
then the arcsin square root of these
values is returned using the following calculation:
$$z[i] = \arcsin{\left(\sqrt{\frac{z[i]}{100}}\right)}$$
Ordinal Decoding
Ordinal decoding takes a transformed cumulative proportion and converts it into an ordinal class value.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intFlag to indicate the arcsine square root transform will be applied to the percentages.static final intFlag to indicate no transformation of percentages.static final intFlag to indicate the square root transform will be applied to the percentages. -
Constructor Summary
ConstructorsConstructorDescriptionUnsupervisedOrdinalFilter(int nClasses, int transform) Constructor forUnsupervisedOrdinalFilter. -
Method Summary
Modifier and TypeMethodDescriptionintdecode(double z) Decodes an encoded ordinal variable.int[]decode(double[] z) Decodes an array of encoded ordinal values.doubleencode(int x) Encodes an ordinal category.double[]encode(int[] x) Encodes an array of ordinal categories into an array of transformed percentages.intRetrieves the number of categories associated with this ordinal variable.double[]Retrieves the cumulative percentages used for encoding and decoding.intRetrieves the transform flag used for encoding and decoding.voidsetPercentages(double[] percentages) Set the untransformed cumulative percentages used during encoding and decoding.
-
Field Details
-
TRANSFORM_NONE
public static final int TRANSFORM_NONEFlag to indicate no transformation of percentages.- See Also:
-
TRANSFORM_SQRT
public static final int TRANSFORM_SQRTFlag to indicate the square root transform will be applied to the percentages.- See Also:
-
TRANSFORM_ASIN_SQRT
public static final int TRANSFORM_ASIN_SQRTFlag to indicate the arcsine square root transform will be applied to the percentages.- See Also:
-
-
Constructor Details
-
UnsupervisedOrdinalFilter
public UnsupervisedOrdinalFilter(int nClasses, int transform) Constructor forUnsupervisedOrdinalFilter.- Parameters:
nClasses- Anintspecifying the number of classes in the data to be filtered.transform- Anintspecifying the transform to be applied to the percentages. Values fortransformare:TRANSFORM_NONE,TRANSFORM_SQRT,TRANSFORM_ASIN_SQRT
-
-
Method Details
-
setPercentages
public void setPercentages(double[] percentages) Set the untransformed cumulative percentages used during encoding and decoding. Setting percentages with this method bypasses calculating cumulative percentages based on the data being encoded. The percentages must be nondecreasing in the interval [0, 100], with the last element equal to 100. If this method is used it must be called prior to any calls to the encoding and decoding methods.- Parameters:
percentages- Adoublearray of lengthnClassescontaining the cumulative percentages to use during encoding and decoding.
-
getPercentages
public double[] getPercentages()Retrieves the cumulative percentages used for encoding and decoding. If a transform has been applied to the percentages then the transformed percentages are returned.- Returns:
- A
doublearray of lengthnClassescontaining the cumulative transformed percentages associated with the ordinal categories.
-
getNumberOfClasses
public int getNumberOfClasses()Retrieves the number of categories associated with this ordinal variable.- Returns:
- An
intcontaining the number of categories associated with this ordinal variable.
-
getTransform
public int getTransform()Retrieves the transform flag used for encoding and decoding.- Returns:
- An
intcontaining the transform flag used for encoding and decoding.
-
encode
public double[] encode(int[] x) Encodes an array of ordinal categories into an array of transformed percentages.- Parameters:
x- Anintarray containing the categories for the ordinal variable. Categories must be numbered from 1 tonClasses.- Returns:
- A
doublearray of the transformed percentages.
-
encode
public double encode(int x) Encodes an ordinal category.- Parameters:
x- Anintcontaining the ordinal category. Must be an integer between 1 andnClasses.- Returns:
- A
doublecontaining the encoded value, a transformed cumulative percentage.
-
decode
public int decode(double z) Decodes an encoded ordinal variable.- Parameters:
z- Adoublecontaining the encoded value to be decoded.- Returns:
- An
intcontaining the ordinal category associated withy.
-
decode
public int[] decode(double[] z) Decodes an array of encoded ordinal values.- Parameters:
z- Adoublearray containing the encoded ordinal data to be decoded.- Returns:
- An
intarray containing the decoded ordinal classifications.
-