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
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)
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)
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))
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_
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_
def __rmul__(self, factor): ''' * operation''' if is_numeric(factor): return self.__mul__(factor) raise TypeError("expected numeric type, received %s" % (type(factor)))
def __getitem__(self, index): result = self.mat[index] if is_numeric(result): return result else: return type(self)(result.copy())