def make_sparse_coded_signal(n_samples, n_components, n_features, n_nonzero_coefs, random_state=None):
 generator = check_random_state(random_state)
 D = generator.randn(n_features, n_components)
 D /= np.sqrt(np.sum((D ** 2), axis=0))
 X = np.zeros((n_components, n_samples))
 for i in range(n_samples):
  idx = np.arange(n_components)
  generator.shuffle(idx)
  idx = idx[:n_nonzero_coefs]
  X[(idx, i)] = generator.randn(n_nonzero_coefs)
 Y = np.dot(D, X)
 return map(np.squeeze, (Y, D, X))

def make_sparse_coded_signal ( n_samples , n_components , n_features , n_nonzero_coefs , random_state = None ) : generator = check_random_state ( random_state ) D = generator . randn ( n_features , n_components ) D /= np . sqrt ( np . sum ( ( D ** 2 ) , axis = 0 ) ) X = np . zeros ( ( n_components , n_samples ) ) for i in range ( n_samples ) : idx = np . arange ( n_components ) generator . shuffle ( idx ) idx = idx [ : n_nonzero_coefs ] X [ ( idx , i ) ] = generator . randn ( n_nonzero_coefs ) Y = np . dot ( D , X ) return map ( np . squeeze , ( Y , D , X ) )
generate a signal as a sparse combination of dictionary elements .