示例#1
0
    def __init__(self, alpha=None, beta=None):
        """
        Constructor.

        Args:
            alpha: alpha parameter, numeric type. Optional, can be set through
            training
            beta: beta parameter, numeric type. Optional, can be set through
            training.

        Raises:
            TypeError if alpha or beta are not numeric.
        """
        self._alpha = 0.5
        self._beta = 0.5
        if not alpha is None:
            if not is_numeric(alpha):
                raise TypeError("Parameter not numeric: %s " % (type(alpha)))
            else:
                self._alpha = alpha

        if not beta is None:
            if not is_numeric(beta):
                raise TypeError("Parameter not numeric: %s " % (type(beta)))
            else:
                self._beta = beta

        if not alpha is None and beta is None:
            self._beta = 1 - self._alpha
示例#2
0
    def __init__(self, alpha=None, beta=None):
        """
        Constructor.

        Args:
            alpha: alpha parameter, numeric type. Optional, can be set through
            training
            beta: beta parameter, numeric type. Optional, can be set through
            training.

        Raises:
            TypeError if alpha or beta are not numeric.
        """
        self._alpha = 0.5
        self._beta = 0.5
        if not alpha is None:
            if not is_numeric(alpha):
                raise TypeError("Parameter not numeric: %s " % (type(alpha)))
            else:
                self._alpha = alpha

        if not beta is None:
            if not is_numeric(beta):
                raise TypeError("Parameter not numeric: %s " % (type(beta)))
            else:
                self._beta = beta

        if not alpha is None and beta is None:
            self._beta = 1 - self._alpha
示例#3
0
 def __mul__(self, factor):
     ''' * operation'''
     if is_numeric(factor):
         return type(self)(self.mat * factor)
     else:
         self._assert_same_type(factor)
         return type(self)(self.mat * factor.mat)
示例#4
0
 def __mul__(self, factor):
     ''' * operation'''
     if is_numeric(factor):
         return type(self)(self.mat * factor)
     else:
         self._assert_same_type(factor)
         return type(self)(self.mat * factor.mat)
示例#5
0
    def __getitem__(self, key):
        """
        Overwrites csr_matrix m[i,:], m[i] operations which are faulty in
        current scipy.sparse releases.

        """

        def __get_row(row):
            start = self.mat.indptr[row]
            end = self.mat.indptr[row + 1]
            return SparseMatrix(
                csr_matrix(
                    (self.mat.data[start:end], self.mat.indices[start:end], [0, end - start]),
                    shape=(1, self.mat.shape[1]),
                    copy=True,
                )
            )

        if isinstance(key, tuple):
            row = key[0]
            col = key[1]
            if isintlike(row) and row >= 0 and isinstance(col, slice):
                if col == slice(None, None, None):
                    return __get_row(row)

        if isintlike(key) and key >= 0:
            return __get_row(key)

        result = self.mat[key]
        if is_numeric(result):
            return result
        else:
            return SparseMatrix(result)
示例#6
0
 def __div__(self, factor):
     ''' / operation'''
     if is_numeric(factor):
         if factor == 0:
             raise ZeroDivisionError("Division by zero")
     else:
         raise TypeError("expected numeric type, received %s" % (type(factor)))
     return type(self)(self.mat / float(factor))    
示例#7
0
 def __div__(self, factor):
     ''' / operation'''
     if is_numeric(factor):
         if factor == 0:
             raise ZeroDivisionError("Division by zero")
     else:
         raise TypeError("expected numeric type, received %s" %
                         (type(factor)))
     return type(self)(self.mat / float(factor))
示例#8
0
    def __init__(self, lambda_=None):
        """
        Constructor.
        
        Args:
            lambda_ : numeric, value of the lambda parameter. Optional.
        """

        if not lambda_ is None:
            if not is_numeric(lambda_):
                raise ValueError("Parameter not numeric: %s " %(type(lambda_)))
            else:
                self._lambda = lambda_
示例#9
0
    def __init__(self, lambda_=None):
        """
        Constructor.

        Args:
            lambda_ : numeric, value of the lambda parameter. Optional.
        """

        if not lambda_ is None:
            if not is_numeric(lambda_):
                raise ValueError("Parameter not numeric: %s " %
                                 (type(lambda_)))
            else:
                self._lambda = lambda_
示例#10
0
 def __rmul__(self, factor):
     ''' * operation'''
     if is_numeric(factor):
         return self.__mul__(factor)
     raise TypeError("expected numeric type, received %s" % (type(factor)))
示例#11
0
 def __rmul__(self, factor):
     ''' * operation'''
     if is_numeric(factor):
         return self.__mul__(factor)
     raise TypeError("expected numeric type, received %s" % (type(factor)))
示例#12
0
 def __getitem__(self, index):
     result = self.mat[index]
     if is_numeric(result):
         return result
     else:
         return type(self)(result.copy())