olpy/classifiers/cw.py
def _update(self, x: np.ndarray, y: int):
        """Updates the weight vector in case a mistake occured.
        
        When presented with a data point, this method evaluates
        the error and based on the result, updates or not the 
        weights vector.

        Args:
            x (:obj:`np.ndarray` or `list`): An array representing
                one single data point. Array needs to be 2D.
            y (`int`): Output value for the data point. Takes value
                between 1 and -1.

        Returns:
            None

        Raises:
            IndexError: if the value x is not 2D.
        """
        decision = self.weights.dot(x)
        v_t = x @ np.diag(np.diag(self._sigma)) @ x.T
        m_t = y * decision
        loss = (self._phi * math.sqrt(v_t) - m_t)
        #print(loss)
        if loss > 0:
            # We scale our learning rate (alpha) using the weight/cost
            alpha_t = self.class_weight_[y] * self._get_alpha(m_t, v_t)
            u_t = 0.25 * (-alpha_t * v_t * self._phi + math.sqrt(
                alpha_t ** 2 * v_t ** 2 * self._phi ** 2 + 4 * v_t)) ** 2
            beta_t = alpha_t * self._phi / (math.sqrt(u_t) +
                                           alpha_t * self._phi * v_t)
            sigma = np.expand_dims(x @ self._sigma, axis=0)
            self.weights += alpha_t * y * np.squeeze(sigma)
            self._sigma -= beta_t * sigma.T @ sigma
Updates the weight vector in case a mistake occured.
        
        When presented with a data point, this method evaluates
        the error and based on the result, updates or not the 
        weights vector.

        Args:
            x (:obj:`np.ndarray` or `list`): An array representing
                one single data point. Array needs to be 2D.
            y (`int`): Output value for the data point. Takes value
                between 1 and -1.

        Returns:
            None

        Raises:
            IndexError: if the value x is not 2D.
        
Updates the weight vector in case a mistake occured.
When presented with a data point, this method evaluates
the error and based on the result, updates or not the
weights vector.
Updates the weight vector in case a mistake occured . When presented with a data point this method evaluates the error and based on the result updates or not the weights vector .
def _update(self, x: np.ndarray, y: int):
        decision = self.weights.dot(x)
        v_t = x @ np.diag(np.diag(self._sigma)) @ x.T
        m_t = y * decision
        loss = (self._phi * math.sqrt(v_t) - m_t)
        if loss > 0:
            alpha_t = self.class_weight_[y] * self._get_alpha(m_t, v_t)
            u_t = 0.25 * (-alpha_t * v_t * self._phi + math.sqrt(
                alpha_t ** 2 * v_t ** 2 * self._phi ** 2 + 4 * v_t)) ** 2
            beta_t = alpha_t * self._phi / (math.sqrt(u_t) +
                                           alpha_t * self._phi * v_t)
            sigma = np.expand_dims(x @ self._sigma, axis=0)
            self.weights += alpha_t * y * np.squeeze(sigma)
            self._sigma -= beta_t * sigma.T @ sigma
def _update ( self , x : np . ndarray , y : int ) : decision = self . weights . dot ( x ) v_t = x @ np . diag ( np . diag ( self . _sigma ) ) @ x . T m_t = y * decision loss = ( self . _phi * math . sqrt ( v_t ) - m_t ) if loss > 0 : alpha_t = self . class_weight_ [ y ] * self . _get_alpha ( m_t , v_t ) u_t = 0.25 * ( - alpha_t * v_t * self . _phi + math . sqrt ( alpha_t ** 2 * v_t ** 2 * self . _phi ** 2 + 4 * v_t ) ) ** 2 beta_t = alpha_t * self . _phi / ( math . sqrt ( u_t ) + alpha_t * self . _phi * v_t ) sigma = np . expand_dims ( x @ self . _sigma , axis = 0 ) self . weights += alpha_t * y * np . squeeze ( sigma ) self . _sigma -= beta_t * sigma . T @ sigma
Updates the weight vector in case a mistake occured.
Updates the weight vector in case a mistake occured .
"""Updates the weight vector in case a mistake occured.
        
        When presented with a data point, this method evaluates
        the error and based on the result, updates or not the 
        weights vector.

        Args:
            x (:obj:`np.ndarray` or `list`): An array representing
                one single data point. Array needs to be 2D.
            y (`int`): Output value for the data point. Takes value
                between 1 and -1.

        Returns:
            None

        Raises:
            IndexError: if the value x is not 2D.
        """ #print(loss) # We scale our learning rate (alpha) using the weight/cost
None
if the value x is not 2D.
if the value x is not 2D .
IndexError
self
x
np.ndarray
y
int
Output value for the data point. Takes value
between 1 and -1.
Output value for the data point . Takes value between 1 and - 1 .
x (
`np.ndarray` or `list`): An array representing
one single data point. Array needs to be 2D.
` np . ndarray ` or ` list ` ) : An array representing one single data point . Array needs to be 2D .