def _calcDistance(self, inputPattern, distanceNorm=None):
if distanceNorm is None:<EOL><INDENT>distanceNorm = self.distanceNorm<EOL><DEDENT>if self.useSparseMemory:<EOL><INDENT>if self._protoSizes is None:<EOL><INDENT>self._protoSizes = self._Memory.rowSums()<EOL><DEDENT>overlapsWithProtos = self._Memory.rightVecSumAtNZ(inputPattern)<EOL>inputPatternSum = inputPattern.sum()<EOL>if self.distanceMethod == "<STR_LIT>":<EOL><INDENT>dist = inputPattern.sum() - overlapsWithProtos<EOL><DEDENT>elif self.distanceMethod == "<STR_LIT>":<EOL><INDENT>dist = inputPatternSum - overlapsWithProtos<EOL>if inputPatternSum > <NUM_LIT:0>:<EOL><INDENT>dist /= inputPatternSum<EOL><DEDENT><DEDENT>elif self.distanceMethod == "<STR_LIT>":<EOL><INDENT>overlapsWithProtos /= self._protoSizes<EOL>dist = <NUM_LIT:1.0> - overlapsWithProtos<EOL><DEDENT>elif self.distanceMethod == "<STR_LIT>":<EOL><INDENT>maxVal = numpy.maximum(self._protoSizes, inputPatternSum)<EOL>if maxVal.all() > <NUM_LIT:0>:<EOL><INDENT>overlapsWithProtos /= maxVal<EOL><DEDENT>dist = <NUM_LIT:1.0> - overlapsWithProtos<EOL><DEDENT>elif self.distanceMethod == "<STR_LIT>":<EOL><INDENT>dist = self._Memory.vecLpDist(self.distanceNorm, inputPattern)<EOL>distMax = dist.max()<EOL>if distMax > <NUM_LIT:0>:<EOL><INDENT>dist /= distMax<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>" %<EOL>self.distanceMethod)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self.distanceMethod == "<STR_LIT>":<EOL><INDENT>dist = numpy.power(numpy.abs(self._M - inputPattern), self.distanceNorm)<EOL>dist = dist.sum(<NUM_LIT:1>)<EOL>dist = numpy.power(dist, <NUM_LIT:1.0>/self.distanceNorm)<EOL>dist /= dist.max()<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError ("<STR_LIT>")<EOL><DEDENT><DEDENT>return dist<EOL>
Calculate the distances from inputPattern to all stored patterns. All
        distances are between 0.0 and 1.0

        :param inputPattern The pattern from which distances to all other patterns
            are calculated

        :param distanceNorm Degree of the distance norm