pychronicles 0.1.6__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pychronicles-0.1.6/pychronicles.egg-info → pychronicles-0.2.0}/PKG-INFO +82 -78
- pychronicles-0.2.0/README.md +362 -0
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pychronicles/__init__.py +3 -2
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pychronicles/abstraction.py +59 -30
- pychronicles-0.2.0/pychronicles/chronicle.py +1268 -0
- pychronicles-0.2.0/pychronicles/fchronicle.py +504 -0
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pychronicles/mtlformula.py +48 -7
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pychronicles/pandas_tpatterns.py +149 -87
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pychronicles/timedsequence.py +61 -22
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pychronicles/utils.py +38 -24
- {pychronicles-0.1.6 → pychronicles-0.2.0/pychronicles.egg-info}/PKG-INFO +82 -78
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pychronicles.egg-info/SOURCES.txt +6 -2
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pychronicles.egg-info/requires.txt +1 -0
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pyproject.toml +14 -3
- {pychronicles-0.1.6 → pychronicles-0.2.0}/setup.py +1 -1
- pychronicles-0.2.0/tests/test_abstraction.py +138 -0
- pychronicles-0.2.0/tests/test_chronicle.py +1012 -0
- pychronicles-0.2.0/tests/test_fchronicle.py +312 -0
- pychronicles-0.2.0/tests/test_mtlformula.py +52 -0
- pychronicles-0.2.0/tests/test_pandas_tpatterns.py +226 -0
- pychronicles-0.2.0/tests/test_projection.py +60 -0
- pychronicles-0.2.0/tests/test_timedsequences.py +154 -0
- pychronicles-0.2.0/tests/test_utils_crs.py +95 -0
- pychronicles-0.1.6/README.md +0 -360
- pychronicles-0.1.6/pychronicles/chronicle.py +0 -1135
- pychronicles-0.1.6/pychronicles/fchronicle.py +0 -357
- pychronicles-0.1.6/tests/test_abstraction.py +0 -50
- pychronicles-0.1.6/tests/test_pandas.py +0 -58
- pychronicles-0.1.6/tests/test_projection.py +0 -60
- pychronicles-0.1.6/tests/test_timedsequences.py +0 -147
- {pychronicles-0.1.6 → pychronicles-0.2.0}/LICENCE.txt +0 -0
- {pychronicles-0.1.6 → pychronicles-0.2.0}/MANIFEST.in +0 -0
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pychronicles.egg-info/dependency_links.txt +0 -0
- {pychronicles-0.1.6 → pychronicles-0.2.0}/pychronicles.egg-info/top_level.txt +0 -0
- {pychronicles-0.1.6 → pychronicles-0.2.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: pychronicles
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: A package for chronicle recognition.
|
|
5
5
|
Author-email: Thomas Guyet <thomas.guyet@inria.fr>
|
|
6
6
|
Maintainer-email: Thomas Guyet <thomas.guyet@inria.fr>
|
|
@@ -202,6 +202,8 @@ Requires-Dist: build; extra == "build"
|
|
|
202
202
|
Requires-Dist: twine; extra == "build"
|
|
203
203
|
Provides-Extra: dev
|
|
204
204
|
Requires-Dist: pytest; extra == "dev"
|
|
205
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
206
|
+
Dynamic: license-file
|
|
205
207
|
|
|
206
208
|
---
|
|
207
209
|
title: README
|
|
@@ -211,18 +213,19 @@ author: Thomas Guyet
|
|
|
211
213
|
[](https://badge.fury.io/py/pychronicles)
|
|
212
214
|
[](https://pepy.tech/project/pychronicles)
|
|
213
215
|
[](https://www.gnu.org/licenses/lgpl-3.0.txt)
|
|
214
|
-
|
|
216
|
+
[](https://gitlab.inria.fr/tguyet/pychronicles/-/commits/master)
|
|
217
|
+
[](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.inria.fr%2Ftguyet%2Fpychronicles/HEAD?labpath=examples%2Fcarepathway_example.ipynb)
|
|
215
218
|
|
|
216
219
|
# PyChronicles package
|
|
217
220
|
|
|
218
|
-
A chronicle is a specification of
|
|
219
|
-
It can be used to recognize complex behaviors in
|
|
220
|
-
|
|
221
|
+
A chronicle is a specification of complex temporal behaviors as a graph of temporal constraints. More specifically, a chronicle is a multiset of events and a set of temporal constraints specifying that the occurrences of pairs of events must occur within given temporal intervals.
|
|
222
|
+
It can be used to recognize complex behaviors in sequences of temporal events.
|
|
223
|
+
PyChronicles is now compatible with Pandas and makes chronicle features [available on dataframes](#dataframe-accessor) representing timed sequences.
|
|
221
224
|
|
|
222
|
-
This library
|
|
223
|
-
The Abstracter class
|
|
225
|
+
This library provides Python classes to define timed sequences and chronicles, and to read/save chronicles in the standard CRS format. The main functionality for chronicles is their efficient matching in timed sequences, or in pandas dataframes (through an accessor).
|
|
226
|
+
The `Abstracter` class makes it possible to create a chronicle from a collection of sequences.
|
|
224
227
|
|
|
225
|
-
For more details about the usage of this package, have a look at the [documentation](https://tguyet.gitlabpages.inria.fr/pychronicles/).
|
|
228
|
+
For more details about the usage of this package, have a look at the [documentation](https://tguyet.gitlabpages.inria.fr/pychronicles/). For more (formal) information about the temporal model of chronicles, see our [book](https://link.springer.com/book/10.1007/978-3-031-33693-5):
|
|
226
229
|
~~~bibtex
|
|
227
230
|
@book{chroniclesbook,
|
|
228
231
|
title = {Chronicles: Formalization of a Temporal Model},
|
|
@@ -235,7 +238,7 @@ For more details about the usage of this package, have a look at the [documentat
|
|
|
235
238
|
|
|
236
239
|
## Package installation
|
|
237
240
|
|
|
238
|
-
The [PyChronicles package](https://pypi.org/project/
|
|
241
|
+
The [PyChronicles package](https://pypi.org/project/pychronicles) is available in the [Python Package Index](https://pypi.org/) and can be installed using any standard Python package manager.
|
|
239
242
|
~~~sh
|
|
240
243
|
pip install pychronicles
|
|
241
244
|
~~~
|
|
@@ -249,14 +252,14 @@ pip install -r requirements.txt
|
|
|
249
252
|
pip install --upgrade .
|
|
250
253
|
~~~
|
|
251
254
|
|
|
252
|
-
|
|
255
|
+
Alternatively, you can install the repository from sources with pip only:
|
|
253
256
|
~~~sh
|
|
254
257
|
git clone --recursive https://gitlab.inria.fr/tguyet/pychronicles
|
|
255
258
|
cd pychronicles
|
|
256
259
|
pip install .
|
|
257
260
|
~~~
|
|
258
261
|
|
|
259
|
-
In case you want to visualize chronicles, you
|
|
262
|
+
In case you want to visualize chronicles, you need to install `networkx` and `matplotlib` manually. By default, they are not installed and the plotting function is disabled.
|
|
260
263
|
~~~sh
|
|
261
264
|
pip install networkx matplotlib
|
|
262
265
|
~~~
|
|
@@ -264,20 +267,21 @@ pip install networkx matplotlib
|
|
|
264
267
|
## Basic Usage Example
|
|
265
268
|
|
|
266
269
|
```python
|
|
267
|
-
import
|
|
270
|
+
import numpy as np
|
|
271
|
+
from pychronicles import TimedSequence, Chronicle
|
|
268
272
|
|
|
269
273
|
# create a timed sequence
|
|
270
274
|
seq = [('a',1),('c',2),('b',3),('a',8)]
|
|
271
|
-
ts = TimedSequence(np.array([e[
|
|
275
|
+
ts = TimedSequence(np.array([e[1] for e in seq], dtype='float'), np.array([e[0] for e in seq]))
|
|
272
276
|
|
|
273
|
-
#create a chronicle
|
|
277
|
+
# create a chronicle
|
|
274
278
|
c=Chronicle()
|
|
275
279
|
c.add_event(0,'a')
|
|
276
280
|
c.add_event(1,'b')
|
|
277
281
|
c.add_constraint(0,1, (0.4,2.3))
|
|
278
282
|
|
|
279
283
|
reco=c.match(ts)
|
|
280
|
-
print(f"Does the chronicle
|
|
284
|
+
print(f"Does the chronicle match the sequence? [{reco}]")
|
|
281
285
|
|
|
282
286
|
reco=c.recognize(ts)
|
|
283
287
|
print(f"What are the occurrences of the chronicle in the sequence? [{reco}]")
|
|
@@ -286,46 +290,46 @@ print(f"What are the occurrences of the chronicle in the sequence? [{reco}]")
|
|
|
286
290
|
|
|
287
291
|
## Efficient chronicle recognition
|
|
288
292
|
|
|
289
|
-
The chronicle recognition package is a pure
|
|
293
|
+
The chronicle recognition package is a pure Python package implemented using numpy features.
|
|
290
294
|
|
|
291
295
|
### Timed Sequences
|
|
292
296
|
|
|
293
|
-
A timed sequence is
|
|
294
|
-
* a pair of lists containing the events and the dates.
|
|
295
|
-
* a simple list of items (`str`, `int` or `None`) with implicit timestamps : `['a', 'b', ..., None, 'c', None, 'd']`. In this case, `None` means that there is no event at the corresponding time instant.
|
|
296
|
-
* a list of explicitly timestamped items (`str` or `int`) : `[ (1,'a'), (23,'b'), (30,'c'), (45, 'd')]`
|
|
297
|
+
A timed sequence is created from a pair of arrays: a numpy array containing the dates, and an array containing the events (with the same length).
|
|
297
298
|
|
|
298
|
-
The dates can be represented with dates (only with `np.datetime64` type) or floats.
|
|
299
|
+
The dates can be represented with dates (only with the `np.datetime64` type) or with floats. Integer dates must be converted into floats (the pandas accessor does it automatically).
|
|
299
300
|
|
|
300
|
-
The type of events must be `str` or `int`.
|
|
301
|
+
The type of the events must be `str` or `int`.
|
|
301
302
|
|
|
302
303
|
_Usage Example_:
|
|
303
304
|
```python
|
|
304
305
|
>>> seq = [('a',1),('c',2),('b',3),('a',8),('a',10),('b',12),('a',15),('c',17), ('b',20),('c',23),('c',25),('b',26),('c',28),('b',30)]
|
|
305
306
|
>>> dates = np.array([np.datetime64('1970-01-01') + np.timedelta64(e[1],'D') for e in seq], dtype='datetime64')
|
|
306
307
|
>>> data = np.array([e[0] for e in seq])
|
|
307
|
-
>>>
|
|
308
|
+
>>> ts = TimedSequence(dates, data)
|
|
308
309
|
```
|
|
309
310
|
|
|
310
311
|
### Chronicles
|
|
311
312
|
|
|
312
|
-
The core of
|
|
313
|
+
The core of this package is the `Chronicle` class, which represents the chronicle temporal model and offers efficient matching functionalities.
|
|
313
314
|
|
|
314
315
|
|
|
315
|
-
|
|
316
|
-
*
|
|
317
|
-
*
|
|
316
|
+
Chronicles handle two models of time (which must be consistent with the model of time of the timed sequences):
|
|
317
|
+
* numerical timestamps using floats,
|
|
318
|
+
* dates using the `datetime64` format. In this case, the temporal constraints of a chronicle must be defined using `np.timedelta64` values.
|
|
318
319
|
|
|
319
|
-
A chronicle
|
|
320
|
+
A chronicle cannot combine constraints of the two different kinds. The first defined constraint defines the model of time of the chronicle.
|
|
320
321
|
|
|
321
322
|
<br>
|
|
322
323
|
|
|
323
|
-
The package implements efficient algorithms to recognize
|
|
324
|
+
The package implements efficient algorithms to recognize chronicles. There are three different ways to _recognize_ a chronicle in a sequence of events:
|
|
325
|
+
|
|
326
|
+
* the absence/presence recognition (`c.match(seq)`): its result is a boolean stating whether the chronicle occurs at least once in the sequence. This is the most efficient algorithm, as it stops as soon as an occurrence is found.
|
|
327
|
+
* the occurrence enumeration (`c.recognize(seq)`): its result is the list of the occurrences of the chronicle in the sequence. Contrary to the first function, it looks for all the possible combinations of events. Thus, it is less efficient, but more informative.
|
|
328
|
+
* the lazy occurrence enumeration (`c.iter_recognize(seq)`): it returns an iterator over the same occurrences, which are computed on demand. This is useful to process the occurrences one at a time, or to stop the enumeration early.
|
|
324
329
|
|
|
325
|
-
|
|
326
|
-
* the occurrence enumeration (`c.recognize(seq)`): its result is a list of occurrences of the chronicle in a sequence. Contrary to the first function, it looks for all possible combination of events. Thus it is less efficient, but more informative.
|
|
330
|
+
In an occurrence, two identical events of a chronicle cannot match the same event of the sequence.
|
|
327
331
|
|
|
328
|
-
Note that a chronicle is somehow similar to a simple temporal network and the set of constraints may be inconsistent or redundant. It is possible to _minimize_ the temporal constraints of a chronicle using the corresponding function.
|
|
332
|
+
Note that a chronicle is somehow similar to a simple temporal network, and the set of constraints may be inconsistent or redundant. It is possible to _minimize_ the temporal constraints of a chronicle using the corresponding function.
|
|
329
333
|
|
|
330
334
|
```python
|
|
331
335
|
>>> c=Chronicle()
|
|
@@ -358,16 +362,16 @@ You can also depict a chronicle as a matplotlib graph:
|
|
|
358
362
|
|
|
359
363
|
### Fuzzy chronicles
|
|
360
364
|
|
|
361
|
-
The `FuzzyChronicle` class
|
|
362
|
-
The temporal model is enriched with the modeling of
|
|
365
|
+
The `FuzzyChronicle` class enables the approximate recognition of a chronicle. A fuzzy chronicle is defined in the same way as a chronicle.
|
|
366
|
+
The temporal model is enriched with the modeling of the fuzziness of the temporal constraints (`lbda` parameter).
|
|
363
367
|
|
|
364
|
-
In addition to the matching
|
|
368
|
+
In addition to the matching functions presented above, it provides a `cmp` function that finds all the occurrences of a chronicle whose degree of matching is above a threshold (parameter `threshold`), together with their similarity. The `iter_cmp` function is its lazy version.
|
|
365
369
|
|
|
366
|
-
More details about fuzzy
|
|
370
|
+
More details about fuzzy chronicles are available in the [article](https://inria.hal.science/hal-02422796v1) (in French):
|
|
367
371
|
```bibtex
|
|
368
372
|
@inproceedings{fchronicles,
|
|
369
373
|
title = {{\'E}num{\'e}ration des occurrences d'une chronique},
|
|
370
|
-
author = {Guyet, Thomas and Besnard, Philippe and
|
|
374
|
+
author = {Guyet, Thomas and Besnard, Philippe and Samet, Ahmed and Ben Salha, Nasreddine and Lachiche, Nicolas},
|
|
371
375
|
booktitle = {Actes de la conférence Extraction et Gestion des Connaissances},
|
|
372
376
|
publisher = {{\'E}ditions RNTI},
|
|
373
377
|
pages = {253--260},
|
|
@@ -377,29 +381,29 @@ More details about fuzzy chroniclesis available in the [article](https://hal.arc
|
|
|
377
381
|
|
|
378
382
|
# Dataframe accessor
|
|
379
383
|
|
|
380
|
-
The `pychronicles` package
|
|
381
|
-
This accessor
|
|
384
|
+
The `pychronicles` package includes a new accessor for pandas dataframes.
|
|
385
|
+
This accessor, denoted `tpattern`, makes it possible to use chronicle functionalities directly with pandas. In this case, you do not even need to manage your timed sequences by hand: everything can be done directly with pandas.
|
|
382
386
|
|
|
383
387
|
The pandas accessor enables:
|
|
384
388
|
|
|
385
389
|
* to match or enumerate occurrences of a chronicle
|
|
386
|
-
* to match
|
|
390
|
+
* to match a Metric Temporal Logic (MTL) formula
|
|
387
391
|
* to abstract a collection of sequences
|
|
388
392
|
* to extract the delays of matching occurrences of a chronicle
|
|
389
393
|
|
|
390
394
|
|
|
391
395
|
## Spirit of the accessor
|
|
392
396
|
|
|
393
|
-
The spirit of our accessor is to use a pandas dataframe to encode a sequence or a collection of
|
|
397
|
+
The spirit of our accessor is to use a pandas dataframe to encode a sequence or a collection of sequences. The index of the dataframe models the time: it can be an integer, float or date index.
|
|
394
398
|
|
|
395
|
-
A column of the dataframe
|
|
399
|
+
A column of the dataframe can be defined to specify the identifier of the sequences. In the following example, the column named `id` denotes this identifier. Intuitively, it can be used to make `groupby` operations, to process a collection of timed sequences.
|
|
396
400
|
|
|
397
|
-
The important feature of our package is that any other column can be added to the dataframe. The idea behind this modeling is that the dataframe
|
|
401
|
+
The important feature of our package is that any other column can be added to the dataframe. The idea behind this modeling is that the dataframe gathers all the information about the events. The columns describe each event (and can contain `None`).
|
|
398
402
|
|
|
399
403
|
|
|
400
|
-
The example below illustrates the representation of a collection of sequences with a Pandas dataframe.
|
|
401
|
-
The basic sequence is repeated three times to create a collection of three timed sequences.
|
|
402
|
-
The event names of the basic sequence feed the column `label`, and we added
|
|
404
|
+
The example below illustrates the representation of a collection of sequences with a Pandas dataframe.
|
|
405
|
+
The basic sequence is repeated three times to create a collection of three timed sequences. In this case, the index of the dataframe is defined with dates.
|
|
406
|
+
The event names of the basic sequence feed the column `label`, and we added three columns:
|
|
403
407
|
|
|
404
408
|
|
|
405
409
|
* a column `str_val` with the string values (twice the label)
|
|
@@ -407,7 +411,7 @@ The event names of the basic sequence feed the column `label`, and we added two
|
|
|
407
411
|
* a column `id` that represents the identifier of a sequence.
|
|
408
412
|
|
|
409
413
|
```python
|
|
410
|
-
#create a basic sequence
|
|
414
|
+
# create a basic sequence
|
|
411
415
|
seq = [('a',1),('c',2),('b',3),('a',8),('a',10),('b',12),('a',15),('c',17)]
|
|
412
416
|
df = pd.DataFrame({
|
|
413
417
|
"label": [e[0] for e in seq]*3,
|
|
@@ -421,19 +425,19 @@ df = pd.DataFrame({
|
|
|
421
425
|
|
|
422
426
|
<br>
|
|
423
427
|
|
|
424
|
-
Then, the
|
|
425
|
-
When used with pandas
|
|
428
|
+
Then, the events of a chronicle are no longer event names, but descriptions of the events of interest through their features.
|
|
429
|
+
When used with pandas dataframes, the events of a chronicle are queries on the dataframe.
|
|
426
430
|
In the example above, an event could be defined by "`label=='a' & num_val>3`".
|
|
427
431
|
|
|
428
|
-
|
|
432
|
+
For the time being, our framework handles string and number attributes. The specification of an event uses the classical operators defined in the [Pandas documentation](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html).
|
|
429
433
|
|
|
430
|
-
## Matching /
|
|
434
|
+
## Matching / enumerating the occurrences of a chronicle
|
|
431
435
|
|
|
432
|
-
Let us now use a dataframe defined as explained in the previous section with chronicle.
|
|
436
|
+
Let us now use a dataframe defined as explained in the previous section with a chronicle.
|
|
433
437
|
|
|
434
|
-
For that, we first need to define a chronicle. It works exactly as before but
|
|
438
|
+
For that, we first need to define a chronicle. It works exactly as before, but the chronicle's events are defined by queries.
|
|
435
439
|
|
|
436
|
-
For instance, the following example illustrates the definition a simple chronicle that uses queries as
|
|
440
|
+
For instance, the following example illustrates the definition of a simple chronicle that uses queries as events:
|
|
437
441
|
```python
|
|
438
442
|
c=Chronicle()
|
|
439
443
|
c.add_event(0,'label=="a"')
|
|
@@ -443,24 +447,24 @@ c.add_constraint(0,1, (np.timedelta64(4,'D'),np.timedelta64(10,'D')))
|
|
|
443
447
|
|
|
444
448
|
For more details about the syntax of queries, please refer to the [Pandas documentation](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html).
|
|
445
449
|
|
|
446
|
-
This chronicle is semantically sound
|
|
450
|
+
This chronicle is semantically sound to be used with the dataframe defined in the example of the previous section.
|
|
447
451
|
|
|
448
452
|
### Dataframe representing a sequence
|
|
449
453
|
|
|
450
454
|
In this section, we consider that the dataframe represents a unique sequence (for instance, we selected the first sequence of the previous dataframe with `df[df.id==1]`).
|
|
451
455
|
|
|
452
|
-
The recognition functionalities are now accessible
|
|
456
|
+
The recognition functionalities are now accessible through the Pandas dataframe:
|
|
453
457
|
|
|
454
|
-
* `df.tpattern.match(c)`
|
|
455
|
-
* `df.tpattern.recognize(c)`
|
|
456
|
-
* `df.tpattern.project(c)`
|
|
458
|
+
* `df.tpattern.match(c)` returns a boolean indicating whether the chronicle occurs in the sequence or not
|
|
459
|
+
* `df.tpattern.recognize(c)` returns the list of the occurrences of `c` in the sequence (`df.tpattern.iter_recognize(c)` is its lazy version)
|
|
460
|
+
* `df.tpattern.project(c)` returns a dataframe with the delays of the temporal constraints of the chronicle `c` in each of its occurrences
|
|
457
461
|
|
|
458
462
|
Note that the `tpattern` keyword gives access to the features of our package.
|
|
459
463
|
|
|
460
464
|
<br>
|
|
461
465
|
|
|
462
|
-
Using chronicles becomes very easy with Pandas
|
|
463
|
-
We keep good computational efficiency of the recognition algorithms thanks to the
|
|
466
|
+
Using chronicles becomes very easy with Pandas dataframes, and they also gain in expressivity thanks to the use of queries as events.
|
|
467
|
+
We keep a good computational efficiency of the recognition algorithms thanks to the rewriting principle developed with semantic chronicles (see the reference below).
|
|
464
468
|
|
|
465
469
|
```bibtex
|
|
466
470
|
@inproceedings{semantic_chronicles,
|
|
@@ -474,20 +478,20 @@ We keep good computational efficiency of the recognition algorithms thanks to th
|
|
|
474
478
|
|
|
475
479
|
### Dataframe representing a collection of sequences
|
|
476
480
|
|
|
477
|
-
To
|
|
481
|
+
To process a dataframe containing several sequences, you can use the following idiom based on `apply`:
|
|
478
482
|
|
|
479
483
|
```python
|
|
480
484
|
reco=df.groupby('id').apply(lambda d: d.tpattern.match(c))
|
|
481
485
|
```
|
|
482
486
|
|
|
483
487
|
In this case, the attribute `id` is used to select the events for each sequence, and then the `match` algorithm is applied to this selection.
|
|
484
|
-
The result is a
|
|
488
|
+
The result is a pandas series containing a boolean value for each sequence id.
|
|
485
489
|
|
|
486
|
-
The same applies
|
|
490
|
+
The same applies to the `recognize` function.
|
|
487
491
|
|
|
488
|
-
## Use of MTL
|
|
492
|
+
## Use of MTL formulas
|
|
489
493
|
|
|
490
|
-
For situation
|
|
494
|
+
For situation recognition, there are strong connections between chronicles and metric temporal logics such as MTL or TPTL. See the [article](https://hal.archives-ouvertes.fr/hal-03777471):
|
|
491
495
|
~~~bibtex
|
|
492
496
|
@inproceedings{chronicle_templogics,
|
|
493
497
|
title = {Logical forms of chronicles},
|
|
@@ -498,12 +502,12 @@ For situation recognitinon, there are strong connection between chronicles and m
|
|
|
498
502
|
}
|
|
499
503
|
~~~
|
|
500
504
|
|
|
501
|
-
To illustrate that the principle of semantic chronicles can be broader, we extended it to the case of MTL
|
|
505
|
+
To illustrate that the principle of semantic chronicles can be broader, we extended it to the case of MTL formulas. This means that our framework makes it possible to express MTL formulas using queries as events.
|
|
502
506
|
|
|
503
507
|
|
|
504
|
-
The `tpattern` accessor provides a function `match_mtl` that is dedicated to the recognition of
|
|
508
|
+
The `tpattern` accessor provides a function `match_mtl` that is dedicated to the recognition of an MTL formula in the timed sequence (only for dataframes indexed by floats or integers). This function returns a boolean value. There is no equivalent to the enumeration of the occurrences of a chronicle.
|
|
505
509
|
|
|
506
|
-
The syntax of an MTL formula is based on the two operators `F` (eventually) and `G` (globally). These operators can be specified with temporal constraints (in brackets). They
|
|
510
|
+
The syntax of an MTL formula is based on the two operators `F` (eventually) and `G` (globally). These operators can be specified with temporal constraints (in brackets). They combine events defined in the same way as chronicle events.
|
|
507
511
|
|
|
508
512
|
```python
|
|
509
513
|
query = ' F(label=="a" & F[2.9,5]( label=="b" & num_val>5 ))'
|
|
@@ -514,13 +518,13 @@ This feature is based on the [Python implementation of MTL](https://github.com/m
|
|
|
514
518
|
|
|
515
519
|
## Abstraction of a sequence
|
|
516
520
|
|
|
517
|
-
Finally, we also provide a function that
|
|
521
|
+
Finally, we also provide a function that abstracts a collection of sequences into a chronicle.
|
|
518
522
|
|
|
519
|
-
Contrary to the recognition functions that can handle several columns, the abstraction requires
|
|
520
|
-
Then, the function, named `abstract
|
|
523
|
+
Contrary to the recognition functions that can handle several columns, the abstraction requires a column that corresponds to the event names. In addition, it requires the name of the attribute that corresponds to the identifier of the sequences.
|
|
524
|
+
Then, the function, named `abstract`, takes these two arguments and outputs a single chronicle that occurs in all the sequences.
|
|
521
525
|
|
|
522
526
|
|
|
523
|
-
The following example extracts a chronicle from the dataframe introduced above.
|
|
527
|
+
The following example extracts a chronicle from the dataframe introduced above. Its events are based on the `label` attribute.
|
|
524
528
|
```python
|
|
525
529
|
chro = df.tpattern.abstract('label', 'id')
|
|
526
530
|
```
|
|
@@ -529,7 +533,7 @@ chro = df.tpattern.abstract('label', 'id')
|
|
|
529
533
|
|
|
530
534
|
## Export / import of chronicles
|
|
531
535
|
|
|
532
|
-
It is possible to specify chronicles using the CRS format. The following code
|
|
536
|
+
It is possible to specify chronicles using the CRS format (see the functions `load` and `to_crs` of the `pychronicles.utils` module). The following code illustrates the syntax for specifying a chronicle in this format.
|
|
533
537
|
|
|
534
538
|
```
|
|
535
539
|
chronicle C27_sub_0[]()
|
|
@@ -550,16 +554,16 @@ chronicle C27_sub_0[]()
|
|
|
550
554
|
|
|
551
555
|
* implementation of chronicle mining algorithms
|
|
552
556
|
* graphical chronicle editor
|
|
553
|
-
*
|
|
557
|
+
* compile the recognition (e.g. with Cython)
|
|
554
558
|
* optimized matching of several chronicles at the same time
|
|
555
559
|
|
|
556
560
|
|
|
557
|
-
If you think that this package can be improved
|
|
561
|
+
If you think that this package can be improved, do not hesitate to contact the author to request additional features. He will do his best to maintain the code and improve it continuously.
|
|
558
562
|
|
|
559
563
|
|
|
560
564
|
# Authorship
|
|
561
565
|
|
|
562
566
|
* **Author:** Thomas Guyet
|
|
563
567
|
* **Institution:** Inria/AIstroSight
|
|
564
|
-
* **date:**
|
|
568
|
+
* **date:** 10/2026
|
|
565
569
|
|