'Trains the classifier with the given document of the given type (i.e., class).
A document can be a Document, Vector, dict, list or string.
If no type is given, Document.type will be used instead.'

def train(self, document, type=None):

    def _update(type, feature, weight, i):
        w = self._weight[type]
        (w0, w1, j) = (w[feature] if (feature in w) else (((random() * 2) - 1), 0, 0))
        w0 += weight
        w[feature] = (w0, (((i - j) * w0) + w1), i)
    (type, vector) = self._vector(document, type=type)
    self._classes[type] = (self._classes.get(type, 0) + 1)
    t1 = type
    t2 = SLP.classify(self, document)
    if (t1 != t2):
        self._iteration += 1
        for f in vector:
            _update(t1, f, (+ 1), self._iteration)
            _update(t2, f, (-1), self._iteration)
