3

I am currently trying to normalize complex values.. as i don't have a good way of doing this, i decided to divide my dataset into two, consisting of data with only the real part and data only with the imaginary part.

def split_real_img(x):
    real_array = x.real
    img_array = x.imag
    return real_array, img_array

And then normalize each separately with

def numpy_minmax(X):
    xmin =  X.min()
    print X.min()
    print X.max()
    return (2*(X - xmin) / (X.max() - xmin)-1)*0.9

after the normalization, is the both dataset supposed to be merged, such that it returns into one data set with complex values?, but how do I do that?

The data normalization is done, such that I can use tanh as activation function, which operates in the ranges -0.9 to 0.9 => which is why I need to the data set to be normalized into these ranges.

I am not Fat
  • 283
  • 11
  • 36
  • You can create a complex array by summing the two components (with `1j` multiplier): `np.allclose(x.real + 1j*x.imag, x)`. Or you can express it as a dot product `np.dot([1,1j],[x.real,x.imag])`. – hpaulj Jan 10 '17 at 21:16

1 Answers1

2

Basically, two steps would be involved :

  • Offset all numbers by the minimum along real and imaginary axes.

  • Divide each by the max. magnitude. To get the magnitude of a complex number, simply use np.abs().

Thus, the implementation would be -

def normalize_complex_arr(a):
    a_oo = a - a.real.min() - 1j*a.imag.min() # origin offsetted
    return a_oo/np.abs(a_oo).max()

Sample runs for verification

Let'start with an array that has a minimum one of [0+0j] and two more elements - [x1+y1*J] & [y1+x1*J]. Thus, their magnitudes after normalizing should be 1 each.

In [358]: a = np.array([0+0j, 1+17j, 17+1j])

In [359]: normalize_complex_arr(a)
Out[359]: 
array([ 0.00000000+0.j        ,  0.05872202+0.99827437j,
        0.99827437+0.05872202j])

In [360]: np.abs(normalize_complex_arr(a))
Out[360]: array([ 0.,  1.,  1.])

Next up, let's add an offset to the minimum element. This shouldn't change their magnitudes after normalization -

In [361]: a = np.array([0+0j, 1+17j, 17+1j]) + np.array([2+3j])

In [362]: a
Out[362]: array([  2. +3.j,   3.+20.j,  19. +4.j])

In [363]: normalize_complex_arr(a)
Out[363]: 
array([ 0.00000000+0.j        ,  0.05872202+0.99827437j,
        0.99827437+0.05872202j])

In [364]: np.abs(normalize_complex_arr(a))
Out[364]: array([ 0.,  1.,  1.])

Finally, let's add another element that is at twice the distance from offsetted origin to make sure this new one has a magnitude of 1 and others are reduce to 0.5 -

In [365]: a = np.array([0+0j, 1+17j, 17+1j, 34+2j]) + np.array([2+3j])

In [366]: a
Out[366]: array([  2. +3.j,   3.+20.j,  19. +4.j,  36. +5.j])

In [367]: normalize_complex_arr(a)
Out[367]: 
array([ 0.00000000+0.j        ,  0.02936101+0.49913719j,
        0.49913719+0.02936101j,  0.99827437+0.05872202j])

In [368]: np.abs(normalize_complex_arr(a))
Out[368]: array([ 0. ,  0.5,  0.5,  1. ])
Divakar
  • 218,885
  • 19
  • 262
  • 358
  • 1
    @IamnotFat Normalize usually mean `0 to 1.0`. Please add the details into the question that you want a range from `0.9 to -0.9`. – Divakar Jan 11 '17 at 08:10