# HG changeset patch # User nikcleju # Date 1322488276 0 # Node ID 4f3bc35195cebec6b8311e760d559065d0aeea7e # Parent 56a35edac462893ab51c29dd68c7a239e8280c7a Fixed bug in GAP.py Generate_Data_Known_Omega(): when n is a number, norm() fails diff -r 56a35edac462 -r 4f3bc35195ce pyCSalgos/GAP/GAP.py --- a/pyCSalgos/GAP/GAP.py Mon Nov 28 13:39:49 2011 +0000 +++ b/pyCSalgos/GAP/GAP.py Mon Nov 28 13:51:16 2011 +0000 @@ -119,10 +119,15 @@ y[:,i] = numpy.dot(M, x0[:,i]) # Add noise - t_norm = numpy.linalg.norm(y[:,i],2); - n = numpy.squeeze(rng.randn(m, 1)); - y[:,i] = y[:,i] + noiselevel * t_norm * n / numpy.linalg.norm(n, 2); - realnoise[:,i] = noiselevel * t_norm * n / numpy.linalg.norm(n, 2) + t_norm = numpy.linalg.norm(y[:,i],2) + n = numpy.squeeze(rng.randn(m, 1)) + # In case n i just a number, nuit an array, norm() fails + if n.ndim == 0: + nnorm = abs(n) + else: + nnorm = numpy.linalg.norm(n, 2); + y[:,i] = y[:,i] + noiselevel * t_norm * n / nnorm + realnoise[:,i] = noiselevel * t_norm * n / nnorm #end return x0,y,M,LambdaMat,realnoise