def make_sparse_spd_matrix(dim=1, alpha=0.95, norm_diag=False, smallest_coef=0.1, largest_coef=0.9, random_state=None):
 random_state = check_random_state(random_state)
 chol = (- np.eye(dim))
 aux = random_state.rand(dim, dim)
 aux[(aux < alpha)] = 0
 aux[(aux > alpha)] = (smallest_coef + ((largest_coef - smallest_coef) * random_state.rand(np.sum((aux > alpha)))))
 aux = np.tril(aux, k=(-1))
 permutation = random_state.permutation(dim)
 aux = aux[permutation].T[permutation]
 chol += aux
 prec = np.dot(chol.T, chol)
 if norm_diag:
  d = np.diag(prec).reshape(1, prec.shape[0])
  d = (1.0 / np.sqrt(d))
  prec *= d
  prec *= d.T
 return prec

def make_sparse_spd_matrix ( dim = 1 , alpha = 0.95 , norm_diag = False , smallest_coef = 0.1 , largest_coef = 0.9 , random_state = None ) : random_state = check_random_state ( random_state ) chol = ( - np . eye ( dim ) ) aux = random_state . rand ( dim , dim ) aux [ ( aux < alpha ) ] = 0 aux [ ( aux > alpha ) ] = ( smallest_coef + ( ( largest_coef - smallest_coef ) * random_state . rand ( np . sum ( ( aux > alpha ) ) ) ) ) aux = np . tril ( aux , k = ( - 1 ) ) permutation = random_state . permutation ( dim ) aux = aux [ permutation ] . T [ permutation ] chol += aux prec = np . dot ( chol . T , chol ) if norm_diag : d = np . diag ( prec ) . reshape ( 1 , prec . shape [ 0 ] ) d = ( 1.0 / np . sqrt ( d ) ) prec *= d prec *= d . T return prec
generate a sparse symmetric definite positive matrix .