Class UnsupervisedNominalFilter
- All Implemented Interfaces:
Serializable
Binary Encoding
Method encode can be used to apply binary encoding.
Referring to the result as z, binary encoding takes each
category in the nominal variable x[], and creates a column in z
containing all zeros and ones. A value of zero indicates that this
category was not present and a value of one indicates that it is present.
For example, if x[]={2, 1, 3, 4, 2, 4} then
nClasses=4, and
$$z =\left[ \begin{array} {rrrr}
0 & 1 & 0 & 0 \\
1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
0 & 1 & 0 & 0 \\
0 & 0 & 0 & 1
\end{array}\right ]$$
Notice that the number of columns in the result, z, is equal to the number
of distinct classes in x. The number of rows in z is
equal to the length of x.
Binary Decoding
Unfiltering can be performed using the method decode.
In this case, z is the input, and we refer to x as the output.
Binary unfiltering takes binary representation in z, and returns the
appropriate class in x.
For example, if a row in z equals \(\{0, 1, 0, 0\}\), then the return value from
decode would be \(2\) for that row. If a row in z equals \(\{1, 0, 0, 0\}\),
then the return value from decode would be \(1\) for that row.
Notice these are the same values as the first two elements of the original
x[] because classes are numbered sequentially from
\(1\) to nClasses. This ensures that the results of
decode are associated with the i-th class in x[].
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionUnsupervisedNominalFilter(int nClasses) Constructor forUnsupervisedNominalFilter. -
Method Summary
Modifier and TypeMethodDescriptionintdecode(int[] z) Decodes a binary encoded array into its nominal category.int[]decode(int[][] z) Decodes a matrix representing the binary encoded columns of the nominal variable.int[]encode(int x) Apply forward encoding to a value.int[][]encode(int[] x) Encodes class data prior to its use in neural network training.intRetrieves the number of classes in the nominal variable.
-
Constructor Details
-
UnsupervisedNominalFilter
public UnsupervisedNominalFilter(int nClasses) Constructor forUnsupervisedNominalFilter.- Parameters:
nClasses- Anintspecifying the number of categories in the nominal variable to be filtered.
-
-
Method Details
-
getNumberOfClasses
public int getNumberOfClasses()Retrieves the number of classes in the nominal variable.- Returns:
- An
intcontaining the number of classes in the nominal variable.
-
encode
public int[][] encode(int[] x) Encodes class data prior to its use in neural network training.- Parameters:
x- Anintarray containing the data to be encoded. Class number must be in the range 1 tonClasses.- Returns:
- An
intmatrix containing the encoded data.
-
encode
public int[] encode(int x) Apply forward encoding to a value.- Parameters:
x- Anintcontaining the value to be encoding. Class number must be in the range 1 tonClasses.- Returns:
- An
intarray containing the encoded data.
-
decode
public int decode(int[] z) Decodes a binary encoded array into its nominal category. This is the inverse of theencode(int)method.- Parameters:
z- Anintarray containing the data to be decoded.- Returns:
- An
intcontaining the number associated with the category encoded inz.
-
decode
public int[] decode(int[][] z) Decodes a matrix representing the binary encoded columns of the nominal variable. This is the inverse of theencode(int[])method.- Parameters:
z- Anintmatrix containing the data to be decoded.- Returns:
- An
intarray containing the decoded data.
-