Skip to content

Commit

Permalink
Added markdown explanation cells to main mpy notebook. Fixed some sma…
Browse files Browse the repository at this point in the history
…ll ulab numpy bugs
  • Loading branch information
James Teversham committed Nov 25, 2021
1 parent 3eee9f3 commit dc282a2
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 1,267 deletions.
4 changes: 2 additions & 2 deletions experimentation/EEG-Analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@
"outputs": [],
"source": [
"def standardise(X):\n",
" axis = np.argmax(X.shape())\n",
" minor_shape = np.min(X.shape())\n",
" axis = np.argmax(X.shape)\n",
" minor_shape = np.min(X.shape)\n",
" mu = np.mean(X, axis=axis).reshape((minor_shape, 1))\n",
" sigma = np.std(X, axis=axis).reshape((minor_shape, 1))\n",
" return (X-mu)/sigma\n",
Expand Down
6 changes: 3 additions & 3 deletions experimentation/Eigenvalue Algorithms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"def solve_eig_qr(A, n_eig, lam_iterations=5):\n",
" # !! note: eigenvectors can only be found reliably if A is symmetric\n",
" Ak = A\n",
" n_eig = min(n_eig, min(A.shape()))\n",
" n_eig = min(n_eig, min(A.shape))\n",
"\n",
" for k in range(lam_iterations):\n",
" Qk, Rk = np.linalg.qr(Ak)\n",
Expand All @@ -95,7 +95,7 @@
" lam = np.diag(Ak) # get eigenvalues\n",
" V = []\n",
" for l in lam[:n_eig]: # now find `n_eig` eigenvectors\n",
" A_null = (A - np.eye(A.shape()[0])*l).transpose()\n",
" A_null = (A - np.eye(A.shape[0])*l).transpose()\n",
" Q, R = np.linalg.qr(A_null) # compute null space of (A-lam*I) to get eigenvector\n",
" V.append(Q[:, -1])\n",
" return lam, np.array(V).transpose()\n",
Expand Down Expand Up @@ -163,7 +163,7 @@
" result = {}\n",
" Cxx = np.dot(X_test, X_test.transpose()) # precompute data auto correlation matrix\n",
" for f in self.stim_freqs:\n",
" Y = harmonic_reference(f, self.fs, np.max(X_test.shape()), Nh=self.Nh, standardise_out=True)\n",
" Y = harmonic_reference(f, self.fs, np.max(X_test.shape), Nh=self.Nh, standardise_out=True)\n",
" rho = self.cca_eig(X_test, Y, Cxx=Cxx) # canonical variable matrices. Xc = X^T.W_x\n",
" result[f] = rho\n",
" return result\n",
Expand Down
10 changes: 5 additions & 5 deletions micropython/lib/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def max_eig(A, iterations, numeric_method="qr"):
else:
if numeric_method != "qr":
print("Unknown `numeric_method` arg: defaulting to QR solver")
lam, v = solve_eig_qr(A, 1, lam_iterations=iterations)
lam, v = solve_eig_qr(A, iterations)
lam = lam[0] # only need first eigen val (largest returned first)
v = v[:, 0] # only first eig vector

Expand All @@ -104,16 +104,16 @@ def resample(X, factor):


def standardise(X):
axis = np.argmax(X.shape())
minor_shape = np.min(X.shape())
axis = np.argmax(X.shape)
minor_shape = np.min(X.shape)
mu = np.mean(X, axis=axis).reshape((minor_shape, 1))
sigma = np.std(X, axis=axis).reshape((minor_shape, 1))
return (X - mu) / sigma


def cov(X, Y, biased=False):
assert (
X.shape() == Y.shape() and len(X.shape()) == 1
X.shape == Y.shape and len(X.shape) == 1
), "Expected data vectors of equal length"
assert len(X) > 1, "At least 2 data points are required"

Expand All @@ -126,7 +126,7 @@ def cov(X, Y, biased=False):

def corr(X, Y):
assert (
X.shape() == Y.shape() and len(X.shape()) == 1
X.shape == Y.shape and len(X.shape) == 1
), "Expected data vectors of equal length"
assert len(X) > 1, "At least 2 data points are required"

Expand Down
2 changes: 1 addition & 1 deletion micropython/lib/decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def harmonic_reference(f0, fs, Ns, Nh=1, standardise_out=False):
Ns : # of samples in trial
Nh : # of harmonics
Output:
y_ref : Generated reference signals with shape (Nf, Ns, 2*Nh)
X : Generated reference signals with shape (Nf, Ns, 2*Nh)
"""
X = np.zeros((Nh * 2, Ns))

Expand Down
4 changes: 2 additions & 2 deletions micropython/lib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from micropython import schedule


class BaseRunner:
class Runner:
def __init__(self, stimulus_freqs=None) -> None:
if stimulus_freqs is None:
self.stim_freqs = config.STIM_FREQS # assign defaults
Expand Down Expand Up @@ -193,7 +193,7 @@ def _setup_logger(self, log_period, logger_type):
self.logger = None


class OnlineRunner(BaseRunner):
class OnlineRunner(Runner):
def setup(
self,
spi_params=None,
Expand Down
Loading

0 comments on commit dc282a2

Please sign in to comment.