Timed Pattern Matching FORMATS14 gan Ulus 1 ere 1 Eugene Asarin 2 - - PowerPoint PPT Presentation

timed pattern matching
SMART_READER_LITE
LIVE PREVIEW

Timed Pattern Matching FORMATS14 gan Ulus 1 ere 1 Eugene Asarin 2 - - PowerPoint PPT Presentation

Timed Pattern Matching FORMATS14 gan Ulus 1 ere 1 Eugene Asarin 2 Oded Maler 1 Do Thomas Ferr` 1 VERIMAG, CNRS and the University of Grenoble-Alpes 2 LIAFA, University of Paris Diderot / CNRS September 10, 2014 Timed Pattern Matching


slide-1
SLIDE 1

Timed Pattern Matching

FORMATS’14 Do˘ gan Ulus1 Thomas Ferr` ere1 Eugene Asarin2 Oded Maler1

1 VERIMAG, CNRS and the University of Grenoble-Alpes 2 LIAFA, University of Paris Diderot / CNRS

September 10, 2014

Timed Pattern Matching Thomas Ferr` ere 1 / 26

slide-2
SLIDE 2

Pattern matching

Problem (Pattern matching for regular expressions)

Given a word w ∈ Σ∗ and a regular expression ϕ find subwords v of w that match ϕ. Classical solutions

◮ algorithms: often based on automata ◮ tools: grep, sed, programming languages: perl, python etc.

Timed Pattern Matching Thomas Ferr` ere 2 / 26

slide-3
SLIDE 3

Timed pattern matching

Why do it?

◮ Monitoring of embedded systems ◮ Hardware specification languages ◮ Timed texts (music, speech) ◮ Quantitative pattern matching (texts, DNA sequences)

Why is it not straightforward?

◮ Classical algorithms based on (implicit) determinization

⇒ heavy subset construction

◮ Timed automaton does not explicitely provide all matches

Timed Pattern Matching Thomas Ferr` ere 3 / 26

slide-4
SLIDE 4

Example

◮ Expression:

ϕ = (p ∧ q) · ¯ q · q[4,5] · ¯ p

◮ Signals:

p 2 4 6 8 10 12 q

◮ Matches:

1.3 2.0 6.06.3 6.8 p ∧ q ¯ q q ¯ p 1.5 2.0 6.0 6.4 7.0 p ∧ q ¯ q q ¯ p Timed Pattern Matching Thomas Ferr` ere 4 / 26

slide-5
SLIDE 5

Outline

1

Problem statement

2

The solution

3

Practical algorithmics

4

Experiments

Timed Pattern Matching Problem statement Thomas Ferr` ere 5 / 26

slide-6
SLIDE 6

Outline

1

Problem statement

2

The solution

3

Practical algorithmics

4

Experiments

Timed Pattern Matching Problem statement Thomas Ferr` ere 6 / 26

slide-7
SLIDE 7

Timed Boolean signals

Example

p 2 4 6 8 10 12 q

Definition (Boolean Signals)

Let T = [0, d] (time domain).

◮ a Boolean signal is a function w : T → Bm. ◮ can be represented using m Boolean variables p(t). ◮ assumption: the number of discontinuities is finite.

Timed Pattern Matching Problem statement Thomas Ferr` ere 7 / 26

slide-8
SLIDE 8

Timed regular expressions – to specify sets of signals

Definition (Syntax of TRE)

ϕ := ǫ | p | p | ϕ · ϕ | ϕ ∨ ϕ | ϕ ∧ ϕ | ϕ∗ | ϕI p propositional variable, I integer bounded interval

Definition (Semantics of TRE)

(w, t, t′) ǫ ↔ t = t′ (w, t, t′) p ↔ t < t′ and ∀t′′ ∈ (t, t′), p[t′′] = 1 (w, t, t′) p ↔ . . . (w, t, t′) ϕ · ψ ↔ ∃t′′ ∈ (t, t′), (w, t, t′′) ϕ and (w, t′′, t′) ψ (w, t, t′) ϕ ∨ ψ ↔ (w, t, t′) ϕ or (w, t, t′) ψ (w, t, t′) ϕ ∧ ψ ↔ . . . (w, t, t′) ϕ∗ ↔ ∃k ≥ 0, (w, t, t′) ϕk (w, t, t′) ϕI ↔ t′ − t ∈ I and (w, t, t′) ϕ

Timed Pattern Matching Problem statement Thomas Ferr` ere 8 / 26

slide-9
SLIDE 9

Timed regular expressions – to specify sets of signals

Definition (Syntax of TRE)

ϕ := ǫ | p | p | ϕ · ϕ | ϕ ∨ ϕ | ϕ ∧ ϕ | ϕ∗ | ϕI p propositional variable, I integer bounded interval

Definition (Semantics of TRE)

(w, t, t′) ǫ ↔ t = t′ (w, t, t′) p ↔ t < t′ and ∀t′′ ∈ (t, t′), p[t′′] = 1 (w, t, t′) p ↔ . . . (w, t, t′) ϕ · ψ ↔ ∃t′′ ∈ (t, t′), (w, t, t′′) ϕ and (w, t′′, t′) ψ (w, t, t′) ϕ ∨ ψ ↔ (w, t, t′) ϕ or (w, t, t′) ψ (w, t, t′) ϕ ∧ ψ ↔ . . . (w, t, t′) ϕ∗ ↔ ∃k ≥ 0, (w, t, t′) ϕk (w, t, t′) ϕI ↔ t′ − t ∈ I and (w, t, t′) ϕ

Timed Pattern Matching Problem statement Thomas Ferr` ere 8 / 26

slide-10
SLIDE 10

Problem statement

Definition (Match-set)

For a signal w and an expression ϕ the match-set is M(ϕ, w) := {(t, t′) ∈ T × T : (w, t, t′) ϕ}

Problem (Timed pattern matching)

Given a signal and an expression compute the match-set.

Timed Pattern Matching Problem statement Thomas Ferr` ere 9 / 26

slide-11
SLIDE 11

Problem statement

Definition (Match-set)

For a signal w and an expression ϕ the match-set is M(ϕ, w) := {(t, t′) ∈ T × T : (w, t, t′) ϕ}

Problem (Timed pattern matching)

Given a signal and an expression compute the match-set.

Timed Pattern Matching Problem statement Thomas Ferr` ere 9 / 26

slide-12
SLIDE 12

Outline

1

Problem statement

2

The solution

3

Practical algorithmics

4

Experiments

Timed Pattern Matching The solution Thomas Ferr` ere 10 / 26

slide-13
SLIDE 13

Data structure

Definition (2d zone)

A 2d zone is a subset of R2 described by inequalities a < x < b c < y < d e < x − y < f with a, b, c, d, e, f real constants.

About 2d zones

◮ convex polygons (with up to 6 edges) ◮ only vertical, horizontal and diagonal edges

Timed Pattern Matching The solution Thomas Ferr` ere 11 / 26

slide-14
SLIDE 14

Data structure

Definition (2d zone)

A 2d zone is a subset of R2 described by inequalities a < x < b c < y < d e < x − y < f with a, b, c, d, e, f real constants.

About 2d zones

◮ convex polygons (with up to 6 edges) ◮ only vertical, horizontal and diagonal edges

Timed Pattern Matching The solution Thomas Ferr` ere 11 / 26

slide-15
SLIDE 15

Main result

Theorem

The match-set M(ϕ, w) is computable as a finite union of 2d zones.

Proof principle

Structural induction over ϕ ⇒ recursive algorithm over the expression syntactic tree

Timed Pattern Matching The solution Thomas Ferr` ere 12 / 26

slide-16
SLIDE 16

Main result

Theorem

The match-set M(ϕ, w) is computable as a finite union of 2d zones.

Proof principle

Structural induction over ϕ ⇒ recursive algorithm over the expression syntactic tree

Timed Pattern Matching The solution Thomas Ferr` ere 12 / 26

slide-17
SLIDE 17

Structural induction: base cases

Empty word

M(ǫ, w) = {(t, t′) : t = t′} and the diagonal is a zone

A literal

M(p, w) is a union of triangles

  • ver the diagonal

Example

Timed Pattern Matching The solution Thomas Ferr` ere 13 / 26

slide-18
SLIDE 18

Structural induction: base cases

Empty word

M(ǫ, w) = {(t, t′) : t = t′} and the diagonal is a zone

A literal

M(p, w) is a union of triangles

  • ver the diagonal

Example

1 2 3 4 5 6 7 8 9 10 11 12

p

1 2 3 4 5 6 7 8 9 10 11 12 p

Timed Pattern Matching The solution Thomas Ferr` ere 13 / 26

slide-19
SLIDE 19

Structural induction: Boolean closure

Intersection

Zones are closed under intersection

Union

Unions of zones are closed under union

Time restriction

M(ϕI, w) = M(ϕ, w)∩{(t, t′) : t′−t ∈ I} is an intersection of zones

Example

Timed Pattern Matching The solution Thomas Ferr` ere 14 / 26

slide-20
SLIDE 20

Structural induction: Boolean closure

Intersection

Zones are closed under intersection

Union

Unions of zones are closed under union

Time restriction

M(ϕI, w) = M(ϕ, w)∩{(t, t′) : t′−t ∈ I} is an intersection of zones

Example

Timed Pattern Matching The solution Thomas Ferr` ere 14 / 26

slide-21
SLIDE 21

Structural induction: Boolean closure

Intersection

Zones are closed under intersection

Union

Unions of zones are closed under union

Time restriction

M(ϕI, w) = M(ϕ, w)∩{(t, t′) : t′−t ∈ I} is an intersection of zones

Example

1 2 3 4 5 6 7 8 9 10 11 12

p[1,2]

1 2 3 4 5 6 7 8 9 10 11 12 p

Timed Pattern Matching The solution Thomas Ferr` ere 14 / 26

slide-22
SLIDE 22

Structural induction: concatenation

Lemma (Concatenation = composition of binary relations)

M(ϕ · ψ, w) = M(ϕ, w) ◦ M(ψ, w)

Composition preserves zones

(t, t′) ∈ z1 ◦ z2 ↔ ∃t′′ : (t, t′′) ∈ z1 ∧ (t′′, t′) ∈ z2. Can be obtained using standard zones operations.

Timed Pattern Matching The solution Thomas Ferr` ere 15 / 26

slide-23
SLIDE 23

Structural induction: concatenation

Lemma (Concatenation = composition of binary relations)

M(ϕ · ψ, w) = M(ϕ, w) ◦ M(ψ, w)

Composition preserves zones

(t, t′) ∈ z1 ◦ z2 ↔ ∃t′′ : (t, t′′) ∈ z1 ∧ (t′′, t′) ∈ z2. Can be obtained using standard zones operations.

Timed Pattern Matching The solution Thomas Ferr` ere 15 / 26

slide-24
SLIDE 24

Example

Concatenation of ϕ = p[1,∞] with ψ = q[0,2]

1 2 3 4 5 6 7 8

ϕ ψ ϕ · ψ

p 1 2 3 4 5 6 7 8 q t′′ t′ p t t′′ t′ q

zones for ϕ, ψ and ϕ · ψ a match (t, t′) of ϕ · ψ

Timed Pattern Matching The solution Thomas Ferr` ere 16 / 26

slide-25
SLIDE 25

Structural induction: Kleene star

Definition (size of a signal)

σ(w) – minimal number of intervals that:

◮ cover the time domain of w ◮ are of length < 1 ◮ w is constant in each interval

Lemma (Star is bounded)

If σ(w) = k then M(ϕ∗, w) = M(ϕ≤2k+1, w).

Timed Pattern Matching The solution Thomas Ferr` ere 17 / 26

slide-26
SLIDE 26

Structural induction: Kleene star

Definition (size of a signal)

σ(w) – minimal number of intervals that:

◮ cover the time domain of w ◮ are of length < 1 ◮ w is constant in each interval

Lemma (Star is bounded)

If σ(w) = k then M(ϕ∗, w) = M(ϕ≤2k+1, w).

Timed Pattern Matching The solution Thomas Ferr` ere 17 / 26

slide-27
SLIDE 27

Example (from introduction)

(p ∧ q) · ¯ q · q[4,5] · ¯ p

p 2 4 6 8 10 12 q

Inductive steps:

1 2 3 4 5 6 7 8 9 10 11 12

p ¯ p q ¯ q p ∧ q (p ∧ q) · ¯ q

1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12

(p ∧ q) · ¯ q · q

1 2 3 4 5 6 7 8 9 10 11 12

(p ∧ q) · ¯ q · q[4,5]

1 2 3 4 5 6 7 8 9 10 11 12

(p ∧ q) · ¯ q · q[4,5] · ¯ p

Timed Pattern Matching The solution Thomas Ferr` ere 18 / 26

slide-28
SLIDE 28

Outline

1

Problem statement

2

The solution

3

Practical algorithmics

4

Experiments

Timed Pattern Matching Practical algorithmics Thomas Ferr` ere 19 / 26

slide-29
SLIDE 29

Overall program structure

function zones(ϕ, w) select ϕ case ǫ, p, p: Zϕ := atom(ϕ, w) case • ψ: Zψ := zones(ψ, w) Zϕ := combine(•, Zψ) case ψ1 • ψ2: Zψ1 := zones(ψ1, w) Zψ2 := zones(ψ2, w) Zϕ := combine(•, Zψ1, Zψ2) end select return Zϕ combine implemented for all operations • ∈ {·, ∨, ∧,∗ , I}

Timed Pattern Matching Practical algorithmics Thomas Ferr` ere 20 / 26

slide-30
SLIDE 30

An important issue for intersection and concatenation

Does it explode?

  • i

zi ∩

  • j

z′

j =

  • ij

zi ∩ z′

j

  • i

zi ◦

  • j

z′

j =

  • ij

zi ◦ z′

j

Not in practice

◮ Most resulting zones are empty. ◮ Plane-sweep algorithm: sorting zones by start / end time allows to

avoid most empty operations

Timed Pattern Matching Practical algorithmics Thomas Ferr` ere 21 / 26

slide-31
SLIDE 31

An important issue for intersection and concatenation

Does it explode?

  • i

zi ∩

  • j

z′

j =

  • ij

zi ∩ z′

j

  • i

zi ◦

  • j

z′

j =

  • ij

zi ◦ z′

j

Not in practice

◮ Most resulting zones are empty. ◮ Plane-sweep algorithm: sorting zones by start / end time allows to

avoid most empty operations

Timed Pattern Matching Practical algorithmics Thomas Ferr` ere 21 / 26

slide-32
SLIDE 32

Star: computed by squaring

function combine( ∗, Z) X := ∅ Y := Z while ∃z ∈ Y, ∀z′ ∈ X, z z′ do X := X ∪ Y ∪ combine(·, X, Y ) Y := combine(·, Y, Y ) end while return X ∪ {ε}

Invariant

After k iterations ∪Xk = (∪Z)<2k and ∪Yk = (∪Z)2k

Lemma

The algorithm stops after log(|Z| + ∆(Z)) iterations

Timed Pattern Matching Practical algorithmics Thomas Ferr` ere 22 / 26

slide-33
SLIDE 33

Star: computed by squaring

function combine( ∗, Z) X := ∅ Y := Z while ∃z ∈ Y, ∀z′ ∈ X, z z′ do X := X ∪ Y ∪ combine(·, X, Y ) Y := combine(·, Y, Y ) end while return X ∪ {ε}

Invariant

After k iterations ∪Xk = (∪Z)<2k and ∪Yk = (∪Z)2k

Lemma

The algorithm stops after log(|Z| + ∆(Z)) iterations

Timed Pattern Matching Practical algorithmics Thomas Ferr` ere 22 / 26

slide-34
SLIDE 34

Outline

1

Problem statement

2

The solution

3

Practical algorithmics

4

Experiments

Timed Pattern Matching Experiments Thomas Ferr` ere 23 / 26

slide-35
SLIDE 35

Experimental setting

◮ Program: Python implementation calling IF zones library. ◮ Signals: random signals of given

◮ variability V (discontinuities per time unit) ◮ length L (number of time units)

◮ Expression: ϕ = (p · ¯

p[0,10])∗ ∧ (q · ¯ q[0,10])∗[80,∞]

Timed Pattern Matching Experiments Thomas Ferr` ere 24 / 26

slide-36
SLIDE 36

A table of results

V L |Zϕ| Time (s) 0.025 40000 0.08 0.025 80000 0.17 0.025 160000 0.37 0.05 40000 0.27 0.05 80000 0.60 0.05 160000 1.27 0.075 40000 1 0.64 0.075 80000 4 1.40 0.075 160000 5 2.88 0.1 40000 10 1.35 0.1 80000 23 2.73 0.1 160000 47 5.83

Timed Pattern Matching Experiments Thomas Ferr` ere 25 / 26

slide-37
SLIDE 37

Conclusion

Contribution

◮ The problem of timed pattern matching stated and solved ◮ A prototype tool developed ◮ Experiments on synthetic data witness scalability

Perspectives

◮ Online matching / monitoring ◮ New operators (mixing expressions and logic, as in hardware

specification languages)

◮ Extending from signals to timed event sequences

Timed Pattern Matching Thomas Ferr` ere 26 / 26