def closestTrainingPattern(self, inputPattern, cat):
dist = self._getDistances(inputPattern)<EOL>sorted = dist.argsort()<EOL>for patIdx in sorted:<EOL><INDENT>patternCat = self._categoryList[patIdx]<EOL>if patternCat == cat:<EOL><INDENT>if self.useSparseMemory:<EOL><INDENT>closestPattern = self._Memory.getRow(int(patIdx))<EOL><DEDENT>else:<EOL><INDENT>closestPattern = self._M[patIdx]<EOL><DEDENT>return closestPattern<EOL><DEDENT><DEDENT>return None<EOL>
Returns the closest training pattern to inputPattern that belongs to
        category "cat".

        :param inputPattern: The pattern whose closest neighbor is sought

        :param cat: The required category of closest neighbor

        :returns: A dense version of the closest training pattern, or None if no
            such patterns exist