public class UnsupervisedOrdinalFilter extends Object implements 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.
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 takes a transformed cumulative proportion and converts it into an ordinal class value.
Modifier and Type | Field and Description |
---|---|
static int |
TRANSFORM_ASIN_SQRT
Flag to indicate the arcsine square root transform will be applied to the percentages.
|
static int |
TRANSFORM_NONE
Flag to indicate no transformation of percentages.
|
static int |
TRANSFORM_SQRT
Flag to indicate the square root transform will be applied to the percentages.
|
Constructor and Description |
---|
UnsupervisedOrdinalFilter(int nClasses,
int transform)
Constructor for
UnsupervisedOrdinalFilter . |
Modifier and Type | Method and Description |
---|---|
int |
decode(double z)
Decodes an encoded ordinal variable.
|
int[] |
decode(double[] z)
Decodes an array of encoded ordinal values.
|
double |
encode(int x)
Encodes an ordinal category.
|
double[] |
encode(int[] x)
Encodes an array of ordinal categories into an array of transformed percentages.
|
int |
getNumberOfClasses()
Retrieves the number of categories associated with this ordinal variable.
|
double[] |
getPercentages()
Retrieves the cumulative percentages used for encoding and decoding.
|
int |
getTransform()
Retrieves the transform flag used for encoding and decoding.
|
void |
setPercentages(double[] percentages)
Set the untransformed cumulative percentages used during encoding and decoding.
|
public static final int TRANSFORM_NONE
public static final int TRANSFORM_SQRT
public static final int TRANSFORM_ASIN_SQRT
public UnsupervisedOrdinalFilter(int nClasses, int transform)
UnsupervisedOrdinalFilter
.nClasses
- An int
specifying the number of classes in the data to be filtered.transform
- An int
specifying the transform to be applied to the percentages.
Values for transform
are:
UnsupervisedOrdinalFilter.TRANSFORM_NONE
,
UnsupervisedOrdinalFilter.TRANSFORM_SQRT
,
UnsupervisedOrdinalFilter.TRANSFORM_ASIN_SQRT
public void setPercentages(double[] percentages)
percentages
- A double
array of length nClasses
containing the cumulative percentages to use during encoding
and decoding.public double[] getPercentages()
double
array of length nClasses
containing the cumulative transformed percentages
associated with the ordinal categories.public int getNumberOfClasses()
int
containing the number of categories
associated with this ordinal variable.public int getTransform()
int
containing the transform flag used for
encoding and decoding.public double[] encode(int[] x)
x
- An int
array containing the categories for the ordinal
variable. Categories must be numbered from
1 to nClasses
.double
array of the transformed percentages.public double encode(int x)
x
- An int
containing the ordinal category. Must be
an integer between 1 and nClasses
.double
containing the encoded value, a transformed cumulative percentage.public int decode(double z)
z
- A double
containing the encoded value to be decoded.int
containing the ordinal category associated with y
.public int[] decode(double[] z)
z
- A double
array containing the encoded ordinal data to be decoded.int
array containing the decoded ordinal classifications.Copyright © 2020 Rogue Wave Software. All rights reserved.