-
Notifications
You must be signed in to change notification settings - Fork 1
/
kuramoto.py
73 lines (58 loc) · 1.8 KB
/
kuramoto.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import numpy as np
from scipy.sparse.coo import coo_matrix
class Kuramoto:
def __init__(
self,
adjacency: "A NxN matrix",
phases: "List of size N",
omegas: "List of size N",
couplings: ""
):
self.is_sparse_matrix = isinstance(
adjacency,
coo_matrix
)
self.adjacency = adjacency
self.phases = phases
self.omegas = omegas
self.couplings = couplings
@property
def num_couplings(self):
return len(self.couplings)
@property
def adjacency(self):
return self._adjacency
@property
def adjacency(self):
return self._adjacency
@adjacency.setter
def adjacency(self, values):
if self.is_sparse_matrix is False:
values = np.array(values)
if values.shape != (values.shape[0], values.shape[0]):
raise Exception("Adjacency Matrix: dimension mismatch")
self._adjacency = values
self.num_oscilators = values.shape[0]
@property
def phases(self):
return self._phases
@phases.setter
def phases(self, values):
if len(values) != self.num_oscilators:
raise Exception("Phases: dimension mismatch with adjacency matrix")
self._phases = values
@property
def omegas(self):
return self._omegas
@phases.setter
def omegas(self, values):
if len(values) != self.num_oscilators:
raise Exception("Omegas: dimension mismatch with adjacency matrix")
self._omegas = values
def __repr__(self):
return "kuramoto(num. oscilators={} num. couplings={}"\
+ " is sparse={})".format(
self.num_oscilators,
self.num_couplings,
int(self.is_sparse_matrix)
)