-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrderParameterCalculator.py
61 lines (43 loc) · 1.96 KB
/
OrderParameterCalculator.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
from dataclasses import dataclass
import numpy as np
from PatternStructure import PatternStructure
from AssociativeNetwork import Network
import functions as fs
from itertools import chain
@dataclass
class OrderParameterCalculator:
memories: PatternStructure
network: Network
coherence_timecourse: np.array = None
attractors_timecourse: np.array = None
retrieved_sequence: np.array = None
def __post_init__(self):
self.coherence_timecourse = fs.coherence_timecourse(
self.memories, self.network.history)
self.attractors_timecourse = fs.attractors_timecourse(
self.memories, self.network.history)
self.retrieved_sequence = fs.retrieved_sequence(
self.memories, self.network.history)
return
def compute_all_retrieval_probability(self, threshold=1):
return fs.compute_retrieval_probability(self.coherence_timecourse, threshold=threshold)
def compute_on_chain_retrieval_probability(self, threshold=1):
on_chain_attractors = np.unique(
list(chain.from_iterable(self.memories.chains)))
on_chain = np.asarray([
True if i in on_chain_attractors else False for i in self.attractors_timecourse])
max_coherence = np.max(self.coherence_timecourse, axis=0)
retrieved = max_coherence > threshold
rp = np.sum(np.logical_and(on_chain, retrieved))/len(max_coherence)
return rp
def compute_off_chain_retrieval_probability(self, threshold=1):
on_chain_attractors = np.unique(
list(chain.from_iterable(self.memories.chains)))
on_chain = np.asarray([
True if i in on_chain_attractors else False for i in self.attractors_timecourse])
max_coherence = np.max(self.coherence_timecourse, axis=0)
retrieved = max_coherence > threshold
rp = np.sum(np.logical_and(~on_chain, retrieved))/len(max_coherence)
return rp
def new_parameter(self, threshold=1):
pass