Esempio n. 1
0
 def _predict(self, x, confidence=False):
     ps = np.array([predict(x, self.W[i], self.b[i]) for i in range(self.k)])
     c = np.argmax(ps)
     if confidence:
         return c, ps[c]
     else:
         return c
Esempio n. 2
0
 def _predict(self, x, confidence=False):
     ps = np.array([predict(x, self.W[i], self.b[i]) for i in range(self.k)])
     c = np.argmax(ps)
     if confidence:
         return c,ps[c]
     else:
         return c
Esempio n. 3
0
    def probdist(self, x):
        """The probability distribution of class assignment.
        Transforms the confidence scores into a probability via a logit function
        :math:`\exp{\mathbf{w}^T \mathbf{x} + b} / Z`. 

        :return: a `k`-dimensional probability vector.
        """
        ps = np.array([np.exp(predict(x, self.W[i], self.b[i]))
                       for i in range(self.k)])
        Z = np.sum(ps)
        return ps / Z
Esempio n. 4
0
    def probdist(self, x):
        """The probability distribution of class assignment.
        Transforms the confidence scores into a probability via a logit function
        :math:`\exp{\mathbf{w}^T \mathbf{x} + b} / Z`. 

        :return: a `k`-dimensional probability vector.
        """
        ps = np.array([np.exp(predict(x, self.W[i], self.b[i]))
                       for i in range(self.k)])
        Z = np.sum(ps)
        return ps / Z
Esempio n. 5
0
    def __call__(self, x, confidence=False):
        """Predicts the target value for the given example. 

        :arg x: An instance in dense or sparse representation.
        :arg confidence: whether to output confidence scores.
        :returns: The class assignment and optionally a confidence score.
        
        """
        if x.dtype != sparsedtype:
            x = dense2sparse(x)
        p = predict(x, self.w, self.bias)
        return p
Esempio n. 6
0
    def __call__(self, x, confidence=False):
        """Predicts the target value for the given example. 

        :arg x: An instance in dense or sparse representation.
        :arg confidence: whether to output confidence scores.
        :returns: The class assignment and optionally a confidence score.
        
        """
        if x.dtype != sparsedtype:
            x = dense2sparse(x)
        p = predict(x, self.w, self.bias)
        return p