-
Notifications
You must be signed in to change notification settings - Fork 10
PatMinr Developer Documentation
pat.analyze
(sequence)
, where sequence
is an array of numbers, detects patterns in the array considered as a string of numbers.
Let's have a closer look at pat.analyze
code to understand how pattern mining is carried out.
Definition of the parametrical space. Here just one dimension.
ps = seq.paramstruct('mystruct',{'dimension'},1);
dimension = seq.paramtype('dimension');
ps = ps.setfield('dimension',dimension);
Creating the root of the pattern tree
root = pat.pattern([],[],[],ps);
Creating the "occurrence" of the root. All pattern occurrences will extend from that "root occurrence" occ0
.
occ0 = root.occurrence([],[]);
Now we consider each successive symbol s
from the input sequence.
The parametrical description of the new event
p = ps.type2val; % Defined from the parametrical space ps by associating a value to each parameter (here just one, the "dimension")
p = p.setfield('dimension',seq.paramval(ps.getfield('dimension'),s));
The event is then instantiated as a pat.event
object
event = pat.event(currentSequence,p);
event.address = i;
Now the two core mechanisms for pattern analysis:
- First trying to extent any pattern occurrence ending at the previous event
previous.syntagm(event,root,1,options);
Calling pat.event.syntagm
which itself calls pat.syntagm
, which looks at all pattern occurrence ending at previous event, and tries to extend these occurrence by calling pat.occurrence.memorize
.
- Then checking if the new event can be the start of a new pattern occurrence (i.e., by extending the "root occurrence"
occ0
)
occ0.memorize(event,root,[],[],1);
And here also, it consists in calling pat.occurrence.memorize
, where the occurrence to extend is the "root occurrence" occ0
.
So we see that in any case it is about extending a pattern occurrence (either one ending at the previous note, or the root occurrence occ0
). So to dig further, let's look at pat.occurrence.memorize
:
There are two steps to consider in a specific order:
-
pattern recognition: checking if the new event extends the occurrence of P into an occurrence of a child of P. This is done by calling
pat.pattern.remember
(cf. below) -
pattern discovery: discovering any new repetition leading to the creation of a new child of P. This is done by calling
pat.memostruct.learn
which itself callspat.memory.combine
(cf. below)
We look at each child C of P. If C's description corresponds to the new event N's description, we can create a new occurrence of C as an extension of O.
We look at any parametric dimension (in the simple example of a sequence of events simply made of number, there is only one dimension). We call for that dimension pat.memoparam.learn
.
pat.memoparam.learn
calls pat.memoparam.find
to checks whether the parameter has been already stored into the memory table (corresponding to a previous occurrence continuing with the same parameter). If this is the case, it calls pat.pattern.link
to check if a new closed pattern has been discovered or not (cf. below). In any case, the new event N is stored also in the memory table.
pat.pattern.link
checks whether the new pattern candidate Q can be accepted or not. The most important test is the closure test (sub function closuretest
, checking that there is no other already existing pattern occurrence ending at N (of a pattern R) where Q is a suffix of R and such that the number of occurrences of R is equal to the number of occurrences of Q. Because if that is the case, the pattern candidate Q is not closed and should be rejected.
Else if the test is successful, pat.pattern.link
creates the new pattern Q and the occurrences of Q. And also calls pat.memoparam.learn
in order to add all continuations of previous occurrences of Q into the memory table. This will enable to discover children of Q.