Skip to content

Commit 4ea3c00

Browse files
committed
applies formatter
1 parent 902f653 commit 4ea3c00

7 files changed

Lines changed: 468 additions & 297 deletions

File tree

source/PSID/IPSID.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
"""
22
Copyright (c) 2020 University of Southern California
33
See full notice in LICENSE.md
44
Parsa Vahidi, Omid G. Sani and Maryam M. Shanechi

source/PSID/PSIDModel.py

Lines changed: 239 additions & 133 deletions
Large diffs are not rendered by default.

source/PSID/PrepModel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
"""
22
Copyright (c) 2020 University of Southern California
33
See full notice in LICENSE.md
44
Omid G. Sani and Maryam M. Shanechi

source/PSID/ReducedRankRegressor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
Optimal linear 'bottlenecking' or 'multitask learning'.
1111
"""
12+
1213
import numpy as np
1314
from scipy import sparse
1415

@@ -29,6 +30,7 @@ class ReducedRankRegressor(object):
2930
- rrank is a rank constraint.
3031
- reg is a regularization parameter (optional).
3132
"""
33+
3234
def __init__(self, X, Y, rank, reg=None):
3335
if np.size(np.shape(X)) == 1:
3436
X = np.reshape(X, (-1, 1))
@@ -45,7 +47,7 @@ def __init__(self, X, Y, rank, reg=None):
4547
self.A = np.dot(np.linalg.pinv(CXX), np.dot(CXY, self.W)).T
4648

4749
def __str__(self):
48-
return 'Reduced Rank Regressor (rank = {})'.format(self.rank)
50+
return "Reduced Rank Regressor (rank = {})".format(self.rank)
4951

5052
def predict(self, X):
5153
"""Predict Y from X."""

source/PSID/mode_tools.py

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
"""
22
Copyright (c) 2020 University of Southern California
33
See full notice in LICENSE.md
44
Omid G. Sani and Maryam M. Shanechi
@@ -14,48 +14,51 @@
1414

1515
logger = logging.getLogger(__name__)
1616

17+
1718
def 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

9599
def 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

Comments
 (0)