-
Notifications
You must be signed in to change notification settings - Fork 0
/
paths.py
49 lines (31 loc) · 1.06 KB
/
paths.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
paths.py
========
Module containing utilities for finding paths through the design matrix.
"""
import abc
import networkx as nx
class IDesignPath(abc.ABC):
def __init__(self, design_matrix):
self.design_matrix = design_matrix
@abc.abstractmethod
def graph(self):
pass
@abc.abstractmethod
def path(self):
pass
class SquareRadiator(IDesignPath):
def __init__(self, design_matrix):
super().__init__(design_matrix)
if len(design_matrix.columns) != 2:
raise ValueError(f"more than two columns in design_matrix: {design_matrix.columns=}")
self.nside = int(np.sqrt(len(self.design_matrix)))
if not (len(self.design_matrix) % self.nside == 0):
raise ValueError(f"{design_matrix=} cannot be square")
k = np.arange(len(self.design_matrix), dtype=int)
self.i = k // self.nside
self.j = (k % self.nside)*(-1)**(self.i % 2) - self.nside**(self.i % 2) - 1 ### ???????
def graph(self):
pass
def path(self):
return self.i, self.j