Skip to content

Commit 706aade

Browse files
authored
CI: fix and enable formatting checks (#39)
* fix CI * CI: only run on PR * CI: push in utils package to scope and avoid name clash * CI: enable formatting check and format everything * fix some imports * CI: enable isort and sort imports * shorten long lines * more formatting fixes
1 parent 3bdec39 commit 706aade

31 files changed

Lines changed: 1334 additions & 849 deletions

.github/workflows/lint_python.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
name: lint_python
2-
on: [pull_request, push]
2+
on: [pull_request]
33
jobs:
44
lint_python:
55
runs-on: ubuntu-latest
66
steps:
7-
- uses: actions/checkout@v2
8-
- uses: actions/setup-python@v2
7+
- uses: actions/checkout@v3
8+
- uses: actions/setup-python@v4
99
with:
10-
python-version: '3.10.1'
10+
python-version: '3.10.12'
1111
- run: pip install bandit black codespell flake8 isort mypy pytest pyupgrade safety
1212
- run: bandit --recursive --skip B101 .
13-
- run: black --check . || true
14-
- run: codespell # --ignore-words-list="" --skip=""
13+
- run: black --check .
14+
- run: codespell --ignore-words-list= Bu
1515
- run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
1616
- run: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=88 --show-source --statistics
17-
- run: isort --check-only --profile black . || true
17+
- run: isort --check-only --profile black .
1818
- run: pip install -r requirements.txt
1919
- run: mypy --ignore-missing-imports --install-types --non-interactive . || true
2020
- run: pytest . || pytest --doctest-modules . || true
2121
- run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true
22-
- run: safety check --full-report || true
22+
- run: safety check

autotune/arx_rls.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,61 +67,67 @@
6767

6868
import numpy as np
6969

70+
7071
class ArxRls(object):
7172
def __init__(self, n, m, d, lbda=1.0):
7273
self._n = n
7374
self._m = m
7475
self._d = d
75-
p = n+m+1 # number of parameters (+1 because of b_0)
76-
self._P = 10000 * np.asmatrix(np.eye(p)) # initialize to a large value
77-
self._theta_hat = np.transpose(np.asmatrix(np.zeros(n+m+1)))
78-
self._y = np.zeros(n+1)
79-
self._u = np.zeros(m+d+1)
76+
p = n + m + 1 # number of parameters (+1 because of b_0)
77+
self._P = 10000 * np.asmatrix(np.eye(p)) # initialize to a large value
78+
self._theta_hat = np.transpose(np.asmatrix(np.zeros(n + m + 1)))
79+
self._y = np.zeros(n + 1)
80+
self._u = np.zeros(m + d + 1)
8081
self._lbda = lbda
8182

8283
def update(self, u, y):
8384
self.addInputOutput(u, y)
8485
phi = self.constructPhi()
8586
lbda = self._lbda
86-
self._P = (self._P - self._P * phi * phi.T * self._P / (lbda + phi.T * self._P * phi))/lbda # eq 3.66
87-
self._theta_hat += self._P * phi*(self._y[self._n] - phi.T * self._theta_hat) # eq 3.67
87+
self._P = (
88+
self._P - self._P * phi * phi.T * self._P / (lbda + phi.T * self._P * phi)
89+
) / lbda # eq 3.66
90+
self._theta_hat += (
91+
self._P * phi * (self._y[self._n] - phi.T * self._theta_hat)
92+
) # eq 3.67
8893

8994
return self._theta_hat, self._P
9095

9196
def addInputOutput(self, u, y):
9297
self.shiftRegisters()
9398
self._y[self._n] = y
94-
self._u[self._m+self._d] = u
99+
self._u[self._m + self._d] = u
95100

96101
def shiftRegisters(self):
97102
for i in range(0, self._n):
98-
self._y[i] = self._y[i+1]
99-
for i in range(0, self._m+self._d):
100-
self._u[i] = self._u[i+1]
103+
self._y[i] = self._y[i + 1]
104+
for i in range(0, self._m + self._d):
105+
self._u[i] = self._u[i + 1]
101106

102107
def constructPhi(self):
103-
phi_a = np.asmatrix([-self._y[self._n-(i+1)] for i in range(self._n)])
104-
phi_b = np.asmatrix([self._u[self._m-i] for i in range(self._m+1)])
108+
phi_a = np.asmatrix([-self._y[self._n - (i + 1)] for i in range(self._n)])
109+
phi_b = np.asmatrix([self._u[self._m - i] for i in range(self._m + 1)])
105110
phi = (np.concatenate((phi_a, phi_b), axis=1)).T
106111
return phi
107112

108-
if __name__ == '__main__':
113+
114+
if __name__ == "__main__":
109115
n = 2
110116
m = 1
111117
d = 1
112118
rls = ArxRls(n, m, d)
113119

114-
assert len(rls._y) == n+1
115-
assert len(rls._u) == m+d+1
120+
assert len(rls._y) == n + 1
121+
assert len(rls._u) == m + d + 1
116122
rls.update(1, 2)
117123
rls.update(3, 4)
118124
rls.update(5, 6)
119125
assert rls._u.item(-1) == 5
120126
assert rls._y.item(-1) == 6
121127
phi = rls.constructPhi()
122128
assert len(phi) == 4
123-
assert phi.item(0) == -4
124-
assert phi.item(1) == -2
125-
assert phi.item(2) == 3
126-
assert phi.item(3) == 1
129+
assert phi.item(0) == -4
130+
assert phi.item(1) == -2
131+
assert phi.item(2) == 3
132+
assert phi.item(3) == 1
127133
print(rls._theta_hat)

0 commit comments

Comments
 (0)