Structural and Syntactic Pattern Recognition
Selim Aksoy
Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr
CS 551, Fall 2019
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 1 / 57
Structural and Syntactic Pattern Recognition Selim Aksoy - - PowerPoint PPT Presentation
Structural and Syntactic Pattern Recognition Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr CS 551, Fall 2019 CS 551, Fall 2019 2019, Selim Aksoy (Bilkent University) c 1 / 57 Introduction
Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 1 / 57
◮ Statistical pattern recognition attempts to classify patterns
◮ Ideally, this is achieved with a rather straightforward
◮ determine the feature vector, ◮ train the system, ◮ classify the patterns.
◮ Unfortunately, there are also many problems where
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 2 / 57
◮ Structural pattern recognition assumes that pattern
◮ Typically, these approaches formulate hierarchical
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 3 / 57
◮ This structure quantification and description are mainly
◮ Relational descriptions (principally graphs), ◮ Formal grammars.
◮ Then, recognition and classification are done using:
◮ Relational graph matching (for relational descriptions), ◮ Parsing (for formal grammars).
◮ We will study graph-theoretic approaches, strings, and
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 4 / 57
◮ Graphs are valuable tools for representing relational
◮ A graph G = {N, R} is an ordered pair represented using:
◮ a set of nodes (vertices), N, ◮ a set of edges (arcs), R ⊆ N × N.
◮ A subgraph of G is itself a graph Gs = {Ns, Rs} where
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 5 / 57
◮ A graph is connected if there is a path between all pairs of
◮ A graph is complete if there is an edge between all pairs of
◮ A relation from set A to set B is a subset of A × B. ◮ It is usually shown using a function f : A → B or b = f(a).
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 6 / 57
◮ For example, the relation “lies on” can contain:
◮ Note that relations have directions, i.e., the order in which
◮ Higher-order relations can be shown as ordered n-tuples
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 7 / 57
◮ In directional graphs (digraphs), edges have directional
◮ When the direction of edges in a graph is not important, i.e.,
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 8 / 57
◮ A relational graph represents a particular relation
◮ A tree is a finite acyclic (containing no closed loops or paths
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 9 / 57
◮ One way to recognize structure using graphs is to let each
◮ An unknown input pattern is then converted into a structural
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 10 / 57
◮ The observed data rarely matches a stored relational
◮ One approach is to check whether the observed data match
◮ Case 1: Any relation not present in both graphs is a failure. ◮ Case 2: Any single match of a relation is a success. ◮ A realistic strategy is somewhere in between these
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 11 / 57
◮ A digraph G with p nodes can be converted to an adjacency
◮ Number each node by an index {1, . . . , p}. ◮ Represent the existence or absence of an edge as
◮ Consider two graphs G1 = {N1, R1} and G2 = {N2, R2}. ◮ A homomorphism from G1 to G2 is a function f from N1 to
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 12 / 57
◮ A stricter test is that of isomorphism, where f is required to
◮ Isomorphism simply states that relabeling of nodes yields
◮ Given two graphs G1 and G2 each with p nodes, to
◮ Label the nodes of each graph with labels 1, . . . , p. ◮ Form the adjacency matrices M1 and M2 for both graphs. ◮ If M1 = M2, G1 and G2 are isomorphic. ◮ Otherwise, consider all the p! possible labelings on G2. CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 13 / 57
a b c d a 0 1 0 1 b 1 0 1 0 c 0 1 0 1 d 1 0 1 0 a’ b’ c’ d’ a’ 0 1 1 0 b’ 1 0 0 1 c’ 1 0 0 1 d’ 0 1 1 0 a” b” c” d” a” 0 1 0 1 b” 1 0 1 0 c” 0 1 0 1 d” 1 0 1 0 f(a) = a′′ f(b) = b′′ f(c) = c′′ f(d) = d′′
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 14 / 57
◮ Unfortunately, determining graph isomorphism is
◮ Furthermore, it is also not a practical similarity measure
◮ G1 and G2 are called subisomorphic if a subgraph of G1 is
◮ Clearly, this is a less restrictive structural match than that of
◮ However, determining subisomorphism is also
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 15 / 57
◮ To allow structural deformations, numerous extensions to
◮ Extract features from graphs G1 and G2 to form feature
◮ Use a matching metric as the minimum number of
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 16 / 57
◮ Common transformations include:
◮ Node insertion, ◮ Node deletion, ◮ Node splitting, ◮ Node merging, ◮ Edge insertion, ◮ Edge deletion.
◮ Note that computational complexity can still be high and it
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 17 / 57
◮ In addition to representing pattern structure, the
◮ An attributed graph G = {N, P, R} is a 3-tuple where
◮ N is a set of nodes, ◮ P is a set of properties of these nodes, ◮ R is a set of relations between nodes. CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 18 / 57
◮ Let pi q(n) denote the value of the q’th property of node n of
◮ Nodes ni ∈ Ni and n2 ∈ N2 are said to form an agreement
q(n1) ∼ p2 q(n2)
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 19 / 57
◮ Let ri j(nx, ny) denote the j’th relation involving nodes
◮ Two assignments (n1, n2) and (n′ 1, n′ 2) are considered
j(n1, n′ 1) ∼ r2 j(n2, n′ 2)
◮ Two attributed graphs G1 and G2 are isomorphic if there
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 20 / 57
◮ A strategy for measuring the similarity between two
◮ A clique of a graph is a totally connected subgraph. ◮ A maximal clique is not included in any other clique. ◮ A match graph is formed from two graphs G1 and G2 as
◮ Nodes of the match graph are assignments from G1 to G2. ◮ An edge in the match graph exists between two nodes if the
◮ The maximal cliques of the match graph provide starting
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 21 / 57
◮ Another similarity measure between two attributed graphs is
◮ These operations are defined as substitution, insertion and
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 22 / 57
◮ Let G1 and G2 be two graphs where each node and edge
◮ Let f1 be the confidence value of the label of a node in the
◮ The cost of node substitution is |f1 − f2| and the cost of
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 23 / 57
◮ Let g1 be the confidence value of the label of an edge in the
◮ The cost of edge substitution is |g1 − g2| and the cost of
◮ The computation of the distance between two attributed
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 24 / 57
The editing distance between these two graphs is computed as: ◮ node substitution:
◮ object 0 in (b) with object 0 in (a) with cost |1.0 − 1.0| = 0 ◮ object 1 in (b) with object 1 in (a) with cost |0.4 − 0.3| = 0.1 ◮ object 2 in (b) with object 3 in (a) with cost |0.1 − 0.2| = 0.1
◮ edge substitution for these nodes:
◮ |0.7 − 0.7| = 0, |0.3 − 0.4| = 0.1, |0.3 − 0.3| = 0
◮ node deletion: object 2 in (a) with cost 0.2 ◮ edge deletion for this node: 0.5, 0.2, 0.1 Total cost of matching is 0.1 + 0.1 + 0.1 + 0.2 + 0.5 + 0.2 + 0.1 = 1.3.
(Taken from Petrakis et al. “ImageMap: An Image Indexing Method Based on Spatial Similarity,” IEEE
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 25 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 26 / 57
The editing distance between these two graphs is computed as: ◮ node substitution:
◮ park in (a) with park in (b) with cost |0.8 − 0.9| = 0.1 ◮ city in (a) with city in (b) with cost |0.9 − 0.9| = 0 ◮ water in (a) with water in (b) with cost |1.0 − 1.0| = 0
◮ edge substitution for these nodes:
◮ |0.9 − 0.8| + 0.8 = 0.9, |1.0 − 1.0| + |0.8 − 0.9| = 0.1, |0.6 − 0.7| = 0.1,
◮ node insertion: field in (a) with cost 0.7 ◮ edge insertion for this node: 0.4, 0.7, 0.6 Total cost of matching is 3.6.
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 27 / 57
(a) (b) (c) (d)
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 28 / 57
◮ Suppose the patterns are represented as ordered
◮ Pattern classification methods based on such strings of
◮ Definitions:
◮ String elements are called characters (or letters, symbols). ◮ String representation of a pattern is also called a word. ◮ A particularly long string is denoted text. ◮ Any contiguous string that is part of another string is called a
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 29 / 57
◮ Important pattern recognition problems that involve
◮ String matching: Given string x and text, determine whether
◮ String edit distance: Given two strings x and y, compute the
◮ String matching with errors: Given string x and text, find the
◮ String matching with the “don’t care” symbol: This is the
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 30 / 57
◮ The most fundamental and useful operation in string
◮ The number of characters in text is usually much larger than
◮ A shift, s, is an offset needed to align the first character of x
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 31 / 57
◮ The basic string matching problem is to find whether there
◮ The general string matching problem is to list all valid shifts. ◮ The most straightforward approach is to test each possible
◮ More sophisticated methods use heuristics to reduce the
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 32 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 33 / 57
◮ The fundamental idea underlying pattern recognition using
◮ We store a full training set of strings and their associated
◮ During classification, a test string is compared to each
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 34 / 57
◮ Edit distance between x and y describes how many of the
◮ Substitutions: A character in x is replaced by the
◮ Insertions: A character in y is inserted into x, thereby
◮ Deletions: A character in x is deleted, thereby decreasing
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 35 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 36 / 57
◮ Given a pattern x and text, string matching with errors
◮ The algorithm for the string matching with errors problem is
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 37 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 38 / 57
◮ String matching with the “don’t care” symbol, ∅, is formally
◮ The straightforward approach is to modify the string
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 39 / 57
◮ Grammars provide detailed models that underlie the
◮ For example, strings representing telephone numbers
◮ Similarly, optical character recognition systems that
◮ In pattern recognition, we are given a sentence (a string
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 40 / 57
◮ Formally, a grammar consists of four components:
◮ Symbols: Every sentence consists of a string of characters
◮ Variables: These are called the nonterminal symbols (or
◮ Root symbol: It is a special variable, the source from which
◮ Productions: The set of production rules (or rewrite rules)
◮ For example, if A is a variable and c a terminal symbol, the
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 41 / 57
◮ The language L(G) generated by a grammar G is the set of
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 42 / 57
◮ Type 0: Free or Unrestricted: Free grammars have no
◮ Type 1: Context-Sensitive: A grammar is called
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 43 / 57
◮ Type 2: Context-Free: A grammar is called context-free if
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 44 / 57
◮ Type 3: Finite State or Regular: A grammar is called regular
◮ The class of grammars of type i includes all grammars of
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 45 / 57
◮ Suppose we are given a test sentence x that was
◮ The test sentence x is classified according to which
◮ Parsing is the inverse process that, given a particular x,
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 46 / 57
◮ Bottom-up parsing starts with the test sentence x, and
◮ The basic approach is to use candidate productions
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 47 / 57
◮ Top-down parsing starts with the root node and
◮ Since it is rare that the sentence is derived in the first
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 48 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 49 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 50 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 51 / 57
◮ A grammar describing four blocks arranged in 2-block
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 52 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 53 / 57
◮ A grammar describing four blocks in 3-block and 1-block
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 54 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 55 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 56 / 57
CS 551, Fall 2019 c 2019, Selim Aksoy (Bilkent University) 57 / 57