1- """
1+ """
22Copyright (c) 2020 University of Southern California
33See full notice in LICENSE.md
44Omid G. Sani and Maryam M. Shanechi
1414
1515logger = logging .getLogger (__name__ )
1616
17+
1718def addConjs (vals ):
1819 """Adds complex conjugate values for each complex value
1920
2021 Args:
2122 vals (list of number): list of numbers (e.g. eigenvalues)
2223
2324 Returns:
24- output (list of numbers): new list of numbers where for each complex value in the original list,
25+ output (list of numbers): new list of numbers where for each complex value in the original list,
2526 the conjugate is also added to the new list. For real values an np.nan is added.
26- """
27+ """
2728 vals = np .atleast_2d (vals ).T
2829 valsConj = vals .conj ()
2930 valsConj [np .abs (vals - valsConj ) < np .spacing (1 )] = np .nan
3031 return np .concatenate ((vals , valsConj ), axis = 1 )
3132
3233
33- def drawRandomPoles (N , poleDist = {}):
34+ def drawRandomPoles (N , poleDist = {}):
3435 """Draws random eigenvalues from the unit dist
3536
3637 Args:
3738 N (int): number of eigenvalues to draw
38- poleDist (dict, optional): information about the distribution.
39+ poleDist (dict, optional): information about the distribution.
3940 For options see the top of the code. Defaults to dict.
4041
4142 Returns:
4243 valsA (list of numbers): drawn random values
43- """
44- nCplx = int (np .floor (N / 2 ))
45-
46- if 'magDist' not in poleDist : poleDist ['magDist' ] = 'beta'
47- if 'magDistParams' not in poleDist and poleDist ['magDist' ] == 'beta' :
48- poleDist ['magDistParams' ] = {'a' : 2 , 'b' : 1 }
49- if 'angleDist' not in poleDist : poleDist ['angleDist' ] = 'uniform'
50-
44+ """
45+ nCplx = int (np .floor (N / 2 ))
46+
47+ if "magDist" not in poleDist :
48+ poleDist ["magDist" ] = "beta"
49+ if "magDistParams" not in poleDist and poleDist ["magDist" ] == "beta" :
50+ poleDist ["magDistParams" ] = {"a" : 2 , "b" : 1 }
51+ if "angleDist" not in poleDist :
52+ poleDist ["angleDist" ] = "uniform"
53+
5154 # mag = np.random.rand(nCplx) # Uniform dist
52- if poleDist [' magDist' ] == ' beta' :
55+ if poleDist [" magDist" ] == " beta" :
5356 a , b = 2 , 1 # Use a, b = 2, 1 for uniform prob over unit circle
54- if 'a' in poleDist [' magDistParams' ]:
55- a = poleDist [' magDistParams' ][ 'a' ]
56- if 'b' in poleDist [' magDistParams' ]:
57- b = poleDist [' magDistParams' ][ 'b' ]
58-
57+ if "a" in poleDist [" magDistParams" ]:
58+ a = poleDist [" magDistParams" ][ "a" ]
59+ if "b" in poleDist [" magDistParams" ]:
60+ b = poleDist [" magDistParams" ][ "b" ]
61+
5962 """
6063 import matplotlib.pyplot as plt
6164 fig, ax = plt.subplots(1, 1)
@@ -66,34 +69,35 @@ def drawRandomPoles(N, poleDist = {}):
6669 plt.show()
6770 """
6871
69- mag = stats .beta .rvs (a = a , b = b , size = nCplx ) # Beta dist
72+ mag = stats .beta .rvs (a = a , b = b , size = nCplx ) # Beta dist
7073 else :
71- raise Exception (' Only beta distribution is supported for the magnitude' )
74+ raise Exception (" Only beta distribution is supported for the magnitude" )
7275
73- if poleDist [' angleDist' ] == ' uniform' :
76+ if poleDist [" angleDist" ] == " uniform" :
7477 theta = np .random .rand (nCplx ) * np .pi
7578 else :
76- raise Exception (' Only uniform distribution is supported for the angle' )
77-
78- vals = mag * np .exp ( 1j * theta )
79+ raise Exception (" Only uniform distribution is supported for the angle" )
80+
81+ vals = mag * np .exp (1j * theta )
7982
8083 valsA = addConjs (vals )
8184 valsA = valsA .reshape (valsA .size )
82- valsA = valsA [ np .logical_not (np .isnan (valsA )) ]
85+ valsA = valsA [np .logical_not (np .isnan (valsA ))]
8386
8487 # Add real mode(s) if needed
85- nReal = N - 2 * nCplx
88+ nReal = N - 2 * nCplx
8689 if nReal > 0 :
8790 # rVals = np.random.rand(nReal)
88- rVals = stats .beta .rvs (a = a , b = b , size = nReal ) # Beta dist
89- rSign = 2 * (((np .random .rand (nReal ) > 0.5 ).astype (float ))- 0.5 )
91+ rVals = stats .beta .rvs (a = a , b = b , size = nReal ) # Beta dist
92+ rSign = 2 * (((np .random .rand (nReal ) > 0.5 ).astype (float )) - 0.5 )
9093
9194 valsA = np .concatenate ((valsA , rVals * rSign ))
9295
93- return valsA
96+ return valsA
97+
9498
9599def generate_random_eigenvalues (count ):
96100 """Generates complex conjugate pairs of eigen values with a uniform distribution in the unit circle"""
97101 # eigvals = 0.95 * np.exp(1j * np.pi/8 * np.array([-1, +1]))
98102 eigvals = drawRandomPoles (count )
99- return eigvals
103+ return eigvals
0 commit comments