3 downloads 1001 Views 8MB Size

HANDBOOK OF APPLIED ALGORITHMS SOLVING SCIENTIFIC, ENGINEERING AND PRACTICAL PROBLEMS Edited by

Amiya Nayak SITE, University of Ottawa Ottawa, Ontario, Canada

Ivan Stojmenovi´c EECE, University of Birmingham, UK

A JOHN WILEY & SONS, INC., PUBLICATION

Copyright © 2008 by John Wiley & Sons, Inc. All rights reserved. Published by John Wiley & Sons, Inc., Hoboken, New Jersey Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400, fax 978-750-4470, or on the web at www.copyright.com. Requests to the Publisher for permission should be addressed to teh Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, 201-748-6011, fax 201-748-6008, or online at http://www.wiley.com/go/permission. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and speciﬁcally disclaim any implied warranties of merchantability or ﬁtness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of proﬁt or any other commerical damages, including but not limited to special, incidental, consequential, or other damages. For general information on our other products and services or for technical support, please contact our Customer Care Department within the United States at 877-762-2974, outside the United States at 317-572-3993 or fax 317-572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic formats. For more information about Wiley products, visit our web site at www.wiley.com.

Library of Congress Cataloging-in-Publication Data: Handbook of applied algorithms: solving scientiﬁc, engineering, and practical problem / edited by Amiya Nayak & Ivan Stojmenovic. p. cm. ISBN 978-0-470-04492-6 1. Computer algorithms. I. Nayak, Amiya. II. Stojmenovic, Ivan. QA76.9.A43H353 2007 005.1–dc22 2007010253 Printed in the United States of America 10 9 8 7 6 5 4 3 2 1

CONTENTS

Preface

vii

Abstracts

xv

Contributors 1. Generating All and Random Instances of a Combinatorial Object

xxiii

1

Ivan Stojmenovic 2. Backtracking and Isomorph-Free Generation of Polyhexes

39

Lucia Moura and Ivan Stojmenovic 3. Graph Theoretic Models in Chemistry and Molecular Biology

85

Debra Knisley and Jeff Knisley 4. Algorithmic Methods for the Analysis of Gene Expression Data

115

Hongbo Xie, Uros Midic, Slobodan Vucetic, and Zoran Obradovic 5. Algorithms of Reaction–Diffusion Computing

147

Andrew Adamatzky 6. Data Mining Algorithms I: Clustering

177

Dan A. Simovici 7. Data Mining Algorithms II: Frequent Item Sets

219

Dan A. Simovici 8. Algorithms for Data Streams

241

Camil Demetrescu and Irene Finocchi v

vi

CONTENTS

9. Applying Evolutionary Algorithms to Solve the Automatic Frequency Planning Problem

271

Francisco Luna, Enrique Alba, Antonio J. Nebro, Patrick Mauroy, and Salvador Pedraza 10. Algorithmic Game Theory and Applications

287

Marios Mavronicolas, Vicky Papadopoulou, and Paul Spirakis 11. Algorithms for Real-Time Object Detection in Images

317

Milos Stojmenovic 12. 2D Shape Measures for Computer Vision

347

ˇ c Paul L. Rosin and Joviˇsa Zuni´ 13. Cryptographic Algorithms

373

Bimal Roy and Amiya Nayak 14. Secure Communication in Distributed Sensor Networks (DSN)

407

Subhamoy Maitra and Bimal Roy 15. Localized Topology Control Algorithms for Ad Hoc and Sensor Networks

439

Hannes Frey and David Simplot-Ryl 16. A Novel Admission Control for Multimedia LEO Satellite Networks

465

Syed R. Rizvi, Stephan Olariu, and Mona E. Rizvi 17. Resilient Recursive Routing in Communication Networks

485

Costas C. Constantinou, Alexander S. Stepanenko, Theodoros N. Arvanitis, Kevin J. Baughan, and Bin Liu 18. Routing Algorithms on WDM Optical Networks

509

Qian-Ping Gu Index

535

PREFACE

Although vast activity exists, especially recent, the editors did not ﬁnd any book that treats applied algorithms in a comprehensive manner. The editors discovered a number of graduate courses in computer science programs with titles such as “Design and Analysis of Algorithms, “Combinatorial Algorithms” “Evolutionary Algorithms” and “Discrete Mathematics.” However, when glancing through the course contents, it appears that they were detached from the real-world applications. On the contrary, recently some graduate courses such as “Algorithms in Bioinformatics” emerged, which treat one speciﬁc application area for algorithms. Other graduate courses heavily use algorithms but do not mention them anywhere explicitly. Examples are courses on computer vision, wireless networks, sensor networks, data mining, swarm intelligence, and so on. Generally, it is recognized that software veriﬁcation is a necessary step in the design of large commercial software packages. However, solving the problem itself in an optimal manner precedes software veriﬁcation. Was the problem solution (algorithm) veriﬁed? One can verify software based on good and bad solutions. Why not start with the design of efﬁcient solutions in terms of their time complexities, storage, and even simplicity? One needs a strong background in design and analysis of algorithms to come up with good solutions. This book is designed to bridge the gap between algorithmic theory and its applications. It should be the basis for a graduate course that will contain both basic algorithmic, combinatorial and graph theoretical subjects, and their applications in other disciplines and in practice. This direction will attract more graduate students into such courses. The students themselves are currently divided. Those with weak math backgrounds currently avoid graduate courses with a theoretical orientation, and vice versa. It is expected that this book will provide a much-needed textbook for graduate courses in algorithms with an orientation toward their applications. This book will also make an attempt to bring together researchers in design and analysis of algorithms and researchers that are solving practical problems. These communities are currently mostly isolated. Practitioners, or even theoretical researchers from other disciplines, normally believe that they can solve problems themselves with some brute force techniques. Those that do enter into different areas looking for “applications” normally end up with theoretical assumptions, suitable for proving theorems and designing new algorithms, not having much relevance for the claimed application area. On the contrary, the algorithmic community is mostly engaged in their own problems and remains detached from reality and applications. They can rarely answer simple questions about the applications of their research. This is valid vii

viii

PREFACE

even for the experimental algorithms community. This book should attract both sides and encourage collaboration. The collaboration should lead toward modeling problems with sufﬁcient realism for design of practical solutions, also allowing a sufﬁcient level of tractability. The book is intended for researchers and graduate students in computer science and researchers from other disciplines looking for help from the algorithmic community. The book is directed to both people in the area of algorithms, who are interested in some applied and complementary aspects of their activity, and people that want to approach and get a general view of this area. Applied algorithms are gaining popularity, and a textbook is needed as a reference source for the use by students and researchers. This book is an appropriate and timely forum, where researchers from academics (both with and without a strong background in algorithms) and emerging industry in new application areas for algorithms (e.g., sensor networks and bioinformatics) learn more about the current trends and become aware of the possible new applications of existing and new algorithms. It is often not the matter of designing new algorithms, but simply the recognition that certain problems have been already solved efﬁciently. What is needed is a starting reference point for such resources, which this book could provide. Handbook is based on a number of stand-alone chapters that together cover the subject matter in a comprehensive manner. The book seeks to provide an opportunity for researchers, graduate students, and practitioners to explore the application of algorithms and discrete mathematics for solving scientiﬁc, engineering, and practical problems. The main direction of the book is to review various applied algorithms and their currently “hot” application areas such as computational biology, computational chemistry, wireless networks, and computer vision. It also covers data mining, evolutionary algorithms, game theory, and basic combinatorial algorithms and their applications. Contributions are made by researchers from United States, Canada, United Kingdom, Italy, Greece, Cyprus, France, Denmark, Spain, and India. Recently, a number of application areas for algorithms have been emerging into their own disciplines and communities. Examples are computational biology, computational chemistry, computational physics, sensor networks, computer vision, and others. Sensor networks and computational biology are currently among the top research priorities in the world. These ﬁelds have their own annual conferences and books published. The algorithmic community also has its own set of annual meetings, and journals devoted to algorithms. Apparently, it is hard to ﬁnd a mixture of the two communities. There are no conferences, journals, or even books with mixed content, providing forum for establishing collaboration and providing directions.

BRIEF OUTLINE CONTENT This handbook consists of 18 self-contained chapters. Their content will be described brieﬂy here.

PREFACE

ix

Many practical problems require an exhaustive search through the solution space, which are represented as combinatorial structures such as permutations, combinations, set partitions, integer partitions, and trees. All combinatorial objects of a certain kind need to be generated to test all possible solutions. In some other problems, a randomly generated object is needed, or an object with an approximately correct ranking among all objects, without using large integers. Chapter 1 describes fast algorithms for generating all objects, random object, or object with approximate ranking, for basic types of combinatorial objects. Chapter 2 presents applications of combinatorial algorithms and graph theory to problems in chemistry. Most of the techniques used are quite general, applicable to other problems from various ﬁelds. The problem of cell growth is one of the classical problems in combinatorics. Cells are of the same shape and are in the same plane, without any overlap. The central problem in this chapter is the study of hexagonal systems, which represent polyhexes or benzenoid hydrocarbons in chemistry. An important issue for enumeration and exhaustive generation is the notion of isomorphic or equivalent objects. Usually, we are interested in enumerating or generating only one copy of equivalent objects, that is, only one representative from each isomorphism class. Polygonal systems are considered different if they have different shapes; their orientation and location in the plane are not important. The main theme in this chapter is isomorph-free exhaustive generation of polygonal systems, especially polyhexes. In general, the main algorithmic framework employed for exhaustive generation is backtracking, and several techniques have been developed for handling isomorphism issues within this framework. This chapter presents several of these techniques and their application to exhaustive generation of hexagonal systems. Chapter 3 describes some graph-theoretic models in chemistry and molecular biology. RNA, proteins, and other structures are described as graphs. The chapter deﬁnes and illustrates a number of important molecular descriptors and related concepts. Algorithms for predicting biological activity of given molecule and its structure are discussed. The ability to predict a molecule’s biological activity by computational means has become more important as an ever-increasing amount of biological information is being made available by new technologies. Annotated protein and nucleic databases and vast amounts of chemical data from automated chemical synthesis and high throughput screening require increasingly more sophisticated efforts. Finally, this chapter describes popular machine learning techniques such as neural networks and support vector machines. A major paradigm shift in molecular biology occurred recently with the introduction of gene-expression microarrays that measure the expression levels of thousands of genes at once. These comprehensive snapshots of gene activity can be used to investigate metabolic pathways, identify drug targets, and improve disease diagnosis. However, the sheer amount of data obtained using the high throughput microarray experiments and the complexity of the existing relevant biological knowledge is beyond the scope of manual analysis. Chapter 4 discusses the bioinformatics algorithms that help analyze such data and are a very valuable tool for biomedical science. Activities of contemporary society generate enormous amounts of data that are used in decision-support processes. Many databases have current volumes in the

x

PREFACE

hundreds of terabytes. The difﬁculty of analyzing this kind of data volumes by human operators is clearly insurmountable. This lead to a rather new area of computer science, data mining, whose aim is to develop automatic means of data analysis for discovering new and useful patterns embedded in data. Data mining builds on several disciplines: statistics, artiﬁcial intelligence, databases, visualization techniques, and others and has crystallized as a distinct discipline in the last decade of the past century. The range of subjects in data mining is very broad. Among the main directions of this branch of computer science, one should mention identiﬁcation of associations between data items, clustering, classiﬁcation, summarization, outlier detection, and so on. Chapters 6 and 7 concentrate on two classes of data mining algorithms: clustering algorithms and identiﬁcation of association rules. Data stream processing has recently gained increasing popularity as an effective paradigm for processing massive data sets. A wide range of applications in computational sciences generate huge and rapidly changing data streams that need to be continuously monitored in order to support exploratory analyses and to detect correlations, rare events, fraud, intrusion, unusual, or anomalous activities. Relevant examples include monitoring network trafﬁc, online auctions, transaction logs, telephone call records, automated bank machine operations, and atmospheric and astronomical events. Due to the high sequential access rates of modern disks, streaming algorithms can also be effectively deployed for processing massive ﬁles on secondary storage, providing new insights into the solution of several computational problems in external memory. Streaming models constrain algorithms to access the input data in one or few sequential passes, using only a small amount of working memory and processing each input item quickly. Solving computational problems under these restrictions poses several algorithmic challenges. Chapter 8 is intended as an overview and survey of the main models and techniques for processing data streams and of their applications. Frequency assignment is a well-known problem in operations research for which different mathematical models exist depending on the application-speciﬁc conditions. However, most of these models are far from considering actual technologies currently deployed in GSM networks, such as frequency hopping. In these networks, interferences provoked by channel reuse due to the limited available radio spectrum result in a major impact of the quality of service (QoS) for subscribers. In Chapter 9, the authors focus on optimizing the frequency planning of a realistic-sized, real-world GSM network by using evolutionary algorithms. Methods from game theory and mechanism design have been proven to be a powerful mathematical tool in order to understand, control and efﬁciently design dynamic, complex networks, such as the Internet. Game theory provides a good starting point for computer scientists in order to understand selﬁsh rational behavior of complex networks with many agents. Such a scenario is readily modeled using game theory techniques, in which players with potentially different goals participate under a common setting with well-prescribed interactions. Nash equilibrium stands out as the predominant concept of rationality in noncooperative settings. Thus, game theory and its notions of equilibria provide a rich framework for modeling the behavior of

PREFACE

xi

selﬁsh agents in these kinds of distributed and networked environments and offering mechanisms to achieve efﬁcient and desirable global outcomes in spite of the selﬁsh behavior. In Chapter 10, we review some of the most important algorithmic solutions and advances achieved through game theory. Real-time face detection in images received growing attention recently. Recognition of other objects, such as cars, is also important. Applications are in similar and content-based real-time image retrieval. The task is currently achieved by designing and applying automatic or semisupervised machine learning algorithms. Chapter 11 will review some algorithmic solutions to these problems. Existing real-time object detection systems appear to be based primarily on the AdaBoost framework, and this chapter will concentrate on it. Emphasis is given on approaches that build fast and reliable object recognizers in images based on small training sets. This is important in cases where the training set needs to be built manually, as in the case of detecting back of cars, studied as a particular example. Existing computer vision applications that demonstrated their validity are mostly based on shape analysis. A number of shapes, such as linear or elliptic ones, are well studied. More complex classiﬁcation and recognition tasks require new shape descriptors. Chapter 12 reviews some algorithmic tools for measuring and detecting shapes. Since shape descriptors are expected to be applied not only to a single object but also to a multiobject or dynamic scene, time complexity of the proposed algorithms is an issue, in addition to accuracy. Cryptographic algorithms are extremely important for secure communication over an insecure channel and have gained signiﬁcant importance in modern day technology. Chapter 13 introduces the basic concepts of cryptography, and then presents general principles, algorithms, and designs for block and stream ciphers, public key cryptography, and key agreement. The algorithms largely use mathematical tools from algebra, number theory, and algebraic geometry and have been explained as and when required. Chapter 14 studies the issues related to secure communication among sensor nodes. The sensor nodes are usually of limited computational ability having low CPU power, small amount of memory, and constrained power availability. Thus, the standard cryptographic algorithms suitable for state of the art computers may not be efﬁciently implemented in sensor nodes. This chapter describes strategies that can work in constrained environment. It ﬁrst presents basic introduction to the security issues in distributed wireless sensor networks. As implementation of public key infrastructure may not be recommendable in low end hardware platforms, chapter describes key predistribution issues in detail. Further it investigates some speciﬁc stream ciphers for encrypted communication that are suitable for implementation in low end hardware. In Chapter 15, the authors consider localized algorithms, as opposed to centralized algorithms, which can be used in topology control for wireless ad hoc or sensor networks. The aim of topology control can be to minimize energy consumption, or to reduce interferences by organizing/structuring the network. This chapter focuses on neighbor elimination schemes, which remove edges from the initial connection graph in order to generate energy efﬁcient, sparse, planar but still connected network in localized manner.

xii

PREFACE

Low Earth Orbit (LEO) satellite networks are deployed as an enhancement to terrestrial wireless networks in order to provide broadband services to users regardless of their location. LEO satellites are expected to support multimedia trafﬁc and to provide their users with some form of QoS guarantees. However, the limited bandwidth of the satellite channel, satellite rotation around the Earth, and mobility of end users makes QoS provisioning and mobility management a challenging task. One important mobility problem is the intrasatellite handoff management. Chapter 16 proposes RADAR—reﬁned admission detecting absence region, a novel call admission control and handoff management scheme for LEO satellite networks. A key ingredient in the scheme is a companion predictive bandwidth allocation strategy that exploits the topology of the network and contributes to maintaining high bandwidth utilization. After a brief review of conventional approaches to shortest path routing, Chapter 17 introduces an alternative algorithm that abstracts a network graph into a logical tree. The algorithm is based on the decomposition of a graph into its minimum cycle basis (a basis of the cycle vector space of a graph having least overall weight or length). A procedure that abstracts the cycles and their adjacencies into logical nodes and links correspondingly is introduced. These logical nodes and links form the next level logical graph. The procedure is repeated recursively, until a loop-free logical graph is derived. This iterative abstraction is called a logical network abstraction procedure and can be used to analyze network graphs for resiliency, as well as become the basis of a new routing methodology. Both these aspects of the logical network abstraction procedure are discussed in some detail. With the tremendous growth of bandwidth-intensive networking applications, the demand for bandwidth over data networks is increasing rapidly. Wavelength division multiplexing (WDM) optical networks provide promising infrastructures to meet the information networking demands and have been widely used as the backbone networks in the Internet, metropolitan area networks, and high capacity local area networks. Efﬁcient routing on WDM networks is challenging and involves hard optimization problems. Chapter 18 introduces efﬁcient algorithms with guaranteed performance for fundamental routing problems on WDM networks.

ACKNOWLEDGMENTS The editors are grateful to all the authors for their contribution to the quality of this handbook. The assistance of reviewers for all chapters is also greatly appreciated. The University of Ottawa (with the help of NSERC) provided an ideal working environment for the preparation of this handbook. This includes computer facilities for efﬁcient Internet search, communication by electronic mail, and writing our own contributions. The editors are thankful to Paul Petralia and Whitney A. Lesch from Wiley for their timely and professional cooperation, and for their decisive support of this project. We thank Milos Stojmenovic for proposing and designing cover page for this book.

PREFACE

xiii

Finally, we thank our families for their encouragement, making this effort worthwhile, and for their patience during the numerous hours at home that we spent in front of the computer. We hope that the readers will ﬁnd this handbook informative and worth reading. Comments received by readers will be greatly appreciated. Amiya Nayak SITE, University of Ottawa, Ottawa, Ontario, Canada Ivan Stojmenovi´c EECE, University of Birmingham, UK November 2007

ABSTRACTS

1 GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT Many practical problems require an exhaustive search through the solution space, which are represented as combinatorial structures, such as, permutations, combinations, set partitions, integer partitions, and trees. All combinatorial objects of a certain kind need to be generated to test all possible solutions. In some other problems, a randomly generated object is needed, or an object with an approximately correct ranking among all objects, without using large integers. Fast algorithms for generating all objects, random object, or object with approximate ranking for basic types of combinatorial objects are described. 2 BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES General combinatorial algorithms and their application to enumerating molecules in chemistry are presented and classical and new algorithms for the generation of complete lists of combinatorial objects that contain only inequivalent objects (isomorphfree exhaustive generation) are discussed. We introduce polygonal systems, and how polyhexes and hexagonal systems relate to benzenoid hydrocarbons. The central theme is the exhaustive generation of nonequivalent hexagonal systems, which is used to walk the reader through several algorithmic techniques of general applicability. The main algorithmic framework is backtracking, which is coupled with sophisticated methods for dealing with isomorphism or symmetries. Triangular and square systems, as well as the problem of matchings in hexagonal systems and their relationship to Kékule structures in chemistry are also presented. 3 GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY The ﬁeld of chemical graph theory utilizes simple graphs as models of molecules. These models are called molecular graphs, and quantiﬁers of molecular graphs are xv

xvi

ABSTRACTS

known as molecular descriptors or topological indices. Today’s chemists use molecular descriptors to develop algorithms for computer aided drug designs, and computer based searching algorithms of chemical databases and the ﬁeld is now more commonly known as combinatorial or computational chemistry. With the completion of the human genome project, related ﬁelds are emerging such as chemical genomics and pharmacogenomics. Recent advances in molecular biology are driving new methodologies and reshaping existing techniques, which in turn produce novel approaches to nucleic acid modeling and protein structure prediction. The origins of chemical graph theory are revisited and new directions in combinatorial chemistry with a special emphasis on biochemistry are explored. Of particular importance is the extension of the set of molecular descriptors to include graphical invariants. We also describe the use of artiﬁcial neural networks (ANNs) in predicting biological functional relationships based on molecular descriptor values. Speciﬁcally, a brief discussion of the fundamentals of ANNs together with an example of a graph theoretic model of RNA to illustrate the potential for ANN coupled with graphical invariants to predict function and structure of biomolecules is included.

4 ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA The traditional approach to molecular biology consists of studying a small number of genes or proteins that are related to a single biochemical process or pathway. A major paradigm shift recently occurred with the introduction of gene-expression microarrays that measure the expression levels of thousands of genes at once. These comprehensive snapshots of gene activity can be used to investigate metabolic pathways, identify drug targets, and improve disease diagnosis. However, the sheer amount of data obtained using high throughput microarray experiments and the complexity of the existing relevant biological knowledge is beyond the scope of manual analysis. Thus, the bioinformatics algorithms that help analyze such data are a very valuable tool for biomedical science. First, a brief overview of the microarray technology and concepts that are important for understanding the remaining sections are described. Second, microarray data preprocessing, an important topic that has drawn as much attention from the research community as the data analysis itself is discussed. Finally, some of the more important methods for microarray data analysis are described and illustrated with examples and case studies.

5 ALGORITHMS OF REACTION–DIFFUSION COMPUTING A case study introduction to the novel paradigm of wave-based computing in chemical systems is presented in Chapter 5. Selected problems and tasks of computational geometry, robotics and logics can be solved by encoding data in conﬁguration

ABSTRACTS

xvii

of chemical medium’s disturbances and programming wave dynamics and interaction.

6 DATA MINING ALGORITHMS I: CLUSTERING Clustering is the process of grouping together objects that are similar. The similarity between objects is evaluated by using a several types of dissimilarities (particularly, metrics and ultrametrics). After discussing partitions and dissimilarities, two basic mathematical concepts important for clustering, we focus on ultrametric spaces that play a vital role in hierarchical clustering. Several types of agglomerative hierarchical clustering are examined with special attention to the single-link and complete link clusterings. Among the nonhierarchical algorithms we present the k-means and the PAM algorithm. The well-known impossibility theorem of Kleinberg is included in order to illustrate the limitations of clustering algorithms. Finally, modalities of evaluating clustering quality are examined.

7 DATA MINING ALGORITHMS II: FREQUENT ITEM SETS The identiﬁcation of frequent item sets and of association rules have received a lot of attention in data mining due to their many applications in marketing, advertising, inventory control, and many other areas. First the notion of frequent item set is introduced and we study in detail the most popular algorithm for item set identiﬁcation: the Apriori algorithm. Next we present the role of frequent item sets in the identiﬁcation of association rules and examine the levelwise algorithms, an important generalization of the Apriori algorithm.

8 ALGORITHMS FOR DATA STREAMS Data stream processing has recently gained increasing popularity as an effective paradigm for processing massive data sets. A wide range of applications in computational sciences generate huge and rapidly changing data streams that need to be continuously monitored in order to support exploratory analyses and to detect correlations, rare events, fraud, intrusion, and unusual or anomalous activities. Relevant examples include monitoring network trafﬁc, online auctions, transaction logs, telephone call records, automated bank machine operations, and atmospheric and astronomical events. Due to the high sequential access rates of modern disks, streaming algorithms can also be effectively deployed for processing massive ﬁles on secondary storage, providing new insights into the solution of several computational problems in external memory. Streaming models constrain algorithms to access the input data in one or few sequential passes, using only a small amount of working memory and processing each input item quickly. Solving computational problems under these restrictions poses several algorithmic challenges.

xviii

ABSTRACTS

9 APPLYING EVOLUTIONARY ALGORITHMS TO SOLVE THE AUTOMATIC FREQUENCY PLANNING PROBLEM Frequency assignment is a well-known problem in operations research for which different mathematical models exist depending on the application-speciﬁc conditions. However, most of these models are far from considering actual technologies currently deployed in GSM networks, such as frequency hopping. In these networks, interferences provoked by channel reuse due to the limited available radio spectrum result in a major impact of the quality of service (QoS) for subscribers. Therefore, frequency planning is of great importance for GSM operators. We here focus on optimizing the frequency planning of a realistic-sized, real-world GSM network by using evolutionary algorithms (EAs). Results show that a (1+10) EA developed by the chapter authors for which different seeding methods and perturbation operators have been analyzed is able to compute accurate and efﬁcient frequency plans for real-world instances.

10 ALGORITHMIC GAME THEORY AND APPLICATIONS Methods from game theory and mechanism design have been proven to be a powerful mathematical tool in order to understand, control, and efﬁciently design dynamic, complex networks, such as the Internet. Game theory provides a good starting point for computer scientists to understand selﬁsh rational behavior of complex networks with many agents. Such a scenario is readily modeled using game theory techniques, in which players with potentially different goals participate under a common setting with well prescribed interactions. The Nash equilibrium stands out as the predominant concept of rationality in noncooperative settings. Thus, game theory and its notions of equilibria provide a rich framework for modeling the behavior of selﬁsh agents in these kinds of distributed and networked environments and offering mechanisms to achieve efﬁcient and desirable global outcomes despite selﬁsh behavior. The most important algorithmic solutions and advances achieved through game theory are reviewed.

11 ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES Real time face detection images has received growing attention recently. Recognition of other objects, such as cars, is also important. Applications are similar and content based real time image retrieval. Real time object detection in images is currently achieved by designing and applying automatic or semi-supervised machine learning algorithms. Some algorithmic solutions to these problems are reviewed. Existing real time object detection systems are based primarily on the AdaBoost framework, and the chapter will concentrate on it. Emphasis is given to approaches that build fast and reliable object recognizers in images based on small training sets. This is important

ABSTRACTS

xix

in cases where the training set needs to be built manually, as in the case of detecting the back of cars, studied here as a particular example. 12 2D SHAPE MEASURES FOR COMPUTER VISION Shape is a critical element of computer vision systems, and can be used in many ways and for many applications. Examples include classiﬁcation, partitioning, grouping, registration, data mining, and content based image retrieval. A variety of schemes that compute global shape measures, which can be categorized as techniques based on minimum bounding rectangles, other bounding primitives, ﬁtted shape models, geometric moments, and Fourier descriptors are described. 13 CYPTOGRAPHIC ALGORITHMS Cryptographic algorithms are extremely important for secure communication over an insecure channel and have gained signiﬁcant importance in modern day technology. First the basic concepts of cryptography are introduced. Then general principles, algorithms and designs for block ciphers, stream ciphers, public key cryptography, and protocol for key-agreement are presented in details. The algorithms largely use mathematical tools from algebra, number theory, and algebraic geometry and have been explained as and when required. 14 SECURE COMMUNICATION IN DISTRIBUTED SENSOR NETWORKS (DSN) The motivation of this chapter is to study the issues related to secure communication among sensor nodes. Sensor nodes are usually of limited computational ability having low CPU power, a small amount of memory, and constrained power availability. Thus the standard cryptographic algorithms suitable for state of the art computers may not be efﬁciently implemented in sensor nodes. In this regard we study the strategies that can work in constrained environments. First we present a basic introduction to the security issues in distributed wireless sensor networks. As implementation of public key infrastructure may not be recommendable in low end hardware platforms, we describe key predistribution issues in detail. Further we study some speciﬁc stream ciphers for encrypted communication that are suitable for implementation in low end hardware. 15 LOCALIZED TOPOLOGY CONTROL ALGORITHMS FOR AD HOC AND SENSOR NETWORKS Localized algorithms, in opposition to centralized algorithms, which can be used in topology control for wireless ad hoc or sensor networks are considered. The aim of topology control is to minimize energy consumption, or to reduce interferences by

xx

ABSTRACTS

organizing/structuring the network. Neighbor elimination schemes, which consist of removing edges from the initial connection graph are focused on.

16 A NOVEL ADMISSION FOR CONTROL OF MULTIMEDIA LEO SATELLITE NETWORKS Low Earth Orbit (LEO) satellite networks are deployed as an enhancement to terrestrial wireless networks in order to provide broadband services to users regardless of their location. In addition to global coverage, these satellite systems support communications with hand-held devices and offer low cost-per-minute access cost, making them promising platforms for personal communication services (PCS). LEO satellites are expected to support multimedia trafﬁc and to provide their users with some form of quality of service (QoS) guarantees. However, the limited bandwidth of the satellite channel, satellite rotation around the Earth and mobility of end-users makes QoS provisioning and mobility management a challenging task. One important mobility problem is the intra-satellite handoff management. While global positioning systems (GPS)-enabled devices will become ubiquitous in the future and can help solve a major portion of the problem, at present the use of GPS for low-cost cellular networks is unsuitable. RADAR—reﬁned admission detecting absence region— a novel call admission control and handoff management scheme for LEO satellite networks is proposed in this chapter. A key ingredient in this scheme is a companion predictive bandwidth allocation strategy that exploits the topology of the network and contributes to maintaining high bandwidth utilization. Our bandwidth allocation scheme is speciﬁcally tailored to meet the QoS needs of multimedia connections. The performance of RADAR is compared to that of three recent schemes proposed in the literature. Simulation results show that our scheme offers low call dropping probability, providing for reliable handoff of on-going calls, and good call blocking probability for new call requests, while ensuring high bandwidth utilization.

17 RESILIENT RECURSIVE ROUTING IN COMMUNICATION NETWORKS After a brief review of conventional approaches to shortest path routing an alternative algorithm that abstracts a network graph into a logical tree is introduced. The algorithm is based on the decomposition of a graph into its minimum cycle basis (a basis of the cycle vector space of a graph having least overall weight or length). A procedure that abstracts the cycles and their adjacencies into logical nodes and links correspondingly is introduced. These logical nodes and links form the next level logical graph. The procedure is repeated recursively, until a loop-free logical graph is derived. This iterative abstraction is called a logical network abstraction procedure and can be used to analyze network graphs for resiliency, as well as become the basis of a new routing methodology. Both these aspects of the logical network abstraction procedure are discussed in some detail.

ABSTRACTS

xxi

18 ROUTING ALGORITHMS ON WDM OPTICAL NETWORKS With the tremendous growth of bandwidth-intensive networking applications, the demand for bandwidth over data networks is increasing rapidly. Wavelength division multiplexing (WDM) optical networks provide promising infrastructures to meet the information networking demands and have been widely used as the backbone networks in the Internet, metropolitan area networks, and high-capacity local area networks. Efﬁcient routing on WDM networks is challenging and involves hard optimization problems. This chapter introduces efﬁcient algorithms with guaranteed performance for fundamental routing problems on WDM networks.

CONTRIBUTORS

Editors Amiya Nayak, received his B.Math. degree in Computer Science and Combinatorics and Optimization from University of Waterloo in 1981, and Ph.D. in Systems and Computer Engineering from Carleton University in 1991. He has over 17 years of industrial experience, working at CMC Electronics (formerly known as Canadian Marconi Company), Defence Research Establishment Ottawa (DREO), EER Systems and Nortel Networks, in software engineering, avionics, and navigation systems, simulation and system level performance analysis. He has been an Adjunct Research Professor in the School of Computer Science at Carleton University since 1994. He had been the Book Review and Canadian Editor of VLSI Design from 1996 till 2002. He is in the Editorial Board of International Journal of Parallel, Emergent and Distributed Systems, and the Associate Editor of International Journal of Computing and Information Science. Currently, he is a Full Professor at the School of Information Technology and Engineering (SITE) at the University of Ottawa. His research interests are in the area of fault tolerance, distributed systems/algorithms, and mobile ad hoc networks with over 100 publications in refereed journals and conference proceedings. Ivan Stojmenovic, received his Ph.D. degree in mathematics in 1985. He earned a third degree prize at the International Mathematics Olympiad for high school students in 1976. He held positions in Serbia, Japan, United States, Canada, France, and Mexico. He is currently a Chair Professor in Applied Computing at EECE, the University of Birmingham, UK. He published over 200 different papers, and edited three books on wireless, ad hoc, and sensor networks with Wiley/IEEE. He is currently editor of over ten journals, and founder and editor-in-chief of three journals. Stojmenovic was cited >3400 times and is in the top 0.56% most cited authors in Computer Science (Citeseer 2006). One of his articles was recognized as the Fast Breaking Paper, for October 2003 (as the only one for all of computer science), by Thomson ISI Essential Science Indicators. He coauthored over 30 book chapters, mostly very recent. He collaborated with over 100 coauthors with Ph.D. and a number of their graduate students from 22 different countries. He (co)supervised over 40 Ph.D. and master theses, and published over 120 joint articles with supervised students. His current research interests are mainly in wireless ad hoc, sensor, and cellular networks. His research interests also include parallel computing, multiplevalued logic, evolutionary computing, neural networks, combinatorial algorithms, computational geometry, graph theory, computational chemistry, image processing, xxiii

xxiv

CONTRIBUTORS

programming languages, and computer science education. More details can be seen at www.site.uottawa.ca/∼ivan.

Authors Andrew Adamatzky, Faculty of Computing, Engineering and Mathematical Science University of the West of England, Bristol, BS16 1QY, UK [[email protected]] Enrique Alba, Dpto. de Lenguajes y Ciencias de la Computaci´on, E.T.S. Ing. Inform´atica, Campus de Teatinos, 29071 M´alaga, Spain [[email protected] www.lcc.uma.es/∼eat.] Theodoros N. Arvanitis, Electronics, Electrical, and Computer Engineering, University of Birmingham, Edgbaston, Birmingham B15 2TT, UK [[email protected]] Kevin J. Baughan, Electronics, Electrical, and Computer Engineering, University of Birmingham, Edgbaston, Birmingham B15 2TT, UK Costas C. Constantinou, Electronics, Electrical, and Computer Engineering, University of Birmingham, and Prolego Technologies Ltd., Edgbaston, Birmingham B15 2TT, UK [[email protected]] Camil Demetrescu, Department of Computer and Systems Science, University of Rome “La Sapienza”, Via Salaria 113, 00198 Rome, Italy [demetres @dis.uniroma1.it] Irene Finocchi, Department of Computer and Systems Science, University of Rome “La Sapienza”, Via Salaria 113, 00198 Rome, Italy Hannes Frey, Department of Mathematics and Computer Science, University of Southern Denmark, Campusvej 55, DK-5230 Odense M, Denmark [[email protected]] Qianping Gu, Department of Computing Science, Simon Fraser University, Burnaby, BC V5A 1S6, Canada [[email protected]] Debra Knisley, Department of Mathematics, East Tennessee State University, Johnson City, TN 37614-0663, USA [[email protected]] Jeff Knisley, Department of Mathematics, East Tennessee State University, Johnson City, TN 37614-0663, USA [[email protected]] Bin Liu, Electronics, Electrical, and Computer Engineering, University of Birmingham, Edgbaston, Birmingham B15 2TT, UK Francisco Luna, Universidad de M´alaga, ETS. Ing. Inform´atica, Campus de Teatinos, 29071 M´alaga, Spain [ﬂ[email protected]]

CONTRIBUTORS

xxv

Subhamoy Maitra, Applied Statistical Unit, Indian Statistical Institute, 203 B.T. Road, Koltkata, India [[email protected]] Patrick Mauroy, Universidad de M´alaga, ETS. Ing. Inform´atica, Campus de Teatinos, 29071 M´alaga, Spain [[email protected]] Marios Mavronicolas, Department of Computer Science, University of Cyprus, Nicosia CY-1678, Cyprus [[email protected]] Uros Midic, Center for Information Science and Technology, Temple University, 300 Wachman Hall, 1805 N. Broad St., Philadelphia, PA 19122, USA Lucia Moura, School of Information Technology and Engineering, University of Ottawa, Ottawa, ON K1N 6N5, Canada [[email protected]] Amiya Nayak, SITE, University of Ottawa, 800 King Edward Ave., Ottawa, ON K1N 6N5, Canada [[email protected]] Antonio J. Nebro, Universidad de M´alaga, ETS. Ing. Inform´atica, Campus de Teatinos, 29071 M´alaga, Spain [[email protected]] Zoran Obradovic, Center for Information Science and Technology, Temple University, 300 Wachman Hall, 1805 N. Broad St., Philadelphia, PA 19122, USA [[email protected]] Stephan Olariu, Department of Computer Science, Old Dominion University, Norfolk, Virginia, 23529, USA [[email protected]] Vicky Papadopoulou, Department of Computer Science, University of Cyprus, Nicosia CY-1678, Cyprus [[email protected]] Salvador Pedraza, Universidad de M´alaga, ETS. Ing. Inform´atica, Campus de Teatinos, 29071 M´alaga, Spain [[email protected]] Mona E. Rizvi, Department of Computer Science, Norfolk State University, 700 Park Avenue, Norfolk, VA 23504, USA [[email protected]] Syed R. Rizvi, Department of Computer Science, Old Dominion University, Norfolk, VA 23529, USA Paul L. Rosin, School of Computer Science, Cardiff University, Cardiff CF24 3AA, Wales, UK [[email protected]] Bimal Roy, Applied Statistical Unit, Indian Statistical Institute, 203 B.T. Road, Kolkata, India [[email protected]] Dan A. Simovici, Department of Mathematics and Computer Science, University of Massachusetts at Boston, Boston, MA 02125, USA [[email protected]] David Simplot-Ryl, IRCICA/LIFL, Univ. Lille 1, CNRS UMR 8022, INRIA Futurs, POPS Research Group, Bˆat. M3, Cit´a Scientiﬁque, 59655 Villeneuve d’Ascq Cedex, France [[email protected]ﬂ.fr]

xxvi

CONTRIBUTORS

Paul Spirakis, University of Patras, School of Engineering, GR 265 00, Patras, Greece [[email protected]] Alexander S. Stepanenko, Electronics, Electrical, and Computer Engineering, University of Birmingham, Edgbaston, Birmingham B15 2TT, UK [[email protected]] Ivan Stojmenovic, SITE, University of Ottawa, Ottawa, ON K1N 6N5, Canada [[email protected]] Milos Stojmenovic, School of Information Technology and Engineering, University of Ottawa, Ottawa, ON K1N 6N5, Canada [[email protected]] Slobodan Vucetic, Center for Information Science and Technology, Temple University, 300 Wachman Hall, 1805 N. Broad St., Philadelphia, PA 19122, USA [[email protected]] Hongbo Xie, Center for Information Science and Technology, Temple University, 300 Wachman Hall, 1805 N. Broad St., Philadelphia, PA 19122, USA ˇ Joviˇsa Zuni´ c, Department of Computer Science, University of Exeter, Harrison Building North Park Road, Exeter EX4 4QF, UK [[email protected]]

CHAPTER 1

Generating All and Random Instances of a Combinatorial Object IVAN STOJMENOVIC

1.1 LISTING ALL INSTANCES OF A COMBINATORIAL OBJECT The design of algorithms to generate combinatorial objects has long fascinated mathematicians and computer scientists. Some of the earliest papers on the interplay between mathematics and computer science are devoted to combinatorial algorithms. Because of its many applications in science and engineering, the subject continues to receive much attention. In general, a list of all combinatorial objects of a given type might be used to search for a counterexample to some conjecture, or to test and analyze an algorithm for its correctness or computational complexity. This branch of computer science can be deﬁned as follows: Given a combinatorial object, design an efﬁcient algorithm for generating all instances of that object. For example, an algorithm may be sought to generate all n-permutations. Other combinatorial objects include combinations, derangements, partitions, variations, trees, and so on. When analyzing the efﬁciency of an algorithm, we distinguish between the cost of generating and cost of listing all instances of a combinatorial object. By generating we mean producing all instances of a combinatorial object, without actually outputting them. Some properties of objects can be tested dynamically, without the need to check each element of a new instance. In case of listing, the output of each object is required. The lower bound for producing all instances of a combinatorial object depends on whether generating or listing is required. In the case of generating, the time required to “create” the instances of an object, without actually producing the elements of each instance as output, is counted. Thus, for example, an optimal sequential algorithm in this sense would generate all n-permutations in θ(n!) time, that is, time linear in the number of instances. In the case of listing, the time to actually “output” each instance in full is counted. For instance, an optimal sequential algorithm generates all n-permutations in θ(nn!) time, since it takes θ(n) time to produce a string.

Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

1

2

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

Let P be the number of all instances of a combinatorial object, and N be the average size of an instance. The delay when generating these instances is the time needed to produce the next instance from the current one. We list some desirable properties of generating or listing all instances of a combinatorial object. Property 1. The algorithm lists all instances in asymptotically optimal time, that is, in time O(NP). Property 2. The algorithm generates all instances with constant average delay. In other words, the algorithm takes O(P) time to generate all instances. We say that a generating algorithm has constant average delay if the time to generate all instances is O(P); that is, the ratio T/P of the time T needed to generate all instances and the number of generated instances P is bounded by a constant. Property 3. The algorithm generates all instances with constant (worst case) delay. That is, the time to generate the next instance from the current one is bounded by a constant. Constant delay algorithms are also called loopless algorithms, as the code for updating given instance contains no (repeat, while, or for) loops. Obviously, an algorithm satisfying Property 3 also satisﬁes Property 2. However, in some cases, an algorithm having constant delay property is considerably more sophisticated than the one satisfying merely constant average delay property. Moreover, sometimes an algorithm having constant delay property may need more time to generate all instances of the same object than an algorithm having only constant average delay property. Therefore, it makes sense to consider Property 3 independently of Property 2. Property 4. The algorithm does not use large integers in generating all instances of an object. In some papers, the time needed to “deal” with large integers is not properly counted in. Property 5. The algorithm is the fastest known algorithm for generating all instances of given combinatorial object. Several papers deal with comparing actual (not asymptotic) times needed to generate all instances of given combinatorial object, in order to pronounce a “winner,” that is, to extract the one that needs the least time. Here, the fastest algorithm may depend on the choice of computer. Some computers support fast recursion giving the recursive algorithm advantage over iterative one. Therefore, the ratio of the time needed for particular instructions over other instructions may affect the choice of the fastest algorithm. We introduce the lexicographic order among sequences. Let a = a1 , a2 , . . . ,ap and b = b1 , b2 , . . . , bq be two sequences. Then a precedes b(a < b) in lexicographic order if and only if there exists i such that aj = bj for j

LISTING ALL INSTANCES OF A COMBINATORIAL OBJECT

3

For example, the lexicographic order of subsets of {1, 2, 3} in the set representation is Ø, {1}, {1, 2}, {1, 2, 3}, {1, 3}, {2}, {2, 3}, {3}. In binary notation, the order of subsets is somewhat different: 000, 001, 010, 011, 100, 101, 110, 111, which correspond to subsets Ø, {3}, {2}, {2, 3}, {1}, {1, 3}, {1, 2}, {1, 2, 3}, respectively. Clearly the lexicographic order of instances depends on their representation. Different notations may lead to different listing order of same instances. Algorithms can be classiﬁed into recursive or iterative, depending on whether or not they use recursion. The iterative algorithms usually have advantage of giving easy control over generating the next instance from the current one, which is often a desirable characteristic. Also some programming languages do not support recursion. In this chapter we consider only iterative algorithms, believing in their advantage over recursive ones. Almost all sequential generation algorithms rely on one of the following three ideas: 1. Unranking, which deﬁnes a bijective function from consecutive integers to instances of combinatorial objects. Most algorithms in this group do not satisfy Property 4. 2. Lexicographic updating, which ﬁnds the rightmost element of an instance that needs “updating” or moving to a new position. 3. Minimal change, which generates instances of a combinatorial object by making as little as possible changes between two consecutive objects. This method can be further speciﬁed as follows: Gray code generation, where changes made are theoretically minimal possible. Transpositions, where instances are generated by exchanging pairs of (not necessarily adjacent) elements. Adjacent interchange, where instances are generated by exchanging pairs of adjacent elements. The algorithms for generating combinatorial objects can thus be classiﬁed into those following lexicographic order and those following a minimal change order. Both orders have advantages, and the choice depends on the application. Unranking algorithms usually follow lexicographic order but they can follow minimal change one (normally with more complex ranking and unranking functions). Many problems require an exhaustive search to be solved. For example, ﬁnding all possible placements of queens on chessboard so that they do not attack each other, ﬁnding a path in a maze, choosing packages to ﬁll a knapsack with given capacity optimally, satisfy a logic formula, and so on. There exist a number of such problems for which polynomial time (or quick) solutions are not known, leaving only a kind of exhaustive search as the method to solve them.

4

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

Since the number of candidates for a solution is often exponential to input size, systematic search strategies should be used to enhance the efﬁciency of exhaustive search. One such strategy is the backtrack. Backtrack, in general, works on partial solutions to a problem. The solution is extended to a larger partial solution if there is a hope to reach a complete solution. This is called an extend phase. If an extension of the current solution is not possible, or a complete solution is reached and another one is sought, it backtracks to a shorter partial solution and tries again. This is called a reduce phase. Backtrack strategy is normally related to the lexicographic order of instances of a combinatorial object. A very general form of backtrack method is as follows: initialize; repeat if current partial solution is extendable then extend else reduce; if current solution is acceptable then report it; until search is over This form may not cover all the ways by which the strategy is applied, and, in the sequel, some modiﬁcations may appear. In all cases, the central place in the method is ﬁnding an efﬁcient test as to whether current solution is extendable. The backtrack method will be applied in this chapter to generate all subsets, combinations, and other combinatorial objects in lexicographic order. Various algorithms for generating all instances of a combinatorial object can be found in the journal Communications of ACM (between 1960 and 1975) and later in ACM Transactions of Mathematical Software and Collected Algorithms from ACM, in addition to hundreds of other journal publications. The generation of ranking and unranking combinatorial objects has been surveyed in several books [6,14,21,25,30,35,40].

1.2 LISTING SUBSETS AND INTEGER COMPOSITIONS Without loss of generality, the combinatorial objects are assumed to be taken from the set {1, 2, . . . , n}, which is also called n-set. We consider here the problem of generating subsets in their set representation. Every subset [or (n,n)-subset] is represented in the set notation by a sequence x1 , x2 , . . . , xr , 1 ≤ r ≤ n, 1 ≤ x1

5

LISTING SUBSETS AND INTEGER COMPOSITIONS

1

12

123 124

13

2

14 15 23 24

3 4 5.

25 34 35 45

125 134 135 145 234 235 245

1234 1235 1245

12345

1345

2345

345

The algorithm is in extend phase when it goes from left to right staying in the same row. If the last element of a subset is n, the algorithm shifts to the next row. We call this the reduce phase. read( n); r ← 0; xr ← 0; repeat if xr

6

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

(3,5)-subsets. This illustrates the backtrack process applied on all subsets to extract (m,n)-subsets. We now present the algorithm for generating variations. A (m,n)-variation out of {p1 , p2 , . . . , pn } can be represented as a sequence c1 c2 . . . cm , where p1 ≤ ci ≤ pn . Let z1 z2 . . . zm be the corresponding array of indices, that is, ci = pzi , 1 ≤ i ≤ m. The next variation can be determined by a backtrack search that ﬁnds an element ct with the greatest possible index t such that zt

1 nm−1

=

1 nm+1 − 1 = O(1). nm n − 1

Subsets may be also represented in binary notation, where each “1” corresponds to the element from the subset. For example, subset {1,3,4} for n = 5 is represented as 11010. Thus, subsets correspond to integers written in the binary number system (i.e., counters) and to bitstrings, giving all possible information contents in a computer memory. A simple recursive algorithm for generating bitstrings is given in the work by Parberry [28]. A call to bitstring (n) produces all bitstrings of length n as follows: procedure bitstring( m); if m = 0 then print out ci ; else cm ← 0; bitstring(m − 1 ); cm ← 1; bitstring(m − 1 ) .

LISTING COMBINATIONS

7

Given an integer n, it is possible to represent it as the sum of one or more positive integers (called parts) ai that is, n = x1 + x2 + · · · + xm . This representation is called an integer partition if the order of parts is of no consequence. Thus, two partitions of an integer n are distinct if they differ with respect to the xi they contain. For example, there are seven distinct partitions of the integer 5 : 5, 4 + 1, 3 + 2, 3 + 1 + 1, 2 + 2 + 1, 2 + 1 + 1 + 1, 1 + 1 + 1 + 1 + 1. If the order of parts is important then the representation of n as a sum of some positive integers is called integer composition. For example, integer compositions of 5 are the following: 5, 4 + 1, 1 + 4, 3 + 2, 2 + 3, 3 + 1 + 1, 1 + 3 + 1, 1 + 1 + 3, 2 + 2 + 1, 2 + 1 + 2, 1 + 2 + 2, 2 + 1 + 1 + 1, 1 + 2 + 1 + 1, 1 + 1 + 2 + 1, 1 + 1 + 1 + 2, 1 + 1 + 1 + 1 + 1. Compositions of an integer n into m parts are representations of n in the form of the sum of exactly m positive integers. These compositions can be written in the form x1 + · · · + xm = n, where x1 ≥ 0, . . . , xm ≥ 0. We will establish the correspondence between integer compositions and either combinations or subsets, depending on whether or not the number of parts is ﬁxed. Consider a composition of n = x1 + · · · + xm , where m is ﬁxed or not ﬁxed. Let y1 , . . . , ym be the following sequence: yi = x1 + · · · + xi , 1 ≤ i ≤ m. Clearly, ym = n . The sequence y1 , y2 , . . . , ym−1 is a subset of {1, 2, . . . , n − 1}. If the number of parts m is not ﬁxed then compositions of n into any number of parts correspond to subsets of {1, 2, . . . , n − 1}. The number of such compositions is in this case CM(n) = 2n−1 . If the number of parts m is ﬁxed then the sequence y1 , . . . , ym−1 is a combinations of m − 1 out of n − 1 elements from {1, . . . , n − 1}, and the number of compositions in question is CO(m, n) = C(m − 1, n − 1). Each sequence x1 . . . xm can easily be obtained from y1 , . . . , ym since xi = yi − yi−1 (with y0 = 0 ). To design a loopless algorithm for generating integer compositions of n, one can use this relation between compositions of n and subsets of {1, 2, . . . , n − 1}, and the subset generation algorithm above.

1.3 LISTING COMBINATIONS A (m,n)-combination out of {p1 , p2 , . . . , pn } can be represented as a sequence c1 , c2 , . . . , cm , where p1 ≤ c1

8

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

Comparisons of combination generation techniques are given in the works by Ak1 [1] and Payne and Ives [29]. Akl [1] reports algorithm by Misfud [23] to be the fastest while Semba [34] improved the speed of algorithm [23]. The sequential algorithm [23] for generating (m,n)-combinations determines the next combination by a backtrack search that ﬁnds an element ct with the greatest possible index t such that zt

3

4

3

2

4

3

2

1

4

3

2

1

d=1 1

2

1

1

3

1

1

1

4

1

1

1

1

0

The algorithm [34] is coded in FORTRAN language using goto statements. Here we code it in PASCAL-like style. z0 ← 1; t ← m; for i ← 1 to m do zi ← i; repeat print out pzi , 1 ≤ i ≤ m; zt ← zt + 1; then t ← t − 1 if zt = n − m + t else for i = t + 1 to m do zi ← zt + i − t; t ← m until t = 0. The algorithm always does one examination to determine the turning point. We now determine the average number d of changed elements. For a ﬁxed t, the number of (m,n)-combinations that have t as the turning point with zt

9

LISTING PERMUTATIONS

total number of updated elements (in addition to the turning point) to generate all combinations is m

(m − t)C(t, n − m + t − 2) =

t=1

m−1

jC(n − j − 2, n − m − 2)

j=0

m C(n − m − 1, n − 1) − m n−m m = C(m, n) − m. n =

Thus, the algorithms updates, on the average, less than m/n + 1<2 elements and therefore the average delay is constant for any m and n(m ≤ n). 1.4 LISTING PERMUTATIONS A sequence p1 , p2 , . . . , pn of mutually distinct elements is a permutation of S = {s1 , s2 , . . . , sn } if and only if {p1 , p2 , . . . , pn } = {s1 , s2 , . . . , sn } = S. In other words, an n-permutation is an ordering, or arrangement, of n given elements. For example, there are six permutations of the set {A, B, C}. These are ABC, ACB, BAC, BCA, CAB, and CBA. Many algorithms have been published for generating permutations. Surveys and bibliographies on the generation of permutations can be found in the Ord-Smith [27] and Sedgewick [31] [27,31]. Lexicographic generation presented below is credited to L.L. Fisher and K.C. Krause in 1812 by Reingold et al. [30]. Following the backtrack method, permutations can be generated in lexicographic order as follows. The next permutation of x1 x2 . . . xn is determined by scanning from right to left, looking for the rightmost place where xi

10

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

ch ← zi ; zi ← zj ; zj ← ch; v ← n; u ← i + 1; while v>u do {ch ← zv ; zv ← zu ; zu ← ch; v ← v − 1; u ← u + 1}}. We prove that the algorithm has constant average delay property. The time complexity of the algorithm is clearly proportional to the number of tests zi ≥ zi+1 in the ﬁrst while inside loop. If ith element is the turning point, the array zi+1 , . . . , zn is decreasing and it takes (n − 1 ) tests to reach zi . The array z1 z2 . . . zi is a (m,n)-permutation. It can be uniquely completed to n-permutation z1 z2 . . . zn such that zi+1 > · · · >zn . Although only these permutations for which zi

11

LISTING EQUIVALENCE RELATIONS OR SET PARTITIONS

1.5 LISTING EQUIVALENCE RELATIONS OR SET PARTITIONS An equivalence relation of the set Z = {p1 , . . . , pn } consists of classes π1 , π2 , . . . , πk such that the intersection of every two classes is empty and their union is equal to Z. Equivalence relations are often referred to as set partitions. For example, let Z = {A, B, C}. Then there are four equivalence relations of Z : {{A, B, C}}, {{A, B}{C}}, {{A, C}{B}}, {{A}, {B, C}}, and {{A}, {B}, {C}}. Equivalence relations of Z can be conveniently represented by codewords c1 c2 . . . cn such that ci = j if and only if element pi is in class πj . Because equivalence classes may be numbered in various ways (k! ways), such codeword representation is not unique. For example, set partition {{A, B}{C}} is represented with codeword 112 while the same partition {{C}{A, B}} is coded as 221. In order to obtain a unique codeword representation for given equivalence relation, we choose lexicographically minimal one among all possible codewords. Clearly c1 = 1 since we can choose π1 to be the class containing p1 . All elements that are in π1 are also coded with 1. The class containing element that is not in π1 and has the minimal possible index is π2 and so on. For example, let {{C, D, E}, {B}, {A, F }} be a set partition of {A, B, C, D, E, F }. The ﬁrst equivalence class is {A, F }, the second is {B}, and the third is {C, D, E}. The corresponding codeword is 123331. A codeword c1 . . . cn represents an equivalence relation of the set Z if and only if c1 = 1 and 1 ≤ cr ≤ gr−1 + 1 for 2 ≤ r ≤ n , where ci = j if i is in πj , and gr = max(c1 , . . . , cr ) for 1 ≤ r ≤ n . This follows from the deﬁnition of lexicographically minimal codeword. Element pt is either one of the equivalence classes with some other element pi (i

1112 = {{A, B, C}, {D}},

1122 = {{A, B}, {C, D}},

1123 = {{A, B}, {C}, {D}},

1211 = {{A, C, D}, {B}},

1212 = {{A, C}, {B, D}},

1121 = {{A, B, D}, {C}},

1213 = {{A, C}, {B}, {D}}, 1221 = {{A, D}, {B, C}}, 1222 = {{A}, {B, C, D}},

1223 = {{A}, {B, C}, {D}}, 1231 = {{A, D}, {B}, {C}},

1232 = {{A}, {B, D}, {C}},

1233 = {{A}, {B}, {C, D}}, 1234 = {{A}, {B}, {C}, {D}}.

12

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

We present an iterative algorithm from the work by Djoki´c et al. [9] for generating all set partitions in the codeword representation. The algorithm follows backtrack method for ﬁnding the largest r having an increasable cr , that is, cr

GENERATING INTEGER COMPOSITIONS AND PARTITIONS

13

an integer partition if the order of parts is of no consequence. Thus, two partitions of an integer n are distinct if they differ with respect to the xi they contain. For example, there are seven distinct partitions of the integer 5: 5, 4 + 1, 3 + 2, 3 + 1 + 1, 2 + 2 + 1, 2 + 1 + 1 + 1, 1 + 1 + 1 + 1 + 1. In the standard representation, a partition of n is given by a sequence x1 , . . . , xm , where x1 ≥ x2 ≥ · · · ≥ xm , and x1 + x2 + · · · + xm = n. In the sequel x will denote an arbitrary partition and m will denote the number of parts of x (m is not ﬁxed). It is sometimes more convenient to use a multiplicity representation for partitions in terms of a list of the distinct parts of the partition and their respective multiplicities. Let y1 > · · · >yd be all distinct parts in a partitions, and c1 , . . . , cd their respective (positive) multiplicities. Clearly c1 y1 + · · · + cd yd = n. We ﬁrst describe an algorithm for generating integer compositions of n into any number of parts and in lexicographic order. For example, compositions of 4 in lexicographic order are the following: 1 + 1 + 1 + 1, 1 + 1 + 2, 1 + 2 + 1, 1 + 3, 2 + 1 + 1, 2 + 2, 3 + 1, 4. Let x1 . . . xm , where x1 + x2 + · · · + xm = n be a composition. The next composition, following lexicographic order, is x1 , . . . , xm−1 + 1, 1, . . . , 1(xm − 1 1s). In other words, the next to last part is increased by one and the xm − 1, 1s are added to complete the next composition. This can be coded as follows: program composition( n); m ← 1; x1 ← n; repeat for j ← 1 to m do print out x1 , x2 , . . . , xm ; m ← m − 1; xm ← xm + 1; for j ← 1 to xm+1 − 1 do {m ← m + 1; xm ← 1} until m = n. In antilexicographic order, a partition is derived from the previous one by subtracting 1 from the rightmost part greater than 1, and distributing the remainder as quickly as possible. For example, the partitions following 9 + 7 + 6 + 1 + 1 + 1 + 1 + 1 + 1 is 9 + 7 + 5 + 5 + 2. In standard representation and antilexicographic order, the next partition is determined from current one x1 x2 . . . xm in the following way. Let h be the number of parts of x greater than 1, that is, xi >1 for 1 ≤ i ≤ h, and xi = 1 for h < i ≤ m. If xm >1 (or h = m ) then the next partition is x1 , x2 , . . . , xm−1 , xm − 1, 1. Otherwise (i.e., h < m ), the next partition is obtained by replacing xh , xh+1 = 1, . . . , xm = 1 with (xh − 1), (xh − 1), . . . , (xh − 1), d, containing c elements, where 0 < d ≤ xh − 1 and (xh − 1)(c − 1) + d = xh + m − h. We describe two algorithms from the work by Zoghbi and Stojmenovic [43] for generating integer partitions in standard representation and prove that they have constant average delay property. The ﬁrst algorithm, named ZS1, generates partitions in antilexicographic order while the second, named ZS2, uses lexicographic order. Recall that h is the index of the last part of partition, which is greater than 1 while m is the number of parts. The major idea in algorithm ZS1 is coming from the

14

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

observation on the distribution of xh . An empirical and theoretical study shows that xh = 2 has growing frequency; it appears in 66 percent of cases for n = 30 and in 78 percent of partitions for n = 90 and appears to be increasing with n. Each partition of n containing a part of size 2 becomes, after deleting the part, a partition of n − 2 (and vice versa). Therefore the number of partitions of n containing at least one part of size 2 is P(n − 2). The ratio P(n − 2)/P(n) approaches 1 with increasing n. Thus, almost all partitions contain at least one part of size 2. This special case is treated separately, and we will prove that it sufﬁces to argue the constant average delay of algorithm ZS1. Moreover, since more than 15 instructions in known algorithms that were used for all cases are replaced by 4 instructions in cases of at least one part of size 2 (which happens almost always), the speed up of about four times is expected even before experimental measurements. The case xh >2 is coded in a similar manner as earlier algorithm, except that assignments of parts that are supposed to receive value 1 is avoided by an initialization step that assigns 1 to each part and observation that inactive parts (these with index >m ) are always left at value 1. The new algorithm is obtained when the above observation is applied to known algorithms and can be coded as follows. Algorithm ZS1 for i ← 1 to n do xi ← 1; x1 ← n; m ← 1; h ← 1; output x1 ; while x1 = 1 do { if xh = 2 then {m ← m + 1; xh ← 1; h ← h − 1} else {r ← xh − 1; t ← m − h + 1; xh ← r; while t ≥ r do {h ← h + 1; xh ← r; t ← t − r} if t = 0 then m ← h else m ← h + 1 if t>1 then {h ← h + 1; xh ← t}} output x1 , x2 , . . . , xm }}. We now describe the method for generating partitions in lexicographic order and standard representation of partitions. Each partition of n containing two parts of size 1 (i.e., m − h>1 ) becomes, after deleting these parts, a partition of n − 2 (and vice versa). Therefore the number of integer partitions containing at least two parts of size 1 is P(n − 2), as in the case of previous algorithm. The coding in this case is made simpler, in fact with constant delay, by replacing ﬁrst two parts of size 1 by one part of size 2. The position h of last part >1 is always maintained. Otherwise, to ﬁnd the next partition in the lexicographic order, an algorithm will do a backward search to ﬁnd the ﬁrst part that can be increased. The last part xm cannot be increased. The next to last part xm−1 can be increased only if xm−2 >xm−1 . The element that will be increased is xj where xj−1 >xj and xj = xj+1 = . . . = xm−1 . The jth part becomes xj + 1, h receives value j, and appropriate number of parts equal to 1 is added to complete the sum to n. For example, in the partition 5 + 5 + 5 + 4 + 4 + 4 + 1 the leftmost 4 is increased, and the next partition is 5 + 5 + 5 + 5 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1. The following is a code of appropriate algorithm ZS2:

GENERATING INTEGER COMPOSITIONS AND PARTITIONS

15

Algorithm ZS2 for i ← 1 to n do xi ← 1 ; output xi , i = 1, 2, . . . , n; x0 ← 1; x1 ← 2; h ← 1; m ← n − 1; output xi , i = 1, 2, . . . , m; while x1 = n do { if m − h>1 then {h ← h + 1; xh ← 2; m ← m − 1} else {j ← m − 2; while xj = xm−1 do {xj ← 1; j ← j − 1}; h ← j + 1; xh ← xm−1 + 1; r ← xm + xm−1 (m − h − 1); xm ← 1; if m − h>1 then xm−1 ← 1; m ← h + r − 1; output x1 , x2 , . . . , xm }. We now prove the constant average delay property of algorithms ZS1 and ZS2. Theorem 1 Algorithms ZS1 and ZS2 generate unrestricted integer partitions in standard representation with constant average delay, exclusive of the output. Proof. Consider part xi ≥ 3 in the current partition. It received its value after a backtracking search (starting from last part) was performed to ﬁnd an index j ≤ i, called the turning point, that should change its value by 1 (increase/decrease for lexicographic/antilexicographic order) and to update values xi for j ≤ i. The time to perform both backtracking searches is O(rj ), where rj = n − x1 − x2 − · · · − xj is the remainder to distribute after ﬁrst j parts are ﬁxed. We decide to charge the cost of the backtrack search evenly to all “swept” parts, such that each of them receives constant O(1) time. Part xi will be changed only after a similar backtracking step “swept” over ith part or recognized ith part as the turning point (note that ith part is the turning point in at least one of the two backtracking steps). There are RP(ri , xi ) such partitions that keep all xj intact. For xi ≥ 3 the number of such partitions, is ≥ ri2 /12. Therefore the average number of operations that are performed by such part i during the “run” of RP(ri , xi ), including the change of its value, is O(1)/RP(ri , xi ) ≤ O(1)/ri2 = O(1/ri2 ) < qi /ri2 , where qi is a constant. Thus the average number of operations for all parts of size ≥ 3 is ≤ q1 /r12 + q2 /r22 + · · · + qs /rs2 ≤ q(1/r12 + · · · + 1/rs2 ) < q(1/n2 + 1/(n − 1)2 + · · · + 1/12 ) < 2q (the last inequality can be obtained easily by applying integral operation on the last sum), which is a constant. The case that was not counted in is when xi ≤ 2 . However, in this case both algorithms ZS1 and ZS2 perform constant number of steps altogether on all such parts. Therefore the algorithm has overall constant time average delay. 䊏 The performance evaluation of known integer partition generation methods is performed in the work by Zoghbi and Stojmenovic [43]. The results show clearly that both algorithms ZS1 and ZS2 are superior to all other known algorithms that generate partitions in the standard representation. Moreover, both algorithms SZ1 and ZS2 were even faster than any algorithm for generating integer partitions in the multiplicity representation.

16

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

1.7 LISTING t-ARY TREES The t-ary trees are data structures consisting of a ﬁnite set of n nodes, which either is empty (n = 0) or consists of a root and t disjoint children. Each child is a t-ary subtree, recursively deﬁned. A node is the parent of another node if the latter is a child of the former. For t = 2, one gets the special case of rooted binary trees, where each node has a left and a right child, where each child is either empty or is a binary tree. A computer representation of t-ary trees with n nodes is achieved by an array of n records, each record consisting of several data ﬁelds, t pointers to children and a pointer to the parent. All pointers to empty trees are nil. The number of t-ary trees with n nodes is B(n, t) = (tn)!/(n!(tn − n)!)/((t − 1)n + 1) (cf. [19,42]). If the data ﬁelds are disregarded, the combinatorial problem of generating binary and, in general, t-ary trees is concerned with generating all different shapes of t-ary trees with n nodes in some order. The lexicographic order of trees refers to the lexicographic order of the corresponding tree sequences. There are over 30 ingenious generating algorithms for generating binary and t-ary trees. In most references, tree sequences are generated in lexicographic order. Each of these generation algorithms causes trees to be generated in a particular order. Almost all known sequential algorithms generate tree sequences, and the inclusion of parent–child relations requires adding a decoding procedure, usually at a cost of greatly complicating the algorithm and/or invalidating the run time analysis. Exceptions are the works by Akl et al. [4] and Lucas et al. [22]. Parent array notation [4] provides a simple sequential algorithm that extends trivially to add parent–children relations. Consider a left-to-right breadth ﬁrst search (BFS) labeling of a given tree. All nodes are labeled by consecutive integers 1, 2, . . . , n such that nodes on a lower level are labeled before those on a higher level, while nodes on the same level are labeled from left to right. Children are ordered as L = 1, . . . , t. Parent array p1 , . . . , pn can be deﬁned as follows: p1 = 1, pi = t(j − 1) + L + 1 if i is the Lth child of node j, 2 ≤ i ≤ n , and it has property pi−1 < pi ≤ ti − t + 1 for 2 ≤ i ≤ n . For example, the binary tree on Figure 1.1 has parent array 1, 3, 4, 5, 7, 8; the 3-ary tree on Figure 1.1 has parent array 1, 2, 3, 4, 8, 10, 18. The algorithm [4] for generating all parent arrays is extended from the work by Zaks [42] to include parent–children relations (the same sequence in the works by Zaks [42] and Akl et al. [4] refers to different trees). The Lth children of node i is denoted by childi,L (it is 0 if no such child exist) while parenti denotes the parent

FIGURE 1.1 Binary tree 1, 3, 4, 5, 7, 8 and ternary tree 1, 2, 3, 4, 8, 10, 18.

LISTING t-ARY TREES

17

node of i. Integer division is used throughout the algorithm. The algorithm generates tree sequences in lexicographic order. for i ← 1 to n do for L ← 1 to t do childi,L ← 0; for i ← 1 to n do {pi ← i; parenti ← (i − 2)/t + 1; L ← pi − 1 − t(parenti − 1); child(i−2)/t+1,L ← i} repeat report t-ary tree; j ← n; while pj < 2j − 1 and j>1 do {i ← parentj ; L ← pi − 1 − t(i − 1); childi,L ← 0; j ← j − 1} pj ← pj + 1; for i ← j + 1 to n do pi ← pi−1 + 1; for i ← j to n do {k ← (pi − 2)/t + 1; parenti ← k; L ← pi − 1 − t(k − 1); childk,L ← i} until p1 = 2 . Consider now generating t-ary trees in the children array notation. A tree is represented using a children array c1 c2 , c3 , . . . , ctn as follows: The jth children of node i is stored in c(i−1)t+j+1 for 1 ≤ i ≤ n − 1 and 1 ≤ j ≤ t; missing children are denoted by 0. The array is, for convenience, completed with c1 = 1 and c(n−1)t+2 = · · · = cnt = 0 (node n has no children). For example, the children array notations for trees in FIGURE 1.1 are 102340560000 and 123400050600000007000. Here we give a simple algorithm to generate children array tree sequences, for the case of t-ary trees (generalized from the work by Akl et al. [4] that gives corresponding generation of binary trees). The rightmost element of array c that can be occupied by an integer j>0, representing node j, is obtained when j is tth child of node j − 1 , that is, it is c(j−1)t+1 . We say that an integer j is mobile if it is not in c(j−1)t+1 and all (nonzero) integers to its right occupy their rightmost positions. A simple sequential algorithm that uses this notation to generate all t-ary trees with n nodes is given below. If numerical order 0 < 1 < · · · < n is assumed, the algorithm generates children array sequences in antilexicographic order. Alternatively, the order may be interpreted as lexicographic if 0, 1, · · · , n are treated as symbols, ordered as “1” < “2” < . . . < “n” < “0”. Numeric lexicographic order may be obtained if 0 is replaced by a number larger than n (the algorithm should always report that number instead of 0). for i ← 1 to n do ci ← i; for i ← n + 1 to tn do ci ← 0; repeat print out c1 , . . . , ctn ; i ← (n − 1)t;

18

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

while ci = 0 or ci = k−1 + 1 and (i > 1) do i ← i − 1; t ci+1 ← ci ; ci ← 0; for k ← 1 to n − ci+1 do ci+k+1 ← ci+k + 1; for k ← i + n − ci+1 + 2 to (n − 1)t + 1 do ck ← 0 until i = 1 . We leave as an exercise to design an algorithm to generate well-formed parenthesis sequences. This can be done by using the relation between well-formed parenthesis sequences and binary trees in the children representation, and applying the algorithm given in this section. An algorithm for generating B-trees is described in the work by Gupta et al. [16]. It is based on backtrack search, and produces B-trees with worst case delay proportional to the output size. The order of generating B-trees becomes lexicographic if B-trees are coded as a B-tree sequence, deﬁned in [5]. The algorithm [16] has constant expected delay in producing next B-tree, exclusive of the output, which is proven in the work by Belbaraka and Stojmenovic [5]. Using a decoding procedure, an algorithm that generates the B-tree data structure (meaning that the parent–children links are established) from given B-tree sequence can be designed, with constant average delay.

1.8 LISTING SUBSETS AND BITSTRINGS IN A GRAY CODE ORDER It is sometimes desirable to generate all instances of a combinatorial object in such a way that successive instances differ as little as possible. An order of all instances that minimizes the difference between any two neighboring instances is called minimal change order. Often the generation of objects in minimal change order requires complicated and/or computationally expensive procedures. When new instances are generated with the least possible changes (by a single insertion of an element, single deletion or single replacement of one element by another, interchange of two elements, updating two elements only, etc.), corresponding sequences of all instances of a combinatorial objects are refereed to as Gray codes. In addition, the same property must be preserved when going from the last to ﬁrst sequence. In most cases, there is no difference between minimal change and Gray code orders. They may differ when for a given combinatorial object there is no known algorithm to list all instances in Gray code order. The best existing algorithm (e.g., one in which two instances differ at two positions whereas instances may differ in one position only) then is referred to achieving minimal change order but not in Gray code order. We describe a procedure for generating subsets in binary notation, which is equivalent to generating all bitstrings of given length. It is based on a backtrack method and sequence comparison rule. Let e1 = 0 and ei = x1 + x2 + · · · + xi−1 for 1 < i ≤ n. Then the sequence that follows x1 x2 . . . xn is x1 x2 . . . xi−1 xi xi+1 . . . xn , where i is the largest index such that ei + xi is even and is complement function

19

GENERATING PERMUTATIONS IN A MINIMAL CHANGE ORDER

(0 = 1, 1 = 0; also x = x + 1 mod 2). read( n); for i ← 0 to n do {xi ← 0; ei ← 0}; repeat print out x1 , x2 , . . . , xn ; i ← n; while xi + ei is odd do i ← i − 1; xi ← xi ; for j ← i + 1 to n do ej ← e j until i = 0 . The procedure has O(n) worst case delay and uses no large integers. We will prove that it generates Gray code sequences with constant average delay. The element xi changes 2i−1 times in the algorithm, and each time it makes n − i + 1 steps back and forth to update xi . Since the time for each step is bounded by a constant, the time to generate all Gray code sequences is ni=1 c2i−1 (n − i + 1). The average delay is obtained when the last number is divided by the number of generated sequences 2n , and is therefore

c

n i=1

2

−n+i−1

(n − i + 1) = c

n i=1

n 1 2 i = c 2 − n − n−1 2 2 −i

< 2c.

An algorithm for generating subsets in the binary notation in the binary reﬂected Gray code that has constant delay in the worst case is described in the work by Reingold et al. [30]. Efﬁcient loopless algorithms for generating k-ary trees are described in the Xiang et al. [41].

1.9 GENERATING PERMUTATIONS IN A MINIMAL CHANGE ORDER In this section we consider generating the permutations of {p1 , p2 , . . . , pn } (p1 < · · · < pn ) in a minimum change order. We present one that is based on the idea of adjacent transpositions, and is independently proposed by Johnson [18] and Trotter [39]. It is then simpliﬁed by Even [14]. In the work by Even [14], a method by Ehrlich is presented, which has constant delay. The algorithm presented here is a further modiﬁcation of the technique, also having constant delay, and suitable as a basis for a parallel algorithm [36]. The algorithm is based on the idea of generating the permutations of {p1 , p2 , . . . , pn } from the permutations of {p1 , p2 , . . . , pn−1 } by taking each such permutation and inserting pn in all n possible positions of it. For example, taking the permutation p1 p2 . . . pn−1 of {p1 , p2 , . . . , pn−1 } we get n permutations of {p1 , p2 , . . . , pn } as follows:

20

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

p1 p2 . . . pn−2 pn−1 pn p1 p2 . . . pn−2 pn p1 p2 . . . p n

pn−1

pn−2 pn−1

· · · pn p1 . . . pn−3 pn−2 pn−1 . The nth element sweeps from one end of the (n − 1) -permutation to the other by a sequence of adjacent swaps, producing a new n-permutation each time. Each time the nth element arrives at one end, a new (n − 1) -permutation is needed. The (n − 1)permutations are produced by placing the (n − 1)th element at each possible position within an (n − 2) -permutation. That is, by applying the algorithm recursively to the (n − 1) elements. The ﬁrst permutation of the set {p1 , p2 , . . . , pn } is p1 , p2 , . . . , pn . Assign a direction to every element, denoted by an arrow above the element. Initially all arrows point to the left. Thus if the permutations of {p1 , p2 , p3 , p4 } are to be generated, we would have ← ← ← ← p 1 p 2 p 3 p 4.

Now an element is said to be mobile if its direction points to a smaller adjacent neighbor. In the above example, p2 , p3 and p4 are mobile, while in ← ←

p

3 p 2 p 1 p

4 only p3 is mobile. The algorithm is as follows: While there are mobile elements do (i) ﬁnd the largest mobile element; call it pm (ii) reverse the direction of all elements larger than pm (iii) switch pm with the adjacent neighbor to which its direction points endwhile. The straightforward implementation of the algorithm leads to an algorithm that exhibits a linear time delay. The algorithm is modiﬁed to achieve a constant delay. After initial permutation, the following steps are then repeated until termination: 1. Move element pn to the left, by repeatedly exchanging it with its left neighbor, and do (i) and (ii) in the process. 2. Generate the next permutation of {p1 , p2 , . . . , pn−1 } (i.e., do step (iii)). 3. Move element pn to the right, by repeatedly exchanging it with its right neighbor, and do (i) and (ii) in the process.

GENERATING PERMUTATIONS IN A MINIMAL CHANGE ORDER

21

4. Generate the next permutation of {p1 , p2 , . . . , pn−1 } (i.e., do step (iii)). For example, permutations of {1, 2, 3, 4} are generated in the following order: 1234, 1243, 1423, 4123 move element 4 to the left 4132 132 is the next permutation of 123, with 3 moving to the left 1432, 1342, 1324 3124 3142, 3412, 4312 4321

move 4 to the right 312 is the next permutation following 132, with 3 moving to the left 4 moves to the left 321 is the next permutation following 312; 2 in 12 moves to the left

3421, 3241, 3214 2314

4 moves to the right 231 follows 321, where 3 moves to the right

2341, 2431, 4231 4213 2413, 2143, 2134

4 moves to the left 213 follows 231, 3 moved to the right 4 moves to the right.

The constant delay is achieved by observing that the mobility of pn has a regular pattern (moves n − 1 times and then some other element moves once). It takes n − 1 steps to move pn to the left or right while (i), (ii), and (iii) together take O(n) time. Therefore, if steps (i), (ii), and (iii) are performed after pn has already ﬁnished moving in a given direction, the algorithm will have constant average delay. If the work in steps (i) and (ii) [step (iii) requires constant time] is evenly distributed between consecutive permutations, the algorithm will achieve constant worst case delay. More precisely, ﬁnding largest mobile element takes n − 1 steps, updating directions takes also n − 1 steps. Thus it sufﬁces to perform two such steps per move of element pn to achieve constant delay per permutation. The current permutation is denoted d1 , d2 , . . . , dn . The direction is stored in a variable a, where ai = −1 for left and ai = 1 for right direction. When two elements are interchanged, their directions are also interchanged implicitly. The algorithm terminates when no mobile element is found. For algorithm conciseness, we assume that two more elements p0 and pn+1 are added such that p0 < p1 < . . . < pn < pn+1 . Variable i is used to move pn from right to left (i = n, n − 1, . . . , 2) or from left to right (i = 1, 2, . . . , n − 1). The work in steps (i) and (ii) is done by two “sweeping” variables l (from left to right) and r (from right to left). They update the largest mobile elements dlm and drm, respectively, and their indices lm and rm, respectively, that they detect in the sweep. When they “meet” (l = r or l = r − 1) the largest mobile element dlm and its index lm is decided, and the information is broadcast (when l>r) to all other elements who use it to update their directions. Obviously the

22

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

sweep of variable i coincides with either the sweep of l or sweep of r. For clarity, the code below considers these three sweeps separately. The algorithm works correctly for n>2. procedure output; { for s ← 1 to n do write( d[s]); writeln} procedure exchange ( c, b: integer); { ch ← d[c + b]; d[c + b] ← d[c]; d[c] ← ch; ch ← a[c + b]; a[c + b] ← a[c]; a[c] ← ch }; procedure updatelm; { l ← l + 1; if (d[l] = pn ) or (d[l + dir] = pn ) then l ← l + 1; if l > r then { if d[l − 1] = pn then l1 ← l − 1 else l1 ← l − 2; if d[l + 1] = pn then l2 ← l + 1 else l2 ← l + 2; if (((a[l] = −1) and (d[l1] < d[l])) or ((a[l] = 1) and (d[l2] < d[l]))) and (d[l]>dlm) then {lm ← l; dlm ← d[l]};}; if ((l = r) or (l = r − 1)) and (drm>dlm) then {lm ← rm; dlm ← drm}; if (l>r) and (d[r]>dlm) then a[r] ← −a[r]; r ← r − 1; if (d[r] = pn ) or (d[r + dir] = pn ) then r ← r − 1; if l < r then { if d[r − 1] = pn then l1 ← r − 1 else l1 ← r − 2; if d[r − 1] = pn then l2 ← r + 1 else l2 ← r + 2; if (((a[r] = −1) and (d[l1] < d[r])) or ((a[r] = 1) and (d[l2] < d[r]))) and (d[r]>drm) then { rm ← r; drm ← d[r] }; }; if ((l = r) or (l = r − 1)) and (drm>dlm) then { lm ← rm; dlm ← drm }; if (lεr) and (d[r]>dlm) then a[r] − a[r]; exchange( i, dir); if i + dir = lm then lm ← i; if i + dir = rm then rm ← i; output; }; read( n); for i ← 0 to n + 1 do read pi ; d[0] ← pn+1 ; d[n + 1] ← pn+1 ; d[n + 2] ← p0 ; for i ← 1 to n do { d[i] ← pi ; a[i] ← −1}; repeat output; l ← 1; r ← n + 1; lm ← n + 2; dlm ← p0 ; rm ← n + 2; drm ← p0 ; dir ← −1; for i ← n downto 2 do updatelm; exchange (lm, a[lm]);

RANKING AND UNRANKING OF COMBINATORIAL OBJECTS

23

output; l ← 1; r ← n + 1; lm ← n + 2; dlm ← p0 ; drm ← p0 ; rm ← n + 2; dir ← 1; for i ← 1 to n − 1 do updatelm; exchange (lm, a[lm]); until lm = n + 2.

1.10 RANKING AND UNRANKING OF COMBINATORIAL OBJECTS Once the objects are ordered, it is possible to establish the relations between integers 1, 2, . . . , N and all instances of a combinatorial object, where N is the total number of instances under consideration. The mapping of all instances of a combinatorial object into integers is called ranking. For example, let f(X) be ranking procedure for subsets of the set {1, 2, 3}. Then, in lexicographic order, f ( ) = 1, f ({1}) = 2, f ({1, 2}) = 3, f ({1, 2, 3}) = 4, f ({1, 3}) = 5, f ({2}) = 6, f ({2, 3}) = 7 and f ({3}) = 8. The inverse of ranking, called unranking, is mapping of integers 1, 2, . . . , N to corresponding instances. For instance, f −1 (4) = {1, 2, 3} in the last example. The objects can be enumerated in a systematic manner, for some combinatorial classes, so that one can easily construct the sth element in the enumeration. In such cases, an unbiased generator could be obtained by generating a random number s in the appropriate range (1,N) and constructing the sth object. In practice, random number procedures generate a number r in interval [0,1); then s = rN is required integer. Ranking and unranking functions exist for almost every kind of combinatorial objects, which has been studied in literature. They also exist for some objects listed in minimal change order. The minimal change order has more use when all instances are to be generated since in this case either the time needed to generate is less or the minimal change order of generating is important characteristics of some applications. In case of generating an instance at random, the unranking functions for minimal change order is usually more sophisticated than the corresponding one following lexicographic order. We use only lexicographic order in ranking and unranking functions presented in this chapter. In most cases combinatorial objects of given kind are represented as integer sequences. Let a1 a2 . . . am be such a sequence. Typically each element ai has its range that depends on the choice of elements a1 , a2 , . . . , ai−1 . For example, if a1 a2 . . . am represents a (m,n)-combination out of {1, 2, . . . , n} then 1 ≤ a1 ≤ n − m + 1, a1 < a2 ≤ n − m + 2, . . . , am−1 < am ≤ n. Therefore element ai has n − m + 1 − ai−1 different choices. Let N(a1 , a2 , . . . , ai ) be the number of combinatorial objects of given kind whose representation starts with a1 a2 . . . ai . For instance, in the set of (4,6)-combinations we have N(2, 3) = 3 since 23 can be completed to (4,6)-combination in three ways: 2345, 2346, and 2356.

24

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

To ﬁnd the rank of an object a1 a2 . . . am , one should ﬁnd the number of objects preceding it. It can be found by the following function: function rank(a1 , a2 , . . . , am ) rank ← 1 ; for i ← 1 to m do for each x < ai rank ← rank + N(a1 , a2 , . . . , ai−1 , x). Obviously in the last for loop only such values x for which a1 a2 . . . ai−1 x can be completed to represent an instance of a combinatorial object should be considered (otherwise adding 0 to the rank does not change its value). We now consider a general procedure for unranking. It is the inverse of ranking function and can be calculated as follows. procedure unrank ( rank, n, a1 , a2 , . . . , am ) i←0; repeat i ← i + 1; x ← ﬁrst possible value; while N(a1 , a2 , . . . , ai−1 , x) ≤ rank do {rank ← rank − N(a1 , a2 , . . . , ai−1 , x); x ← next possible value}; ai ← x until rank = 0; a1 a2 . . . am ← lexicographically ﬁrst object starting by a1 a2 . . . ai . We now present ranking and unranking functions for several combinatorial objects. In case of ranking combinations out of {1, 2, . . . , n}, x is ranged between ai−1 + 1 and ai − 1. Any (m, n)-combination that starts with a1 a2 . . . ai−1 x is in fact a (m − i, n − x)- combination. The number of such combinations is C(m − i, n − x). Thus the ranking algorithm for combinations out of {1, 2, . . . , n} can be written as follows (a0 = 0 in the algorithm): function rankcomb (a1 , a2 , . . . , am ) rank ← 1 ; for i ← 1 to m do for x ← ai−1 + 1 to ai − 1 do rank ← rank + C(m − i, n − x). In lexicographic order, C(4, 6) = 15 (4,6)-combinations are listed as 1234, 1235, 1236, 1245, 1246, 1256, 1345, 1346, 1356, 1456, 2345, 2346, 2356, 2456, 3456. The rank of 2346 is determined as 1 + C(4 − 1, 6 − 1) + C(4 − 4, 6 − 5) = 1 + 10 + 1 = 12 where last two summands correspond to combinations that start with 1 and 2345, respectively. Let us consider a larger example. The rank of 3578 in

RANKING AND UNRANKING OF COMBINATORIAL OBJECTS

25

(4,9)-combinations is 1 + C(4 − 1, 9 − 1) + C(4 − 1, 9 − 2) + C(4 − 2, 9 − 4) + C(4 − 3, 9 − 6) = 104 where four summands correspond to combinations starting with 1, 2, 34, and 356, respectively. A simpler formula is given in the work by Lehmer [21]: the rank of combination a1 a2 . . . am is C(m, n) − m j=1 C(j, n − 1 − am−j+1 ). It comes from the count of the number of combinations that follow a1 a2 . . . am in lexicographic order. These are all combinations of j out of elements {am−j+1 + 1, am−j+1 + 2, . . . , an }, for all j, 1 ≤ j ≤ m. In the last example, combinations that follow 3578 are all combinations of 4 out of {4, 5, 6, 7, 8, 9}, combinations with ﬁrst element 3 and three others taken from {6, 7, 8, 9}, combinations which start with 35 and having two more elements out of set {8, 9} and combination 3579. The function calculates the rank in two nested for loops while the formula would require one for loop. Therefore general solutions are not necessarily best in the particular case. The following unranking procedure for combinations follows from general method. procedure unrankcomb (rank, n, a1 , a2 , . . . , am ) i ← 0; a0 ← 0; repeat i ← i + 1; x ← ai−1 + 1; while C(m − i, n − x) ≤ rank do {rank ← rank − C(m − i, n − x); x ← x + 1}; ai ← x until rank = 0; for j = i + 1 to m do aj ← n − m + j. What is 104th (4,9)-combination? There are C(3, 8) = 56 (4,9)-combinations starting with a 1 followed by C(3, 7) = 35 starting with 2 and C(3, 6) = 20 starting with 3. Since 56 + 35 ≤ 104 but 56 + 35 + 20 > 104 the requested combination begins with a 3, and the problem is reduced to ﬁnding 104 − 56 − 35 = 13th (3,6)-combination. There are C(2, 5) = 10 combinations starting with 34 and C(2, 4) = 6 starting with a 5. Since 13 > 10 but 13 < 10 + 6 the second element in combination is 5, and we need to ﬁnd 13 − 10 = 3rd (2,4)-combination out of {6, 7, 8, 9}, which is 78, resulting in combination 3578 as the 104th (4,9)-combination. We also consider the ranking of subsets. The subsets in the set and in the binary representation are listed in different lexicographic orders. In binary representation, the ranking corresponds to ﬁnding decimal equivalent of an integer in binary system. Therefore the rank of a subset b1 , b2 , . . . , bn is bn + 2bn−1 + 4bn−2 + · · · + 2n−1 b1 . For example, the rank of 100101 is 1 + 4 + 32 = 37 . The ranks are here between 0 and 2n − 1 since in many applications empty subset (here with rank 0) is not taken into consideration. The ranking functions can be generalized to variations out of {0, 1, . . . , m − 1} by simply replacing all “2” by “m” in the rank expression. It corresponds to decimal equivalent of a corresponding number in number system with base m.

26

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

Similarly, the unranking of subsets in binary representation is equivalent to converting a decimal number to binary one, and can be achieved by the following procedure that uses the mod or remainder function. The value rank mod 2 is 0 or 1, depending whether rank is even or odd, respectively. It can be generalized for m-variations if all “2” are replaced by “m”. function unranksetb(n, a1 a2 . . . am ) rank ← m; a0 ← 0; for i ← m downto 1 do {bi ← rank mod 2; rank ← rank − bi 2n−i }. In the set representation, the rank of n-subset a1 a2 . . . am is found by the following function from the work by Djoki´c et al. [10]. function rankset(n, a1 a2 . . . am ) rank ← m; a0 ← 0; for i ← 1 to m − 1 do for j ← ai + 1 to ai+1 − 1 do rank ← rank + 2n−j . The unranking function [10] gives n-subset with given rank in both representations but the resulting binary string b1 b2 . . . bn is assigned its rank in the lexicographic order of the set representation of subsets. function unranksets(rank, n, a1 a2 . . . am ) m ← 0; k ← 1; for i ← 1 to n do bi ← 0 ; repeat if rank ≤ 2n−k then {bk ← 1; m ← m + 1; am ← k}; rank ← rank − (1 − bk )2n−k − bk ; k ←k+1 until k>n or rank = 0. As noted in the work by Djoki´c [10], the rank of a subset a1 a2 . . . am among all (m, n)-subsets is given by ranks(a1 a2 . . . am ) = rankcomb(a1 a2 . . . am ) + rankcomb(a1 a2 . . . am−1 ) + · · · + rankcomb(a1 a2 ) + rankcomb(a1 ). Let L(m, n) = C(1, n) + C(2, n) + · · · + C(n, m) be the number of (m, n)subsets. The following unranking algorithm [10] returns the subset a1 a2 . . . am with given rank. function unranklim (rank, n, m, a1 a2 . . . ar ) r ← 0; i ← 1; repeat s ← t − 1 − L(m − r − 1, n − i);

RANKING AND UNRANKING OF SUBSETS AND VARIATIONS IN GRAY CODES

27

if s>0 then t ← s else {r ← r + 1; ar ← i; rank ← rank − 1}; i←i+1 until i = n + 1 or rank = 0. Note that the (m, n)-subsets in lexicographic order also coincide with a minimal change order of them. This is a rare case. Usually it is trivial to show that lexicographic order of instances of an object is not a minimal change order. Ranking and unranking functions for integer compositions can be described by using the relation between compositions and either subsets or combinations (discussed above). A ranking algorithm for n-permutations is as follows [21]: function rankperm(a1 a2 . . . an ) rank ← 1 ; for i ← 1 to n do rank ← rank + k(n − i)! where k = |{1, 2, . . . , ai − 1}\ {a1 , a2 , . . . , ai−1 }|. For example, the rank of permutation 35142 is 1 + 2 × 4! + 3 × 3! + 1 × 1! = 68 where permutations starting with 1, 2, 31, 32, 34, and 3512 should be taken into account. The unranking algorithm for permutations is as follows [21]. Integer division is used (i.e., 13/5 = 2 ). procedure unrankperm(rank, n, a1 a2 . . . an ) for i ← 1 to n do { rank − 1 k← ; (n − i)! ai ← kth element of {1, 2, . . . , n}\{a1 , a2 , . . . , ai−1 }; rank ← rank − (k − 1)(n − i)!}. The number of instances of a combinatorial object is usually exponential in size of objects. The ranks, being large integers, may need O(n) or similar number of memory location to be stored and also O(n) time for the manipulation with them. Avoiding large integers is a desirable property in random generation in some cases. The following two sections offer two such approaches.

1.11 RANKING AND UNRANKING OF SUBSETS AND VARIATIONS IN GRAY CODES In a Gray code (or minimal change) order, instances of a combinatorial object are listed such that successive instances differ as little as possible. In this section we study Gray codes of subsets in binary representation. Gray code order of subsets is an ordered cyclic sequence of 2n n-bit strings (or codewords) such that successive codewords differ by the complementation of a single bit. If the codewords are considered to be

28

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

vertices of an n-dimensional binary cube, it is easy to conclude that Gray code order of subsets corresponds to a Hamiltonian path in the binary cube. We will occasionally refer in the sequel to nodes of binary cubes instead of subsets. Although a binary cube may have various Hamiltonian paths, we will deﬁne only one such path, called the binary-reﬂected Gray code [17] that has a number of advantages, for example, easy generation and traversing a subcube in full before going to other subcube. The (binary reﬂected) Gray code order of nodes of n-dimensional binary cube can be deﬁned in the following way: For n = 1 the nodes are numbered g(0) = 0 and g(1) = 1, in this order, If g(0), g(1), . . . , g(2n − 1) is the Gray code order of nodes of an n-dimensional binary cube, then g(0) = 0g(0), g(1) = 0g(1), . . . , g(2n − 1) = 0g(2n − 1), g(2n ) = 1g(2n − 1), g(2n + 1) = 1g(2n − 2), . . . , g(2n+1 − 2) = 1g(1), g(2n+1 − 1) = 1g(0) is a Gray code order of nodes of a (n + 1)-dimensional binary cube. As an example, for n = 3 the order is g(0) = 000, g(1) = 001, g(2) = 011, g(3) = 010, g(4) = 110, g(5) = 111, g(6) = 101, g(7) = 100. First, let us see how two nodes u and v can be compared in Gray code order. We assume that a node x is represented by a bitstring x1 ≥ x2 . . . xn . This corresponds to decimal node address x = 2n−1 x1 + 2n−2 x2 + · · · + 2xn−1 + xn where 0 ≤ x ≤ 2n − 1. Let i be the most signiﬁcant (or leftmost) bit where u and v differ, that is, u[l] = v[l] for l < i and u[i] = v[i]. Then u < v if and only if u[1] + u[2] + · · · + u[i] is an even number. For instance, 11100 < 10100 < 10110. The above comparison method gives a way to ﬁnd Gray code address t of a node u (satisfying g(t) = u ), using the following simple procedure; it ranks the Gray code sequences. procedure rank GC(n, u, t); sum ← 0; t ← 0; for l ← 1 to n do { sum ← sum + u[l]; if sum is odd then t ← t + 2n−l }. The inverse operation, ﬁnding the binary address u of node having Gray code address t (0 ≤ t ≤ 2n − 1), can be performed by the following procedure; it unranks the Gray code sequences. procedure unrank GC( n,u,t); sum ← 0; q ← t; size ← 2n ; for l ← 1 to n do { size ← size/2; if q ≥ size then {q ← q − size; s ← 1} else s ← 0 ; if sum + s is even then u[l] ← 0 else u[l] ← 1; sum ← sum + u[l]}.

RANKING AND UNRANKING OF SUBSETS AND VARIATIONS IN GRAY CODES

29

The important property of the Gray code order is that corresponding nodes of a binary cube deﬁne an edge of the binary cube whenever they are neighbors in the Gray code order (this property is not valid for the lexicographic order 0, 1, 2, . . . , 2n − 1 of binary addresses). The reﬂected Gray code order for subsets has been generalized for variations [7,15]. Gray codes of variations have application in analog to digital conversion of data. We establish a n-ary reﬂected Gray code order of variations as follows. Let x = x1 ≥ x2 . . . xm and y = y1 y2 . . . ym be two variations. Then x < y iff there exist i, 0 ≤ i ≤ m, such that xj = yj for j < i and either x1 + x2 + . . . + xi−1 is even and xi < yi or x1 + x2 + · · · + xi−1 is odd and xi >yi . We now prove that the order is a minimal change order. Let x and y be two consecutive variations in given order, x < y, and let xj = yj for j < i and xi = yi . There are two cases. If xi < yi then Xi = x1 + x2 + · · · + xi−1 is even and yi = xi + 1. Thus Xi+1 and Yi+1 have different parity, since Yi+1 = Xi+1 + 1. It means that either xi+1 = yi+1 = 0 or xi+1 = yi+1 = n − 1 (the (i + 1)th element in x is the maximum at that position while the (i + 1) –the element in y is the minimum at given position, and they are the same because of different parity checks). Similarly we conclude Yj = Xj + 1 and xj = yj for all j>i + 1. The case xi >yi can be analyzed in analogous way, leading to the same conclusion. As an example, 3-ary reﬂected Gray code order of variations out of {0, 1, 2} is as follows (the variations are ordered columnwise):

000 122 200 001 002 012 011 010

121 120 110 111 112

201 202 212 211 210

020 102 220 021 101 221 022 100 222.

It is easy to check that, at position i(1 ≤ i ≤ m), each element repeats nm−i times. The repetition goes as follows, in a cyclic manner: 0 repeats nm−i times, 1 repeats nm−i times, . . . , n − 1 repeats nm−i times, and then these repetitions occur in reverse order, that is n − 1 repeats nm−i times, . . . , 0 repeats nm−i times. Ranking and unranking procedures for variations in the n-ary reﬂected Gray code are described in the work by Flores [15].

30

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

1.12 GENERATING COMBINATORIAL OBJECTS AT RANDOM In many cases (e.g., in probabilistic algorithms), it is useful to have means of generating elements from a class of combinatorial objects uniformly at random (an unbiased generator). Instead of testing new hypothesis on all objects of given kind, which may be time consuming, several objects chosen at random can be used for testing, and likelihood of hypothesis can be established with some certainty. There are several ways of choosing a random object of given kind. All known ways are based on the correspondence between integer or real number(s) and combinatorial objects. This means that objects should be ordered in a certain fashion. We already described two general ways for choosing a combinatorial object at random. We now describe one more way, by using random number series. This method uses a series of random numbers in order to avoid large integers in generating a random instance of an object. Most known techniques in fact generate a series of random numbers. This section will present methods for generating random permutations and integer partitions. A random subset can easily be generated by ﬂipping coin for each of its elements. 1.12.1

Random Permutation and Combination

There exist a very simple idea of generating a random permutation of A = {a1 , . . . , an }. One can generate an array x1 , x2 , . . . , xn of random numbers, sort them, and obtain the destination indices for each element of A in a random permutation. The ﬁrst m elements of the array can be used to determine a random (m, n)-combination (the problem of generating combinations at random is sometimes called random sampling). Although very simple, the algorithm has O(n log n) time complexity [if random number generation is allowed at most O(log n) time]. We therefore describe an alternative solution that leads to a linear time performance. Such techniques for generating permutations of A = {a1 , . . . , an } at random ﬁrst appeared in the works by the Durstenfeld [8] and Hoses [24], and repeated in the works by Nijeshius [25] and Reingold [30]. The algorithm uses a function random (x) that generates a random number x from interval (0,1), and is as follows. for i ← 1 to n − 1 do { random(xi ); ci xi (n − i + 1) + 1; j ← i − 1 + ci ; exchange ai with aj }. As an example, we consider generating a permutation of {a, b, c, d, e, f } at random. Random number x1 = 0.7 will choose 6 × 0.7 + 1 = 5th element e as the ﬁrst element in a random permutation, and decides the other elements considering the set {b, c, d, a, f } (e exchanged with a). The process is repeated: another random number, say x2 = 0.45, chooses 5 × 0.45 + 1 = 3rd element d from {b, c, d, a, f } to be the

GENERATING COMBINATORIAL OBJECTS AT RANDOM

31

second element in a random permutation, and b and d are exchanged. Thus, random permutation begins with e, d, and the other elements are decided by continuing same process on the set {c, b, a, f }. Assuming that random number generator takes constant time, the algorithm runs in linear time. The same algorithm can be used to generate combinations at random. The ﬁrst m iterations of the for loop determine (after sorting, if such output is preferable) a combination of m out of n elements. Uniformly distributed permutations cannot be generated by sampling a ﬁnite portion of a random sequence and the standard method [8] does not preserve randomness of the x-values due to computer truncations. Truncation problems appear with other methods as well.

1.12.2

Random Integer Partition

We now present an algorithm from the work by Nijenhius and Wilf [26] that generates a random integer partition. It uses the distribution of the number of partitions RP(n,m) of n into parts not greater than m. First, we determine the ﬁrst part. An example of generating random partition of 12 will be easier to follow than to show formulas. Suppose a random number generator gives us r1 = 0.58. There are 77 partitions of 12. In lexicographic order, the random number should point to 0.58 × 77 = 44.66th integer partition. We want to avoid rounding and unranking here. Thus, we merely determine the largest part such. Looking at the distribution RP(12,m) of partitions of 12 (Section 1.2), we see that all integer partitions with ranks between 35 and 47 have the largest part equal to 5. What else we need in a random partition of 12? We need a random partition of 12 − 5 = 7 such that its largest part is 5 (the second part cannot be larger than the ﬁrst part). There are RP(7, 5) = 13 such partitions. Let the second random number be r2 = 0.78. The corresponding partition of 7 has the rank 0.78 × 13 = 10.14. Partitions of 7 ranked between 9 and 11 have the largest part equal to 4. It remains to ﬁnd a random partition of 7 − 4 = 3 with largest part 4 (which in this case is not a real restriction). There are RP(3, 3) = 3 partitions as candidates let r3 = 0.20. Then 0.20 × 3 = 0.6 points to the third (and remaining) parts of size 1. However, since the random number is taken from open interval (0,1), in our scheme the partition n = n will never be chosen unless some modiﬁcation to our scheme is made. Among few possibilities, we choose that the value < 1 as the rank actually points to the available partition with the maximal rank. Thus, we decide to choose partition 3 = 3, and the random partition of 12 that we obtained is 12 = 5 + 4 + 3. An algorithm for generating random rooted trees with prescribed degrees (where the number of nodes of each down degree is speciﬁed in advance) is described in the work by Atkinson [3]. A linear time algorithm to generate binary trees uniformly at random, without dealing with large integers is given in the work by Korsch [20]. An algorithm for generating valid parenthesis strings (each open parenthesis has its matching closed one and vice versa) uniformly at random is described in the work

32

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

by Arnold and Sleep [2]. It can be modiﬁed to generate binary trees in the bitstring notation at random.

1.13 UNRANKING WITHOUT LARGE INTEGERS Following the work by Stojmenovic [38], this section describes functions mapping the interval [0 . . . 1) into the set of combinatorial objects of certain kind, for example, permutations, combinations, binary and t-ary trees, subsets, variations, combinations with repetitions, permutations of combinations, and compositions of integers. These mappings can be used for generating these objects at random, with equal probability of each object to be chosen. The novelty of the technique is that it avoids the use of very large integers and applies the random number generator only once. The advantage of the method is that it can be applied for both random object generation and dividing all objects into desirable sized groups. We restrict ourselves to generating only one random number to obtain a random instance of a combinatorial object but request no manipulation with large integers. Once a random number g in [0,1) is taken, it is mapped into the set of instances of given combinatorial object by a function f(g) in the following way. Let N be the number of all instances of a combinatorial object. The algorithm ﬁnds the instance x such that the ratio of the number of instances that precede x and the total number of instances is ≤ g . In other words, it ﬁnds the instance f(g) with the ordinal number

gN + 1. In all cases that will be considered in this section, each instance of given combinatorial object may be represented as a sequence x1 . . . xm , where xi may have integer values between 0 and n (m and n are two ﬁxed numbers), subject to constraints that depend on particular case. Suppose that the ﬁrst k − 1 elements in given instance are ﬁxed, that is, xi = ai , 1 ≤ i < k. We call them (k − 1) -ﬁxed instances. Let a1 < · · · < ah be all possible values of xk of a given (k − 1) -ﬁxed instance. By S(k, u), S(k, ≤ u), and S(k, ≥ u), we denote the ratio of the number of (k − 1) -ﬁxed instances for which xk = au (xk ≤ au , and xk ≥ au respectively) and the number of (k − 1) -ﬁxed instances. In other words, these are the probabilities (under uniform distribution) that an instance for which xi = ai , 1 ≤ i < k, has the value in variable xk which is = au , ≤ au , and ≥ au , respectively. Clearly, S(k, u) = S(k, ≤ u) − S(k, ≤ u − 1) and S(k, ≥ u) = 1 − S(k, ≤ u − 1). Thus S(k, ≤ u) − S(k, ≤ u − 1) S(k, u) = . S(k, ≥ u) 1 − S(k, ≤ u − 1) Therefore S(k, ≤ u) = S(k, ≤ u − 1) + (1 − S(k, ≤ u − 1))

S(k, u) . S(k, ≥ u)

Our method is based on the last equation. The large numbers can be avoided in cases when S(k, u)/S(k, ≥ u) is explicitly found and is not a very large integer. This

33

UNRANKING WITHOUT LARGE INTEGERS

condition is satisﬁed for combinations, permutations, t-ary trees, variations, subsets, and other combinatorial objects. Given g from [0, . . . , 1), let l be chosen such that S(1, ≤ u − 1) < g ≤ S(1, ≤ u). Then x1 = au and the ﬁrst element of combinatorial object ranked g is decided. To decide the second element, the interval [S(1, ≤ u − 1) . . . S(1, ≤ u)) containing g can be linearly mapped to interval [0 . . . 1) to give the new value of g as follows: g←

g − S(1, ≤ u − 1) . S(1, ≤ u) − S(1, ≤ u − 1)

The search for the second element proceeds with the new value of g. Similarly the third, . . . , mth elements are found. The algorithm can be written formally as follows, where p and p stand for S(k, ≤ u − 1) and S(k, ≤ u) , respectively. procedure object( m, n, g); p ← 0;

for k ← 1 to m do u ← 1; p ← S(k, 1);

while p ≤ g do p ← p; u ← u + 1;

S(k, u) p ← p + (1 − p ) S(k, ≥ u) xk ← au ; g − p g← . p − p

Therefore the technique does not involve large integers iff S(k, u)/S(k, ≥ u) is not a large integer for any k and u in the appropriate ranges (note that S(k, ≥ 1) = 1 ). The method gives theoretically correct result. However, in practice the random number g and intermediate values of p are all truncated. This may result in computational imprecision for larger values of m or n. The instance of a combinatorial object obtained by a computer implementation of above procedure may differ from the theoretically expected one. However, the same problem is present with other known methods (as noted in the previous section) and thus this method is comparable with others in that sense. Next, in applications, randomness is practically preserved despite computational errors. 1.13.1

Mapping [0 . . . 1) Into the Set of Combinations

Each (m, n)-combination is speciﬁed as an integer sequence x1 , . . . , xm such that 1 ≤ x1 < · · · < xm ≤ n. The mapping f(g) is based on the following lemma. Recall that (k-1)-ﬁxed combinations are speciﬁed by xi = ai , 1 ≤ i < k. Clearly, possible values for xk are a1 = ak−1 + 1, a2 = ak−1 + 2, . . . , ah = n (thus h = n − ak−1 ).

34

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

Lemma 1. The ratio of the number of (k − 1 )-ﬁxed (m,n)-combinations for which xk = j and the number of (k − 1 )-ﬁxed combinations for which xk ≥ j is (m − k + 1)/(n − j + 1) whenever j>ak−1 . Proof. Let yk−i = xi − j, k < i ≤ n. The (k − 1 )-ﬁxed (m,n)-combinations for which xk = j correspond to (m − k, n − j) -combinations y1 , . . . , ym−k , and their number is C(m − k, n − j). Now let yk−i+1 = xi − j + 1, k ≤ i ≤ n. The (k − 1 )-ﬁxed combinations for which xk ≥ j correspond to (m − k + 1, n − j + 1) -combinations y1 . . . ym−k+1 , and their number is C(m − k + 1, n − j + 1). The ratio in question is C(m − k, n − j) m−k+1 = .䊏 C(m − k + 1, n − j + 1) n−j+1 Using the notation introduced in former section for any combinatorial objects, let u = j − ak−1 . Then, from Lemma 1 it follows that S(k, u) m−k+1 = S(k, ≥ u) n − u − ak−1 + 1 for the case of (m,n)-combinations, and we arrive at the following procedure that ﬁnds the (m,n)-combination with ordinal number gC(m, n) + 1. The procedure uses variable j instead of u, for simplicity. procedure combination( m,n,g); j ← 0; p ← 0;

for k ← 1 to m do j ← j + 1; m−k+1 p← ; n−j+1

while p ≤ g do p ← p; j ← j + 1; p ← p + (1 − p ) xk ← j; g − p . g← p − p

m−k+1 n−j+1

A random sample of size m out of the set of n objects, that is, a random (m,n)combination can be found by choosing a real number g in [0, . . . , 1) and applying the map f (g) = combination(m,n,g). Each time the procedure combination (m,n,g) enters for or while loop, the index j increases by 1; since j has n as upper limit, the time complexity of the algorithm is O(n), that is, linear in n. Using the correspondences established in Chapter 1, the same procedure may be applied to the case of combinations with repetitions and compositions of n into m parts.

UNRANKING WITHOUT LARGE INTEGERS

1.13.2

35

Random Permutation

Using the deﬁnitions and obvious properties of permutations, we conclude that, after choosing k − 1 beginning elements in a permutation, each of the remaining n − k + 1 elements has equal chance to be selected next. The list of unselected elements is kept in an array remlist. This greatly simpliﬁes the procedure that determines the permutation x1 . . . xn with index gP(n) + 1. procedure permutation( n,g); for i ← 1 to n do remlisti ← i; for k ← 1 to n do { u ← g(n − k + 1) + 1; xk ← remlistu ; for i ← u to n − k do remlisti ← remlisti+1 ; g ← g(n − k + 1) − u + 1}. The procedure is based on the same choose and exchange idea as the one used in the previous section but requires one random number generator instead of a series of n generators. Because the lexicographic order of permutations and the ordering of real numbers in [0 . . . 1) coincide, the list of remaining elements is kept sorted, which causes higher time complexity O(n2 ) of the algorithm. Consider an example. Let n = 8 and g = 0.1818. Then 0.1818 ∗ 8! +1 = 7331 and the ﬁrst element of 7331st 8-permutation is u = 0.1818 × 8 + 1 = 2; the remaining list is 1,3,4,5,6,7,8 (7331 − 1 × 5040 = 2291; this step is for veriﬁcation only, and is not part of the procedure). The new value of g is g = 0.1818 × 8 − 2 + 1 = 0.4544, and new u is u = 0.4544 × 7 + 1 = 4; the second element is 4th one in the remaining list, which is 5; the remaining list is 1,3,4,6,7,8. Next update is g = 0.4544 × 7 − 3 = 0.1808 and u = 0.1808 × 6 + 1 = 2; the 3rd element is the 2nd in the remaining list, that is, 3; the remaining list is 1,4,6,7,8. The new iteration is g = 0.1808 × 6 − 1 = 0.0848 and u = 0.0848 × 5 + 1 = 1; the 4th element is 1st in the remaining list, that is, 1; the remaining list is 4,6,7,8. Further, g = 0.0848 × 5 = 0.424 and u = 0.424 × 4 + 1 = 2; the 5th element is 2nd in the remaining list, that is, 6; the new remaining list is 4,7,8. The next values of g and u are g = 0.424 × 4 − 1 = 0.696 and u = 0.696 × 3 + 1 = 3; the 6th element is 3rd in the remaining list, that is, 8; the remaining list is 4,7. Finally, g = 0.696 × 3 − 2 = 0.088 and u = 0.088 × 2 + 1 = 1; the 7th element is 1st in the remaining list, that is, 4; now 7 is left, which is the last, 8th element. Therefore, the required permutation is 2,5,3,1,6,8,4,7. All (m,n)-permutations can be obtained by taking all combinations and listing permutations for each combination. Such an order that is not lexicographic one, and (m,n)-permutations are in this case refereed to as the permutations of combinations. Permutation of combinations with given ordinal number can be obtained by running the procedure combination ﬁrst, and continuing the procedure permutation afterwards, with the new value of g that is determined at the end of the procedure combination.

36

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

1.13.3

Random t-Ary Tree

The method requires to determine S(k, 1), S(k, u), and S(k, ≥ u). Each element bk has two possible values, that is, bk = a1 = 0 or bk = a2 = 1; thus it is sufﬁcient to ﬁnd S(k,1) and S(k, ≥ 1). S(k, ≥ 1) is clearly equal to 1. Let the sequence bk . . . btn contains q ones, the number of such sequences is D(k − 1, q). Furthermore, D(k,q) of these sequences satisfy bk = 0. Then S(k, 1) =

(t(n − q) − k + 1)(tn − k − q + 2) D(k, q) = . D(k − 1, q) (t(n − q) − k + 2)(tn − k + 1)

This leads to the following simple algorithm that ﬁnds the t-ary tree f(g) with the ordinal number gB(t, n) + 1. procedure tree( t, n, g); p ← 0; q ← n;

for k ← 1 to tn do bk ← 0; (t(n − q) − k + 1)(tn − k − q + 2) ; p← (t(n − q) − k + 2)(tn − k + 1) if p ≤ g then { p ← p; bk ← 1; q ← q − 1; p ←1 } g−p g← p − p The time complexity of the above procedure is clearly linear, that is, O(tn). 1.13.4

Random Subset and Variation

There is a fairly simple mapping procedure for subsets in binary representation. Let g = 0. a1 . . . an an+1 . . . be number g written in the binary numbering system. Then the subset with ordinal number gS(n) + 1 is coded as a1 . . . an . Using a relation between subsets and compositions of n into any number of parts, described procedure can be also used to ﬁnd the composition with ordinal number gCM(n) + 1 . A mapping procedure for variations is a generalization of the one used for subsets. Suppose that the variations are taken out of the set {0, 1, . . . , n − 1}. Let g = 0. a1 a2 . . . am am+1 . . . be the number g written in the number system with the base n, that is, 0 ≤ ai ≤ n − 1 for 1 ≤ i ≤ m. Then the variation indexed gV (m, n) + 1 is coded as a1 a2 . . . am . If variations are ordered in the n-ary reﬂected Gray code then the variation indexed

gV (m, n) + 1 is coded as b1 b2 . . . bm , where b1 = a1 , bi = ai if a1 + a2 + · · · + ai−1 is even and bi = n − 1 − ai otherwise (2 ≤ i ≤ m ).

REFERENCES

37

REFERENCES 1. Akl SG. A comparison of combination generation methods. ACM Trans Math Software 1981;7(1):42–45. 2. Arnold DB. Sleep MR. Uniform random generation of balanced parenthesis strings. ACM Trans Prog Lang Syst 1980;2(1):122–128. 3. Atkinson M. Uniform generation of rooted ordered trees with prescribed degrees. Comput J 1993;36(6):593–594. 4. Akl SG, Olariu S, Stojmenovic I. A new BFS parent array encoding of t-ary trees, Comput Artif Intell 2000;19:445–455. 5. Belbaraka M, Stojmenovic I. On generating B-trees with constant average delay and in lexicographic order. Inform Process Lett 1994;49(1):27–32. 6. Brualdi RA. Introductory Combinatorics. North Holland; 1977. 7. Cohn M. Afﬁne m-ary gray codes, Inform Control 1963;6:70–78. 8. Durstenfeld R. Random permutation (algorithm 235). Commun ACM 1964;7:420. 9. Djoki´c B, Miyakawa M, Sekiguchi S, Semba I, Stojmenovi´c I. A fast iterative algorithm for generating set partitions. Comput J 1989;32(3):281–282. 10. Djoki´c B, Miyakawa M, Sekiguchi S, Semba I, Stojmenovi´c I. Parallel algorithms for generating subsets and set partitions. In: Asano T, Ibaraki T, Imai H, Nishizeki T, editors. Proceedings of the SIGAL International Symposium on Algorithms; August 1990; Tokyo, Japan. Lecture Notes in Computer Science. Volume 450. p 76–85. 11. Ehrlich G. Loopless algorithms for generating permutations, combinations and other combinatorial conﬁgurations. J ACM 1973;20(3):500–513. 12. Er MC. Fast algorithm for generating set partitions. Comput J 1988;31(3):283–284. 13. Er MC. Lexicographic listing and ranking t-ary trees. Comp J 1987;30(6):569–572. 14. Even S. Algorithmic Combinatorics. New York: Macmillan; 1973. 15. Flores I. Reﬂected number systems. IRE Trans Electron Comput 1956;EC-5:79–82. 16. Gupta UI, Lee DT, Wong CK. Ranking and unranking of B-trees. J Algor 1983;4: 51–60. 17. Heath FG. Origins of the binary code. Sci Am 1972;227(2):76–83. 18. Johnson SM. Generation of permutations by adjacent transposition, Math Comput 1963;282–285. 19. Knuth DE. The Art of Computer Programming, Volume 1: Fundamental Algorithms. Reading, MA: Addison-Wesley; 1968. 20. Korsch JF. Counting and randomly generating binary trees. Inform Process Lett 1993;45:291–294. 21. Lehmer DH. The machine tools of combinatorics. In: Beckenbach E, editor. Applied Combinatorial Mathematics. Chapter 1. New York: Wiley; 1964. p 5–31. 22. Lucas J, Roelants van Baronaigien D, Ruskey F. On rotations and the generation of binary trees. J Algor 1993;15:343–366. 23. Misfud CJ, Combination in lexicographic order (Algorithm 154). Commun ACM 1963;6(3):103. 24. Moses LE, Oakford RV. Tables of Random Permutations. Stanford: Stanford University Press; 1963.

38

GENERATING ALL AND RANDOM INSTANCES OF A COMBINATORIAL OBJECT

25. Nijenhius A, Wilf H. Combinatorial Algorithms. Academic Press; 1978. 26. Nijenhius A, Wilf HS. A method and two algorithms on the theory of partitions. J Comb Theor A 1975;18:219–222. 27. Ord-Smith RJ. Generation of permutation sequences. Comput J 1970;13:152–155 and 1971;14:136–139. 28. Parberry I. Problems on Algorithms. Prentice Hall; 1995. 29. Payne WH, Ives FM. Combination generators. ACM Transac Math Software 1979;5(2):163–172. 30. Reingold EM, Nievergelt J, Deo N. Combinatorial Algorithms. Englewood Cliffs, NJ: Prentice Hall; 1977. 31. Sedgewick R. Permutation generation methods. Comput Survey 1977;9(2):137–164. 32. Semba I. An efﬁcient algorithm for generating all partitions of the set {1, . . . , n}. J Inform Process 1984;7:41–42. 33. Semba I. An efﬁcient algorithm for generating all k-subsets (1 ≤ k ≤ m ≤ n) of the set {1, 2, . . . , n} in lexicographic order. J Algor 1984;5:281–283. 34. Semba I. A note on enumerating combinations in lexicographic order. J Inform Process 1981;4(1):35–37. 35. Skiena S. Implementing Discrete Mathematics: Combinatorics and Graph Theory with Mathematica. Addison-Wesley; 1990. 36. Stojmenovic I. Listing combinatorial objects in parallel. Int J Parallel Emergent Distrib Syst 2006;21(2):127–146. 37. Stojmenovi´c I, Miyakawa M. Applications of a subset generating algorithm to base enumeration, knapsack and minimal covering problems. Comput J 1988;31(1):65–70. 38. Stojmenovi´c I. On random and adaptive parallel generation of combinatorial objects. Int J Comput Math 1992;42:125–135. 39. Trotter HF, Algorithm 115. Commun ACM 1962;5:434–435. 40. Wells MB, Elements of Combinatorial Computing. Pergamon Press; 1971. 41. Xiang L, Ushijima K, Tang C. Efﬁcient loopless generation of Gray codes for k-ary trees. Inform Process Lett 2000;76:169–174. 42. Zaks S. Lexicographic generation of ordered trees. Theor Comput Sci 1980;10:63–82. 43. Zoghbi A, Stojmenovi´c I. Fast algorithms for generating integer partitions. Int J Comput Math 1998;70:319–332.

CHAPTER 2

Backtracking and Isomorph-Free Generation of Polyhexes LUCIA MOURA and IVAN STOJMENOVIC

2.1 INTRODUCTION This chapter presents applications of combinatorial algorithms and graph theory to problems in chemistry. Most of the techniques used are quite general, applicable to other problems from various ﬁelds. The problem of cell growth is one of the classical problems in combinatorics. Cells are of the same shape and are in the same plane, without any overlap. If h copies of the same shape are connected (two cells are connected by sharing a common edge), then they form an h-mino, polyomino, animal, or polygonal system (various names given in the literature for the same notion). Three special cases of interest are triangular, square, and hexagonal systems, which are composed of equilateral triangles, squares, and regular hexagons, respectively. Square and hexagonal systems are of genuine interest in physics and chemistry, respectively. The central problem in this chapter is the study of hexagonal systems. Figure 2.1 shows a molecule and its corresponding hexagonal system. Enumeration and exhaustive generation of combinatorial objects are central topics in combinatorial algorithms. Enumeration refers to counting the number of distinct objects, while exhaustive generation consists of listing them. Therefore, exhaustive generation is typically more demanding than enumeration. However, in many cases, the only available methods for enumeration rely on exhaustive generation as a way of counting the objects. In the literature, sometimes “enumeration” or “constructive enumeration” are also used to refer to what we call here “exhaustive generation.” An important issue for enumeration and exhaustive generation is the notion of isomorphic or equivalent objects. Usually, we are interested in enumerating or generating only one copy of equivalent objects, that is, only one representative from each isomorphism class. Polygonal systems are considered different if they have

Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

39

40

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

FIGURE 2.1 (a) A benzenoid hydrocarbon and (b) its skeleton graph.

different shapes; their orientation and location in the plane are not important. For example, the two hexagonal systems in Figure 2.2b are isomorphic. The main theme in this chapter is isomorph-free exhaustive generation of polygonal systems, especially polyhexes. Isomorph-free generation provides at the same time computational challenges and opportunities. The computational challenge resides in the need to recognize or avoid isomorphs, which consumes most of the running time of these algorithms. On the contrary, the fact that equivalent objects do not need to be generated can substantially reduce the search space, if adequately exploited. In general, the main algorithmic framework employed for exhaustive generation is backtracking, and several techniques have been developed for handling isomorphism issues within this framework. In this chapter, we present several of these techniques and their application to exhaustive generation of hexagonal systems. In Section 2.2, we present benzenoid hydrocarbons, a class of molecules in organic chemistry, and their relationship to hexagonal systems and polyhexes. We also take a close look at the parameters that deﬁne hexagonal systems, and at the topic of symmetries in hexagonal systems. In Section 2.3, we introduce general algorithms for isomorph-free exhaustive generation of combinatorial structures, which form the

FIGURE 2.2 Hexagonal systems with (a) h = 11 and (b) h = 4 hexagons.

POLYHEXES AND HEXAGONAL SYSTEMS

41

theoretical framework for the various algorithms presented in the sections that follow. In Section 2.4, we provide a historical overview of algorithms used for enumeration and generation of hexagonal systems. In Sections 2.5–2.7, we present some of the main algorithmic techniques used for the generation of polyhexes. We select algorithms that illustrate the use of different general techniques, and that were responsible for breakthroughs regarding the sizes of problems they were able to solve at the time they appeared. Section 2.5 presents a basic backtracking algorithm for the generation of hexagonal, square, and triangular systems. In Section 2.6, we describe a lattice-based algorithm that uses a “cage” to reduce the search space. In Section 2.7, we present two algorithms based on McKay’s canonical construction path, each combined with a different way of representing a polyhex. Finally, Section 2.8 deals with a different problem involving chemistry, polygonal systems, and graph theory, namely perfect matchings in hexagonal systems and the Kekul´e structure of benzenoid hydrocarbons.

2.2 POLYHEXES AND HEXAGONAL SYSTEMS 2.2.1

Benzenoid Hydrocarbons

We shall study an important class of molecules in organic chemistry, the class of benzenoid hydrocarbons. A benzenoid hydrocarbon is a molecule composed of carbon (C) and hydrogen (H) atoms. Figure 2.1a shows a benzenoid called naphthalene, with molecular formula C10 H8 (i.e., 10 carbon atoms and 8 hydrogen atoms). In general, a class of benzenoid isomers is deﬁned by a pair of invariants (n, s) and written as the chemical formula Cn Hs , where n and s are the numbers of carbons and hydrogens, respectively. Every carbon atom with two neighboring carbon atoms bears a hydrogen, while no hydrogen is attached to the carbon atoms with three neighboring carbon atoms. A simpliﬁed representation of the molecule as a (skeleton) graph is given in Figure 2.1b. Carbon atoms form six-membered rings, and each of them has four valences. Hydrogen atoms (each with one valence) and double valences between carbon atoms are not indicated in the corresponding graph, which has carbon atoms as vertices with edges joining two carbon atoms linked by one or two valences. In the sequel, we shall study the skeleton graphs, which will be called polyhex systems. A polyhex (system) is a connected system of congruent regular hexagons such that any two hexagons either share exactly one edge or are disjoint. The formula C6 H6 is represented by only one hexagon and is the simplest polyhex, called benzene. Presently, we shall be interested only in the class of geometrically planar, simply connected polyhexes. A polyhex is geometrically planar when it does not contain any overlapping edges, and it is simply connected when it has no holes. The geometrically planar, simply connected polyhexes may conveniently be deﬁned in terms of a cycle on a hexagonal lattice; the system is found in the interior of this cycle, which represents the boundary (usually called the “perimeter”) of the system. With the aim of avoiding confusion, we have adopted the term “hexagonal system” (HS) for a geometrically planar, simply connected polyhex (see Fig. 2.2a for an HS with

42

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

h = 11 hexagons). A plethora of names has been proposed in the literature for what we just deﬁned (or related objects), such as benzenoid systems, benzenoid hydrocarbons, hexagonal systems, hexagonal animal, honeycomb system, fusene, polycyclic aromatic hydrocarbon, polyhex, and hexagonal polyomino, among others. A polyhex in plane that has holes is called circulene; it has one outer cycle (perimeter) and one or a few inner cycles. The holes may have the size of one or more hexagons. Coronoids are circulenes such that all holes have the size of at least two hexagons. There are other classes of polyhexes; for instance, a helicenic system is a polyhex with overlapping edges or hexagons if drawn in a plane (or a polyhex in three-dimensional space). Fusenes are generalizations of polyhexes in which the hexagons do not need to be regular. 2.2.2

Parameters of a Hexagonal System

We shall introduce some parameters and properties of HSs in order to classify them. The leading parameter is usually the number of hexagons h in an HS (it is sometimes called the “area”). For example, HSs in Figures 2.1b, 2.2a and b have h = 2, 11, and 4 hexagons, respectively. The next parameter is the perimeter p, or the number of vertices (or edges) on its outer boundary. The HSs in Figures 2.1b, 2.2a and b have perimeter p = 10, 32, and 16, respectively. A vertex of an HS is called internal (external) if it does not (does, respectively) belong to the outer boundary. A vertex is internal if and only if it belongs to three hexagons from the given HS. The number of internal vertices i of HSs in Figures 2.1b, 2.2a and b is i = 0, 7 and 1, respectively. Let the total number of vertices and edges in HSs be n = p + i and m, respectively. From Euler theorem, it follows that n − m + h = 1. There are p external and m − p internal edges. Since every internal edge belongs to two hexagons, we obtain 6h = 2(m − p) + p, that is, m = 3h + p/2. Therefore, n − 2h − p/2 = 1 and i = 2h − p/2 + 1 [31]. It follows that p must be even, and that i is odd if and only if p is divisible by 4. Consider now the relation between invariants n and s of a benzenoid isomer class Cn Hs and other parameters of an HS. The number of vertices is n = i + p = 2h + p/2 + 1 = 4h − i + 2. We shall ﬁnd the number of hydrogen atoms s, which is equal to the number of degree-2 vertices in an HS (all such vertices belong to the perimeter). Let t be the number of tertiary (degree 3) carbon atoms on the perimeter. Therefore, p = s + t since each vertex on the perimeter has degree either 2 or 3. We have already derived m = 3h + p/2. Now, if one assigns each vertex to all its incident edges, then each edge will be “covered” twice; since each internal vertex has degree 3, it follows that 2m = 3i + 3t + 2s. Thus, 6h + p = 3i + 3t + 2s, that is, 3t = 6h + p − 3i − 2s. By replacing t = p − s, one gets 3p − 3s = 6h + p − 3i − 2s, which implies s = 2p − 6h + 3i. Next, i = 2h − p/2 + 1 leads to s = p/2 + 3. It is interesting that s is a function of p independent of h. The reverse relation reads p = 2s − 6, which, together with p = s + t, gives another direct relation t = s − 6. Finally, h = (n − s)/2 + 1 follows easily from 2h = n − p/2 − 1 and p = 2s − 6. Therefore, there exists a oneto-one correspondence between pairs (h, p) and (n, s). More precisely, the number of different HSs corresponding to the same benzenoid isomer class Cn Hs is equal to the number of (nonisomorphic) HSs with area h = (n − s)/2 + 1 and perimeter

POLYHEXES AND HEXAGONAL SYSTEMS

43

p = 2s − 6. The study of benzenoid isomers is surveyed by Brunvoll et al. [9] and Cyrin et al. [15]. We shall list all the types of chemical isomers of HSs for increasing values of h ≤ 5; h = 1: C6 H6 ; h = 2: C10 H8 ; h = 3: C13 H9 , C14 H10 ; h = 4: C16 H10 , C17 H11 , C18 H12 ; h = 5: C19 H11 , C20 H12 , C21 H13 , C22 H14 . The number of edges m of all isomers with given formula Cn Hs is m = (3n − s)/2. The number of edges m and number of internal vertices i are sometimes used as basic parameters; for example, n = (4m − i + 6)/5, s = (2m − 3i + 18)/5. The Dias parameter is an invariant for HSs and is deﬁned as the difference between the number of vertices and number of edges in the graph of internal edges, obtained by deleting the perimeter from a given HS, reduced by 1. In other words, it is the number of tree disconnections of internal edges. The number of vertices of the graph of internal edges is i + t (only s vertices with degree 2 on the perimeter do not “participate”), and the number of internal edges is m − p. Thus, the Dias parameter for an HS is d = i + t − m + p − 1 = h − i − 2 = p/2 − h − 3. The pair of invariants (d, i) plays an important role in connection with the periodic table for benzenoid hydrocarbons [19,21]. The other parameters of an HS can be expressed in terms of d and i as follows: n = 4d + 3i + 10, s = 2d + i + 8, h = d + i + 2, and p = 4d + 2i + 10. The pair (d, i) can be obtained from pair (n, s) as follows: d = (3s − n)/2 − 7, i = n − 2s + 6. There are several classiﬁcations of HSs. They are naturally classiﬁed with respect to their area and perimeter. Another classiﬁcation is according to the number of internal vertices: catacondensed systems have no internal vertices (i = 0), while pericondensed systems have at least one internal vertex (i > 0). For example, HSs in Figures 2.1a, 2.3b, c and d are catacondensed, while HSs in Figures 2.2a,b and 2.3a are pericondensed. An HS is catacondensed if and only if p = 4h + 2. Thus, the perimeter of a catacondensed system is an even number not divisible by 4. All catacondensed systems are Hamiltonian, since the outer boundary passes through all vertices. Catacondensed HSs are further subdivided into unbranched (also called chains, where each hexagon, except two, has two neighbors) and branched (where at least one hexagon has three neighboring hexagons). Pericondensed HSs are either basic or composite, depending on whether they cannot (or can, respectively) be cut into two pieces by cutting along only one edge. 2.2.3

Symmetries of a Hexagonal System

We introduce the notion of free and ﬁxed HSs. Free HSs are considered distinct if they have different shapes; that is they are not congruent in the sense of Euclidean geometry. Their orientation and location in the plane are of no importance. For example, the two systems shown in Figure 2.2b represent the same free HS. Different free HSs are nonisomorphic. Fixed HSs are considered distinct if they have different shapes or orientations. Thus, the two systems shown in Figure 2.2b are different ﬁxed HSs. The key to the difference between ﬁxed and free HSs lies in the symmetries of the HSs. An HS is said to have a certain symmetry when it is invariant under the transformation(s) associated with that symmetry. In other words, two HSs are considered to be the same ﬁxed HSs, if one of them can be obtained by translating the other, while two

44

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

HSs are considered the same free HSs, if one of then can be obtained by a sequence of translations and rotations that may or may not be followed by a central symmetry. A regular hexagon has 12 different transformations that map it back to itself. These are rotations for 0˚, 60˚, 120˚, 180˚, 240˚, 300˚, and central symmetry followed by the same six rotations. Let us denote the identity transformation (or rotation for 0˚) by ε, rotation for 60˚ by ρ, and central symmetry by μ (alternatively, a mirror symmetry can be used). Then, these 12 transformation can be denoted as ε, ρ, ρ2 , ρ3 , ρ4 , ρ5 , μ, ρμ, ρ2 μ, ρ3 μ, ρ4 μ, and ρ5 μ, respectively. They form a group generated by ρ and μ. When these transformations are applied on a given HS, one may or may not obtain the same HS, depending on the kinds of symmetries that it has. The transformations of an HS that produce the same ﬁxed HS form a subgroup of the transformation group G = {ε, ρ, ρ2 , ρ3 , ρ4 , ρ5 , μ, ρμ, ρ2 μ, ρ3 μ, ρ4 μ, ρ5 μ}. Every free HS corresponds to 1, 2, 3, 4, 6, or 12 ﬁxed HSs, depending on its symmetry properties. Thus, the HSs are classiﬁed into symmetry groups of which there are eight possibilities, which are deﬁned here as subgroups of G: D6h = G, C6h = {ε, ρ, ρ2 , ρ3 , ρ4 , ρ5 }, D3h = {ε, ρ2 , ρ4 , μ, ρ2 μ, ρ4 μ}, C3h = {ε, ρ2 , ρ4 }, D2h = {ε, ρ3 , μ, ρ3 μ}, C2h = {ε, ρ3 }, C2v = {ε, μ}, and Cs = {ε}. The number of ﬁxed HSs for each free HS under these symmetry groups are speciﬁcally (in the same order): 1, 2, 2, 4, 3, 6, 6, and 12. Note that the number of elements in the subgroup multiplied by the number of ﬁxed HSs for each free HS is 12 for each symmetry group. For example, HS in Figure 2.1b has symmetry group D2h , while HSs in Figure 2.2a and b are associated with Cs (have no symmetries). Examples of HSs with other symmetry groups are given in Figure 2.3.

FIGURE 2.3 Hexagonal systems and their symmetry groups.

POLYHEXES AND HEXAGONAL SYSTEMS

45

Let H(h) and N(h) denote the number of ﬁxed and free (nonisomorphic) HSs with h hexagons, respectively. Furthermore, N(h) can be split into the numbers for the different symmetries, say N(G, h), where G indicates the symmetry group. Then H(h) = N(D6h , h) + 2N(C6h , h) + 2N(D3h , h) + 4N(C3h , h) + 3N(D2h , h) + 6N(C2h , h) + 6N(C2v , h) + 12N(Cs , h). For the free HSs, N(h) = N(D6h , h) + N(C6h , h) + N(D3h , h) + N(C3h , h) + N(D2h , h) + N(C2h , h)+ N(C2v , h) + N(Cs , h). Eliminating N(Cs , h), we get N(h) =

1 12

[11N(D6h , h) + 10N(C6h , h) + 10N(D3h , h) + 8N(C3h , h) +9N(D2h , h) + 6N(C2h , h) + 6N(C2v , h) + H(h)] .

(2.1)

As we will see later, some algorithms use the above formula in order to compute N(h) via computing the quantities on the right-hand side and avoiding the often costly computation of N(Cs , h). 2.2.4

Exercises

1. Let n = p + i be the number of vertices and m be the number of edges of an HS. Show that m = 5h + 1 − i. 2. Prove that√ the maximal number of internal vertices of a HS, for ﬁxed area h, is 2h + 1 − 12h − 3 [30,37]. Also, show that the perimeter of an HS satisﬁes √ 2 12h − 3 ≤ p ≤ 4h + 2. 3. Prove that 0 ≤ ≤ h/3and1/2(1 − (−1)i ) ≤ ≤ i [9]. 4. Prove the following upper and lower bounds for the Dias parameter [9]: √ 12h − 3 − h − 3 ≤ d ≤ h − 2. √ 5. Prove that 2h + 1 + 12h − 3 ≤ n ≤ 4h + 2 [37]. √ 6. Prove that 3 + 12h − 3 ≤ s ≤ 2h + 4 [33].

√ 12h − 3 ≤ m ≤ 5h + 1 [30,37]. 7. Prove that 3h + 8. Prove that√the possible values of s are within the range [30,37] 2 1/2(n + 6n) − n ≤ s ≤ n + 2 − 2 (n − 2)/4 . √

9. Prove that n − 1 + (n − 2)/4 ≤ m ≤ 2n − (n + 6n)/2 [37]. 10. Show that s + 3 s/2 − 9 ≤ m ≤ s + (s2 − 6s)/12 − 2 [15].

√ 11. Prove that (m − 1)/5 ≤ h ≤ m − (2m − 2 + 4m + 1)/3 [37].

√ 12. Prove that 1 + (2m − 2 + 4m + 1)/3 ≤ n ≤ m + 1 − (m − 1)/5 [37].

√ 13. Show that 3 − 2m + 3 (2m − 2 + 4m + 1)/3 ≤ s ≤ m + 3 − 3 (m − 1)/5 [9]. 14. Let d(r, s) be the distance between the vertices r and s in an HS (which is the length of the shortest path between them) [32]. The Wiener index W is the sum of all distances (between all pairs of vertices) in a given HS. Show that if B1 and B2 are catacondensed HSs with an equal number of hexagons, then W(B1 ) = W(B2 ) (mod 8).

46

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

2.3 GENERAL ALGORITHMS FOR ISOMORPH-FREE EXHAUSTIVE GENERATION In this section, we present general algorithms for generating exactly one representative of each isomorphism class of any kind of combinatorial objects. The reader is referred to the works by Brinkmann [6] and McKay [46] for more information on this type of methods and to the survey by Faulon et al. [26] for a treatment of these methods in the context of enumerating molecules. The algorithms in this section generate combinatorial objects of size n + 1 from objects of size n via backtracking, using a recursive procedure that should be ﬁrst called with parameters of an empty object, namely X = [ ] and n = 0. They are presented in a very general form that can be tailored to the problem at hand. In particular, procedures IsComplete(X) and IsExtendible(X) can be set to ensure that all objects of size up to n or exactly n are generated, depending on the application. In addition, properties of the particular problem can be used in order to employ further prunings, which cannot be speciﬁed in such a general framework but which are of crucial importance. The basic algorithms we consider here (Algorithms BasicGenA and BasicGenB) exhaustively generate all objects using backtracking and only keep one representative from each isomorphism class. They both require a method for checking whether the current object generated is the one to be kept in its isomorphism class. In Algorithm BasicGenA, this is done by remembering previously generated objects, which are always checked for isomorphism against the current object. Algorithm BasicGenA (X = [x1 , x2 , . . . , xn ], n) redundancyFound = false if (IsComplete(X)) then if (for all Y ∈ GenList: ¬ AreIsomorphic(X, Y )) then GenList = GenList ∪ {X} process X else redundancyFound = true if ((¬redundancyFound) and (IsExtendible(X))) then for all extensions of X: X = [x1 , x2 , . . . , xn , x ] if (IsFeasible(X )) then BasicGenA(X , n + 1) The third line of Algorithm BasicGenA is quite expensive in terms of time, since an isomorphism test AreIsomorphic(X, Y ) between X and each element Y in GenList must be computed; see the works by Kocay [43] and McKay [44] for more information on isomorphism testing and by McKay [45] for an efﬁcient software package for graph isomorphism. In addition, memory requirements for this algorithm become a serious issue as all the previously generated objects must be kept. In Algorithm BasicGenB, deciding whether the current object is kept is done by a rule specifying who is the canonical representative of each isomorphism class. Based on this rule, the current object is only kept if it is canonical within its isomorphism class. A commonly used rule is that the canonical object be the lexicographically

GENERAL ALGORITHMS FOR ISOMORPH-FREEEXHAUSTIVE GENERATION

47

smallest one in its isomorphism class. In this case, a simple method for canonicity testing (a possible implementation of procedure IsCanonical(X) below) is one that generates all objects isomorph to the current object X by applying all possible symmetries, and rejecting X if it ﬁnds a lexicographically smaller isomorph. Algorithm BasicGenB (X = [x1 , x2 , . . . , xn ], n) redundancyFound = false if (IsComplete(X)) then if (IsCanonical(X)) then process X else redundancyFound = true if ((¬redundancyFound) and (IsExtendible(X))) then for all extensions of X: X = [x1 , x2 , . . . , xn , x ] if (IsFeasible(X )) then BasicGenB(X , n + 1) In Algorithm BasicGenB, the pruning given by the use of ﬂag redundancyFound assumes that the canonicity rule guarantees that a complete canonical object that has a complete ancestor must have a canonical complete ancestor. This is a reasonable assumption, which is clearly satisﬁed when using the “lexicographically smallest” rule. The next two algorithms substantially reduce the size of the backtracking tree by making sure it contains only one copy of each nonisomorphic partial object. That is, instead of testing isomorphism only for complete objects, isomorphism is tested at each tree level. Faradzev [24] and Read [50] independently propose an orderly generation algorithm. This algorithm also generates objects of size n by extending objects of size n − 1 via backtracking. Like in Algorithm BasicGenB, it uses the idea that there is a canonical representative of every isomorphism class that is the object that needs to be generated (say, the lexicographically smallest). When a subobject of certain size is generated, canonicity testing is performed, and if the subobject is not canonical, the algorithm backtracks. Note that the canonical labeling and the extensions of an object must be deﬁned so that each canonically labeled object is the extension of exactly one canonical object. In this way, canonical objects of size n are guaranteed to be the extension of exactly one previously generated canonical object of size n − 1. Algorithm OrderlyGeneration (X = [x1 , x2 , . . . , xn ], n) if (IsComplete(X)) then process X. if (IsExtendible(X)) then for all extensions of X: X = [x1 , x2 , . . . , xn , x ] if (IsFeasible(X )) then if (IsCanonical(X )) then OrderlyGeneration(X , n + 1) McKay [46] proposes a related but distinct general approach, where generation is done via a canonical construction path, instead of a canonical representation. In this method, objects of size n are generated from objects of size n − 1, where only canonical augmentations are accepted. So, in this method the canonicity testing is

48

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

substituted by testing whether the augmentation from the smaller object is a canonical one; the canonicity of the augmentation is veriﬁed by the test IsParent(X,X ) in the next algorithm. The canonical labeling does not need to be ﬁxed as in the orderly generation algorithm. Indeed, the relabeling of an object of size n − 1 must not affect the production of an object of size n via a canonical augmentation. Algorithm McKayGeneration1 (X = [x1 , x2 , . . . , xn ], n) if (IsComplete(X)) then process X. if (IsExtendible(X)) then for all inequivalent extensions of X: X = [x1 , x2 , . . . , xn , x ] if (IsFeasible(X )) then if (IsParent(X,X )) then /* if augmentation is canonical */ McKayGeneration1(X , n + 1) The previous algorithm may appear simpler than it is, because a lot of its key features are hidden in the test (IsParent(X,X )). This test involves several concepts and computations related to isomorphism. We delay discussing more of these details until they are needed in the second application of this method in Section 2.7.2. The important and nontrivial fact established by McKay regarding this algorithm is that if X has two extensions X1 and X2 for which X is the parent, then it is enough that these objects be inequivalent extensions to guarantee that they are inequivalent. In other words, Algorithm McKayGeneration1 produces the same generation as Algorithm McKayGeneration2 below: Algorithm McKayGeneration2 (X = [x1 , x2 , . . . , xn ], n) if (IsComplete(X)) then process X. if (IsExtendible(X)) then S=∅ for all extensions of X: X = [x1 , x2 , . . . , xn , x ] if (IsFeasible(X )) then if (IsParent(X,X ) then /* if augmentation is canonical */ S = S ∪ {X } Remove isomorph copies from S for all X ∈ S do McKayGeneration2(X , n + 1) Indeed, McKay establishes that in Algorithm McKayGeneration2 the isomorph copies removed from set S must come from symmetrical extensions with respect to the parent object X, provided that the function IsParent(X,X ) is deﬁned as prescribed in his article [46]. Algorithm McKayGeneration1 is the stronger, more efﬁcient version of this method, but for some applications it may be more convenient to use the simpler form of Algorithm McKayGeneration2. McKay’s method is related to the reverse search method of Avis and Fukuda [1]. Both are based on the idea of having a rule for deciding parenthood for objects, which could otherwise be generated as extensions of several smaller objects. However, they differ in that Avis and Fukuda’s method is not concerned with eliminating isomorphs, but simply repeated objects. Note that all the given algorithms allow for generation from scratch when called with parameters X = [ ] and n = 0, as well as from the complete isomorph-free list

HISTORICAL OVERVIEW OF HEXAGONALSYSTEM ENUMERATION

49

of objects at level n by calling the algorithm once for each object. In the latter case, for Algorithms BasicGenB and OrderlyGeneration, the list of objects at level n must be canonical representatives, while for Algorithms BasicGenA and McKayGeneration, any representative of each isomorphism class can be used.

2.4 HISTORICAL OVERVIEW OF HEXAGONAL SYSTEM ENUMERATION In this section, we concentrate on the main developments in the enumeration and generation of hexagonal systems, which are geometrically planar and simply connected polyhexes, as deﬁned earlier. A similar treatment can be found in the article by Brinkmann et al. [8]. For more information on the enumeration and generation of hexagonal systems and other types of polyhexes, the reader is referred to the books by Dias [19,20], Gutman and Cyvin [17,33,34], Gutman et al. [36], and Trinajstic [59]. For a recent treatment on generating and enumerating molecules, see the survey by Faulon et al. [26]. The enumeration of HSs is initiated by Klarner [40] who lists all HSs for 1 ≤ h ≤ 5 and is followed by a race for counting HSs for larger values of h. The presence of faster computers and development of better algorithms enabled the expansion of known generation and enumeration results. The ﬁrst class of algorithms is based on the boundary code. Knop et al. [42] used this method for counting and even drawing HSs for h ≤ 10. Using the same approach, HSs were exhaustively generated for h = 11 [53] and h = 12 [38]. The boundary code is explained in Section 2.5, where we give a basic backtracking algorithm (following the framework of Algorithm BasicGenB) for the generation of triangular, square, and hexagonal systems. The next generation of algorithms uses the dualistic angle-restricted spanning tree (DAST) code [49], which is based on the dualistic approach associated with a general polyhex [3]. This approach was used for generating all HSs with h = 13 [47], h = 14 [48], h = 15 [49], and h = 16 [41]. This method uses a graph embedded on the regular hexagonal lattice containing the HS. Each vertex is associated with the center of a hexagon, and two vertices are connected if they share an edge. This graph is rigid; that is, angles between adjacent edges are ﬁxed. Therefore, any spanning tree of this graph completely determines the HS. DAST algorithms exhaustively generate canonical representatives of dualist spanning trees using again a basic backtracking algorithm. The next progress was made by Tosic et al. [56], who propose a lattice-based method that uses a “cage,” which led to the enumeration of HSs for h = 17. This is a completely different method from the previous ones. The lattice-based approach focuses on counting the number of HSs on the right-hand side of equation (2.1) in order to compute N(h). This algorithm accomplishes this by generating nonisomorphic HSs with nontrivial symmetry group based on a method of Redelmeier [51], and by generating all ﬁxed HSs by enclosing them on a triangular region of the hexagonal lattice, which they call a cage. The cage algorithm is described in Section 2.6.

50

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

The boundary edge code algorithm by Caporossi and Hansen [12] enabled the generation of all HSs for h = 18 to h = 21. The labeled inner dual algorithm by Brinkmann et al. [7] holds the current record for the exhaustive generation of polyhexes, having generated all polyhexes for h = 22 to h = 24. Each of these two algorithms use a different representation for the HSs, but both use the generation by canonical path introduced by McKay [46] given by the framework of Algorithms McKayGeneration1 and McKayGeneration2 from Section 2.3. Both algorithms are described in Section 2.7. TABLE 2.1

Results on the Enumeration and Exhaustive Generation of HSs

h

N(h)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

1 1 3 7 22 81 331 1453 6505 30086 141229 669584 3198256 15367577 74207910 359863778 1751594643 8553649747 41892642772 205714411986 1012565172403 4994807695197 24687124900540 122238208783203

25 26 27 28 29 30 31 32 33 34 35

606269126076178 3011552839015720 14980723113884739 74618806326026588 372132473810066270 1857997219686165624 9286641168851598974 46463218416521777176 232686119925419595108 1166321030843201656301 5851000265625801806530

Algorithm

Type

– – – – – – – – – BC BC BC DAST DAST DAST DAST CAGE BEC BEC BEC BEC LID LID LID

– – – – – – – – – G G G G G G G E G G G G G G G

FLM FLM FLM FLM FLM FLM FLM FLM FLM FLM FLM

E E E E E E E E E E E

Year

Reference

1965 1983 1986 1988 1989 1990 1990 1990 1995

[40] [42] [53] [38] [47] [48] [49] [41] [56]

1998

[12]

2002

[7]

2002

[60]

BACKTRACKING FOR HEXAGONAL, SQUARE,AND TRIANGULAR SYSTEMS

51

Finally, V¨oge et al. [60] give an algorithm that enables a breakthrough on the enumeration of HSs, allowing for the counting of all HSs with h = 25 to h = 35. Like the cage algorithm, they use a lattice-based approach, but instead of brute force generation of all ﬁxed HSs, they employ transfer matrices and the ﬁnite lattice method by Enting [23] to compute H(h). Their algorithm is based on counting using generating functions, so they enumerate rather than exhaustively generate HSs. Table 2.1 provides a summary of the results obtained by enumeration and exhaustive generation algorithms. For each h, it shows in order: the number N(h) of free HSs with h hexagons, the ﬁrst algorithmic approach that computed it, whether the algorithm’s type was exhaustive generation (G) or enumeration (E), publication year, and reference. When the year and reference are omitted, it is to be understood that it can be found in the next row for which these entries are ﬁlled.

2.5 BACKTRACKING FOR HEXAGONAL, SQUARE, AND TRIANGULAR SYSTEMS In this section, we presents a basic backtracking algorithm, based on the boundary code, for listing all nonisomorphic polygonal systems. This algorithm is applicable for hexagonal [53], triangular [22], and square [54] systems. First, each of these “animals” is decoded as a word over an appropriate alphabet. A square system can be drawn such that each edge is either vertical or horizontal. If a counterclockwise direction along the perimeter of a square system is followed, each edge can be coded with one of four characters, say from the alphabet {0, 1, 2, 3}, where 0, 1, 2, and 3 correspond to four different edge orientations (see Fig. 2.4b). For example, the square system in Figure 2.4a can be coded, starting from the bottom-left corner, as the word 001001221000101221012232212332330333. The representation of a square system is obviously not unique, since it depends on the starting point. Similarly, each hexagonal or triangular system can be coded using words from the alphabet {0, 1, 2, 3, 4, 5}, where each character corresponds to one of six possible edge orientations, as indicated in Figure 2.4d. Figure 2.4c shows a triangular system that can be coded, starting from bottommost vertex and following counterclockwise order, as 11013242345405; the hexagonal system in Figure 2.4e can be coded, starting from the bottom-left vertex and following counterclockwise direction, as 01210123434505. Let li (u) denote the number of appearances of the letter i in the word u. For example, l4 (01210123434505) = 2, since exactly two characters in the word are equal to 4. Lemma 1 [54] A word u corresponds to a square system if and only if the following conditions are satisﬁed: 1. l0 (u) = l2 (u) and l1 (u) = l3 (u), and 2. for any nonempty proper subword w of u, l0 (w) = l2 (w) or l1 (w) = l3 (w). Proof. A given closed path along the perimeter can be projected onto Cartesian coordinate axes such that 0 and 2 correspond to edges in the opposite directions (and,

52

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

FIGURE 2.4 Boundary codes for polygonal systems.

similarly, edges 1 and 3), as indicated in Figure 2.4b. Since the number of projected “unit” edges in direction 0 must be equal to the number of projected unit edges in direction 2, it follows that l0 (u) = l2 (u). Similarly, l1 (u) = l3 (u). To avoid selfintersections along the perimeter, both equalities shall not be met simultaneously for any proper subword of u. 䊏 Lemma 2 [53] A word u = u1 u2 ...up corresponds to a hexagonal system if and only if the following conditions are satisﬁed: 1. l0 (u) = l3 (u), l1 (u) = l4 (u), and l2 (u) = l5 (u), 2. for any nonempty proper subword w of u, l0 (w) = l3 (w) or l1 (w) = l4 (w), or l2 (w) = l5 (w), and 3. ui+1 = ui ± 1 (mod 6), i = 1, 2, ..., p − 1. Proof. Condition 3 follows easily from the hexagonal grid properties. To verify condition 1, consider, for example, a vertical line passing through the middle of each horizontal edge (denoted by 0 or 3). Each such vertical line intersects only edges marked by 0 or 3, and no other edge. Therefore, in order to return to the starting

BACKTRACKING FOR HEXAGONAL, SQUARE,AND TRIANGULAR SYSTEMS

53

point of the perimeter, each path along the boundary must make equal number of moves to the right and to the left; thus, the number of 0s and 3s in a hexagonal system is equal. The other two equalities in 1 follow similarly. Condition 2 assures that no self-intersection of the boundary occurs. 䊏 Lemma 3 [22] A word u corresponds to a triangular system if and only if the following conditions are satisﬁed: 1. l0 (u) − l3 (u) = l4 (u) − l1 (u) = l2 (u) − l5 (u), and 2. no proper subword of u satisﬁes condition 1. Proof. Project all edges of a closed path onto a line normal to directions 2 and 5. All edges corresponding to characters 2 and 5 have zero projections while the length of projections of edges 0, 1, 3, and 4 are equal; edges 0 and 1 have equal sign, which is opposite to the sign of projections of edges 3 and 4. The sum of all projections for a closed path is 0 and therefore l0 (u) + l1 (u) = l3 (u) + l4 (u). Analogously, l1 (u) + l2 (u) = l4 (u) + l5 (u). 䊏 The same polygonal system can be represented by different words. Since the perimeter can be traversed starting from any vertex, there are p words in the clockwise and p words in the counterclockwise direction for the same ﬁxed polygonal system u1 u2 ...up . In addition, central symmetry and rotations can produce additional isomorphic polygonal systems. In the case of hexagonal and triangular systems, each free polygonal system corresponds to at most 12 ﬁxed ones, as discussed above (the symmetry groups for hexagonal and triangular systems coincide). Thus, each HS or TS (triangular system) may have up to 24p isomorphic words (words that deﬁne the same free system). They can be generated by repeated application and combination of the following transformations: α(u1 u2 ...up ) = u2 u3 ...up u1 , β(u1 u2 ...up ) = up up−1 ...u2 u1 and σ(u1 u2 ...up ) = σ(u1 )σ(u2 )...σ(up ), where σ is an arbitrary element of the transformation group G described above. G is generated by permutations μ = 123450 (μ(t) = t + 1 (mod 6)) and ρ = 345012 (ρ(t) = 3+ t (mod 6)). In the case of square systems, each word has similarly up to 2p words obtained by starting from an arbitrary vertex and following (counter) clockwise direction, and up to eight isomorphic systems corresponding to the symmetry group of a square. The group is generated by a rotation of π/4 and a central symmetry, which correspond to permutations μ = 1230 (μ(t) = t + l (mod 4)) and ρ = 2301 (ρ(t) = 2 + t (mod 4)), respectively. The transformation group contains eight elements {ε, μ, μ2 , μ3 , ρ, μρ, μ2 ρ, μ3 ρ}. In summary, each polygonal system can be coded by up to 24p words and only one of them shall be selected to represent it. We need a procedure to determine whether or not a word that corresponds to a polygonal system is the representative among all words that correspond to the same polygonal system. As discussed in Section 2.3, Algorithm BasicGenA is time and space inefﬁcient when used for large computations, where there are millions of representatives. Instead, we employ

54

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

Algorithm BasicGenB. We may select, say, the lexicographically ﬁrst word among all isomorphic words as the canonical representative. We shall now determine the area of a polygonal system, that is the number of polygons in its interior. Given a closed curve, it is well known that the curvature integration gives the area of the interior of the curve. Let (xi , yi ) be the Cartesian coordinates of the vertex where the ith edge (corresponding to the element ui in the word u) starts. Then, the area obtained by curvature integration along the perimeter of a given by a word u = u1 u2 . . . un is p p polygonal system that is represented P = 1/2 i=1 (xi+1 − xi )(yi+1 − yi ) = 1/2 i=1 (xi yi+1 − xi+1 yi ). The number of polygons h in the interior of a polygonal √ system √ is then obtained when P is divided by the area of one polygon, namely 3/4, 3 3/2, and 1 for triangular, hexagonal, and square systems, respectively, where each edge is assumed to be of length 1. It remains to compute the coordinates (xi , yi ) of vertices along the perimeter. They can be easily obtained by projecting each of the unit vectors corresponding to directions 0, 1, 2, 3, 4, and 5 of triangular/hexagonal and 0, 1, 2, and 3 of square system onto the Cartesian coordinates. Let u = u1 u2 ...uj be a given word over the appropriate alphabet. If it represents a polygonal system, then conditions 1 and 2 are satisﬁed from the appropriate lemma (Lemma 1, 2, or 3). Condition 1 means that the corresponding curve is closed and condition 2 that it has no self-intersections. Suppose that condition 2 is satisﬁed but not condition 1; that is, the corresponding curve has no self-intersections and is not closed. We call such a word addable. It is clear that u can be completed to a word u = u1 u2 ...up , for some p > j, representing a polygonal system if and only if u is addable. If u is addable, then it can be extended to a word u1 u2 ...uj uj+1 , where uj+1 has the following possible values: uj − 1, uj + 1 (mod 6) for hexagonal, uj + 4, uj + 5, uj , uj + 1, and uj + 2 (mod 6) for triangular (note that obviously uj+1 = uj + 3 (mod 6)), and uj − 1, uj , and uj + 1 (mod 4) for square (note that uj+1 = uj + 2 (mod 4)) systems. Algorithm BacktrackSj,h (p) Procedure GenPolygonalSystem(U = [u1 , . . . , uj ], j, p) { if (U = [u1 , . . . , uj ] represents a polygonal system) then if (U = [u1 , . . . , uj ] is a canonical representative) then { ﬁnd its area h; Sj,h ← Sj,h + 1; print u1 , . . . , uj } else if (U = (u1 , . . . , uj is addable) and (j < p) then for all feasible values of uj+1 with respect to U do GenPolygonalSystem([u1 , . . . , uj , uj+1 ], j + 1, p) } begin main u1 ← 0; GenPolygonalSystem([u1 ], 1, p) end main

55

BACKTRACKING FOR HEXAGONAL, SQUARE,AND TRIANGULAR SYSTEMS

TABLE 2.2

Number of Square and Triangle Systems with h Polygons h

S T

1

2

3

4

5

6

7

8

9

10

11

12

13

1 1

1 1

2 1

5 3

12 4

25 12

107 24

363 66

1248 159

4460 444

1161

3226

8785

Algorithm BacktrackSj,h (p) determines the numbers Sj,h of polygonal systems with perimeter j and area h, for j ≤ p (i.e., for all perimeters ≤ p simultaneously). Due to symmetry and lexicographical ordering for the choice of a canonical representative, one can ﬁx u1 = 0. This algorithm follows the framework given by Algorithm BasicGenB in Section 2.3. This algorithm was used to produce the numbers Sp,h and the results were obtained for the following ranges: p ≤ 15 for triangular [22], p ≤ 22 for square [54], and p ≤ 46 for hexagonal [53] systems. Using the relation p ≤ 4h + 2 for hexagonal, p ≤ h + 2 for triangular, and p ≤ 2h + 2 for square systems, the numbers of polygonal systems with exactly h polygons are obtained for the following ranges of h: h ≤ 13 (triangular), h ≤ 10 (square), and h ≤ 11 (hexagonal systems). These numbers are given for square and triangular systems in Table 2.2. The data for hexagonal systems can be found in the corresponding entries in Table 2.1. Table 2.3 gives some enumeration results [53] for the number of nonisomorphic HSs with area h and perimeter p.

TABLE 2.3

Hexagonal Systems with Area h and Perimeter p h

p=6 p=8 p = 10 p = 12 p = 14 p = 16 p = 18 p = 20 p = 22 p = 24 p = 26 p = 28 p = 30 p = 32 p = 34 p = 36 p = 38

1

2

3

4

5

6

7

8

9

1 — — — — — — — — — — — — — — — — 1

— — 1 — — — — — — — — — — — — — — 1

— — — 1 2 — — — — — — — — — — — — 3

— — — — 1 1 5 — — — — — — — — — — 7

— — — — — 1 3 6 12 — — — — — — — — 22

— — — — — — 3 4 14 24 36 — — — — — — 81

— — — — — — 1 3 10 25 68 106 118 — — — — 331

— — — — — — — 1 9 21 67 144 329 453 411 — — 1435

— — — — — — — — 4 15 55 154 396 825 1601 1966 1489 6505

56

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

2.5.1

Exercises

1. Prove that p ≤ h + 2 for triangular systems. 2. Prove that p ≤ 2h + 2 for square systems. 3. Find the projections of each unit vector corresponding to directions 0, 1, 2, 3, 4, and 5 of triangular/hexagonal and 0, 1, 2, and 3 of square system onto the x and y coordinate axes. 4. An unbranched catacondensed HS can be coded as a word u = u1 u2 ...up over the alphabet {0, 1, 2, 3, 4, 5}, where ui corresponds to the vector joining ith and (i + l)th hexagon in the HS (the vector notation being as deﬁned in Fig. 2.4). Prove that a word u is the path code of an unbranched catacondensed HS if and only if for every subword y of u, |l0 (y) + l5 (y) − l3 (y) − l2 (y)| + |l1 (y) + l2 (y) − l4 (y) − l5 (y)| > 1. Show that there always exist a representative of an equivalence class beginning with 0 and having 1 as the ﬁrst letter different from 0 [55]. 5. Describe an algorithm for generating and counting unbranched catacondensed HSs [55]. 6. The test for self-intersection given as condition 2 in Lemmas 1–3 requires O(n) time (it sufﬁces to apply it only for subwords that have different beginning but the same ending as the tested word). Show that one can use an alternative testing that will require constant time, by using a matrix corresponding to the appropriate grid that stores 1 for every grid vertex occupied by a polygon and 0 otherwise. 7. Design an algorithm for generating and counting branched catacondensed HSs [11]. 8. Design an algorithm for generating and enumerating coronoid hydrocarbons, which are HSs with one hole (they have outer and inner perimeters) [10]. 9. Let u1 u2 . . . up be a boundary code of an HS as deﬁned above. Suppose that an HS is traced along the perimeter in the counterclockwise direction. A new boundary code x = x1 x2 ...xp is deﬁned over the alphabet {0, 1} such that xi = 0 if ui = ui−1 + l (mod 6) and xi = 1 if ui = ui−1 − 1 (mod 6) (where y0 = yp ). Show that the number of 1s is t while the number of 0s is s, where s and t are deﬁned in Section 2.2.2. Design an algorithm for generating and counting HSs based on the new code. 10. Design an algorithm for generating HSs with area h which would be based on adding a new hexagon to each HS of area h − 1. 11. Let h, p, i, m, n, and d be deﬁned for square (triangular, respectively) systems analogously to their deﬁnitions for HSs. Find the corresponding relations between them. 2.5.2

Open Problems

Find a closed formula or a polynomial time algorithm to compute the number of nonisomorphic hexagonal (triangular, square) systems with area h.

GENERATION OF HEXAGONAL SYSTEMSBY A CAGE ALGORITHM

57

2.6 GENERATION OF HEXAGONAL SYSTEMS BY A CAGE ALGORITHM This section describes an algorithm by Tosic et al. [56] that enumerates nonisomorphic hexagonal systems and classiﬁes them according to their perimeter length. This algorithm therefore performs the same counting as the one in the previous section but is considerably faster (according to the experimental measurements), and was the ﬁrst to enumerate all HSs with h ≤ 17. The algorithm is a lattice-based method that uses the results of the enumeration and classiﬁcation of polyhex hydrocarbons according to their various kinds of symmetry and equation (2.1). These enumerations are performed by separate programs, which are not discussed here. Known results on the enumeration and classiﬁcation of HSs according to symmetries are surveyed by Cyrin et al. [14]. In the present computation, the symmetry of the HSs is exploited by adopting the method of Redelmeier [51]. This method is improved in some aspects by using a boundary code (see the previous section) for the HSs. The exploitation of symmetry involves separate enumeration of the ﬁxed HSs on one hand (H(h)) and free HSs of speciﬁc (nontrivial) symmetries on the other (other values on the right-hand side of equation (2.1)). The easiest way to handle a beast (HS) is to put it in a cage. A cage is a rather regular region of the hexagonal grid in which we try to catch all relevant hexagonal systems. This algorithm uses a triangular cage. Let Cage(n) denote a triangular cage with n hexagons along each side. Figure 2.5 shows Cage(9) and exempliﬁes how a coordinate system can be introduced in Cage(n). It is almost obvious that each hexagonal system that ﬁts inside a cage can be placed in the cage in such a way that at least one of its hexagons is on the x-axis of the cage, and at least one of its hexagons is on the y-axis of the cage. We say that such HSs are properly placed in the cage. Thus, we generate and enumerate all HSs that are properly placed in the cage.

FIGURE 2.5 A hexagonal system properly placed in a cage.

58

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

Let B be a free HS with h hexagons and let GB be its symmetry group. It can be easily shown that B can be properly placed in Cage(h) in exactly |GB | ways. Therefore, we can use equation (2.1) in order to determine N(h). This requires the knowledge of N(D6h , h), N(C6h , h), N(D3h , h), N(C3h , h), N(D2h , h), N(C2h , h), and N(C2v , h)), which are found by separate generation algorithms not discussed here, as well as of H(h), the total number of ﬁxed hexagons, which is determined by the algorithm discussed in this section. By using this approach, we completely avoid isomorphism tests, which are considered to be the most time-consuming parts of similar algorithms. Note that this is sufﬁcient for enumeration, but if we need exhaustive generation, isomorphism tests would be required. One needs Cage(h) to be able to catch all properly placed HSs with up to h hexagons. However, it turns out that the beasts are not that wild. Almost all hexagonal systems with h hexagons appear in Cage(h − 1). This allows a signiﬁcant speedup due to the reduction in the search space. Those HSs that cannot be properly placed in Cage(h − 1) can easily be enumerated (see Exercise 3). Therefore, we can restrict our attention to Cage(h − 1), when dealing with hexagonal systems with h hexagons. Let p and q be the smallest x- and y-coordinates (respectively) of all (centers of) hexagons of an HS that is properly placed in Cage(h − 1). Hexagons with coordinates (p, 0) and (0, q) (with respect to the coordinate system of the cage) are named key hexagons. Let H(p, q) denote the set of all HSs with ≤ h hexagons that are properly placed in Cage(h − 1) and their key hexagons on x- and y-axes have coordinates (p, 0) and (0, q), respectively. Figure 2.5 shows one element of H(4, 2). The family {H(p, q) : 0 ≤ p ≤ h − 2, 0 ≤ q ≤ h − 2} is a partition of the set of all hexagonal systems that are well placed in Cage(h − 1). Because of symmetry, it can be veriﬁed that |H(p, q)| = |H(q, p)|, for all p, q ∈ {0, 1, . . . , h − 2}. Thus, the job of enumeration of all properly placed hexagons is reduced to determining |H(p, q)| for all p ≥ q. Given the numbers 0 ≤ p ≤ q ≤ h − 2 and Cage(h − 1), determining |H(p, q)| reduces to generating all hexagons systems from H(p, q). We do that by generating their boundary line. A quick glance at Figure 2.5 reveals that the boundary line of a hexagonal system can be divided into two parts: the left part of the boundary (from the readers point of view), which starts on the y-axis below the key hexagon and ﬁnishes at the ﬁrst junction with x-axis, and the rest of the boundary, which we call the right part of the boundary. We recursively generate the left part of the boundary line. As soon as it reaches the x-axis, we start generating the right part. We maintain the length of the boundary line as well as the area of the hexagonal system. The trick that gives the area of the hexagonal system is simple: hexagons are counted in each row separately, starting from y-axis, such that their number is determined by their x-coordinate. Each time the boundary goes up (down), we add (subtract, respectively) the corresponding x-coordinate. When following the contour of HS in counterclockwise direction (i.e., in the direction of generating HS, see Fig. 2.5), there remain some hexagons out of HS to the left of the vertical contour line that goes down while hexagons to the left of

GENERATION OF HEXAGONAL SYSTEMSBY A CAGE ALGORITHM

59

the vertical line that goes up belong to the HS. The “zigzag” movements do not interfere with the area. Once the generation is over, the area of the HS gives the number of hexagons circumscribed in this manner. The area count is used to eliminate HSs with more than h hexagons, which appear during the generation of systems with h hexagons that belong to H(p, q). However, it would be a waste of time (and computing power) to insist on generating elements of H(p, q) strictly. This would require additional tests to decide whether the left part of the boundary has reached x-axis precisely at hexagon p or not. In addition, once we ﬁnd out we have reached the x-axis at hexagon, say, p + 2, why should we ignore it for the calculation of H(p + 2, q)? We shall therefore introduce another partition of the set of all properly placed HSs. Given h and Cage(h − 1), let H ∗ (q) = h−2 j=0 H(j, q), for all q = 0, 1, . . . , h − 2. It is obvious that {H ∗ (q) : 0 ≤ q ≤ h − 2} is a partition of the set of all HSs with h hexagons that are properly placed in Cage(h − 1). Instead of having two separate phases (generating H(p, q) and adding appropriate number to total), we now have one phase in which generating and counting are put together. We should prevent appearances of hexagonal systems from H(p, q) with p < q. This requires no computational overhead because it can be achieved by forbidding some left and some down turns in the matrix representing the cage. On the contrary, avoiding the forbidden turns accelerates the process of generating the boundary line. The algorithm is a school example of backtracking, thus facing all classical problems of the technique: Even for small values of h the search tree misbehaves, so it is essential to cut it as much as possible. One idea that cuts some edges of the tree is based on the fact that for larger values of q there are some parts of the cage that cannot be reached by hexagonal systems with ≤ h hexagons, but can easily be reached by useless HSs that emerge as a side effect. That is why we can, knowing q, forbid some regions of the cage. The other idea that reduces the search tree is counting the boundary hexagons. A boundary hexagon is a hexagon that has at least one side in common with the boundary line and that is in the interior of the hexagonal system we are generating. It is obvious that boundary hexagons shall be part of the HS, so we keep track of their number. We use that number as a very good criterion for cutting off useless edges in the search tree. The idea is simple: further expansion of the left/right part of the boundary line is possible if and only if there are less than h boundary hexagons the boundary line has passed by. The next idea that speeds up the algorithm is living on credit. When we start generating the left part of the boundary, we do not know where exactly is it going to ﬁnish on the x-axis, but we know that it is going to ﬁnish on the x-axis. In other words, knowing that there is one hexagon on the x-axis that is going to become a part of the HS, we can count it as a boundary hexagon in advance. It represents a credit of the hexagonal bank, which is very eagerly exploited. Thus, many useless HSs are discarded before the left part of the boundary lands on the x-axis. All these ideas together represent the core of the algorithm, which can be outlined as follows.

60

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

Algorithm CageAlgorithm(h) procedure ExpandRightPart(ActualPos,BdrHexgns) { if (EndOfRightPart) then { n ←NoOfHexagons() if (n ≤ h) then { determine p; if (p = q) then total[n] ← total[n] + 1 else total[n] ← total[n] + 2 } } else { FindPossible(ActualPos,FuturePos) while (RightPartCanBeExpanded(ActuallPos, FuturePos)) and (BdrHexgns≤ h) do { ExpandRightPart(FuturePos,update(BdrHexgns)) CalcNewFuturePos(ActualPos,FuturePos) } } } procedure ExpandLeftPart(ActualPos,BdrHexgns) { if (EndOfLeftPart) then ExpandRightPart (RightlnitPos(q), updCredit(BdrHexgns)) else { FindPossible(ActualPos,FuturePos) while (LeftPartCanBeExpanded(ActualPos, FuturePos)) and (BdrHexgns ≤ h) do { ExpandLeftPart(FuturePos,update(BdrHexgns)) CalcNewFuturePos(ActualPos,FuturePos) } } } begin main initialize Cage(h-1); total[1..h] ← 0 for q ← 0 to h − 2 do { initialize y-axis key hexagon(q) ExpandLeftPart(LeftInitPos(q),InitBdrHexgns(q)) } end main

2.6.1

Exercises

1. Design algorithms for counting square and triangular systems, using analogous ideas as these presented in this section for HSs.

TWO ALGORITHMS FOR THE GENERATION OF HSs USING MCKAY’S METHOD

61

2. Design algorithms for generating all HSs with area h and perimeter p, which belong to a given kind of symmetry of HSs (separate algorithms for each of these symmetry classes). 3. Prove that the number of HSs with h hexagons that cannot be placed properly in Cage(h − 1) is (h2 − h + 4)2h−3 . Show that, among them, there are (h2 − 3h + 2)2h−4 pericondensed (with exactly one inner vertex) and (h2 + h + 6)2h−4 catacondensed HSs [56].

2.7 TWO ALGORITHMS FOR THE GENERATION OF HSs USING MCKAY’S METHOD 2.7.1 Generation of Hexagonal Systems Using the Boundary Edge Code Caporossi and Hansen [12] give an algorithm, based on Algorithm McKayGeneration2 seen in Section 2.3, for isomorph-free generation of hexagonal systems represented by their boundary edge code (BEC). Their algorithm was the ﬁrst to generate all the HSs with h = 18 to h = 21 hexagons. We ﬁrst describe the BEC representation of an HS, exempliﬁed in Figure 2.6. Select an arbitrary external vertex of degree 3, and follow the boundary of the HS recording the number of boundary edges of each hexagon it traverses. Then, apply circular shifts and/or a reversal, in order to obtain a lexicographically maximum code. Note that each hexagon can appear one, two or three times as digits in the BEC code. Caporossi and Hansen [12] prove that an HS always start with a digit greater than or equal to 3. Now, two aspects of the algorithm need speciﬁcation: How to determine which sub-HS (of order h − 1) of an HS of order h will be selected to be its parent in the generation tree, and how hexagons are added to existing HSs to create larger HSs. In Figure 2.7, we show the generation tree explored by this algorithm for h = 4. Note that, for example, from the HS with code 5351 we can produce six nonisomorphic HSs, but only three of them are kept as its legitimate children. The rule for determining the parent of an HS is to remove the hexagon corresponding to the ﬁrst digit of its BEC code. In other words, the parent of an HS is the one obtained by

+ b

−

c

a

d e h g

f

a b c d e f g h

+

−

15115315 51153151 11531515 15315151 53151511 31515115 15151153 51511531

51351151 15135115 51513511 15151351 11515135 51151513 35115151 13511515

FIGURE 2.6 Boundary edge code for a hexagonal system.

62

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

FIGURE 2.7 Isomorph-free search tree for h = 4.

removing its ﬁrst hexagon. This operation in rare cases may disconnect the HS. This occurs precisely when the ﬁrst hexagon occurs twice rather than once in the code. In such cases, the HS is orphan and cannot be generated via the algorithm’s generation tree. A specially designed method for generation of orphan HSs must be devised in these cases. However, Caporossi and Hansen [12] proved that orphan HSs do not occur for h ≤ 28, so they did not have to deal with the case of orphan HSs in their search. Next, we describe how hexagons are added to create larger HSs. There are three ways in which a hexagon can be added to an HS, exempliﬁed in Figure 2.8a: 1. A digit x ≥ 3 in the BEC code corresponding to edges of a hexagon such that one of the edges belong only to this hexagon can be replaced by a5b, where a + b + 1 = x and a ≥ 1 and b ≥ 1. 2. A sequence xy in the BEC code with x ≥ 2 and y ≥ 2 can be replaced by (x − 1)4(y − 1). 3. A sequence x1y with x ≥ 2 and y ≥ 2 in the BEC code can be replaced by (x − 1)3(y − 1). In each of the above cases, we must make sure that the addition of the hexagon does not produce holes. This can be accomplished by checking for the presence of a hexagon in up to three adjacent positions, as shown in Figure 2.8b; if any of these hexagons is present, this addition is not valid. Procedure GenerateKids that generates, from an HS P with j hexagons, its children in the search with j + 1 hexagons is outlined next. 1. Addition of hexagons: Any attempt to add a hexagon in the steps below is preceded by a test that guarantees that no holes are created.

TWO ALGORITHMS FOR THE GENERATION OF HSs USING MCKAY’S METHOD

63

FIGURE 2.8 Ways of adding a hexagon to the boundary of an HS.

• Add a 5 in every possible way to the BEC code of P. • If the BEC code of P does not begin with a 5, then add a 4 in every possible way to the BEC code of P; otherwise, only consider the addition of a 4 adjacent to the initial 5. • If the BEC code of P has no 5 and at most two 4s, consider the addition of a 3. 2. Parenthood validation: For each HS generated in the previous step, verify that its BEC code can begin on the new hexagon. Reject the ones that cannot. The correctness of the above procedure comes from the rule used to deﬁne who is the parent of an HS, and from the lexicographical properties of the BEC code. Now, putting this into the framework of Algorithm McKayGeneration2, from Section 2.3,

64

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

gives the ﬁnal algorithm. Algorithm BECGeneration(P, Pcode, j) if (j = h) then output P else { S=GenerateKids(P, Pcode) Remove isomorph copies from S for all (P , Pcode ) ∈ S do BECGeneration(P , Pcode , j + 1) } Caporossi and Hansen [12] discuss the possibility of using Algorithm McKayGeneration1, which require computing the symmetries of the parent HS to avoid the isomorphism tests on the fourth line of the above algorithm. However, they report that experiments with this variant gave savings of only approximately 1 percent. Thus, this seem to be a situation in which it is worth using the simpler algorithm given by Algorithm McKayGeneration2. 2.7.2 Generation of Hexagonal Systems and Fusenes Using Labeled Inner Duals Brinkmann et al. [7,8] exhaustively generate HSs using an algorithm that constructs all fusenes and ﬁlters them for HSs. Fusenes are a generalization of polyhexes that allows for irregular hexagons. They only consider simply connected fusenes, of which HSs are therefore a special case. In this section, we shall describe their algorithm for constructing fusenes. Testing whether a fusene ﬁts the hexagonal lattice (checking whether it is an HS) can be easily done, and it is not described here. This algorithm was the ﬁrst, and so far the only one, to exhaustively generate all HSs with h = 22 to h = 24. We ﬁrst describe the labeled inner dual graph representation of a fusene. The inner dual graph has one vertex for each hexagon, and two vertices are connected if their corresponding hexagons share an edge. This graph does not uniquely describe a fusene, but using an appropriate labeling together with this graph does, see Figure 2.9. Following the boundary cycle of the fusene, associate as many labels with a vertex as the number of times its corresponding hexagon is traversed, so that each label records the number of edges traversed each time. In the cases in which the hexagon occurs only once in the boundary, the label is omitted, as the number of edges in the 3 (5)

(5) 1

2 (5)

(5) 2

FIGURE 2.9 Hexagonal systems, their inner dual, and labeled inner dual graphs.

TWO ALGORITHMS FOR THE GENERATION OF HSs USING MCKAY’S METHOD

65

boundary is completely determined from 6−deg(v), where deg(v) is the degree of the corresponding vertex. Brinkmann et al. characterize the graphs that are inner duals of fusenes, which they call id-fusenes. They show that a planar embedded graph G is an id-fusene if and only if (1) G is connected, (2) all bounded faces of G are triangles, (3) all vertices not on the boundary have degree 6, and (4) for all vertices, the total degree, that is, the degree plus the number of times it occurs in the boundary cycle of the outer face, is at most 6. Before we describe the algorithm, we need some basic deﬁnitions related to graph isomorphisms. Two graphs G1 and G2 are isomorphic if there exists a bijection (isomorphism) from the vertex set of G1 to the vertex set of G2 that maps edges to edges (and nonedges to nonedges). An isomorphism from a graph to itself is called an automorphism (also called a symmetry). The set of all automorphisms of a graph form a permutation group called the automorphism group of the graph, denoted Aut(G). The orbit of a vertex v under Aut(G) is the set of all images of v under automorphisms of G; that is, orb(v) = {g(v) : g ∈ Aut(G)}. This deﬁnition can be naturally extended to a set S of vertices as orb(S) = {g(S) : g ∈ Aut(G)}, where g(S) = {g(x) : x ∈ S}. In the ﬁrst step of the algorithm, nonisomorphic inner dual graphs of fusenes (idfusenes) are constructed via Algorithm McKayGeneration1, described in Section 2.3. This ﬁrst step is going to be described in more detail later in this section. In the second step, labeled inner duals are generated. We have to assign labels, in every possible way, to the vertices that occur more than once on the boundary, so that the sum of the labels plus the degrees of each vertex equals 6. In this process, we must make sure that we do not construct isomorphic labeled inner dual graphs, which can be accomplished by using some isomorphism testing method. To this end, the authors use the homomorphism principle developed by Kerber and Laue (see, for instance, the article by Gr¨uner et al. [28]), which we do not describe here. However, it turns out that isomorphism testing is not needed for the labelings of most inner dual graphs, as discussed in the next paragraph, so the method that we choose for the second step is not so relevant. One of the reasons for the efﬁciency of this algorithm is given next. For two labeled inner dual graphs to be isomorphic, we need that their inner dual graphs be isomorphic. Since the ﬁrst step of the algorithm generates only one representative of each isomorphism class of inner dual graphs, isomorphic labeled inner dual graphs can only result from automorphisms of the same inner dual graph. So, if the inner dual graph has a trivial automorphism group, each of its generated labelings do not have to be tested for isomorphism. It turns out that the majority of fusene inner dual graphs have trivial automorphism group. For instance, for n = 26 trivial automorphism groups occur in 99.9994% of the inner dual graphs, each of them with more than 7000 labelings in average. So, this method saves a lot of unnecessary isomorphism tests in the second step of the algorithm. Now, we give more details on the ﬁrst step of the algorithm, namely the isomorphfree generation of the inner dual graphs via Algorithm McKayGeneration1, as described by Brinkmann et al. [7]. We need to specify how hexagons are added to

66

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

FIGURE 2.10 Valid augmentations of an id-fusene.

existing id-fusenes to create larger ones and how to determine which subgraphs (of order v − 1) of an id-fusene of order v will be selected to be its parent in the generation tree. In order to describe how we augment an id-fusene, we need some deﬁnitions. A boundary segment of an id-fusene is a set of l − 1 consecutive edges of the boundary cycle. The vertices of the boundary segment are the end vertices of its edges (there are l of them). For convenience, a single vertex in the boundary cycle is a boundary segment with l = 1. A boundary segment is said to be augmenting if the following properties hold: l ≤ 3, its ﬁrst and last vertices have total degree at most 5, if l = 1 its only vertex has total degree at most 4, and if l = 3 and the middle occurs only once in the boundary, it has total degree 6; see examples of valid augmentations in Figure 2.10. The augmentation algorithm is based on the following lemma. Lemma 4 All id-fusenes can be constructed from the inner dual of a single hexagon (a single vertex graph) by adding vertices and connecting them to each vertex of an augmenting boundary segment. McKay [46] describes a general way of determining parenthood in Algorithm McKayGeneration1 based on a canonical choice function f . When applied to the case of the current algorithm with the given augmentation, f is chosen to be a function that takes each id-fusene G to an orbit of vertices under the automorphism group of G that satisfy the following conditions: 1. f (G) consists of boundary vertices that occur only once in the boundary cycle and have degree at most 3; 2. f (G) is independent of the vertex numbering of G; that is, if is an isomorphism from G to G , then (f (G)) = f (G ). Now, as described by McKay [46], graph G is deﬁned to be the parent of graph G ∪ {v} if and only if v ∈ f (G ∪ {v}). The speciﬁc f used by Brinkmann et al. [7] is a bit technical and would take a page or more to properly explain, so we refer the interested reader to their paper. Procedure GenerateKidsIDF that generates, from an id-fusene G with v hexagons, its children in the search tree with v + 1 hexagons is outlined next.

TWO ALGORITHMS FOR THE GENERATION OF HSs USING MCKAY’S METHOD

67

1. Addition of hexagons: • Compute the orbit of the set of vertices of each augmenting boundary segment of G. • Connect the new vertex n + 1 to the vertices in one representative of each orbit, creating a new potential child graph G per orbit. 2. Parenthood validation: For each G created in the previous step, if n + 1 ∈ f (G ) then add G to S, the set of children of G. As discussed in the presentation of Algorithm McKayGeneration1, from Section 2.3, no further isomorphism tests are needed between elements of S, unlike the algorithm in Section 2.7.1. Now, putting all these elements into the given framework gives the ﬁnal algorithm for the isomorph-free generation of id-fusenes. Algorithm IDFGeneration(G, n) if (n = h) then output G else { S=GenerateKidsIDF(G, n) for all G ∈ S do IDFGeneration(G , n + 1) } For this algorithm and for the one in Section 2.7.1, it is possible and convenient to distribute the generation among several computers, each expanding part of the generation tree. This can be done by having each computer build the generation tree up to certain level and then start the generation starting on a node at that level. 2.7.3

Exercises

1. Draw the edges and vertices in the next level (h = 5) of the search tree of the BEC algorithm generation given in Figure 2.7. Recall that it must contain exactly 22 nodes (and edges). 2. Prove that the BEC code of an HS always begins with a digit greater than or equal to 3 [12] . 3. Prove that no HS obtained by the addition of a hexagon sharing more than three consecutive edges with the current HS can be one of its legitimate children in the search tree of Algorithm BECGeneration [12]. 4. Consider the three types of addition of hexagons to an HS, given in Figure 2.8a. For each of these cases, prove that the added hexagon creates a polyhex with a hole if and only if at least one of the positions marked with “?” (in the corresponding ﬁgure in Fig. 2.8b) contains a hexagon. 5. Prove that any HS with h ≥ 2 can be obtained from the HS with h = 2 by successive additions of hexagons satisfying rules 1–3 in Section 2.7.1 for hexagon additions in the BEC code algorithm. 6. Prove, by induction on n, that a graph with n vertices is an id-fusene if and only if the four properties listed in Section 2.7.2 are satisﬁed.

68

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

7. Give an example of an id-fusene graph that does not correspond to a hexagonal system. 8. Write an algorithm for ﬁltering fusenes for hexagonal systems, that is, an algorithm that veriﬁes whether a labeled inner dual graph of a fusene can be embedded into the hexagonal lattice. 9. Prove Lemma 4 [7]. 10. Prove that Algorithm IDFGeneration accepts exactly one member of every isomorphism class of id-fusenes with n vertices [7,46].

2.8 PERFECT MATCHINGS IN HEXAGONAL SYSTEMS The transformation from molecular structure (e.g., Fig. 2.1a) to an HS (e.g., Fig. 2.1b) leaves out the information about double valences between carbon atoms. Clearly, each carbon atom has a double valence link with exactly one of its neighboring carbon atoms. Thus, double valences correspond to a perfect matching in an HS. Therefore, an HS is the skeleton of a benzenoid hydrocarbon molecule if and only if it has a perfect matching. An HS that has at least one perfect matching is called Kekul´ean; otherwise, it is called non-Kekul´ean. Kekul´ean HSs are further classiﬁed as either normal (if every edge belongs to at least one perfect matching) or essentially disconnected (otherwise). Classiﬁcation of HSs according to the perfect matching property is summarized by Cyvin et al. [14]. An HS with a given perfect matching is called a Kekul´e structure in chemistry and has great importance. Figure 2.11a and b shows two Kekul´e structures that corresponds to the HS in Figure 2.1b. If the number of vertices of an HS is odd, then clearly there is no perfect matching. We denote by K(G) the number of perfect matchings of a graph G, and refer to it as the

FIGURE 2.11 (a–c) Kekul´e structures and (d–f ) vertex coloring of hexagonal systems.

PERFECT MATCHINGS IN HEXAGONAL SYSTEMS

69

K number of G. When G is an HS, K(G) is the number of its Kekul´e structures. The edges belonging to a given Kekul´e structure are double bonds while others are single bonds. The stability and other properties of HSs have been found to correlate with their K numbers. A whole book [17] is devoted to Kekul´e structures in benzenoid hydrocarbons. It contains a list of other references on the problem of ﬁnding the “Kekul´e structure count” for hydrocarbons. The vertices of an HS may be divided into two groups, which are conveniently called black and white. Choose a vertex and color it white, and color all its neighboring vertices black. Continue the process such that all vertices adjacent to a black vertex are white and vice versa. Figure 2.11d shows an example of such coloring. The black and white internal vertices correspond to two different conﬁgurations of edges as drawn in Figure 2.11e and f. Every edge joins a black and a white vertex; therefore, HSs are bipartite graphs. Let the number of white and black vertices be nw and nb, respectively, and = |nw − nb|. Clearly, nw + nb = p + i (recall that p is the perimeter and i is the number of internal vertices of an HS). Every edge of a perfect matching of a given HS joins a black and a white vertex. Therefore, if the HS is Kekul´ean then = 0. The reverse is not always true. Non-Kekul´ean HSs with = 0 exist and are called concealed, while for > 0 they are referred to as the obvious non-Kekul´ean. 2.8.1

K Numbers of Hexagonal, Square, and Pentagonal Chains

This section contains a study of the numbers of perfect matchings of square, pentagonal, and hexagonal chains, that is the graphs obtained by concatenating squares, pentagons, and hexagons, respectively. A mapping between square (pentagonal) and hexagonal chains that preserves the number of perfect matchings is established. The results in this section are by Tosic and Stojmenovic [58] (except for the proof of Theorem 1, which is original). By a polygonal chain Pk,s we mean a ﬁnite graph obtained by concatenating s k-gons in such a way that any two adjacent k-gons (cells) have exactly one edge in common, and each cell is adjacent to exactly two other cells, except the ﬁrst and last cells (end cells) that are adjacent to exactly one other cell each. It is clear that different polygonal chains will result, according to the manner in which the cells are concatenated. Figure 2.12a shows a hexagonal chain P6,11 . The LA-sequence of a hexagonal chain is deﬁned by Gutmann [29] as follows. A hexagonal chain P6,s is represented by a word of length s over the alphabet {A, L}. The ith letter is A (and the corresponding hexagons is called a kink) if and only if 1 < i < s and the ith hexagon has an edge that does not share a common vertex with any of its two neighbors. Otherwise, the ith letter is L. For instance, the hexagonal chain in Figure 2.12a is represented by the word LAALALLLALL, or, in abbreviated form, LA2 LAL3 AL2 . The LA-sequence of a hexagonal chain can always be written in the form P6 x1 , x2 , . . . , xn to represent Lx1 ALx2 A . . . ALxn , where x1 ≥ 1, xn ≥ 1, xi ≥ 0 for i = 2, 3, . . . , n − 1. For instance, the LA-sequence of the hexagonal chain in Figure 2.12 may be written in the form P6 1, 0, 1, 3, 2, which represents LAL0 ALAL3 AL2 . It is well known that

70

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

FIGURE 2.12 LA-sequences of (a) hexagonal and (b) square chains.

the K number of a hexagonal chain is entirely determined by its LA-sequence, no matter which way the kinks go [33]. The term isoarithmicity for this phenomenon is coined. Thus, P6 x1 , x2 , . . . , xn represents a class of isoarithmic hexagonal chains. Figure 2.12b shows a square chain P4,11 . We introduce a representation of square chains in order to establish a mapping between square and hexagonal chains that will enable us to obtain the K numbers for square chains. A square chain P4,s is represented by a word of length s over the alphabet {A, L}, also called its LAsequence. The ith letter is A if and only if each vertex of the ith square also belongs to an adjacent square. Otherwise the ith letter is L. For instance, the square chain in Figure 2.12b is represented by the word LAALALLLALL, or, in abbreviated form, LA2 LAL3 AL2 . Clearly, the LA-sequence of a square chain can always be written in the form P4 x1 , x2 , . . . , xn to represent Lx1 ALx2 A . . . ALxn , where x1 ≥ 1, xn ≥ 1, xi ≥ 0 for i = 2, 3, ..., n − 1. For example, the LA-sequence of the square chain in Figure 2.12 may be written in the form P4 1, 0, 1, 3, 2 to represent LAL0 ALAL3 AL2 . We show below that all square chains of the form P4 x1 , . . . , xn are isoarithmic. We will draw pentagonal chains so that each pentagon has two vertical edges and a horizontal one that is adjacent to both vertical edges. The common edge of any two adjacent pentagons is drawn vertical. We shall call such way of drawing a pentagonal chain the horizontal representation of that pentagonal chain. From the horizontal representation of a pentagonal chain one can see that it is composed of a certain number (≥ 1) of segments; that is, two adjacent pentagons belong to the same segment if and only if their horizontal edges are adjacent. We denote by P5 x1 , x2 , . . . , xn the pentagonal chain consisting of n segments of lengths x1 , x2 , . . . , xn , where the segments are taken from left to right. Figure 2.15a shows P5 3, 2, 4, 8, 5. Notice that one can assume that x1 > 1 and xn > 1. Among all polygonal chains, the hexagonal chains were studied the most extensively, since they are of great importance in chemistry. We deﬁne P6 as the hexagonal chain with no hexagons.

PERFECT MATCHINGS IN HEXAGONAL SYSTEMS

Theorem 1

71

[58] K(P6 ) = 1, K(P6 x1 ) = 1 + x1 ,

K(P6 x1 , . . . , xn−1 , xn ) = (xn + 1)K(P6 x1 , . . . , xn−1 ) +K(P6 x1 , . . . ., xn−2 ), for n ≥ 2.

Proof. It is easy to deduce the K formula for a single linear chain (polyacene) of x1 hexagons, K(P6 x1 ) = 1 + x1 [27]. Let H be the last kink (A-mode hexagon) of x1 , . . . , xn and u and v be the vertices belonging only to hexagon H (Fig. 2.13a). We apply the method of fragmentation by attacking the bond uv (Fig. 2.13a). If a perfect matching (Kekul´e structure) contains the double bond uv, then the rest of such a perfect matching will be the perfect matching of the graph consisting of two components: xn and x1 , . . . , xn−1 (Fig. 2.13a). The number of such perfect matchings is K(P6 xn )K(P6 x1 , ..., xn−1 ), that is, (xn + l)K(P6 x1 , ..., xn−1 ). On the contrary, each perfect matching not containing uv (uv is a single bond in the corresponding Kekul´e structure) must contain all the double bonds indicated in Figure 2.13b. The rest of such a perfect matching will be a perfect matching of x1 , x2 , . . . , xn−2 and the number of such perfect matchings is K(P6 x1 , . . . , xn−2 ). The recurrence relation now follows easily. 䊏

FIGURE 2.13 Recurrence relation for the K number of hexagonal systems.

72

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

FIGURE 2.14 Transforming square chains into hexagonal chains.

Theorem 2

[58] K(P4 x1 , x2 , . . . , xn ) = K(P6 x1 , x2 , . . . , xn ).

Proof. Referring to Figure 2.14, it is easy to see that if in a square chain some (or all) structural details of the type A, B, and C are replaced by A*, B*, and C*, respectively, the K number will remain the same. By accomplishing such replacements, each square chain can be transformed into a hexagonal chain with the same LA-sequence. Therefore, a square chain and corresponding hexagonal chain represented by the same LA-sequence have the same K number. For example, the square chain in Figure 2.12b can be transformed into the hexagonal chain in Figure 2.12a. Note that the corner squares of a square chain correspond to the linear hexagons, and vice versa, in this transformation. 䊏 It is clear that all other properties concerning the K numbers of square chains can be derived from the corresponding results for hexagonal chains and that the investigation of square chains as a separate class from that point of view is of no interest. Let us now study the K number of pentagonal chains. First, let us recall a general result concerning matchings of graphs. Let G be a graph and u, x, y, v distinct vertices, such that ux, xy, yv are edges of G, u and v are not adjacent, and x and y have degree 2. Let the graph H be obtained from G by deleting the vertices x and y and by joining u and v. Conversely, G can be considered as obtained from H by inserting two vertices (x and y) into the edge uv). We say that G can be reduced to H, or that G is reducible to H; clearly, K(G) = K(H). Theorem 3 [58] If x1 + x2 + · · · + xn is odd, then K(P5 x1 , . . . , xn ) = 0. Otherwise (i.e., if the sequence x1 , x2 , . . . , xn contains an even number of odd integers), let s(j1 ), s(j2 ), . . . , s(jt ), j1 < j2 < · · · < jt , be the odd numbers in the sequence s(r) = x1 + · · · + xr , r = 1, 2, . . . , n, and let s(j0 ) = −1, and s(jt+1 ) = s(n) + 1; then K(P5 x1 , . . . , xn ) = K(P6 y1 , y2 , . . . , yt+1 ), where y1 = (s(j1 ) − 1)/2 = (s(j1 ) − s(j0 ) − 2)/2, yt+1 = (s(n) − s(jt ) − 1)/2 = (s(jt+1 ) − s(jt ) − 2)/2, and, for 2 ≤ i ≤ t, yi = (s(ji ) − s(ji−1 ) − 2)/2. Proof. Clearly, a pentagonal chain consisting of p pentagons has 3p + 2 vertices. Hence, a pentagonal chain with an odd number of pentagons has no perfect matching. Therefore, we assume that it has an even number of segments of odd length.

PERFECT MATCHINGS IN HEXAGONAL SYSTEMS

73

FIGURE 2.15 Transforming (a) pentagonal chains into (b) octagonal chains.

Consider a horizontal representation of P5 x1 , x2 , . . . , xn (Fig. 2.15a). Label the vertical edges by 0, 1, ..., s(n), from left to right. Clearly, no edge labeled by an odd number can be included in any perfect matching of P5 x1 , x2 , . . . , xn , since there are an odd number of vertices on each side of such an edge. By removing all edges labeled with odd numbers we obtain an octagonal chain consisting of s(n)/2 octagons (Fig. 2.15b). This octagonal chain can be reduced to a hexagonal chain with s(n)/2 hexagons (Fig. 2.12a). It is evident that in the process of reduction, each octagon obtained from the two adjacent pentagons of the same segment becomes an L-mode hexagon, while each octagon obtained from the two adjacent pentagons of different segments becomes a kink. The number of kinks is t, since each kink corresponds to an odd s(r). It means that this hexagonal chain consists of t + 1 segments. Let yi be the number of L-mode hexagons in the ith segment. Then the sequence y is deﬁned as given in the theorem. Since reducibility preserves K numbers, it follows that K(P5 x1 , x2 , ..., xn ) = K(P6 y1 , y2 , . . . , yt+1 ). 䊏 Corollary 1 [58] Let x1 , x2 , . . . , xn be even positive integers, n ≥ 1. Then, K(P5 x1 , . . . , xn ) = (x1 + · · · + xn )/2 + 1. Proof. Since all partial sums s(r) in Theorem 3 are even, no kink is obtained in the process of reduction to a hexagonal chain. Thus, a linear hexagonal chain consisting of h = (x1 + x2 + · · · + xn )/2 hexagons is obtained (i.e. P6 h = Lh ). Since K(P6 h) = h + 1, it follows that K(P5 x1 , . . . , xn ) = h + 1. 䊏 2.8.2

Clar Formula

A hexagon q in an HS is said to be an aromatic sextet when it has exactly three (alternating) single and three double bonds in a given perfect matching. In some references, an aromatic sextet q is called a resonant hexagon, deﬁned as a hexagon such that the subgraph of the HS obtained by deleting from it the vertices of q together with their edges has at least one perfect matching. For instance, the upper hexagon in Figure 2.11a is an aromatic sextet. When single and double bonds are exchanged in an aromatic sextet (as in Fig. 2.11b), one obtains another Kekul´e structure of the

74

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

same HS. Aromatic sextets are usually marked by circles inside the hexagon, and such a circle corresponds to two possible matchings of the edges of the hexagon. Figure 2.11c shows an HS with a circle that replaces matchings of Figure 2.11a and b. Clearly, it is not allowed to draw circles in adjacent hexagons. Circles can be drawn in hexagons if the rest of the hexagonal system has at least one perfect matching. The so-called Clar formula of an HS is obtained when the maximal number of circles is drawn such that it leads to a Kekul´e structure of the HS. Therefore, not all perfect matchings correspond to a Clar formula (only the maximal ones, when the placement of additional circles is not possible by changing some edges of the matching). In this section, we shall study Clar formulas of hexagonal chains. We denote by S(B) the number of circles in a Clar formula of a hexagonal chain B. The benzenoid chains with a unique Clar formula (Clar chains) are characterized. All the results are taken from the work by Tosic and Stojmenovic [57]. It is clear that the chain with exactly one hexagon (h = 1) is a Clar chain. The following theorem describes Clar chains for h > 1. Theorem 4 A hexagonal chain B is a Clar chain if and only if its LA-sequence is of the form LAm1 LAm2 L . . . LAmk L, where k ≥ 1 and all the numbers m1 , m2 , . . . , mk are odd. Proof. Let B be a benzenoid chain given by its LA-sequence

Lm0 Am1 Lm1 Am2 Lm2 . . . Lmk−1 Amk Lmk , where m 0 ≥ 1; m k ≥ 1; m i ≥ 0 for i = 1, . . . , k − 1; and mk ≥ 1, for i = 1, 2, . . . , k. The part of this chain between the two successive appearances of the A-mode hexagon is said to be an open segment of B. The ﬁrst m 0 L-mode hexagons and m k last L-mode hexagons also constitute the segments (end segments) of lengths m 0 and m k , respectively. An inner open segment may be without any hexagon: no-hexagon segment. A closed segment is obtained by adding to an open segment two A-mode hexagons that bound it, if it is an inner segment, or one A-mode hexagon that bounds it, if it is an end segment. Two adjoined closed segments always have exactly one common A-mode hexagon. It easily follows that between any two circles in a Clar-type formula of a benzenoid chain, there must be at least one A-mode hexagon (kink) of that chain. Also, each closed segment of a benzenoid chain contains exactly one circle in any Clar formula of that chain. Let B be a Clar chain and let H be an A-mode hexagon of B, adjacent to at least one L-mode hexagon of B. Consider a closed segment of B with at least one L-mode hexagon. If any of the two A-mode hexagons of that segment is with circle in a Clar formula of B, then that circle can be replaced by a circle in any of the L-mode hexagon of that segment, producing another Clar formula of B. It is in contradiction with the fact that B is a Clar chain. Thus, H is without circle in any Clar formula of B. We now show that a Clar chain B does not contain two adjacent L-mode hexagons. Consider a closed segment of B with at least two L-mode hexagons. Neither of the end

PERFECT MATCHINGS IN HEXAGONAL SYSTEMS

75

hexagons of that segment is circled in the Clar formula of B. According to the above two observations, exactly one of the L-mode hexagons of that segment is circled. However, it is clear that each of them can be chosen to be circled. So, the existence of two adjacent L-mode hexagons imply that the Clar formula of B is not unique; that is, B is not a Clar chain. Therefore, each L-mode hexagon of a Clar chain is circled in the Clar formula of that chain. A benzenoid chain with h hexagons in which all hexagons except the ﬁrst and the last are A-mode hexagons is called a zigzag chain and is denoted by A(h). We show that a zigzag chain A(h) with h hexagons is a Clar chain if and only if h is an odd number. A chain with h hexagons cannot have more than h/2 circles in its Clar formula. Now, if h = 2k + 1 is odd, then the choice of h/2 = k + 1 nonadjacent hexagons of A(h) is unique and obviously it determines the unique Clar formula of A(h). Consider now an A(h) with h even. The number of circles in that Clar formula is not greater than h/2. However, one can easily draw h/2 circles in every second hexagon, thus obtaining two different Clar formulas. Thus, A(h) is not a Clar chain for even h. The proof proceeds by induction on k. If k = 1, then the statement of the theorem follows from the last observation on zigzag chains. Consider the case when B is not a zigzag chain. In that case, B has at least three L-mode hexagons. (⇒) Suppose that B is a Clar chain and for some i, 1 ≤ i ≤ k, mi is even. Consider the part of B corresponding to the subword Ami (Fig. 2.16), which is a zigzag chain A(mi ). Two L-mode hexagons that bound this zigzag chain in B are with circles in the unique Clar formula of B. It follows that the ﬁrst and the last hexagons of A(mi ) (numbered by 1 and mi in Fig. 2.16) are without circles in that formula. The remaining part of A(mi ) is a zigzag chain A(mi − 2) with an even number of hexagons and it is independent from the rest of B with respect to the distribution of circles in the Clar formula of B. So, A(mi − 2) itself must be a Clar chain. This is contradiction with the previous observation on zigzag chains. It means that mi cannot be even. Thus, all mi , i = 1, 2, . . . , k, are odd. The number of hexagons of B is h = m1 + m2 + · · · + mk + (k + 1), where all m1 , m2 , · · · , mk , are odd numbers; so h must be odd.

FIGURE 2.16 Clar chain with an even mi (contradiction).

76

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

FIGURE 2.17 LA-sequence with odd mi ’s.

(⇐) Let B be a hexagonal chain with the LA-sequence LAm1 LAm2 L . . . LAmk L, where all the numbers m1 , m2 , . . . , mk are odd, and k > 1. Consider B as obtained from two chains B1 and B2 with LA-sequences, respectively, LAm1 L and LAm2 LAm3 L · · · LAmk L, by identifying the last L-mode hexagon of B1 and the ﬁrst L-mode hexagon of B2 (the second L-mode hexagon in Fig. 2.17). By induction hypothesis, both B1 and B2 are Clar chains. The common L-mode hexagon of B1 and B2 is with circle in both Clar formulas, for B1 and B2 . Hence, B is a Clar chain. 䊏 Let B be a Clar chain with h hexagons. From the discussions in the proof of the previous theorem it follows that, starting from a circled end hexagon, hexagons with and without circle alternate. Thus, the number of circles in the unique Clar formula of B is S(B) = (h + 1)/2. We say that two LA-sequences are equivalent if they coincide or can be obtained from each other by reversing. Two benzenoid chains with the same number of hexagons h are isoarithmic if they have equivalent LA-sequences. So, the number of nonisoarithmic chains with h hexagons is equal to the number of nonequivalent LA-sequences of the length h. We shall determine the number of nonisoarithmic chains with h hexagons and with a unique Clar formula. We denote this number by N(h). Clearly, N(h) = 0, if h is an even number, and N(1) = 1. Theorem 5

Let h be an odd positive integer, h > 1. Then N(h) = 2(h−5)/2 + 2 (h−1)/4−1 .

Proof. From Theorem 4, it follows that N(h) is equal to the number of LAsequences LAm1 LAm2 L . . . LAmk L, such that m1 + m2 + · · · + mk = h − k − 1, k ≥ 1, and all the numbers m1 , m2 , . . . , mk are odd. Now, the number of such LAsequences is equal to the number of compositions of h − 1 into even positive integers, that is, to the number of compositions of n = (h − 1)/2 into positive integers. This last number is equal to 2n−1 = 2(h−3)/2 . Among these compositions there are 2 n/2 = 2 (h−1)/4 of those that are symmetric, that is, those that correspond

PERFECT MATCHINGS IN HEXAGONAL SYSTEMS

77

to symmetric (self-reversible) LA-sequences. So, the number of nonequivalent LAsequences in question is (2(h−3)/2 − 2 (h−1)/4 )/2 + 2 (h−1)/4 = 2(h−5)/2 + 2 (h−1)/4−1 . That is at the same time the number of nonisoarithmic Clar chains. Among them, 2 (h−1)/4 are self-isoarithmic. 䊏

2.8.3

Exercises

1. Show that every catacondensed HS is normal [33]. 2. Assume that an HS is drawn so that some of its edges are vertical. Then, we distinguish peaks and valleys among the vertices on the perimeter. A peak lies above its nearest neighboring vertices, while a valley lies below its nearest neighbors. Let np and nv denote the number of peaks and valleys in a given HS. Prove that |np − nv| = |nb − nw| = [17]. 3. Prove that an HS B is Kekul´ean if and only if it has equal numbers of black and white vertices, and if for all edge cuts of B, the fragment F1 does not have more white vertices than black vertices. An edge cut decomposes HS into two parts F1 and F2 (mutually disconnected but each of them is a one-component graph) such that black end vertices of all edges in the cut belong to F1 [63]. 4. Prove that the K number of an HS satisﬁes h + 1 ≤ K ≤ 2h−1 + 1 [32]. 5. Let x, y, and z denote the number of double bounds of an HS for each of three edge orientations (i.e., parallel to three alternating edges of a hexagon), respectively. Prove that all Kekul´e structures of an HS have the same triplet {x, y, z}. 6. Prove that a triplet (x, y, z), x ≤ y ≤ z, corresponds to a catacondensed HS if and only if x + y + z is odd and x + y ≥ z + 1 [65]. 7. Prove that every perfect matching of an HS contains three edges, which cover all the six vertices of a hexagon [31]. 8. Prove by induction that

= fn+1

K(P6 x1 , ..., xn−1 , xn ) + fn+1−ik fik −ik−1 · · · fi2 −i1 fi1 xi1 xi2 · · · xik , 0

where fn is the nth Fibonacci number [58]. 9. Prove that the K number for the chain LAp−1 LAq−1 L is fp+q+2 + fp+1 fq+1 [35,58]. 10. Prove that the K number for the hexagonal chain with n segments of the same length m is [4]

78

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

K(P6 m, . . . , m) n+1 n+1 m + 1 + (m + 1)2 + 4 − m + 1 − (m + 1)2 + 4 = . 2n+1 (m + 1)2 + 4 11. Prove that the K number for the LA-sequence Lm ALm−1 A . . . ALm−1 ALm (with n − 1 As) is [2] m + √ m2 + 4 n 1 2 √ m +4+2 2 m2 + 4 m − √ m2 + 4 n + m2 + 4 − 2 . 2

12. Prove that the K number for pentagonal chains is [58] K(P5 x1 , . . . , xn−1 , xn ) = ft+2 +

0=i0

(ft+2−ir )/2r

r

(s(jil ) − s(jil −l ) − 2)fil −il−1 ,

l=1

where fk is the kth Fibonacci number and the sequence s is deﬁned in the text. 13. Let m be an odd positive integer > 1. Then, K(P5 m2 ) = (m2 + 2m + 5)/4, and K(P5 m4 ) = (m3 + 2m2 + 5m + 4)/4 [25,58]. 14. Prove that the K number of the zigzag hexagonal chain with LA-sequence LAk−2 L is fk+2 [58,61]. 15. Prove that the K number of pentagonal zigzag chain with 2k pentagons and the K number of hexagonal zigzag chains with k hexagons are the same [58]. 16. Prove that K(P5 12k ) = fk+2 [25,58]. 17. Design a general algorithm for the enumeration of Kekul´e structures (K numbers) of benzenoid chains and branched catacondensed benzenoids [16,27]. 18. Suppose that some edges of an HSs are vertical. Peaks (valleys) are vertices on the perimeter with degree 2 such that both their neighbors are below (above, respectively) them. Prove that the absolute magnitude of the difference between the numbers of peaks and valleys is equal to . Show that the numbers of peaks and valleys in a K´ekulean HS are the same. 19. A monotonic path in an HS is a path connecting a pick with a valley, such that starting at the pick we always go downward. Two paths are said to be independent if they do not have common vertices. A monotonic path system of an HS is a collection of independent monotonic paths that involve all the

REFERENCES

20.

21. 22.

23.

24. 25.

26.

27.

79

peaks and all the valleys of the HS. Prove that the number of Kekul´e structures of the HS is equal to the number of distinct monotonic path systems of the HS [27,52]. Let p1 , p2 , . . . , pk be the picks and v1 , v2 , . . . , vk the valleys of a given HS. Deﬁne a square matrix W of order k such that (W)ij is equal to the number of monotonic paths in the HS starting at pi and ending at vj . Prove that the number of Kekul´e structures of the HS is | det(W)| (i.e., the determinant of matrix W) [39]. If A is the adjacency matrix of an HS B with n vertices, then prove that det(A) = (−1)n/2 K(B)2 [13,18]. The dual graph of an HS is obtained when the centers of all neighboring hexagons are joined by an edge. The outer boundary of the dual graph of a hexagon-shaped HS is a hexagon with parallel edges of size m, n, and k, respectively. n that the number of Kekul´e structures of such an HS is k−1 n Prove / j=0 m+n+j n+j [5]. Suppose that some edges of an HS are drawn vertically. Prove that in all perfect matchings of the HS a ﬁxed horizontal line, passing through the center of at least one hexagon, intersects an equal number of double bonds [52]. Prove that all Kekul´e structures of a given HS have an equal number of vertical double bonds (again, some edges are drawn vertically) [64]. An edge of an HS is called a single (double) ﬁxed bond if it does not belong (belongs, respectively) to all perfect matchings of the HS. Design an O(h2 ) algorithm for the recognition of all ﬁxed bonds in an HS and for determining whether or not a given HS is essentially disconnected [66]. A cycle of edges of an HS is called an alternating cycle if there exists a perfect matching of the HS such that edges in the cycle alternatingly belong and do not belong to the perfect matching. Prove that every hexagon of an HS is resonant (i.e., an aromatic sextet) if and only if the perimeter of the HS is an alternating cycle of the HS [62]. Determine the number of nonisoarithmic hexagonal chains with h hexagons [17].

ACKNOWLEDGMENTS The authors would like to thank Gilles Caporossi and Brendan McKay for valuable feedback and suggestions on the presentation and contents of this chapter.

REFERENCES 1. Avis D, Fukuda K. Reverse search for enumeration. Discrete Appl Math 1996;6: 21–46.

80

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

2. Balaban AT, Tomescu I. Algebraic expressions for the number of Kekul´e structure of isoarithmic catacondensed benzenoid polycyclic hydrocarbons. Match 1983;14:155–182. 3. Balasubramanian K, Kaufman JJ, Koski WS, Balaban AT. Graph theoretical characterisation and computer generation of certain carcinogenic benzenoid hydrocarbons and identiﬁcation of bay regions. J Comput Chem 1980;1:149–157. 4. Bergan JL, Cyvin BN, Cyvin SJ. The Fibonacci numbers and Kekul´e structures of some corona-condensed benzenoids (corannulenes). Acta Chim Hung 1987;124:299. 5. Bodroza O, Gutman I, Cyvin SJ, Tosic R. Number of Kekul´e structures of hexagon-shaped benzenoids. J Math Chem 1988;2:287–298. 6. Brinkmann G. Isomorphism rejection in structure generation programs. In: Hansen P, Fowler P, Zheng M, editors. Discrete Mathematical Chemistry. Providence, RI: American Mathematical Society; 2000. p 25–38. 7. Brinkmann G, Caporossi G, Hansen P. A constructive enumeration of fusenes and benzenoids. J Algorithm 2002;45:155–166. 8. Brinkmann G, Caporossi G, Hansen P. A survey and new results on computer enumeration of polyhex and fusene hydrocarbons. J Chem Inform Comput Sci 2003;43:842– 851. 9. Brunvoll J, Cyvin BN, Cyvin SJ. Benzenoid chemical isomers and their enumeration. Topics in Current Chemistry. Volume 162. Springer-Verlag; 1992. 10. Brunvoll J, Cyvin SJ, Gutman I, Tosic R, Kovacevic M. Enumeration and classiﬁcation of coronoid hydrocarbons. J Mol Struct (Theochem) 1989;184:165–177. 11. Brunvoll J, Tosic R, Kovacevic M, Balaban AT, Gutman I, Cyvin SJ. Enumeration of catacondensed benzenoid hydrocarbons and their numbers of Kekul´e structures. Rev Roumaine Chim 1990;35:85. 12. Caporossi G, Hansen P. Enumeration of polyhex hydrocarbons to h = 21. J Chem Inform Comput Sci 1998;38:610–619. 13. Cvetkovic D, Doob M, Sachs H. Spectra of Graphs, Theory and Applications. New York: Academic Press; 1980. 14. Cyvin BN, Brunvoll J, Cyvin SJ. Enumeration of benzenoid systems and other polyhexes. Topics in Current Chemistry. Volume 162. Springer-Verlag; 1992. 15. Cyvin SJ, Cyvin BN, Brunvoll J. Enumeration of benzenoid chemical isomers with a study of constant-isomer series. Topics in Current Chemistry. Volume 166. Springer-Verlag; 1993. 16. Cyvin SJ, Gutman I. Topological properties of benzenoid systems. Part XXXVI. Algorithm for the number of Kekul´e structures in some pericondensed benzenoids. Match 1986;19:229–242. 17. Cyvin SJ, Gutman I. Kekul´e Structures in Benzenoid Hydrocarbons. Berlin: SpringerVerlag; 1988. 18. Dewar MJS, Longuet-Higgins HC. The correspondence between the resonance and molecular orbital theories. Proc R Soc Ser A 1952;214:482–493. 19. Dias JR. Handbook of Polycyclic Hydrocarbons. Part A. Benzenoid Hydrocarbons. Amsterdam: Elsevier; 1987. 20. Dias JR. Handbook of Polycyclic Hydrocarbons. Part B. Polycyclic Isomers and Heteroatom Analogs of Benzenoid Hydrocarbons. Amsterdam: Elsevier; 1989.

REFERENCES

81

21. Dias JR. Molecular Orbital Calculations Using Chemical Graph Theory. Berlin: Springer; 1993. 22. Doroslovacki R, Stojmenovic I, Tosic R. Generating and counting triangular systems, BIT 1987;27:18–24. 23. Enting IG. Generating functions for enumerating self-avoiding rings on the square lattice. J Phys A 1980;13:3713–3722. 24. Faradzev IA. Constructive enumeration of combinatorial objects. Problemes Combinatoires et Theorie des Graphes Colloque Internat. CNRS 260. Paris: CNRS; 1978. p 131– 135. 25. Farrell EJ. On the occurrences of Fibonacci sequences in the counting of matchings in linear polygonal chains. Fibonacci Quart 1986;24:238–246. 26. Faulon JL, Visco DP, Roe D. Enumerating molecules. In: Lipkowitz K, editor, Reviews in Computational Chemistry. Volume 21. Wiley-VCH; 2005. 27. Gordon M, Davison WHT. Resonance topology of fully aromatic hydrocarbons. J Chem Phys 1952;20:428–435. 28. Gr¨uner T, Laue R, Meringer M. Algorithms for group action applied to graph generation. In: Finkelstein L, Kantor WM, editors. Groups and Computation II, Workshop on Groups and Computation. DIMACS Ser Discrete Math Theor Comput Sci 1997;28: 113–123. 29. Gutman I. Topological properties of benzenoid systems—an identity for the sextet polynomial. Theor Chim Acta 1977;45:309–315. 30. Gutman I. Topological properties of benzenoid molecules. Bull Soc Chim Beograd 1982;47:453–471. 31. Gutman I. Covering hexagonal systems with hexagons. Proceedings of the 4th Yugoslav Seminar on Graph Theory; University of Novi Sad, Novi Sad; 1983. p 151– 160. 32. Gutman I. Topological properties of benzenoid systems. Topics in Current Chemistry. Volume 162. Springer-Verlag; 1992. p 1–28. 33. Gutman I, Cyvin SJ. Introduction to the Theory of Benzenoid Hydrocarbons. SpringerVerlag; 1989. 34. Gutman I, Cyvin SJ. Advances in the Theory of Benzenoid Hydrocarbons. Springer-Verlag; 1990. 35. Gutman I, Cyvin SJ. A result on 1-factors related to Fibonacci numbers. Fibonacci Quart 1990; 81–84. 36. Gutman I, Cyvin SJ, Brunvoll J. Advances in the Theory of Benzenoid Hydrocarbons II. Springer-Verlag; 1992. 37. Harary F, Harborth H. Extremal animals. J Comb Inform Syst Sci. 1976;1:1–8. 38. He WJ, He QX, Wang QX, Brunvoll J, Cyvin SJ. Supplements to enumeration of benzenoid and coronoid hydrocarbons. Z Naturforsch. 1988;43a:693–694. 39. John P, Sachs H. Wegesysteme und Linearfaktoren in hexagonalen und quadratischen Systemen (Path systems and linear factors in hexagonal and square systems). Graphen in Forschung und Unterricht. Bad Salzdetfurth, Germany:Verlag Barbara Franzbecker; 1985. p 85–101. 40. Klarner DA. Some results concerning polyominoes. Fibonacci Quart 1965;3:9–20.

82

BACKTRACKING AND ISOMORPH-FREE GENERATION OF POLYHEXES

41. Knop JV, M¨uller WP, Szymanski K, Trinajstic N. Use of small computers for large computations: enumeration of polyhex hydrocarbons. J Chem Inform Comput Sci 1990;30:159– 160. 42. Knop JV, Szymanski K, Jericevic Z, Trinajstic N. Computer enumeration and generation of benzenoid hydrocarbons and identiﬁcation of bay regions. J Comput Chem 1983;4:23–32. 43. Kocay W. On writing isomorphism programs. In: Wallis WD editor. Computational and Constructive Design Theory. Kluwer; 1996. p 135–175. 44. McKay BD. Practical graph isomorphism. Congr Numer 1981;30:45–87. 45. McKay BD. Nauty user’s guide. Technical Report TR-CS-90-02. Computer Science Department, Australian National University; 1990. 46. McKay BD. Isomorph-free exhaustive generation. J Algorithms 1998;26:306–324. 47. M¨uller WR, Szymanski K, Knop JV. On counting polyhex hydrocarbons. Croat Chem Acta 1989;62:481–483. 48. M¨uller WR, Szymanski K, Knop JV, Nikoli´c S, Trinajsti´c N. On the enumeration and generation of polyhex hydrocarbons. J Comput Chem 1990;11:223–235. 49. Nikoli´c S, Trinajsti´c N, Knop JV, M¨uller WR, Szymanski K. On the concept of the weighted spanning tree of dualist. J Math Chem 1990;4:357–375. 50. Read RC. Every one a winner. Ann Discrete Math 1978;2:107–120. 51. Redelmeier DH. Counting polyominoes: yet another attack, Discrete Math 1981;36:191– 203. 52. Sachs H. Perfect matchings in hexagonal systems. Combinatorica 1984;4:89–99. 53. Stojmenovic I, Tosic R, Doroslovacki R. Generating and counting hexagonal systems. Graph Theory. Proceedings of 6th Yugoslav Seminar on Graph Theory; Dubrovnik, 1985; University of Novi Sad; 1986. p 189–198. 54. Tosic R, Doroslovacki R, Stojmenovic I. Generating and counting square systems. Graph Theory. Proceedings of the 8th Yugoslav Seminar on Graph Theory; University of Novi Sad, Novi Sad; 1987. p 127–136. 55. Tosic R, Kovacevic M. Generating and counting unbranched catacondensed benzenoids. J Chem Inform Comput Sci 1988;28:29–31. 56. Tosic R, Masulovic D, Stojmenovic I, Brunvol J, Cyvin BN, Cyvin SJ. Enumeration of polyhex hydrocarbons to h = 17. J Chem Inform Comput Sci 1995;35: 181–187. 57. Tosic R, Stojmenovic I. Benzenoid chains with the unique Clarformula. J Mol Struct (Theochem) 1990;207:285–291. 58. Tosic R, Stojmenovic I. Fibonacci numbers and the numbers of perfect matchings of square, pentagonal, and hexagonal chains. The Fibonacci Quart 1992;30:315–321. 59. Trinajstic N. Chemical Graph Theory. Boca Raton: CRC Press; 1992. 60. V¨oge M, Guttman J, Jensen I. On the number of benzenoid hydrocarbons. J Chem Inform Comput Sci 2002;42:456–466. 61. Yen TF. Resonance topology of polynuclear aromatic hydrocarbons. Theor Chim Acta 1971;20:399–404. 62. Zhang F, Chen R. When each hexagon of a hexagonal system covers it. Discrete Appl Math 1991;30:63–75. 63. Zhang FJ, Chen RS, Guo XF. Perfect matchings in hexagonal systems. Graphs Comb 1985;1:383.

REFERENCES

83

64. Zhang FJ, Chen RS, Guo XF, Gutman I. An invariant of the Kekul´e structures of benzenoid hydrocarbons. J Serb Chem Soc 1986;51:537. 65. Zhang FJ, Guo XF. Characterization of an invariant for benzenoid systems. Match 1987;22:181–194. 66. Zhang F, Li X, Zhang H. Hexagonal systems with ﬁxed bonds. Discrete Appl Math 1993;47:285–296.

CHAPTER 3

Graph Theoretic Models in Chemistry and Molecular Biology DEBRA KNISLEY and JEFF KNISLEY

3.1 INTRODUCTION 3.1.1

Graphs as Models

A graph is a mathematical object that is frequently described as a set of points (vertices) and a set of lines (edges) that connect some, possibly all, of the points. If two vertices in the graph are connected by an edge, they are said to be adjacent, otherwise they are nonadjacent. Every edge is incident to exactly two vertices; thus, an edge cannot be drawn unless we identify the two vertices that are to be connected by the edge. The number of edges incident to a vertex is the degree of the vertex. How the edges are drawn, straight, curved, long, or short, is irrelevant, only the connection is relevant. There are many families of graphs and sometimes the same graph can belong to more than one family. For example, a cycle graph is a connected graph where every vertex is of degree 2, meaning every vertex is incident to exactly two edges. A bipartite graph is a graph with the property that there exists a partition of the vertex set into two sets such that there are no edges between any two vertices in the same set. Figure 3.1 shows two drawings of the same graph that can be described both as a cycle on six vertices and as a bipartite graph. The two graphs in Figure 3.1 are said to be isomorphic. Two graphs are isomorphic if there exists a one-to-one correspondence between the vertex sets that preserves adjacencies. In general, it is a difﬁcult problem to determine if two graphs are isomorphic. An alternate deﬁnition of a graph is a set of elements with a well-deﬁned relation. Each element in the set can be represented by a point and if two elements in the set are related by the given relationship, then the corresponding points are connected by an edge. Thus, the common deﬁnition of a graph is really a visual representation of a relationship that is deﬁned on a set of elements. In graph theory, one then studies the relational representation as an object in its own right, discerning properties of the object and quantifying the results. These quantities are called graphical invariants

Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

85

86

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

FIGURE 3.1 (a) A cycle. (b) A bipartite graph.

since their values are the same regardless of how the graph is drawn. The graphical invariants, in turn, tell us about the consequences the relation has on the set. To utilize a graph as a model, we must ﬁrst determine the set and the relation on the set that we want to study. For example, suppose we want to consider a group of six people, three men and three women. None of the men have ever met each other and none of the women have ever met, but some of the men have met some of the women. Suppose the graph in Figure 3.1b models this set of people where the two people are “related” or associated if they have previously met. Since the two graphs in Figure 3.1 are isomorphic, we immediately know that it is possible to seat the six people around a circular table so that each person is seated next to someone that they have previously met. This illustration shows the usefulness of graphs even with a very simple example. Graphs are frequently used in chemistry to model a molecule. Given the atoms in a molecule as the set, whether or not a bond joins two atoms is well deﬁned and hence the graphical representation of a molecule is the familiar representation. What is a mathematical model? What is a graph theoretic model? Since graph theory is a ﬁeld of mathematics, one would assume that a graph theoretic model is a special case or a particular kind of mathematical model. While this is true, the generally accepted deﬁnition of a mathematical model among applied mathematicians is somewhat different from the idea of a model in graph theory. In mathematical settings, a model is frequently associated with a set of equations. For example, a biological system is often modeled by a system of equations, and solutions to the equations are used to predict how the biological system responds to stimuli. Molecular biology and biochemistry, however, are more closely aligned with chemistry methodology and literature. Models of molecules in chemistry are often geometric representations of the actual molecule in various formats such as the common ball and stick “model” where balls are used to represent atoms and bonds between the atoms are represented by sticks. As we have seen, this straightforward model of a molecule gives easy rise to a graph where the balls are the vertices and the sticks are the edges. The ﬁrst appearance of a graph as a model or representation of a molecule appeared in the early nineteenth century. In fact, chemistry and graph theory have been paired since the inception of graph theory and we ﬁnd that the early work in physical chemistry coincided with the development of graph theory. As we have seen, a graphical invariant is a measure of some aspect of a graph that is not dependent upon how the graph is drawn. For example, the girth of a graph is the length of its shortest cycle. A graph that has no cycle is said to be of inﬁnite girth. The most obvious of invariants are the order (number of vertices) and the size (number of edges). The minimum number of vertices whose removal will disconnect the graph

87

INTRODUCTION

FIGURE 3.2 G.

is the (vertex) connectivity number. The graph in Figure 3.2 has girth 4, is of order 6, size 7, and connectivity 2.

3.1.2

Early Models in Chemistry

One of the ﬁrst theorems of graph theory can be stated as follows: The sum of the degrees of a graph is twice the number of edges. Since the sum of the degrees of the vertices of even degree is necessarily an even number, the sum of the degrees of the vertices of odd degree must also be even. As a corollary to the above theorem, we know that the number of vertices of odd degree must be even. As far back as 1843, Laurent [1] and Gerhardt [2] established that the number of atoms of odd valence (degree) in a molecule was always even. What constituted an edge was not well established though. One of the earliest formulations of graphs appeared in 1854 in the work by Couper [3], and in 1861, a chemical bond was represented by a graphical edge following the introduction of the term “molecular structure” by Butlerov [4]. The concept of valence of an atom was later championed by Frankland whose work was published in 1866 [5]. Arthur Cayley, a well-known mathematician from the late 1800s, used combinatorial mathematics to construct chemical graphs [6]. Using mathematics, Cayley enumerated the saturated hydrocarbons by determining the generating function for rooted trees. As an illustration, consider the expansion of the expression (a + b)3 . The coefﬁcients of the terms are 1, 3, 3, and 1, respectively, in the expanded form: 1a3 b0 + 3a2 b1 + 3a1 b2 + 1a0 b3 . Note that the exponents in each term sum to 3 and each term represents a distinct way we can obtain the sum of 3 using two distinct ordered terms. If we let b represent the number of ways we can select to insert an edge (or not to insert an edge), then the corresponding coefﬁcients yield the number of ways this selection can be done. Hence, corresponding to the coefﬁcients, there is one graph with no edges, three graphs with exactly one edge, three graphs with exactly two edges, and one graph with three edges. These are drawn in Figure 3.3. This is the idea behind generating functions. Since the graphical representations of the saturated hydrocarbons are trees, Cayley determined how many such trees are combinatorially possible. At that time, his count exceeded the number of known saturated hydrocarbons by 2. Soon after, two additional hydrocarbons were found. How does one prove that a graphical representation of a saturated hydrocarbon is a tree? First, we must deﬁne a tree. A tree is a connected graph with no cycles. These two properties, connected and acyclic, imply that any tree with n vertices must contain exactly n − 1 edges.

88

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

FIGURE 3.3 All possible graphs with three vertices.

A saturated hydrocarbon has the maximum possible number of hydrogen atoms for the number of carbon atoms in a molecule and is denoted by the formula Cm H2m+2 . The tree representation of butane, C4 H10 , is shown in Figure 3.4. In order to prove that a graphical representation of a molecule with the above formula will always be represented by a tree, we must conclude that it is connected and acyclic. Since it is molecule, it is inherently connected. Thus, we must show that it will be impossible for a cycle to occur. This is equivalent to showing that there will always be exactly one less edge than the number of vertices. So we proceed with the counting argument. We know that there are m + 2m + 2 vertices total by adding the carbon and hydrogen atoms. Thus, there are 3m + 2 vertices. To count the edges we observe that each carbon atom is incident to exactly four edges and hence there are 4(m) edges associated with the carbon atoms. Also, each hydrogen atom is incident to exactly one edge and thus we have 1(2m + 2) additional edges. Since each edge is incident to exactly two vertices, each edge has now been counted exactly twice. Thus, the number of edges total is (1/2)(4m + 2m + 2) = 3m + 1. Note that 3m + 1 is exactly one less than the number of vertices. The mathematician Clifford was ﬁrst to demonstrate that a saturated hydrocarbon could not possess any cycles and in fact showed that a hydrocarbon with the general formula Cm H2m+2−2x must contain x cycles [7]. In 1878, Sylvester founded the American Journal of Mathematics. In its very ﬁrst issue he wrote a lengthy article on atomic theory and graphical invariants. By labeling the vertices of the graphs, Sylvester was able to devise a method for validating the existence of different types of chemical graphs. This was the ﬁrst usage of the word graph in the graph theoretic sense [8]. Through the years, chemical graph theory has survived as a little known niche in the ﬁeld of graph theory. Most textbook applications of graphs have centered on computer networks, logistic problems, optimal assignments strategies, and data structures. Chemical graph theorists persisted and developed a subﬁeld of graph

FIGURE 3.4 Butane.

INTRODUCTION

89

theory built upon molecular graphs. Quantiﬁers of the molecular graphs are known as “descriptors” or topological indices. These topological indicators are equivalent to graphical invariants in the realm of mathematical graph theory. In the following sections we discuss some of the early graph theoretic models, as well as some of the ﬁrst graphical invariants and topological indices. For more information on chemical graph theory see the works by Bonchev and Rouvray [9] and Trinajstic [10,11]. 3.1.3

New Directions in Chemistry and Molecular Biology

Today graphs are being used extensively to model both chemical molecules and biomolecules. Chemists use molecular descriptors that yield an accurate determination of structural properties to develop algorithms for computer-aided drug designs and computer-based searching algorithms of chemical databases. Just as bioinformatics is the ﬁeld deﬁned as belonging in the intersection of biology and computer science, cheminformatics lies in the intersection of chemistry and computer science. Cheminformatics can be deﬁned as the application of computational tools to address problems in the efﬁcient storage and retrieval of chemical data. New related ﬁelds are emerging, such as chemical genomics and pharmacogenomics. Organic chemicals frequently referred to as “small molecules” are playing a signiﬁcant part in the discovery of new interacting roles of genes. The completion of the Human Genome Project has changed the way new drugs are being targeted and the expansion of chemical libraries aided by techniques from combinatorial chemistry is seeing more and more graph theoretic applications. While it is generally accepted that graphs are a useful tool for small molecules, graphs are also being utilized for larger biomolecules as well. Graphs are appearing in the literature as DNA structures, RNA structures, and various protein structures. We ﬁnd that graphs are becoming an invaluable tool for modeling techniques in proteomics and protein homology and thus one could say that chemical graph theory has contributed indirectly to these ﬁelds as well. Using graphs to model a molecule has evolved from the early days of chemical graph theory to become an integral part of cheminformatics, combinatorial and computational chemistry, chemical genomics, and pharmacogenomics. Algorithms that determine maximum common induced subgraphs or other structure similarity searches have played a key role in computational chemistry and cheminformatics. An obvious problem associated with such algorithms is the rapid increase in the number of possible conﬁgurations. The exponential growth of the number of graphs with an increasing number of vertices is a difﬁcult challenge that must be addressed. Large graphs result in nonpolynomial time algorithms creating excessive computational expense. In addition, intuition that can often be an aid in determining appropriate molecular descriptors and thus the investigation is greatly hindered by large graphs that cannot be visualized. Methods have been developed for reducing the size of graphs, and such graphs are commonly referred to as reduced graphs. These methods have had a signiﬁcant impact on the ability to model the relevant biomolecular structures and provide summary representations of chemical and biochemical structures. Reduced graphs offer the ability to represent molecules in terms of their high level features [12,13].

90

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

In 2005, in partial fulﬁllment of the NIH Roadmap stated objectives, NIH announced a plan to fund 10 cheminformatic research centers in response to the identiﬁcation of critical cheminformatics needs of the biomedical research community. The centers will formulate the strategies to address those needs and will also allow awardees to become familiar with the operation and interactions among the various components of the NIH Molecular Libraries Initiative. These centers are intended to promote multidisciplinary, multiinstitutional collaboration among researchers in computational chemistry, chemical biology, data mining, computer science, and statistics. Stated components of proposed research include the calculation of molecular descriptors, similarity metrics, and specialized methodologies for chemical library design and virtual screening. For example, the Carolina Exploratory Center for Cheminformatics Research plans to establish and maintain an integrated publicly available Cheminformatics Workbench (ChemBench) to support experimental chemists in the Chemical Synthesis centers and quantitative biologists in the Molecular Libraries Screening Centers Network. The Workbench is intended to be a data analytical extension to PubChem.

3.2 GRAPHS AND ALGORITHMS IN CHEMINFORMATICS 3.2.1

Molecular Descriptors

Values calculated from a representation of a molecule that encode some aspect of the chemical or biochemical structure and activities are called molecular descriptors. There are an enormous number of descriptors that have been deﬁned and utilized by researchers in ﬁelds such as cheminformatics, computational chemistry, and mathematical chemistry. The Handbook of Molecular Descriptors [14] is an encyclopedic collection of more than 3000 descriptors. Molecular descriptors fall into three general categories. Molecular descriptors that quantify some measure of shape and/or volume are called steric descriptors. Electronic descriptors are those that measure electric charge and electrostatic potential, and there are those that measure a molecule’s afﬁnity for a lipophilic environment such as log P. log P is calculated as the log ratio of the concentration of the solute in the solvent. Examples of steric descriptors are surface area and bond connectivity. Surface area is calculated by placing a sphere on each atom with the radius given by the Van der Waals radius of the atom. Electronic descriptors include the number of hydrogen bond donors and acceptors and measures of the pi–pi donor–acceptor ability of molecules. With the support of the EU, INTAS (the International Association for the Promotion of Cooperation with Scientists) from the New Independent States (NIS) of the Former Soviet Union created The Virtual Computational Chemistry Laboratory (VCCL) with the aim to promote free molecular properties calculations and data analysis on the Internet [15]. E-Dragon, a program developed by the Milano Chemometrics and QSAR Research Group [16] and a contributor to the VCCL, can calculate more than 1600 molecular descriptors that are divided into 20 categories. Its groups of indices include walk-and-path counts, electronic, connectivity, and information indices. The molecular descriptors

GRAPHS AND ALGORITHMS IN CHEMINFORMATICS

91

that E-Dragon categorizes as topological indices are obtained from molecular graphs (usually H-depleted) that are conformationally independent. E-Dragon is available at VCCL. All chemical structures can be represented by a simpliﬁed linear string using a speciﬁc set of conversion and representation rules known as SMILES (Simpliﬁed molecular input line entry system). SMILES strings can be converted to representative 3D conformations and 2D representations. While 1D representations are strings and 3D representations are geometric, 2D representations are primarily graphs consisting of vertices (nodes) and their connecting edges. SMILES utilizes the concept of a graph with vertices as atoms and edges as bonds to represent a molecule. The development of SMILES was initiated by the author, David Weininger, at the Environmental Research Laboratory, USEPA, Duluth, MN; the design was completed at Pomona College in Claremont, CA. It was embodied in the Daylight Toolkit with the assistance of Cedar River Software. Parentheses are used to indicate branching points and numeric labels designate ring connection points [17]. Quantities derived from all three representations are considered molecular descriptors. Since we are primarily concerned with graph theoretic models, we will focus on 2D descriptors from graphs and refer to these as topological descriptors or topological indices. Graphs are also useful for 3D models since 3D information can be contained in vertex and edge labeling [18,19]. Descriptors calculated from these types of representations are sometimes called information descriptors. While the 2D graphical model neglects information on bond angles and torsion angles that one ﬁnds in 3D models, this can be advantageous since it allows ﬂexibility of the structure to occur without a resulting change in the graph. Methods and tools from computational geometry also often aid in the quantiﬁcation and simulation of 3D models. Molecular descriptors are a valuable tool in the retrieval of promising pharmaceuticals from large databases and also in clustering applications. (ADAPT) (Automated Data Analysis Using Pattern Recognition Toolkit) has a large selection of molecular descriptor generation routines (topological, geometrical, electronic, and physicochemical) and the ability to generate hybrid descriptions that combine features. ADAPT was developed by Peter Jurs, the Jurs Research Group at Penn State, and is available over the Internet [20]. The Molecular operating environment (MOE) offered by the Chemical Computing Group [21] has a developed a pedagogical toolkit for educators including a cheminformatics package. This toolkit can calculate approximately 300 descriptors including topological indices, structural keys, and E-state indices. 3.2.2

Graphical Invariants and Topological Indices

A topological index is a number associated with a chemical structure represented by a connected graph. The graph is usually a hydrogen-depleted graph, where atoms are represented by vertices and covalent bonds by edges. On the contrary, many results in graph theory have focused on large graphs and asymptotic results in general. Since chemical graphs are comparatively small, it is not too surprising that graphical invariants and topological indices have evolved separately. However, with the new avenues

92

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

of research in biochemical modeling of macromolecules, the ﬁeld of mathematical graph theory may bring new tools to the table. In chemical graph theory, the number of edges, that is, the number of bonds, is an obvious and well-utilized molecular descriptor. Theorems from graph theory or graphical invariants from related ﬁelds such as computational complexity and computer architecture may begin to shed new light on the structure and properties of proteins and other large molecules. In recent results by Haynes et al., parameters based on graphical invariants from mathematical graph theory showed promising results in this direction of research [22,23]. It certainly appears that a thorough review of theoretical graphical invariants with an eye toward new applications in biomolecular structures is warranted Without a doubt, there will be some overlap of concepts and deﬁnitions. For example, one of the most highly used topological indices was deﬁned by Hoyosa in 1971 [24]. This index is the sum of the number of ways k disconnected edges can be distributed in a graph G. I(G) =

n/2

θ(G, k),

k=0

where θ(G, 0) = 1 and θ(G, 1) is the number of edges in G. Let us deviate for a moment and deﬁne the graphical invariant, k-factor. To do so, we ﬁrst deﬁne a few other graph theoretic terms. A graph is k-regular if every vertex has degree k. A graph H is a spanning subgraph of G if it is a subgraph that has the same vertex set of G. A subgraph H is a k-factor if it is a k-regular spanning subgraph. A 1-factor is a spanning set of edges and a 2-factor of a graph G is a collection of cycle subgraphs that span the vertex set of G. If the collection of spanning cycles consists of a single cycle, then the graph is Hamiltonian. Hamiltonian theory is an area that has received substantial attention among graph theorists, as well as the topic of k-factors. We note that θ(G, 1) is the number of edges in G and that θ(G, n/2) is equivalent to the number of 1-factors in G [9]. In the following sections, we deﬁne selected graphical invariants and topological indices, most of which were utilized in the work by Haynes et al. [22,23]. Domination numbers of graphs have been utilized extensively in ﬁelds such as computer network design and fault tolerant computing. The idea of domination is based on sets of vertices that are near (dominate) all the vertices of a graph. A set of vertices dominate the vertex set if every vertex in the graph is either in the dominating set or adjacent to at least one vertex in the dominating set. The minimum cardinality among all dominating sets of vertices in the graph is the domination number. For more information on the domination number of graphs see Haynes [25]. If restrictions are placed on the set of vertices that we may select to be in the dominating set, then we obtain variations on the domination number. For example, the independent domination number is the minimum number of nonadjacent vertices that can dominate the graph. Consider Figure 3.5, which contains two trees of order 7, one with independent domination number equal to 3 and the other with independent domination number equal to 2. The vertices in each independent minimum dominating set are labeled {u, w, z} and {u, z}, respectively. Domination numbers have been highly studied in

GRAPHS AND ALGORITHMS IN CHEMINFORMATICS

93

FIGURE 3.5 Dominating vertices {u, w, z} and {u, z}, respectively.

mathematical graph theory and have applications in many ﬁelds such as computer networks and data retrieval algorithms. The eccentricity of a vertex is the maximum distance from a vertex v to any other vertex in the graph where distance is deﬁned to be the length of the shortest path and is denoted by d(u, v). The diameter of G, diam (G), is the maximum eccentricity where this maximum is taken over all eccentricity values in the graph. That is, diam(G) = max d(v, u) u,v∈V

and the radius of a graph G, denoted by rad (G), is given by the minimum eccentricity value, that is, rad(G) = min max{d(x, y)}. x∈V

y∈V

The diameter and radius are both highly utilized graphical invariants and topological indices. The line graph of G, denoted by L(G), is a graph derived from G so that the edges in G are replaced by vertices in L(G). Two vertices in L(G) are adjacent whenever the corresponding edges in G share a common vertex. Beineke and Zamﬁrescu [26] studied the kth ordered line graphs and Dix [27] applied the second ordered line graphs to concepts in computational geometry. Figure 3.6 shows a graph G with L(G) and L2 (G), the second iterated line graph. Note that vertex x in L2 (G) corresponds to the edge x in L(G). The edge x in L(G) is deﬁned by the two vertices a and b. These two vertices in L(G) correspond to the two edges a and b in G. Topological indices do not account for angle measures; however, two incident edges represent an angle and thus vertex x in L2 (G) corresponds to the angle, or path of length 2, namely {1, 3, 2}. Given that there are over 3000 molecular descriptors deﬁned in the Handbook of Molecular Descriptors, we will make no attempt to provide an extensive list of topological indices. Rather we have selected a few representatives that are classical and well known as examples. The Gordon–Scantlebury index is deﬁned as the number of distinct ways a chain fragment of length 2 can be embedded on the carbon skeleton of a molecule [28]. Thus, if G is the graph in Figure 3.6, then the Gordon–Scantlebury number is 4. The second iterated line graph discussed above not only provides an easy way to determine this index, but also tells us how these paths are related. Notice that the vertices z, w, and y in L2 (G) form a triangle; that is, they are all pairwise adjacent. This is because they are all incident to vertex c in L(G). Since vertex c in L(G) corresponds to edge c in G, we know that the three paths of length 2 corresponding to the vertices in z, w, and y in L2 (G) all share edge c.

94

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

FIGURE 3.6 A graph, its line graph, and the second iterated line graph.

Among the earliest topological indices are the connectivity indices. The classical connectivity index deﬁned by Randic [29] is given by R0 (G) =

v∈V

R1 (G) =

uv∈E

1 √ , ∂(v)

√

1 . ∂(u)∂(v)

√ The √ Randic numbers for the graph G√in Figure 3.6 √ are R0 (G)√= 1 + 1 + 1/ 3 + 1/ 2 + 1 = 4.28 and R1 (G) = 2(1/ 1 · 3) + 1/ 2 · 3 + 1/ 1 · 2) = 2.27. This index can be generalized for paths of length l to deﬁne the generalized Randic number Rl (G). One can consider paths as a special type of subgraph. More recently, Bonchev introduced the concept of overall connectivity of a graph G, denoted by TC(G), which is deﬁned to be the sum of vertex degrees of all subgraphs of G [30]. The adjacency matrix is a straightforward way to represent a graph in a computer. Given a graph with n vertices labeled V = {v1 , v2 , ..., vn }, the adjacency matrix A is an n × n matrix with a 1 in the ith row and jth column if vertex vi is adjacent to vertex vj and zeros elsewhere. The degree matrix D is the n × n matrix with dij = deg(vi ) and dij = 0 if i = j. The Laplacian matrix is deﬁned as the difference of the adjacency matrix and the degree matrix, L = D − A. The spectrum of a graph is the set of eigenvalues of the Laplacian matrix. The eigenvalues are related to the density distribution of the edge set, and the pattern of a graph’s connectivity is closely related to its spectrum. The second smallest eigenvalue, denoted by λ2 (often called the Fiedler eigenvalue), is the best measure of the graph’s connectivity among all of the eigenvalues. Large values for λ2 correspond to vertices of high degree that are in close proximity whereas small values for λ2 correspond to a more equally dispersed edge set. The Balaban index [31], sometimes called the distance sum connectivity index, is considered to be a highly discriminating topological index. The Balaban index B(G) of a graph G is deﬁned as B(G) =

1 q , √ μ(G) + 1 si sj edges

where si is the sum of the distance of the ith vertex to the other vertices in the graph, q is the number of edges, and μ is the minimum number of edges whose removal results in an acyclic graph. The distance matrix T is the n × n matrix with dij = dist(vi , vj ).

95

GRAPHS AND ALGORITHMS IN CHEMINFORMATICS

dij = dist(vi , vj ). The distance matrix and B(G) for G in Figure 3.6 are given below. ⎡

0 ⎢ ⎢2 ⎢ T =⎢ ⎢1 ⎢ ⎣2 3 B(G) = 4

⎤ 2123 ⎥ 0 1 2 3⎥ ⎥ 1 0 1 2⎥ ⎥, ⎥ 2 1 0 1⎦ 3210

1 1 1 1 √ +√ +√ +√ 6·9 8·5 8·5 5·6

.

The reverse Wiener index was introduced in 2000 [32]. Unlike the distance sums, reverse Wiener indices increase from the periphery toward the center of the graph. As we have seen, there are an enormous number of molecular descriptors utilized in computational chemistry today. These descriptors are frequently used to build what are known as quantitative structure–activity relationships (QSAR). A brief introduction of QSAR is given in the following section. 3.2.3

Quantitative Structure–Activity Relationships

The structure of a molecule facilitates the molecule’s properties and its related activities. This is the premise of a QSAR study. QSAR is a method for building models that associate the structure of a molecule with the molecule’s corresponding biological activity. QSAR was ﬁrst developed by Hansch and Fujita in the early 1960s and remains a key player in computational chemistry. The fundamental steps in QSAR are molecular modeling, calculation of molecular descriptors, evaluation and reduction of descriptor set, linear or nonlinear model design, and validation. Researchers at the University of North Carolina at Chapel Hill recently extended the four steps to an approach that employs various combinations of optimization methods and descriptory types. Each descriptor type was used with every QSAR modeling technique, so in total 16 combinations of techniques and descriptor types were considered [33]. A successful QSAR algorithm is predictive. That is, given a molecule and its structure, one can make a reasonable prediction of its biological activity. The ability to predict a molecule’s biological activity by computational means has become more important as an ever-increasing amount of biological information is being made available by new technologies. Annotated protein and nucleic databases and vast amounts of chemical data from automated chemical synthesis and high throughput screening require increasingly more sophisticated efforts. QSAR modeling requires the selection of molecular descriptors that can then be used for either a statistical model or a computational neural network model. Current methods in QSAR development necessarily include feature selection. It is generally accepted that after descriptors have been calculated, this set must be reduced to a set of descriptors that measure the desired structural characteristics. This is obvious, but not always as straightforward as one would hope since the interpretation of a large

96

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

number of descriptors is not always easy. Since many descriptors may be redundant in the information that they contain, principal component analysis has been the standard tool for descriptor reduction, often reducing the set of calculated invariants. This is accomplished by a vector space description analysis that looks for descriptors that are orthogonal to one another where descriptors that contain essentially the same information are linearly dependent. For example, a QSAR algorithm was developed by Viswanadahn et al. in which a set of 90 graph theoretic and information descriptors representing various structural/topological characteristics of these molecules were calculated. Principal component analysis was used to compress these 90 into the 8 best orthogonal composite descriptors [34]. Often molecular descriptors do not contain molecular information that is relevant to the particular study, which is another drawback one faces in selecting descriptors for a QSAR model. Due to the enormous number of descriptors available, coupled with the lack of interpretation one has for the molecular characteristics they exhibit, very little selection of descriptors is made a priori. Randic and Zupan reexamined the structural interpretation of several well-known indices and recommended partitioning indices into bond additive terms [35]. Advances in neural network capabilities may allow for the intermediate steps of molecular descriptor reduction and nonlinear modeling to be combined. Consequently, neural network algorithms are discussed in greater detail in Section 3.4. Applications of QSAR can be found in the design of chemical libraries, in molecular similarity screening in chemical databases, and in virtual screening in combinatorial libraries. Combinatorial chemistry is the science of synthesizing and testing compound en masse and QSAR predictions have proven to be a valuable tool. The QSAR and Modeling Society Web site is a good source for more information on QSAR and its applications.

3.3 GRAPHS AS BIOMOLECULES The Randic index is an example of a well-known and highly utilized topological index in cheminformatics. In 2002, Randic and Basak used the term “biodescriptor” when applying a QSAR model for a biomolecular study [36,37]. While graphs have historically been used to model molecules in chemistry, they are beginning to play a fundamental role in the quantiﬁcation of biomolecules. A new technique for describing the shape and property distribution of proteins, called PPEST (protein property-encoded surface translator) has been developed to help elucidate the mechanism behind protein interactions [38]. The utility of graphs as models of proteins and nucleic acids is fertile ground for the discovery of new and innovative methods for the numerical characterization of biomolecules. 3.3.1

Graphs as RNA

The information contained in DNA must be accessed by the cell in order to be utilized. This is accomplished by what is known as transcription, a process that copies the information contained in a gene for synthesis of genetic products. This copy, RNA,

GRAPHS AS BIOMOLECULES

97

is almost identical to the original DNA, but a letter substitution occurs as thymine (T) is replaced by uracil (U). The other three bases A, C, and G are the same. Since newly produced (synthesized) RNA is single stranded, it is ﬂexible. This allows it to bend back on itself to form weak bonds with another part of the same strand. The initial string is known as the primary structure of RNA and the 2D representation in Figure 3.7 is an example of secondary RNA structure. While scientists originally believed that the sole function of RNA was to serve as a messenger of DNA to encode proteins, it is now known that there are noncoding or functional RNA sequences. In fact, the widespread conservation of secondary structure points to a very large number of functional RNAs in the human genome [39,40]. Many classes of RNA molecules are characterized by highly conserved secondary structures that have very different primary structure (or primary sequence), which implies that both sequential and structural information is required in order to expand the current RNA databases [41]. RNA was once thought to be the least interesting since it is merely a transcript of DNA. However, since it is now known that RNA is involved in a large variety of processes, including gene regulation, the important task of classifying RNA molecules remains far from complete. Graph theory is quickly becoming one of the fundamental tools used in efforts to determine and identify RNA molecules. It is assumed that the natural tendency of the RNA molecule is to reach its most energetically stable conformation and this is the premise behind many RNA folding algorithms such as Zucker’s well-known folding algorithms [42]. More recently, however, the minimum free energy assumption has been revisited and one potential new player is graph theoretic modeling and biodescriptors. Secondary structure has been represented by various forms in the literature and representations of RNA molecules as graphs is not new. In the classic work of Waterman [43], secondary RNA structure is deﬁned as a graph where each vertex ai represents a nucleotide base. If ai pairs with aj and ak is paired with al where i < k < j, then i < l < j. More recently, secondary RNA structures have been represented by various modeling methods as graph theoretic trees. RNA tree graphs were ﬁrst developed by Le et al. [44] and Benedetti and Morosetti [45] to determine structural similarities in RNA.

FIGURE 3.7 Secondary RNA structure and its graph.

98

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

A modeling concept developed by Barash [46] and Heitsch et al. [47] who noted that the essential arrangement of loops and stems in RNA secondary structure is captured by a tree if one excludes the pseudoknots. A pseudoknot can be conceptualized as switchbacks in the folding of secondary structure. With the exclusion of pseudoknots, the geometric skeleton of secondary RNA structure is easily visualized as a tree as in Figure 3.7. Unlike the classic model developed by Waterman et al. where atoms are represented by vertices and bonds between the atoms by edges in the graph, this model represents stems as edges and breaks in the stems that result in bulges and loops as vertices. A nucleotide bulge, hairpin loop, or internal loop are each represented by a vertex when there is more than one unmatched nucleotide or noncomplementary base pair. Researchers at New York University in the Computational Biology Group led by Tamar Schlick used this method to create an RNA topology database called RAG (RNA As Graphs) that is published and available at BMC Bioinformatics and Bioinformatics [48,49]. The RNA motifs in RAG are cataloged by their vertex number and Fiedler eigenvalues. This graph theoretic representation provides an alternative approach for classifying all possible RNA structures based on their topological properties. In this work, Schlick et al. ﬁnd that existing RNA classes represent only a small subset of possible 2D RNA motifs [50,51]. This indicates that there may be a number of additional naturally occuring secondary structures that have not yet been identiﬁed. It also points to possible structures that may be utilized in the synthesis of RNA in the laboratory for drug design purposes. The discovery of new RNA structures and motifs is increasing the size of specialized RNA databases. However, a comprehensive method for quantifying and cataloging novel RNAs remains absent. The tree representation utilized by the RAG database provides a useful resource to that end. Other good online resources in addition to the RAG database include the University of Indiana RNA Web site, RNA World, and RNA Base [52]. 3.3.2

Graphs as Proteins

Proteins are molecules that consist of amino acids. There are 20 different amino acids; hence, one can think of a chain or sequence from an alphabet of size 20 as the primary structure of a protein. Each amino acid consists of a central carbon atom, an amino group, a carboxyl group, and a unique “side chain” attached to the central carbon. Differences in the side chains distinguish different amino acids. As this string is being produced (synthesized) in the cell, it folds back onto itself creating a 3D object. For several decades or more, biologists have tried to discover how a completely unfolded protein with millions of potential folding outcomes almost instantaneously ﬁnds the correct 3D structure. This process is very complex and often occurs with the aid of other proteins known as chaperones that guide the folding protein. The majority of protein structure prediction algorithms are primarily based on dynamic simulations and minimal energy requirements. More recently, it has been suggested that the high mechanical strength of a protein ﬁber, for example, is due to the folded structural linking rather than thermodynamic stability. This suggest the feasibility and validity of a graph theoretic approach as a model for the molecule.

GRAPHS AS BIOMOLECULES

99

The 3D structure of the protein is essential for it to carry out its speciﬁc function. The 3D structure of a protein has commonly occurring substructures that are referred to as secondary structures. The two most common are alpha helices and beta strands. Bonds between beta strands form beta sheets. We can think of alpha helices and beta sheets as building blocks of the 3D or tertiary structure. As in the case for the secondary RNA trees, graph models can be designed for amino acids, secondary, and tertiary protein structures. In addition to protein modeling, protein structure prediction methods that employ graph theoretic modeling focus on predicting the general protein topology rather than the 3D coordinates. When sequence similarity is poor, but the essential topology is the same, these graph theoretic methods are more advantageous. The idea of representing a protein structure as a graph is not new and there have been a number of important results on protein structure problems obtained from graphs. Graphs are used for identiﬁcation of tertiary similarities between proteins by Mitchell et al. [53] and Grindley et al [54]. Koch et al. apply graph theory to the topology of structures in proteins to automate identiﬁcation of certain motifs [55]. Graph spectral analysis has provided information on protein dynamics, protein motif recognition, and fold. Identiﬁcation of proteins with similar folds is accomplished using the graph spectra in the work by Patra and Vishveshwara [56]. Clusters important for function, structure, and folding were identiﬁed by cluster centers also using the graph’s eigenvalues [57]. Fold and pattern identiﬁcation information was gained by identifying subgraph isomorphisms [58]. For additional information on these results, see the work by Vishveshwara et al. [59]. It is worth noting that all of the above methods relied heavily on spectral graph theory alone. Some of the early work on amino acid structure by graph theoretic means was accomplished in the QSAR arena. Use of crystal densities and speciﬁc rotations of amino acids described by a set of molecular connectivity indices was utilized by Pogliani in a QSAR study [60]. Pogliani also used linear combinations of connectivity indices to model the water solubility and activity of amino acids [61]. Randic et al. utilized a generalized topological index with a multivariate regression analysis QSAR model to determine characteristics of the molar volumes of amino acids [62]. On a larger scale, a vertex can represent an entire amino acid and edges are present if the amino acids are consecutive on the primary sequence or if they are within some speciﬁed distance. The graph in the Figure 3.8 shows the modeling of an alpha helix and a beta strand with a total of 24 amino acids. By applying a frequent subgraph mining algorithm to graph representations of a 3D protein structure, Huan et al. found recurring amino acid residue packing patterns that are characteristic of protein structural families [63]. In their model, vertices represent amino acids, and edges are chosen in one of three ways: ﬁrst, using a threshold for contact distance between residues; second, using Delaunay tessellation; and third, using the recently developed almost-Delaunay edges. For a set of graphs representing a protein family from the Structural Classiﬁcation of Proteins (SCOP) database [64], subgraph mining typically identiﬁes several hundred common subgraphs corresponding to the residue packing pattern. They demonstrate that graphs based on almost-Delaunay edges signiﬁcantly reduced the number of edges in the graph representation and hence presented computational advantage.

100

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

FIGURE 3.8 An alpha helix and a beta strand.

Researchers at the University of California at Berkley and at the Dana Farber Cancer Institute at Harvard Medical School have used aberration multigraphs to model chromosome aberrations [65]. A multigraph is a graph that allows multiple edges between two vertices. Aberration multigraphs characterize and interrelate three basic aberration elements: (1) the initial conﬁguration of a chromosome; (2) the exchange process whose cycle structure helps to describe aberration complexity; and (3) the ﬁnal conﬁguration of rearranged chromosomes. An aberration multigraph refers in principle to the actual biophysical process of aberration formation. We ﬁnd that graphical invariants provide information about the processes involved in chromosome aberrations. High diameter for the multigraph corresponds to many different cycles in the exchange process, linked by the fact that they have some chromosomes in common. Girth 2 in a multigraph usually corresponds to a ring formation and girth 3 to inversions. Aberration multigraphs are closely related to cubic multigraphs. An enormous amount is known about cubic multigraphs, mainly because they are related to work on the four-color theorem. Results on cubic multigraphs suggest a mathematical classiﬁcation of aberration multigraphs. The aberration multigraph models the entire process of DNA damage, beginning with an undamaged chromosome and ending with a damaged one. A relation is symmetric if “a is related to b" implies “b is related to a." Clearly, not all relations are symmetric. If a graph models a relation that is not symmetric, then directions are assigned to the edges. Such graphs are known as digraphs and networks are usually modeled by digraphs. Some network applications exist in chemical graph theory [66]. Since a reaction network in chemistry is a generalization of a graph, the decomposition of the associated graph reﬂects the submechanisms by closed directed cycles. A reaction mechanism is direct if no distinct mechanisms for the same reaction can be formed from a subset of the steps. Although the decomposition is not unique, the set of all direct mechanisms for a reaction is a unique attribute of a directed graph. Vingron and Waterman [67] utilized the techniques and concepts from electrical networks to explore applications in molecular biology. A variety of novel modeling methods that exploit various areas of mathematical graph theory such as random graph theory are emerging with exciting results. For more examples applications of graphs in molecular biology, see the work by Boncher et al. [68].

MACHINE LEARNING WITH GRAPHICAL INVARIANTS

3.4

101

MACHINE LEARNING WITH GRAPHICAL INVARIANTS

Graphical invariants of graph theoretic models of chemical and biological structures can sometimes be used as descriptors [23] in a fashion similar to molecular descriptors in QSPR and QSAR models. Over the past decade, the tools of choice for using descriptors to predict such functional relationships have increasingly been artiﬁcial neural networks (ANNs) or algorithms closely related to ANNs [69]. More recently, however, support vector machines (SVMs) have begun to supplant the use of ANNs in QSAR types of applications because of their ability to address issues such as overﬁtting and hard margins (see, e.g., the works by Xao et al. [70] and Guler and Kocer [71]). Speciﬁcally, the possible properties or activities of a chemical or biological structure deﬁne a ﬁnite number of speciﬁc classes. The ANNs and SVMs use descriptors for a given structure to predict the class of the structure, so that properties and activities are predicted via class membership. Algorithms that use descriptors to predict properties and functions of structures are known as classiﬁers. Typically, a collection of structures whose functional relationships have been classiﬁed a priori are used to train the classiﬁer so that the classiﬁer can subsequently be used to predict the classiﬁcation of a structure whose functional relationships have yet to be identiﬁed [72]. 3.4.1

Mathematics of Classiﬁers

Before describing SVMs and ANNs more fully, let us establish a mathematical basis for the study of classiﬁcation problems. Because a descriptor such as a graphical invariant is real valued, a number n of descriptors of a collection of biological structures form an n-tuple x = (x1 , ..., xn ) in n-dimensional real space. A classiﬁer is a method that partitions n-dimensional space so that each subset in the partition contains points corresponding to only one class. Training corresponds to using a set of n-tuples for structures with a priori classiﬁed functional relationships to approximate such a partition. Classiﬁcation corresponds to using the approximate partition to make predictions about a biological structure whose class is not known [72]. If there are only two classes, as was the case in the work by Haynes et al. [23] where graph theoretic trees were classiﬁed as either RNA-like or not RNA-like, the goal is to partition an n-dimensional space into two distinct subsets. If the two subsets can be separated by a hyperplane, then the two classes are said to be linearly separable. An algorithm that identiﬁes a suitable separating hyperplane is known as a linear classiﬁer (Fig. 3.9). In a linearly separable classiﬁcation problem, there are constants w1 , ..., wn and b such that w1 x1 + · · · + wn xn + b > 0 when (x1 , ..., xn ) is in one class and w1 x1 + · · · + wn xn + b < 0

102

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

FIGURE 3.9 Linear separability.

when (x1 , ..., xn ) is in the other. Training reduces to choosing the constants so that the distance between the hyperplane and the training data is maximized, and this maximal distance is then known as the margin. If there are more than two classes and the classes are not linearly separable, then there are at least two different types of classiﬁers that can be used. An SVM supposes that some mapping φ(x) from n-space into a larger dimensional vector space known as a feature space will lead to linear separability in the larger dimensional space, at which point an optimal hyperplane is computed in the feature space by maximizing the distance between the hyperplane and the closest training patterns. The training patterns that determine the hyperplane are known as support vectors. If K(x,y) is a symmetric, positive deﬁnite function, then it can be shown that there exists a feature space with an inner product for which K (x, y) = φ (x) · φ (y) . The function K(x,y) is known as the kernel of the transformation, and it follows that the implementation of an SVM depends only on the choice of a kernel and does not require the actual speciﬁcation of the mapping or the feature space. Common kernels include the following: Inner product: K (x, y) = x · y. Polynomial: K (x, y) = (x · y + 1)N , where N is a positive integer. Radial: K (x, y) = e−ax−y2 . Neural: K (x, y) = tanh (ax · y + b), where a and b are parameters. Within the feature space, an SVM is analyzed as a linear classiﬁer [73]. Several implementations of SVMs are readily available. For example, mySVM and YALE, which can be found at http://www.support-vector-machines.org, can be downloaded as windows executables or Java applications [74]. There are also several books, tutorials, and code examples that describe in detail how SVMs are implemented and trained [75].

MACHINE LEARNING WITH GRAPHICAL INVARIANTS

103

FIGURE 3.10 An artiﬁcial neuron.

ANNs are alternatives to SVMs that use networks of linear-like classiﬁers to predict structure–function classiﬁcations. Speciﬁcally, let us suppose that the two classes of a linear classiﬁer can be associated with the numbers 1 and 0. If we also deﬁne a ﬁring function by 1 if s > 0,

g (s) =

0 if s < 0,

(3.1)

then the linear classiﬁer can be interpreted to be a single artiﬁcial neuron, which is shown in Figure 3.10. In this context, w1 , ..., wn are known as synaptic weights and b is known as a bias. The ﬁring function is also known as the activation function, and its output is known as the activation of the artiﬁcial neuron. The terminology comes from the fact that artiﬁcial neurons began as a caricature of real-world neurons, and indeed, real-world neurons are still used to guide the development of ANNs [76]. The connections with neurobiology also suggest that the activation function g(s) should be sigmoidal, which means that it is differentiable and nondecreasing from 0 up to 1. A commonly used activation function is given by g (s) =

1 , 1 + e−κs

(3.2)

where κ > 0 is a parameter [77], which is related to the hyperbolic tangent via g(s) =

1 2

tanh(κ s) + 21 .

The choice of a smooth activation function allows two different approaches to training—the synaptic weights can be estimated from a training set either using linear algebra and matrix arithmetic or via optimization with the synaptic weights as dependent variables. The latter is the idea behind the backpropagation method, which is discussed in more detail below. A multilayer feedforward network (MLF) is a network of artiﬁcial neurons organized into layers as shown in Figure 3.11, where a layer is a collection of neurons connected to all the neurons in the previous and next layers, but not to any neurons in the layer itself. The ﬁrst layer is known as the input layer, the last layer is known as the output layer, and the intermediate layers are known as hidden layers. Figure 3.11 shows a typical three-layer MLF.

104

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

FIGURE 3.11 A three-layer MLP.

In the prediction or feedforward stage, the descriptors x1 , · · · , xn are presented to the input layer neurons, and their activations are calculated as in Figure 3.10. Those activations are multiplied by the synaptic weights wij between the ith input neuron and the jth output neuron and used to calculate the activations of the hidden layer neurons. Similarly, the synaptic weights αjk between the kth hidden neurons and the jth output neurons are used to calculate the activations y1 , · · · , yr from the output neurons, which are also the predicted classiﬁcation of the structure that generated the initial descriptors. If the classiﬁcation q = (q1 , . . . , qr ) for an n-tuple of descriptors p = (p1 , . . . , pn ) is known, then the pair pattern. Training a (p, q)is known as a training three-layer MLF using a collection p1 , q1 , . . . , pt , qt of training patterns means using nonlinear optimization to estimate the synaptic weights. In addition, the synaptic weights can be used for feature selection, which is to say that a neural network can be used to determine how signiﬁcant a descriptor is to a classiﬁcation problem by examining how sensitive the training process is to the values of that descriptor. 3.4.2

Implementation and Training

Both general-purpose and informatics-targeted implementations of MLFs are readily available. For example, the neural network toolbox for MatLab and the modeling kit ADAPT allow the construction of MLFs and other types of neural networks [75,77]. There are also many variations on the MLF ANN structure and training methods, including self-organizing feature maps (SOFM) [78,79] and Bayesian regularized neural network [80]. In addition, several different implementations of neural networks in programming code are also available. However, it is important not to treat ANNs or SVMs as “canned” routines, because they are similar to other nonlinear regression methods in that they can overﬁt the data and they can be overtrained to the training set [69]. Overtraining corresponds to the network’s “memorizing” of the training set, thus leading to poor predictions for structures not in the training set. This issue is often addressed using cross-validation or “leave-one-out” training methods in which a part of the training set is removed,

MACHINE LEARNING WITH GRAPHICAL INVARIANTS

105

the network is trained on the remaining training patterns, and then the classiﬁcation of the removed training patterns is predicted. Overﬁtting is a more serious and less avoidable problem [81]. Typically, there is small variation or “noise” in the descriptor values, so that if there are too many parameters—for example, too many neurons in the hidden layer—then training may lead to an “interpolation” of the slightly ﬂawed training set at the expense of poor generalization of the training set. In both overﬁtting and overtraining, convergence of the nonlinear optimization algorithm is common, but predictions are either meaningless in the case of overﬁtting or too dependent on the choice of the training. Because graphical invariants are often discrete valued and highly dependent on the construction of the graphical model, overﬁtting and overtraining are important issues that cannot be overlooked. For this reason, we conclude with a more mathematical exploration of the ANN algorithm so that their training and predictive properties can be better understood. To begin with, suppose that y = (y1 , ..., yn ) denotes the output from a three-layer MLF that has r input neurons connected to m hidden layer neurons that are connected to n neurons in the output layer. It has been shown that with the appropriate selection of synaptic weights, a three-layer MLF can approximate any absolutely integrable mapping of the type f (x1 , . . . , xr ) = (y1 , . . . , yn ) to within any > 0 [82]. That is, a three-layer MLP can theoretically approximation the solution to any classiﬁcation problem to within any given degree of accuracy, thus leading MLFs to be known as universal classiﬁers. However, in practice the number of hidden layer neurons may necessarily be large, thus contradicting the desire to use small hidden layers to better avoid overﬁtting and overtraining. To gain further insights into the innerworkings of a three-layer MLF, let wk = (wk1 , . . . , wkr ) denote the vector of weights between the input layer and the kth-hidden neuron. It follows that yj = g sj − bj , where bj denotes the bias of the jth output neuron, where

sj =

m

αjk g (wk (x − θk )),

k=1

and where θk denotes the bias for the kth hidden neuron. A common method for estimating synaptic weights given a collection p1 , q1 , . . . , pt , qt of training patterns is to deﬁne an energy function 1 y − qi y − qi , 2 t

E=

i=1

106

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

FIGURE 3.12 The energy surface.

and then train the MLP until we have closely approximated ∂E =0 ∂wkl

and

∂E =0 ∂αjk

at the inputs pi for all l = 1, . . . , r, k = 1, . . . , m, and j = 1, . . . , n. Because these equations cannot be solved directly, a gradient-following method called the backpropagation algorithm is used instead. The backpropagation algorithm is based on the fact that if g is the sigmoidal function deﬁned in equation (3.2), then g = κg (1 − g). In particular, for each training pattern pi , qi , a three-layer MLP ﬁrst calculates y as the output to pi , which is the feedforward step. The weights αjk are subsequently adjusted using αjk → αjk + λδj ξk , where ξk = g (wk · x − θk ) , where λ > 0 is a ﬁxed parameter called the learning rate, and where i δj = κyj 1 − yj q j − yj . The weights wkr are adjusted using wkl → wkl + λρk xl , where xl = g pil − θl and where ρk = κξk (1 − ξk )

n

αjk δj .

j=1

Cybenko’s theorem implies that the energy E should eventually converge to 0, so training continues until the energy is sufﬁciently small in magnitude. However, it is possible that the energy for a given training set does not converge. For example, it is possible for training to converge to a local minimum of the energy function, as depicted in Figure 3.12. When this happens, the network can make errant

107

GRAPHICAL INVARIANTS AS PREDICTORS

predictions known as spurious states. To avoid such local minima, it may be necessary to add small random inputs into each neuron so that training continues beyond any local minima, or it may be necessary to use a process such as simulated annealing to avoid such local minima [77]. Similarly, if the synaptic weights are not initialized to small random values, then the network tends to overtrain immediately on the ﬁrst training pattern presented to it and thus may converge only very slowly. Overtraining can often be avoided by calculating the energy on both the training set and a validation set at each iteration. However, overﬁtting may not necessarily be revealed by the behavior of the energy during training. This is because the quantities that deﬁne the training process are δj = κyj 1 − yj qji − yj and ρk = κξk (1 − ξk )

n

αjk δj ,

j=1

both of which are arbitrarily close to 0 when δj is arbitrarily close to 0. In overﬁtting, this means that once yj is sufﬁciently close to qji , the quantities ξk can vary greatly without changing the convergence properties of the network. That is, convergence of the output to the training set does not necessarily correspond to convergence of the hidden layer to a deﬁnite state. Often this means that two different training sessions with the same training set may lead to different values for the synaptic weights [69]. Careful design and deployment of the network can often avoid many of the issues that may affect ANNs. Large hidden layers are typically not desirable, and often an examination of the synaptic weights over several “test runs” will give some insight into the arbitrariness of the dependent variables ξk for the hidden layer, thus indicating when the hidden layer may possibly be too large. In addition, as the network begins to converge, modifying the learning parameter λ as the network converges may “bump” the network out of a local minimum without affecting overall convergence and performance.

3.5

GRAPHICAL INVARIANTS AS PREDICTORS

We conclude with an example of the usefulness of graphical invariants as predictors of biomolecular structures. The RAG database [48] contains all possible unlabeled trees of orders 2 through 10. For the trees of orders 2 through 8, each tree is classiﬁed as an RNA tree, an RNA-like tree or not RNA-like tree. For the trees of order 9 and 10, those that represent a known secondary RNA structure are identiﬁed as an RNA tree, but no trees are shown to be candidate structures, that is, RNA-like. In the works by Haynes et al. [22,23], the tree modeling method is used to quantify secondary RNA

108

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

structures with graphical parameters that are deﬁned by variations of the domination number of a graph. Note that a single graphical invariant may not be sufﬁcient to differentiate between trees that are RNA-like and those that are not. For example, the domination number for trees of order 7, 8, and 9 range from 1 to 4 with no discernable relationship between the value of the invariant and the classiﬁcation of the tree. However, deﬁning three parameters in terms of graphical invariants does prove to be predictive. Speciﬁcally, an MLP with three input neurons, ﬁve hidden neurons, and two output neurons is trained using values of the three parameters γ + γ t + γa , n γL + γ D P2 = , n diam(L(T )) + rad(L(T )) + |B| , P3 = n P1 =

where γ is the domination number, γt is the total domination number, γa is the global alliance number, γ L is the locating domination number of the line graph, and γD is the differentiating dominating number. For more on variations of the domination numbers of graphs, see the work by Haynes et al. [25]. Additionally, diam(L(T )) is the diameter of the line graph, rad(L(T )) is the radius of the line graph, |B| is the number of blocks in the line graph of the tree, and n is the order of a tree. The use of leave-one-out cross-validation during training addresses possible overﬁtting. We also use the technique of predicting complements (also known as leave-v-out crossvalidation) with 6, 13, and 20 trees, respectively, in the complement. Table 3.1 shows the average error and standard deviation in predicting either a “1” for a RNA tree or a “0” for a tree that is not RNA-like. The resulting MLP predicts whether trees of orders 7, 8, and 9 are RNA-like or are not RNA-like. The results are shown in Table 3.2. For the trees of order 7 and 8, the network predictions coincide with the RAG classiﬁcation with the exception of 2 of the 34 trees. Also, the network was able to predict an additional 28 trees of order 9 as being RNA-like in structure. This information may assist in the development of synthetic RNA molecules for drug design purposes [49]. The use of domination-based parameters as biomolecular descriptors supports the concept of using graphical invariants that are normally utilized in ﬁelds such as computer network design to quantify and identify biomolecules. By ﬁnding graphical invariants of the trees of orders 7, 8, and using the four additional trees of order 9 in TABLE 3.1

Accuracy Results for the RNA Classiﬁcation

Average error Standard deviation

|Comp| = 6

|Comp| = 13

|Comp| = 20

0.084964905 0.125919698

0.161629391 0.127051425

0.305193489 0.188008046

109

REFERENCES

TABLE 3.2 RAGa

Classb

Errorc

RAG

Class

Error

7.4 7.5 7.7 7.8 8.1 8.2 8.4 8.6 8.8 8.12 8.13 8.16 9.1 9.2 9.3 9.4 9.5 9.7 9.8

0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1

0.00947 0.0245 7.45E−05 1.64E−07 1.05E−06 1.24E−06 0.0138 0.0138 5.43E−05 3.59E−06 0.0157 8.81E−06 1.48E−07 0.0151 0.0121 4.05E−07 5.24E−05 6.38E−05 6.38E−05

9.9 9.10 9.12 9.14 9.15 9.16 9.17 9.18 9.19 9.20 9.21 9.22 9.23 9.24 9.25 9.26 9.28 9.29 9.30

0 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 0 1 1

0.0554 2.65E−06 5.28E−07 2.32E−07 1.82E−04 5.35E−04 6.24E−06 4.87E−07 6.06E−07 0.0247 6.38E−05 0.0247 7.41E−05 1.47E−05 3.85E−07 1.48E−04 7.41E−05 3.61E−07 1.47E−05

a b c

RNA Prediction Results RAG Class 9.31 9.32 9.33 9.34 9.35 9.36 9.37 9.38 9.39 9.40 9.41 9.42 9.43 9.44 9.45 9.46 9.47

1 0 1 1 0 0 0 1 0 0 0 1 1 1 0 0 0

Error 0.0247 1.99E−06 0.0462 0.00280 2.46E−06 7.41E−05 7.41E−05 4.86E−05 2.46E−06 4.79E−08 4.79E-08 2.51E−07 4.86E−05 0.0247 7.41E−05 4.79E−08 2.33E−08

Labels from the RAG RNA database [48]. Class = 1 if predicted to be an RNA tree; class = 0 if not RNA-like. Average deviation from predicted class.

the RAG database, Knisley et al. [23] utilize a neural network to identify novel RNAlike structures from among the unclassiﬁed trees of order 9 and thereby illustrate the potential for neural networks coupled with mathematical graphical invariants to predict function and structure of biomolecules.

ACKNOWLEDGMENTS This work was supported by a grant from the National Science Foundation, grant number DMS-0527311.

REFERENCES 1. 2. 3. 4. 5. 6.

Laurent A. Rev Sci 1843;14:314. Gerhardt C. Ann Chim Phys 1843;3(7):129. Russell C. The History of Valency. Leicester: Leicester University Press; 1971. Butlerov A. Zeitschr Chem Pharm 1861;4:549. Frankland E. Lecture Notes for Chemical Students. London: Van Voorst; 1866. Cayley A. Philos Mag 1874;47:444.

110

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

7. Lodge O. Philos Mag 1875;50:367. 8. Sylvester J. On an application of the new atomic theory to the graphical representation of the invariants and coinvariants of binary quantics. Am J Math 1878; 1:1. 9. Bonchev D. Rouvray D, editors. Chemical Graph Theory: Introduction and Fundamentals. Abacus Press/Gordon & Breach Science Publishers; 1990. 10. Trinajstic N. Chemical Graph Theory. Volume 1. CRC Press; 1983. 11. Trinajstic N. Chemical Graph Theory. Volume 2. CRC Press; 1983. 12. Barker E, Gardiner E, Gillet V, Ketts P, Morris J. Further development of reduced graphs for identifying bioactive compounds. J Chem Inform Comput Sci 2003;43:346–356. 13. Barker E, Buttar D, Cosgraove D, Gardiner E, Kitts P, Willett P, Gillet V. Scaffold hopping using clique detection applied to reduced graphs. J Chem Inform Model 2006;46:503–511. 14. Todeschini R, Consonni V. In: Mannhold R, Kubinyi H, Timmerman H, editors. Handbook of Molecular Descriptors. Volume 11. Series of Methods and Principles in Medicinal Chemistry. Wiley; 2000. 15. Tetko IV, Gasteiger J, Todeschini R, Mauri A, Livingstone D, Ertl P, Palyulin VA, Radchenko EV, Zeﬁrov NS, Makarenko AS, Tanchuk VY, Prokopenko VV. Virtual computational chemistry laboratory—design and description. J Comput Aided Mol Des 2005;19:453– 463. Available at http://www.vcclab.org/ 16. Talete: http://www.talete.mi.it/. 17. Weininger D. SMILES, A chemical language and information system. J Chem Inform Comput Sci 1988;28(1):31–36. 18. Schuffenhauer A, Gillet V, Willett P. Similarity searching in ﬁles of three-dimensional chemical structures: analysis of the BIOSTER databases using two-dimensional ﬁngerprints and molecular ﬁeld descriptors. J Chem Inform Comput Sci 2000;40:296–307. 19. Bemis G, Kuntz I. A fast and efﬁcient method for 2D and 3D molecular shape description. J Comput Aided Mol Des 1992;6(6):607–628. 20. Jurs Research Group, http://research.chem.psu.edu/pcjgroup/. 21. The Chemical Computing Group—MOE, http://www.chemcomp.com. 22. Haynes T, Knisley D, Seier E, Zou Y. A quantitative analysis of secondary RNA structure using domination based parameters on trees. BMC Bioinform 2006;7:108, doi:10.1186/1471-2105-7-108. 23. Haynes T, Knisley D, Knisley J, Zoe Y. Using a neural network to identify RNA structures quantiﬁed by graphical invariants. Submitted. 24. Hoyosa HB. Chem Soc Jpn 1971;44:2332. 25. Haynes T, Hedetniemi S, Slater P. Fundamentals of Domination in Graphs. Marcel Dekker; 1998. 26. Beineke, L. Zamﬁrescu C. Connection digraphs and second order line graphs. Discrete Math 1982;39:237–254. 27. Dix D. An application of iterated line graphs to biomolecular conformations. Preprint. 28. Gordon M, Scantlebury G. Trans Faraday Soc 1964;60:604. 29. Randic M. J Am Chem Soc 1975;97:6609. 30. Bonchev D. The overall Weiner index—a new tool for the characterization of molecular topology. J Chem Inform Comput Sci 2001;41(3):582–592. 31. Balaban A. Chem Phys Lett 1982;89:399–404.

REFERENCES

111

32. Balaban A, Mills D, Ivanciuc O, Basak. Reverse wiener indices. CCACAA 2000;73(4):923– 941. 33. Lima P, Golbraikh A, Oloff S, Xiao Y, Tropsha. Combinatorial QSAR modeling of P-glycoprotein substrates. J Chem Inform Model 2006;46:1245–1254. 34. Viswanadhan V, Mueller G, Basak S, Weinstein. Comparison of a neural net-based QSAR algorithm with hologram and multiple linear regression-based QSAR approaches: application to 1,4-dihydropyridine-based calcium channel antagonists. J Chem Inform Comput Sci 2001;41:505–511. 35. Randic M, Zupan J. On interpretation of well-known topological indices. J Chem Inform Comput Sci 2001;41:550–560. 36. Randic M, Basak S. A comparative study of proteomic maps using graph theoretical biodescriptors. J Chem Inform Comput Sci 2002;42:983–992. 37. Bajzer Z, Randic M, Plavisic M, Basak S. Novel map descriptors for characterization of toxic effects in proteomics maps. J Mol Graph Model 2003;22(1):1–9. 38. Breneman, CM, Sundling, CM, Sukumar N, Shen L, Katt WP, Embrechts MJ. New developments in PEST—shape/property hybrid descriptors. J Comput Aid Mol Design 2003;17:231–240. 39. Washietl S, Hofacker I, Stadler P. Fast and reliable prediction of noncoding RNAs. Proc Natl Acad Sci USA 2005;101:2454–2459. 40. Washietl S, Hofacker I, Lukasser M, Huttenhofer A, Stadler P. Mapping of conserved RNA secondary structures predicts thousands of functional noncoding RNAs in the human genome. Nat Biotechnol 2005;23(11):1383–1390. 41. Backofen R, Will S. Local sequence–structure motifs in RNA. J Biol Comp Biol 2004; 2(4):681–698. 42. Zuker M, Mathews DH, Turner DH. Algorithms and thermodynamics for RNA secondary structure prediction: a practical guide. In: Barciszewski J, Clark BFC, editors. RNA Biochemistry and Biotechnology. NATO ASI Series. Kluwer Academic Publishers; 1999. 43. Waterman M. An Introduction to Computational Biology: Maps, Sequences and Genomes. Chapman Hall/CRC; 2000. 44. Le S, Nussinov R, Maziel J. Tree graphs of RNA secondary structures and their comparison. Comput Biomed Res 1989;22:461–473. 45. Benedetti G, Morosetti S. A graph-topological approach to recognition of pattern and similarity in RNA secondary structures. Biol Chem 1996;22:179–184. 46. Barash D. Spectral decomposition of the Laplacian matrix applied to RNA folding prediction. Proceedings of the Computational Systems Bioinformatics (CSB); 2003. p 602–6031. 47. Heitsch C, Condon A, Hoos H. From RNA secondary structure to coding theory: a combinatorial approach. In: Hagiya M, Ohuchi A, editors. DNA 8; LNCS; 2003. p 215–228. 48. Fera D, Kim N, Shiffeidrim N, Zorn J. Laserson U, Gan H, Schlick, T. RAG: RNA-AsGraphs web resource. BMC Bioinform 2004;5:88. 49. Gan H, Fera D, Zorn J, Shiffeldrim N, Laserson U, Kim N, Schlick T. RAG: RNA-AsGraphs database—concepts, analysis, and features. Bioinformatics 2004;20:1285–1291. 50. Gan H, Pasquali S, Schlick T. Exploring the repertoire of RNA secondary motifs using graph theory: implications for RNA design. Nucl Acids Res 2003;31(11):2926–2943.

112

GRAPH THEORETIC MODELS IN CHEMISTRY AND MOLECULAR BIOLOGY

51. Zorn J, Gan HH, Shiffeldrim N, Schlick T. Structural motifs in ribosomal RNAs: implications for RNA design and genomics. Biopolymers 2004;73:340–347. 52. RNA Resources (online): (1) www.indiana.edu/˜tmrna; (2) www. imb-jena.de/RNA.html; (3) www.rnabase.org. 53. Mitchell E, Artymiuk P, Rice D, Willet P. Use of techniques derived from graph theory to compare secondary structure motifs in proteins. J Mol Biol 1989;212(1):151. 54. Grindley H, Artymiuk P, Rice D, Willet. Identiﬁcation of tertiary structure resemblance in proteins. J Mol Biol 1993;229(3):707. 55. Koch I, Kaden F, Selbig J. Analysis of protein sheet topologies by graph–theoretical techniques. Proteins 1992;12:314–323. 56. Patra S, Vishveshwara S. Backbone cluster identiﬁcation in proteins by a graph theoretical method. Biophys Chem 2000;84:13–25. 57. Kannan K, Vishveshwara S. Identiﬁcation of side-chain clusters in protein structures by a graph spectral method. J Mol Biol 1999;292:441–464. 58. Samudrala R, Moult J. A graph–theoretic algorithm for comparative modeling of protein structure. J Mol Biol 1998;279:287–302. 59. Vishveshwara S, Brinda K, Kannan N. Protein structures: insights from graph theory. J Theor Comput Chem 2002;I(1):187–211. 60. Pogliani L. Structure property relationships of amino acids and some dipeptides. Amino Acids 1994;6(2):141–153. 61. Pogliani L. Modeling the solubility and activity of amino acids with the LCCI method. Amino Acids 1995;9(3):217–228. 62. Randic M, Mills D, Basak S. On characterization of physical properties of amino acids. Int J Quantum Chem 2000;80:1199–1209. 63. Huan J, Bandyopadhyay D, Wang W, Snoeyink J, Prins J, Tropsha A. Comparing graph representations of protein structure for mining family-speciﬁc residue-based packing motifs. J Comput Biol 2005;12:(6):657–671. 64. Murzin A, Brenner S, Hubbard T, Chothia C. SCOP: a structural classiﬁcation of proteins database for the investigation of sequences and structures. J Mol Biol 1995;247(4):536–540. 65. Sachs R, Arsuaga J, Vazquez M, Hiatky L, Hahnfeldt P. Using graph theory to describe and model chromosome aberrations. Radiat Res 2002;158:556–567. 66. Gleiss P, Stadler P, Wagner A. Relevant cycles in chemical reaction networks. Adv Complex Syst 2001;1:1–18. 67. Vingron, Waterman M. Alignment networks and electrical networks. Discrete Appl Math: Comput Mol Biol 1996. 68. Bonchev D, Rouvray D. Complexity in Chemistry, Biology and Ecology. Springer; 2005. 69. Winkler D. The role of quantitative structure–activity relationships (QSAR) in biomolecular discovery. Brieﬁngs Bioinform 2002;3(1):73–86. 70. Xao XJ, Yao X, Panaye A, Doucet J, Zhang R, Chen H, Liu M, Hu Z, Fan B. Comparative study of QSAR/QSPR correlations using support vector machines, radial basis function neural networks, and multiple linear regression. J Chem Inform Comput Sci 2004;44(4):1257–1266. 71. Guler NF, Kocer S. Use of support vector machines and neural network in diagnosis of neuromuscular disorders. J Med Syst 2005;29(3):271–284.

REFERENCES

113

72. Ivanciuc O. Molecular graph descriptors used in neural network models. In: Devillers J, Balaban AT, editors. Topological Indices and Related Descriptors in QSAR and QSPR. The Netherlands: Gordon and Breach Science Publishers; 1999. p 697–777. 73. Vapnik V. Statistical Learning Theory. New York: Wiley-Interscience; 1998. 74. Rüping S. mySVM, University of Dortmund, http://www-ai.cs.uni-dortmund.de/SOFTWARE/MYSVM/. 75. Kecman V. Learning and Soft Computing: Support Vector Machines, Neural Networks, and Fuzzy Logic Models. Cambridge, MA: The MIT Press; 2001. 76. Knisley J, Glenn L, Joplin K, Carey P. Artiﬁcial neural networks for data mining and feature extraction. In: Hong D, Shyr Y, editors. Quantitative Medical Data Analysis Using Mathematical Tools and Statistical Techniques. Singapore: World Scientiﬁc; forthcoming. 77. Bose NK, Liang P. Neural Network Fundamentals with Graphs, Algorithms, and Applications. New York: McGraw-Hill; 1996. 78. Tamayo P, Slonim D, Mesirov J, Zhu Q, Kitareewan S, Dmitrovsky E, Lander E, Golub T. Interpreting patterns of gene expression with self-organizing maps methods and application to hematopoietic differentiation. Proc Natl Acad Sci USA 1999;96:2907–2912. 79. Bienfait, B. Applications of high-resolution self-organizing maps to retrosynthetic and QSAR analysis. J Chem Inform Comput Sci 1994;34:890–898. 80. Burden FR, Winkler DA. Robust QSAR models using Bayesian regularized neural networks. J Med Chem 1999;42(16):3183–3187. 81. Lawrence S, Giles C, Tsoi A. Lessons in neural network training: overﬁtting may be harder than expected. Proceedings of the 14th National Conference on Artiﬁcial Intelligence. AAAI-97; 1997. p 540–545. 82. Cybenko G. Approximation by superposition of a sigmoidal function. Math Control Signal Syst 1989;2(4):303–314.

CHAPTER 4

Algorithmic Methods for the Analysis of Gene Expression Data HONGBO XIE, UROS MIDIC, SLOBODAN VUCETIC, and ZORAN OBRADOVIC

4.1 INTRODUCTION The traditional approach to molecular biology consists of studying a small number of genes or proteins that are related to a single biochemical process or pathway. A major paradigm shift recently occurred with the introduction of gene expression microarrays that measure the expression levels of thousands of genes at once. These comprehensive snapshots of gene activity can be used to investigate metabolic pathways, identify drug targets, and improve disease diagnosis. However, the sheer amount of data obtained using the high throughput microarray experiments and the complexity of the existing relevant biological knowledge are beyond the scope of manual analysis. Thus, the bioinformatics algorithms that help to analyze such data are a very valuable tool for biomedical science. This chapter starts with a brief overview of the microarry technology and concepts that are important for understanding the remaining sections. Second, microarray data preprocessing, an important topic that has drawn as much attention from the research community as the data analysis itself, is addressed. Finally, some of the most important methods for microarray data analysis are described and illustrated with examples and case studies. 4.1.1

Biology Background

Most cells within the same living system have identical copies of DNA that store inherited genetic traits. DNA and RNA are the carriers of the genetic information. They are both polymers of nucleotides. There are four different types of nucleotides: adenine (A), thymine/uracil (T/U), guanine (G), and cytosine (C). Thymine is present in DNA, while uracil replaces it in RNA. Genes are fundamental blocks of DNA that encode genetic information and are transcribed into messenger RNA, or mRNA

Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

115

116

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

FIGURE 4.1 Central dogma of molecular biology: DNA–RNA–protein relationship.

(hereafter noted simply as “RNA”). RNA sequences are then translated into proteins, which are the primary components of living systems and which regulate most of a cell’s biological activities. Activities regulated and/or performed by a protein whose code is contained in the speciﬁc gene are also considered functions of that gene. For a gene, the abundance of the respective RNA in a cell (called the “expression level” for that gene) is assumed to correlate with the abundance of the protein into which the RNA translates. Therefore, the measurement of genes’ expression levels elucidates the activities of the respective proteins. The relationship between DNA, RNA, and proteins is summarized in the Central Dogma of molecular biology as shown in Figure 4.1. DNA consists of two helical strands; pairs of nucleotides from two strands are connected by hydrogen bonds, creating the so-called base pairs. Due to the chemical and steric properties of nucleotides, adenine can only form a base pair with thymine, while cytosine can only form a base pair with guanine. As a result, if one strand of DNA is identiﬁed, the other strand is completely determined. Similarly, the strand of RNA produced during the transcription of one strand of DNA is completely determined by that strand of DNA. The only difference is that uracil replaces thymine as a complement to adenine in RNA. Complementarity of nucleotide pairs is a very important biological feature. Preferential binding—the fact that nucleotide sequences only bind with their complementary nucleotide sequences—is the basis for the microarray technology. 4.1.2

Microarray Technology

Microarray technology evolved from older technologies that are used to measure the expression levels of a small number of genes at a time [1,2]. Microarrays contain a large number—hundreds or thousands—of small spots (hence the term “microarray”), each of them designed to measure the expression level of a single gene. Spots are made up of synthesized short nucleotide sequence segments called probes, which are attached to the chip surface (glass, plastic, or other material). Probes

INTRODUCTION

117

FIGURE 4.2 Binding of probes and nucleotide sequences. Probes in one spot are designed to bind only to one particular type of RNA sequences. This simpliﬁed drawing illustrates how only the complementary sequences bind to a probe, while other sequences do not bind to the probe.

in each spot are designed to bind only to the RNA of a single gene through the principle of preferential binding of complementary nucleotide sequences, as illustrated in Figure 4.2. The higher the RNA expression level is for a particular gene, the more of its RNA will bind (or “hybridize”) to probes in the corresponding spot. Single-channel and dual-channel microarrays are the two major types of gene expression microarrays. Single-channel microarrays measure the gene expression levels in a single sample and the readings are reported as absolute (positive) values. Dual-channel microarrays simultaneously measure the gene expression levels in two samples and the readings are reported as relative differences in the expression between the two samples. A sample (or two samples for dual-channel chips) and the microarray chip are processed with a speciﬁc laboratory procedure (the technical details of which are beyond the scope of this chapter). Part of the procedure is the attachment of a special ﬂuorescent substrate to all RNA in a sample (this is called the “labeling”). When a ﬁnalized microarray chip is scanned with a laser, the substrate attached to sequences excites and emits light. For dual-channel chips, two types of substrates (cy3 and cy5) that emit light at two different wavelengths are used (Fig. 4.3). The intensity of light is proportional to the quantity of RNA bound to a spot, and this intensity correlates to the expression level of the corresponding gene.

118

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

FIGURE 4.3 Dual-channel cDNA microarray. A sample of dual-channel microarray chip images, obtained from an image scanner. All images contain only a portion of the chip. From left to right: cy3 channel, cy5 channel, and the computer-generated joint image of cy3 and cy5 channels. A light gray spot in the joint image indicates that the intensity of the cy3 channel spot is higher than intensity of the cy5 channel spot, a dark gray spot indicates a reverse situation, and a white spot indicates similar intensities.

Images obtained from scanning are processed with image processing software. This software transforms an image bitmap into a table of spot intensity levels accompanied by additional information such as estimated spot quality. The focus of this chapter is on the analysis of microarray data starting from this level. The next section describes methods for data preprocessing, including data cleaning, transformation, and normalization. Finally, the last section provides an overview of methods for microarray data analysis and illustrates how these methods are used for knowledge discovery. The overall process of microarray data acquisition and analysis is shown in Figure 4.4.

FIGURE 4.4 Data ﬂow schema of microarray data analysis.

MICROARRAY DATA PREPROCESSING

4.1.3

119

Microarray Data Sets

Microarray-based studies consider more than one sample and most often produce several replicates for each sample. The minimum requirement for a useful biological study is to have two samples that can be hybridized on a single dual-channel or on two single-channel microarray chips. A data set for a single-channel microarray experiment can be described as an M × N matrix in which each column represents gene expression levels for one of the N chips (arrays), and each row is a vector containing expression levels of one of the M genes in different arrays (called “expression proﬁle”). A data set for a dual-channel microarray experiment can be observed as a similar matrix in which each chip is represented by a single column of expression ratios between the two channels (cy3 and cy5), or by two columns of absolute expression values of the two channels. A typical microarray data table has a fairly small number of arrays and a large number of genes (M N); for example, while microarrays can measure the expression of thousands of genes, the number of arrays is usually in the range from less than 10 (in small-scale studies) to several hundred (in large-scale studies). Methods described in this chapter are demonstrated by case studies on acute leukemia, Plasmodium falciparum intraerythrocytic developmental cycle, and chronic fatigue syndrome microarray data sets. Acute leukemia data set [3] contains 7129 human genes with 47 arrays of acute lymphoblastic leukemia (ALL) samples and 25 arrays of acute myeloid leukemia (AML) samples. The data set is used to demonstrate a generic approach to separating two types of human acute leukemia (AML versus ALL) based on their gene expression patterns. This data set is available at http://www.broad.mit.edu/cgi-bin/cancer/publications/pub paper.cgi? mode=view&paper id=43. Plasmodium falciparum data set [4] contains 46 arrays with samples taken during 48 h of intraerythrocytic developmental cycle of Plasmodium falciparum to provide the comprehensive overview of the timing of transcription throughout the cycle. Each array consists of 5080 spots, related to 3532 unique genes. This data set is available at http://biology.plosjournals.org/archive/15457885/1/1/supinfo/10.1371 journal.pbio.0000005.sd002.txt. Chronic fatigue syndrome (CFS) data set contains 79 arrays from 39 clinically identiﬁed CFS patients and 40 non-CFS (NF) patients [5]. Each chip measures expression levels of 20,160 genes. This data set was used as a benchmark at the 2006 Critical Assessment of Microarray Data Analysis (CAMDA) contest and is available at http://www.camda.duke.edu/camda06/datasets.

4.2 MICROARRAY DATA PREPROCESSING Images obtained by scanning microarray chips are preprocessed to identify the spots, estimate their intensities, and ﬂag the spots that cannot be read reliably. Data obtained from a scanner are usually very noisy; the use of raw unprocessed data would likely bias the study and possibly lead to false conclusions. In order to reduce these problems, several preprocessing steps are typically performed and are described in this section.

120

4.2.1

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

Data Cleaning and Transformation

4.2.1.1 Reduction of Background Noise in Microarray Images The background area outside of the spots in a scanned microarray image should ideally be dark (indicating no level of intensity), but in practice, the microarray image background has a certain level of intensity known as background noise. It is an indicator of the systematic error introduced by the laboratory procedure and microarray image scanning. This noise can often effectively be reduced by estimating and subtracting the mean background intensity from spot intensities. A straightforward approach that uses the mean background intensity of the whole chip is not appropriate when noise intensity is not uniform in all parts of the chip. In such situations, local estimation methods are used to estimate the background intensity individually for each spot from a small area surrounding the spot. 4.2.1.2 Identiﬁcation of Low Quality Gene Spots Chip scratching, poor washing, bad hybridization, robot injection leaking, bad spot shape, and other reasons can result in microarray chips containing many damaged spots. Some of these gene spot problems are illustrated in Figure 4.5. Low quality gene spots are typically identiﬁed by comparing the spot signal and its background noise [6,7]. Although statistical techniques can provide a rough identiﬁcation of problematic gene spots, it is important to carefully manually evaluate the microarray image to discover the source of the problem and to determine how to address problematic spots. The most simplistic method is to remove all data for the corresponding genes from further analysis. However, when the spots in question are the primary focus of the biological study, it is preferable to process microarray images using specialized procedures [8]. Unfortunately, such a process demands intensive manual and computational work. To reduce the data uncertainty due to damaged spots, it is sometimes necessary to repeat the hybridization of arrays with a large area or fraction of problematic spots.

FIGURE 4.5 Examples of problematic spots. The light gray ovals in the left image are examples of poor washing and scratching. The black circle spots in the right image are goodquality spots. The light gray circles indicate empty (missing) spots. The dark gray circles mark badly shaped spots.

MICROARRAY DATA PREPROCESSING

121

FIGURE 4.6 Data distribution before and after logarithmic transformation. Histograms show gene expression data distribution for patient sample #1 from acute lymphoblastic leukemia data set (X-axis represents the gene expression levels and Y -axis represents the amount of genes with given expression level). The distribution of raw data on the left is extremely skewed. The log-2 transformed data have a bell-shaped, approximately normal distribution, shown on the right.

4.2.1.3 Microarray Data Transformation After the numerical readings are obtained from the image, the objective of microarray data transformation is to identify outliers in the data and to adjust the data to meet the distribution assumptions implied by statistical analysis methods. A simple logarithmic transformation illustrated in Figure 4.6 is commonly used. It reshapes the data distribution into a bell shape that resembles normal distribution. This transformation is especially beneﬁcial for data from dual-channel arrays, since data from these arrays are often expressed as ratios of signal intensities of pairs of samples. Alternative transformations used in practice include arcsinh function, linlog transformation, curve-ﬁtting transformations, and shift transformation [9]; among them, the linlog transformation was demonstrated to be the most beneﬁcial. 4.2.2

Handling Missing Values

Typical data sets generated by microarray experiments contain large fractions of missing values caused by low quality spots. Techniques for handling missing values have to be chosen carefully, since they involve certain assumptions. When these assumptions are not correct, artifacts can be added into the data set that may substantially bias the evaluation of biological hypotheses. The straightforward approach is to completely discard genes with at least one missing value. However, if a large fraction of genes are eliminated because of missing values, then this approach is not appropriate. A straightforward imputation method consists of replacing all missing values for a given gene with the mean of its valid expression values among all available arrays. This assumes that the data for estimating the most probable value of a missing gene expression were derived under similar biological conditions; for instance, they could

122

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

be derived from replicate arrays. Most microarray experiments lack replicates due to the experimental costs. When there are no replicates available, a better choice for imputation is to replace all of the missing data in an array with the average of valid expression values within the array. The k-nearest-neighbor based method (KNN) does not demand experimental replicates. Given a gene with missing gene expression readings, k genes with the most similar expression patterns (i.e., its k neighbors) are found. The given gene’s missing values are imputed as the average expression values of its k neighbors [10], or predicted with the local least squares (LLS) method [11]. Recent research has demonstrated that the weighted nearest-neighbors imputation method (WeNNI), in which both spot quality and correlations between genes were used in the imputation, is more effective than the traditional KNN method [12]. Domain knowledge can help estimate missing values based on the assumption that genes with similar biological functions have similar expression patterns. Therefore, a missing value for a given gene can be estimated by evaluating the expression values of all genes that have the same or similar functions [13]. Although such an approach is reasonable in terms of biology, its applicability is limited when the function is unknown for a large number of the genes. In addition to the problems that are related to poor sample preparation, such as chip scratching or poor washing, a major source of problematic gene spots is relatively low signal intensity compared to background noise. It is important to check the reasons for low signal intensity. Gene expression might be very low, for instance, if the biological condition successfully blocks the gene expression. In this case, the low gene expression signal intensity is correct and the imputation of values estimated by the above-mentioned methods would probably produce a value that is too high. An alternative is to replace such missing data with the lowest obtained intensity value within the same chip or with an arbitrary small number. 4.2.3

Normalization

Microarray experiments are prone to systematic errors that cause changes in the data distribution and make statistical inference unreliable. The objective of normalization is to eliminate the variation in data caused by errors of the experimental methods, making further analysis based only on the real variation in gene expression levels. All normalization methods may introduce artifacts and should be used with care. Most methods are sensitive to outliers, so outlier removal is crucial for the success of normalization. There are two major types of normalization methods: within-chip normalization uses only the data within the same chip and is performed individually on each chip, while between-chip normalization involves microarray data from all chips simultaneously. Reviews on microarray data normalization methods are provided in [14–16]. 4.2.3.1 Within-Chip Normalization Several within-chip normalization methods are based on linear transformations of the form new value =(original value–

MICROARRAY DATA PREPROCESSING

123

a)/b, where parameters a and b are ﬁxed for one chip. Standardization normalization assumes that the gene expression levels in one chip follow the standard normal distribution. Parameter a is set to the mean, while parameter b is set to the standard deviation of gene expression levels in a chip. This method can be applied to both dual-channel and single-channel microarray data. Linear regression normalization [15] is another linear transformation that uses a different way to choose parameters a and b. The basic assumption for dualchannel arrays is that for a majority of genes, the intensity for the cy3 channel is similar to intensity for the cy5 channel. As a result, the two intensities should be highly correlated, and the ﬁtted regression line should be very close to the main diagonal of the scatterplot. Parameters a and b in linear transformation are chosen so that the regression line for transformed data points aligns with the main diagonal. A more advanced normalization alternative is the loess transformation. It uses a scatterplot of log ratio of two channel intensities (log(cy3/cy5)) against average value of two channel intensities ((cy3 + cy5)/2). A locally weighted polynomial regression is used on this scatterplot to form a smooth regression curve. Original data are then transformed using the obtained regression curve. Loess normalization can also be used with single-channel microarrays where two arrays are observed as two channels and normalized together. For data from more than two arrays, loess normalization can be iteratively applied on all distinct pairs of arrays, but this process has larger computational cost. Some other forms of loess normalization are local loess [17], global loess, and two-dimensional loess [18]. Several normalization methods make use of domain knowledge. All organisms have a subset of genes—called housekeeping genes—that maintain necessary cell activities, and, as a result, their expression levels are nearly constant under most biological conditions. All the above-mentioned methods can be modiﬁed so that all transformation parameters are calculated based only on the expression levels of housekeeping genes. 4.2.3.2 Between-Chip Normalization Row–column normalization [19] is applied to a data set comprised of several arrays, observed as a matrix with M rows (representing genes) and N columns (representing separate arrays and array channels). In one iteration, the mean value of a selected row (or column) is subtracted from all of the elements in that row (or column). This is iteratively repeated for all rows and columns of the matrix, until the mean values of all rows and columns approach zero. This method ﬁxes variability among both genes and arrays. A major problem with this method is its sensitivity to outliers, a problem that can signiﬁcantly increase computation time. Outlier removal is thus crucial for the performance of this method. The computation time can also be improved if standardization is ﬁrst applied to all individual arrays. Distribution (quantile) normalization [20] is based on the idea that a quantile– quantile plot is a straight diagonal line if two sample vectors come from the same distribution. Data samples can be forced to have the same distribution by projecting data points onto the diagonal line. For microarray data matrix with m rows

124

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

and n columns, each column is separately sorted in descending order, and the mean values are calculated for all rows in the new matrix. Each value in the original matrix is then replaced with the mean value of the row in the sorted matrix where that value was placed during sorting. Distribution normalization may improve the reliability of statistical inference. However, it may also introduce artifacts; after normalization, low intensity genes may have the same (very low) intensity across all arrays. Statistical model-ﬁtting normalization involves the ﬁtting of gene expression level data using a statistical model. The ﬁtting residues can then be treated as bias-free transformation of expression data. For example, for a given microarray data set with genes g (g = 1, . . . , n), biological conditions Ti (i = 1, . . . , m), and arrays Aj (j = 1, . . . , k), the intensity I of gene g at biological condition i and array j can be ﬁtted using a model [21] Igij = u + Ti + Aj + (TA)ij + εgij . The ﬁtting residues εgij for this model can be treated as bias-free data for gene g at biological condition i and array j after normalization. In experiments with dual-channel arrays, it is possible to distribute (possibly multiple) samples representing m biological conditions over k arrays in many different ways. Many statistical models have recently been proposed for model-ﬁtting normalization [22,23]. The normalization approaches of this type have been demonstrated to be very effective in many applications, especially in the identiﬁcation of differentially expressed genes [21,24]. 4.2.4

Data Summary Report

The data summary report is used to examine preprocessed data in order to ﬁnd and correct inconsistencies in the data that can reduce the validity of statistical inference. Unlike other procedures, there are no golden standards for this step. It is a good practice to evaluate the data summary report before and after data preprocessing. Approaches used to inspect the data include the evaluation of a histogram to provide information about data distribution in one microarray, a boxplot of the whole data set to check the similarities of all data distributions, and the evaluation of correlation coefﬁcient maps (see Fig. 4.7) to check consistency among arrays. Correlation coefﬁcient heat maps plot the values of correlation coefﬁcients between pairs of arrays. For a given pair of arrays, #i and #j, their expression proﬁles are observed as vectors and the correlation coefﬁcient between the two vectors is plotted as two pixels—in symmetrical positions (ij) and (ji)—in the heat map (the magnitude of correlation coefﬁcient is indicated by the color of the pixel). Correlation coefﬁcients are normally expected to be high, since we assume that the majority of gene expression levels are similar in different arrays. A horizontal (and the corresponding vertical) line in a heat map represents all of the correlation coefﬁcients between a given array and all other arrays. If a line has a near-constant color representing a very low value, we should suspect a problem with the corresponding array.

MICROARRAY DATA ANALYSIS

125

FIGURE 4.7 Correlation coefﬁcient heat maps. The left heat map shows the correlation coefﬁcients among the 79 samples of the CFS data set. The ﬁrst 40 samples are from the nonfatigue (control) group. The remaining 39 samples are from the group of CFS patients. The shade of a pixel represents the magnitude of the correlation coefﬁcient (as shown in the shaded bar on the right). The correlation coefﬁcients on the diagonal line are 1, since they compare each sample to itself. There are two clearly visible horizontal and vertical lines in the heat map on the left, corresponding to the sample #42. This indicates that this sample is different from the others; its correlation coefﬁcients with all other samples are near zero. Therefore, we need to inspect this sample’s chip image. Another sample that draws our attention is sample #18, which also has near-uniform correlation coefﬁcients (around 0.5) with other samples. After inspecting the sample’s chip image, we found that these correlation coefﬁcients reﬂected sample variation and that we should not exclude sample #18 from our study. A similar heat map on the right shows the correlation coefﬁcients among the 47 ALL samples from the acute leukemia data set. Overall data consistency is fairly high with an average correlation coefﬁcient over 0.89.

4.3 MICROARRAY DATA ANALYSIS This section provides a brief outline of methods for the analysis of preprocessed microarray data that include the identiﬁcation of differentially expressed genes, discovery of gene expression patterns, characterization of gene functions, pathways analysis, and discovery of diagnostic biomarkers. All methods described in this section assume that the data have been preprocessed; see Section 4.2 for more details on microarray data preprocessing methods.

4.3.1

Identiﬁcation of Differentially Expressed Genes

A gene is differentially expressed if its expression level differs signiﬁcantly for two or more biological conditions. A straightforward approach for the identiﬁcation of differentially expressed genes is based on the selection of genes with absolute values of log-2 ratio of expression levels larger than a prespeciﬁed threshold (such as 1). This simple approach does not require replicates, but is subject to high error rate (both false positive and false negative) due to the large variability in microarray data.

126

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

More reliable identiﬁcation is possible by using statistical tests. However, these methods typically assume that the gene expression data follow a certain distribution, and require sufﬁciently large sample size that often cannot be achieved due to microarray experimental conditions or budget constraints. Alternative techniques, such as bootstrapping, impose less rigorous requirements on the sample size and distribution while still providing reliable identiﬁcation of differentially expressed genes. Given the data, a statistical test explores whether a null hypothesis is valid and calculates the p-value, which refers to the probability that the observed statistics are generated by the null model. If the p-value is smaller than some ﬁxed threshold (e.g., 0.05), the null hypothesis is rejected. If the p-value is above the threshold, however, it should not be concluded that the original hypothesis is conﬁrmed; the result of the test is that the observed events do not provide a reason to overturn it [25]. The most common null hypothesis in microarray data analysis is that there is no difference between two groups of expression values for a given gene. In this section, we brieﬂy introduce the assumptions and requirements for several statistical tests that are often used for the identiﬁcation of differentially expressed genes. 4.3.1.1 Parametric Statistical Approaches The Student’s t-test examines the null hypothesis that the means of distributions from which two samples are obtained are equal. The assumptions required for t-test are that the two distributions are normal and that their variances are equal. The null hypothesis is rejected if the p-value for the t-statistics is below some ﬁxed threshold (e.g., 0.05). The t-test is used in microarray data analysis to test—for each individual gene—the equality of the means of expression levels under two different biological conditions. Genes for which a t-test rejects the null hypothesis are considered differentially expressed. The t-test has two forms: dependent sample t-test and independent sample t-test. Dependent sample t-test assumes that each member in one sample is related to a speciﬁc member of the other sample; for example, this test can be used to evaluate the drug effects by comparing the gene expression levels of a group of patients before and after they are given a certain type of drug. Independent sample t-test is used when the samples are independent of each other; for example, this test can be used to evaluate the drug effects by comparing gene expression levels for a group of patients treated with the drug to the gene expression levels of another group of patients treated with a placebo. The problem with using the t-test in microarray data analysis is that the distribution normality requirement is often violated in microarray data. One-way analysis of variance (ANOVA) is a generalization of the t-test to samples from more than two distributions. ANOVA also requires that the observed distributions are normal and that their variances are approximately equal. ANOVA is used in microarray data analysis when gene expression levels are compared under two or more biological conditions, such as for a comparison of gene expression levels for a group of patients treated with drug A, a group of patients treated with drug B, and a group of patients treated with placebo. The volcano plot (see Fig. 4.8) is often used in practice for the identiﬁcation of differentially expressed genes; in this case, it is required that a gene both

MICROARRAY DATA ANALYSIS

127

FIGURE 4.8 The volcano plot of signiﬁcance versus fold change. This ﬁgure is a plot of the signiﬁcance (p-value from ANOVA test, on a –log-10 scale) against fold change (log-2 ratio), for testing the hypothesis on the differences in gene expression levels between the AML group and the ALL group in the acute leukemia data set. The horizontal line represents a signiﬁcance level threshold of 0.05. The two vertical lines represent the absolute fold-change threshold of 2. The genes plotted in the two “A” regions are detected as signiﬁcant by both methods, while the genes plotted in region “C” are detected as insigniﬁcant by both methods. This type of plot demonstrates two types of errors that occur with the ratio-based method: false positive errors plotted in the two “D” regions, and false negative errors plotted in the “B” region. A common practice is to identify only the genes plotted in the two “A” regions as differentially expressed and discard the genes plotted in the “B” region.

passes the signiﬁcance test and that its expression level log ratio is above the threshold. 4.3.1.2 Nonparametric Statistical Approaches Nonparametric tests relax the assumptions posed by the parametric tests. Two popular nonparametric tests are the Wilcoxon rank-sum test for equal median and the Kruskal–Wallis nonparametric one-way analysis of variance test. The Wilcoxon rank-sum test (also known as Mann–Whitney U-test) tests the hypothesis that two independent samples come from distributions with equal medians. This is a nonparametric version of the t-test. It replaces real data values with their sorted ranks and uses the sum of ranks to obtain a p-value. Kruskal–Wallis test compares the medians of the samples. It is a nonparametric version of the oneway ANOVA, and an extension of the Wilcoxon rank-sum test to more than two groups.

128

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

FIGURE 4.9 Importance of data distribution type for the choice of statistical test. Two histograms show the distribution of expression levels for gene #563 in two groups of samples in the acute leukemia data set: ALL on the left and AML on the right. The two distributions are clearly different. When testing the equality of means of two groups, the Kruskal–Wallis test gives us the p-value of 0.16, and the ANOVA test gives us the p-value of 0.05. Since the data distribution in the right panel has two major peaks, it is not close to normal distribution; therefore, it is preferable to choose the Kruskal–Wallis test.

Nonparametric tests tend to reject less null hypotheses than the related parametric tests and have lower sensitivity, which leads to an increased rate of false negative errors. They are more appropriate when the assumptions for parametric tests are not satisﬁed, as is often the case with microarray data (see Fig. 4.9). However, this does not imply that nonparametric tests will necessarily identify a smaller number of genes as differentially expressed than the parametric test, or that the sets of genes identiﬁed by one parametric test and one nonparametric test will necessarily be in a subset relationship. To illustrate the difference in results we used both ANOVA and the Kruskal–Wallis test to identify differentially expressed genes in the acute leukemia data set. Out of 7129 genes, 1030 genes were identiﬁed as differentially expressed by both methods. In addition to that, 155 genes were identiﬁed only by ANOVA, while 210 genes were identiﬁed only by the Kruskal–Wallis test. 4.3.1.3 Advanced Statistical Models Recently, more sophisticated models and methods for the identiﬁcation of differentially expressed genes have been proposed [26,27]. For example, when considering the factors of array (A), gene (G), and biological condition (T), a two-step mix-model [21] ﬁrst ﬁts the variance of arrays, biological conditions, and interactions between arrays and biological conditions using one model, and then uses the residues from ﬁtting the ﬁrst model to ﬁt the second model. An overview of mix-model methods is provided in the work by Wolﬁnger et al. [28]. Other advanced statistical approaches with demonstrated good results in identifying differentially expressed genes include the signiﬁcance analysis of microarray (SAM) [29], regression model approaches [30], empirical Bayes analysis [31], and the bootstrap approach to gene selection (see the case study below).

Case Study 4.1: Bootstrapping Procedure for Identiﬁcation of Differentially Expressed Genes We illustrate the bootstrapping procedure for the identiﬁcation of differentially expressed genes on an acute leukemia data set. The objective is to identify the genes that are differentially expressed between 47 ALL and 25 AML arrays. For each gene, we ﬁrst calculate the p-value p0 of two-sample t-test on the gene’s expression levels in AML group versus ALL group. Next, the set of samples is randomly split into two subsets with 47 and 25 elements, and a similar t-test is performed with these random subsets and p-value p1 is obtained. This step is repeated a large number of times (n>1000), and as a result we obtain p-values p1 , p2 , p3 , . . . , pn . These p-values are then compared to the original p0 . We deﬁne the bootstrap p-value as pb = c/n, where c is the number of times when values pi (i = 1, . . . , n) are smaller than p0 . If pb is smaller than some threshold (e.g., 0.05), then we consider the gene to be differentially expressed. For the 88th gene in the data set, the expression levels are ALL 759, 1656, 1130, 1062, 822, 1020, 1068, 1455, 1099, 1164, 662, 753, 728, 918, 943, 644, 2703, 916, 677, 1251, 138, 1557, 750, 814, 667, 616, 1187, 1214, 1080, 1053, 674, 708, 1260, 1051, 1747, 1320, 730, 825, 1072, 774, 690, 1119, 866, 564, 958, 1377, 1357

AML 1801, 1024, 3084, 1974, 1084, 1090, 908, 2474, 1635, 1591, 1323, 857, 1872, 1593, 1981, 2668, 1128, 3601, 2153, 1603, 769, 893, 2513, 2903, 2147

Figure 4.10 The p-value of the t-test for this gene is p0 = 3.4E − 007, which is smaller than the threshold 0.05. The distribution of p-values obtained on randomly selected subsets (p1 , . . . , p1000 ) is shown in Figure 4.10. The bootstrap p-value is pb = 0, so the bootstrapping procedure conﬁrms the result of the t-test, that is, the 88th gene is differentially expressed.

130

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

FIGURE 4.11 Benjamini–Hochberg FDR control. This ﬁgure compares the use of constant p-value threshold (in this case 0.05) and the use of Benjamini–Hochberg (BH) FDR control method for the two-sample t-test on acute leukemia data set. The curve is the plot of the original p-values obtained from the t-tests for individual genes, sorted in an increasing order. The horizontal line represents the constant p-value threshold of 0.05. There are 2106 genes with a p-value smaller than this threshold. The slanted line represents the p-value thresholds pi = α0 · i/N that BH method uses to control the FDR at level of α0 = 0.05 (N is the total number of genes). It intersects with the curve at p-value 0.0075. Only the 1071 genes whose p-values are smaller than 0.0075 are considered to be signiﬁcantly differentially expressed. The remaining 935 genes are considered to be false positive discoveries made by individual t-tests.

4.3.1.4 False Discovery Rate (FDR) Control Statistical procedures for the identiﬁcation of differentially expressed genes can be treated as multiple hypothesis testing. A p-value threshold that is appropriate for a single test does not provide good control on false positive discovery for the overall procedure. For example, testing of 10,000 genes with p-value threshold of 0.05 is expected to identify 10, 000 × 0.05 = 500 genes as differentially expressed even if none of the genes are actually differentially expressed. The false positive rate can be controlled by evaluating the expected proportion of true rejected null hypotheses out of the total number of rejected null hypothesis. An example of FDR control is shown in Figure 4.11. If N is the total number of genes, α0 is the p-value threshold, and pi (i = 1, . . . , N) are p-values in ascending order, then the ith ranked gene is selected if pi ≤ α0 · i/N [32]. A comprehensive review of this statistical FDR control is presented in the work by Qian and Huang [33]. It is worth noting that a bootstrap procedure for FDR control has also been introduced [29] and was shown to be suitable for gene selecting when data distribution deviates from normal distribution.

MICROARRAY DATA ANALYSIS

131

FIGURE 4.12 Part of the Gene Ontology direct acyclic graph. The shortest path between GO:0007275:development and GO:0009948:anterior/posterior axis speciﬁcation is 3 (the nearest common ancestor for the two terms is GO:0007275:development). The shortest path between the terms GO:0007275:development and GO:0008152:metabolism is 3 but the only ancestor for them is GO:0008150:biological processes, so the distance between them is 3 + 23, where 23 is the added penalty distance, which is the maximum distance in Biological Process part of Gene Ontology DAG.

4.3.2

Functional Annotation of Genes

One of the goals of microarray data analysis is to aid in discovering biological functions of genes. One of the most important sources of domain knowledge on gene functions is Gene Ontology (GO), developed and maintained by the Gene Ontology Consortium [34,35]. Using a controlled and limited vocabulary of terms describing gene functions, each term in Gene Ontology consists of a unique identiﬁer, a name, and a deﬁnition that describes its biological characteristic. GO terms are split into three major groups: biological processes, molecular functions, and cellular component categories. Within each category, GO terms are organized in a direct acyclic graph (DAG) structure, where each term is a node in the DAG, and each node can have several child and parent nodes. The GO hierarchy is organized with a general-to-speciﬁc relation between higher and lower level GO terms (see Fig. 4.12). Sometimes, it is useful to compare several GO terms and determine if they are similar. Although there is no commonly accepted similarity measure between different GO terms, various distance measures were proposed for measuring the similarity between GO terms [36,37]. For example, the distance between nodes X and Y in a DAG can be measured as the length of the shortest path between X and Y within the GO hierarchy normalized by the length of maximal chain from the top to the bottom of the DAG [38]. One possible modiﬁcation, illustrated in Figure 4.12, is to add a large penalty for paths that cross the root of a DAG to account for unrelated terms. 4.3.3

Characterizing Functions of Differentially Expressed Genes

After identifying differentially expressed genes, the next step in analysis is often to explore the functional properties of these genes. This information can be extremely

132

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

useful to domain scientists for the understanding of biological properties of different sample groups. Commonly used methods for such analysis are described in this section. The chi-square and the Fisher’s exact tests are used to test whether the selected genes are overannotated with a GO term F, as compared to the set of remaining genes spotted on a microarray [39,40]. For instance, the following 2 × 2 contingency table contains the data that can be used to test whether the frequency of genes annotated with a GO term F among the selected genes is different than the same frequency among the remaining genes: Number of genes

Annotated with a GO term F Not annotated with a GO term F Total

Selected genes

Remaining genes

Total

f11 f21 c1

f12 f22 c2

r1 r2 S

Chi-square test uses a χ2 statistic with formula 2 2 (fij − ri cj /S)2 χ = . ri cj /S 2

i=1 i=1

The chi-square test is not suitable when any of the expected values ri cj /S are smaller than 10. Fisher’s exact test is more appropriate in such cases. In practice, all genes annotated with term F and all terms in the subtree of term F are considered to be annotated with F. 4.3.4

Functional Annotation of Uncharacterized Genes

The functional characterization of genes involves a considerable amount of biological laboratory work. Therefore, only a small fraction of known genes and proteins is functionally characterized. An important microarray application is the prediction of gene functions in a cost-effective manner. Numerous approaches use microarray gene expression patterns to identify unknown gene functions [41–43]. In the following section, we outline some of the most promising ones. 4.3.4.1 Unsupervised Methods for Functional Annotation Gene expression proﬁles can be used to measure distances among genes. The basic assumption in functional annotation is that genes with similar biological functions are likely to have similar expression proﬁles. The functions of a given gene could be inferred by considering the known functions of genes with similar expression proﬁles. A similar approach is to group all gene expression proﬁles using clustering methods and to ﬁnd the overrepresented functions within each cluster [44,45]. Then, all genes within a cluster are annotated with the overrepresented functions of that cluster. An alternative is to ﬁrst cluster only the genes with known functions. An averaged expression proﬁle

MICROARRAY DATA ANALYSIS

133

of all genes within the cluster can then be used as the representative of a cluster [4]. The gene with the unknown function can be assigned functions based on its distance to the representative expression proﬁles. Conclusions from these procedures are often unreliable: a gene may have multiple functions that may be quite distinctive; also, genes with the same function can have quite different expression proﬁles. Therefore, it is often very difﬁcult to select representative functions from a cluster of genes. Many unsupervised methods for functional annotation face the issue of model selection in clustering, such as choosing the proper number of clusters, so that the genes within the cluster have similar functions. Domain knowledge is often very helpful in the model selection [46]. As we already mentioned, nearest-neighbor and clustering methods for assigning functions to genes are based on assumptions that genes with similar functions will have similar expression proﬁles [47]. However, this assumption is violated for more than half of the GO terms [48]. A more appropriate approach, therefore, is to ﬁrst determine a subset of GO terms for which the assumption is valid, and use only these GO terms in gene function annotation. 4.3.4.2 Supervised Methods for Functional Annotation Supervised methods for functional characterization involve building classiﬁcation models that predict gene functions based on gene expression proﬁles. A predictor for a given function is trained to predict whether a given gene has that function or not [49]. Such a predictor is trained and tested on a collection of genes with known functions. If testing shows that the accuracy of the predictor is signiﬁcantly higher than that for a trivial predictor, the predictor can then be used on the uncharacterized genes to annotate them. Previous research shows that the support-vector machines (SVM) model achieves the best overall accuracy when compared to other competing prediction methods [50]. The SVM-based predictor can overcome some of the difﬁculties that are present with the unsupervised methods. It can ﬂexibly select the expression proﬁle similarity measure Case Study 4.2: Identiﬁcation of GO Terms with Conserved Expression Proﬁles We applied a bootstrapping procedure to identify GO terms that have conserved gene expression proﬁles in the Plasmodium data set that contains 46 arrays. Each of the 46 arrays in the Plasmodium data set measures expression levels of 3532 genes at a speciﬁc time point over the 48-h Plasmodium falciparum intraerythrocytic developmental cycle (IDC). The bootstrap procedure was applied to 884 GO terms that are associated with at least two genes. For a given GO term with l associated genes, we collected their expression proﬁles and calculated the average pairwise correlation coefﬁcients ρ0 . We compared ρ0 to average expression proﬁle correlation coefﬁcients of randomly selected pairs of genes. In each step of the bootstrap procedure, we randomly selected l genes and computed their average correlation coefﬁcient ρi . This was repeated 10,000 times to obtain ρ1 , ρ2 , . . . , ρ10,000 . We counted the number c of ρi that are greater than ρ0 and calculated the bootstrap p-value as pb = c/n. If pb is smaller than 0.05, the expression proﬁles of the GO term are considered to be conserved.

134

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

Figure 4.13 The plot in the left part of Figure 4.13 shows the cumulative number of GO terms with p-value smaller than x. Four hundred and twenty-eight (48.4 percent) of the 884 GO terms have p-value smaller than 0.05; 199 of these are molecular function and 229 are biological process GO terms. This result validates to a large extent the hypothesis that genes with identical functions have similar expression proﬁles. However, it also reveals that for a given microarray experiment, a large fraction of functions do not follow this hypothesis. Figure 4.13 also contains expression proﬁles of genes annotated with GO term GO:0006206 (pyrimidine base metabolism; bootstrap p-value 0) and its representative expression proﬁle.

and handle a large feature space. The unresolved problem of the supervised approach is the presence of multiple classes and class imbalance; a function can be associated with only a few genes, and there are several thousand functions describing genes in a given microarray data set. 4.3.5

Correlations Among Gene Expression Proﬁles

A major challenge in biological research is to understand the metabolic pathways and mechanisms of biological systems. The identiﬁcation of correlated gene expressions in a microarray experiment is aimed at facilitating this objective. Several methods for this task are described in this section. 4.3.5.1 Main Methods for Clustering of Gene Expression Proﬁles Hierarchical clustering and K-means clustering are two of the most popular approaches for the clustering of microarray data. The hierarchical clustering approach used with microarray data is the bottom-up approach. This approach begins with single-member clusters, and small clusters are iteratively grouped together to form larger clusters,

MICROARRAY DATA ANALYSIS

135

FIGURE 4.14 Visualization of hierarchically clustered data with identiﬁed functional correlation. The Plasmodium data set was clustered using hierarchical clustering. Rows of pixels represent genes’ expression levels at different time points. Columns of pixels represent the expression level of all genes in one chip at one given time point in the IDC process, and their order corresponds to the order of points in time. The cluster hierarchy tree is on the left side. The image contains clearly visible patterns of dark gray and light gray pixels that correspond to upregulated and downregulated expression levels, respectively. A domain expert investigated the higher level nodes in the clustering tree, examining the similarity of functions in each cluster for genes with known functions. Five examples of clusters for which the majority of genes are annotated with a common function are marked using the shaded bars and the names of the common functions. These clusters can be used to infer the functions of the genes within the same cluster whose function is unknown or unclear.

136

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

until a single cluster containing the whole set is obtained. In each iteration, the two clusters that are chosen for joining are two clusters with the closest distance to each other. The result of hierarchical clustering is a binary tree; descendants of each cluster in that tree are the two subclusters of which the cluster consists. The distance between two clusters in the tree reﬂects their correlation distance. Hierarchical clustering provides a visualization of the relationships between gene expression proﬁles (see Fig. 4.14). K-means clustering groups genes into a prespeciﬁed number of clusters by minimizing the distances within each cluster and maximizing the distances between clusters. The K-means clustering method ﬁrst chooses k genes called centroids (which can be done randomly or by making sure that their expression proﬁles are very different). It then examines all gene expression proﬁles and assigns each of these to the cluster with the closest centroid. The position of a centroid is recalculated each time a gene expression proﬁle is added to the cluster by averaging all proﬁles within the cluster. This procedure is iteratively repeated until stable clusters are obtained, and no gene expression proﬁles switch clusters between iterations. The K-means method is computationally less demanding than hierarchical clustering. However, an obvious disadvantage is the need for the selection of parameter k, which is generally not a trivial task. 4.3.5.2 Alternative Clustering Methods for Gene Expression Proﬁles Alternative clustering methods that are used with gene expression data include the self-organizing map (SOM) and random forest (RF) clustering. An SOM is a clustering method implemented with a neural network and a special training procedure. The comparison of SOM with hierarchical clustering methods shows that an SOM is superior in both robustness and accuracy [51]. However, as K-means clusters, an SOM requires the value of parameter k to be prespeciﬁed. RF clustering is based on an RF predictor that is a collection of individual classiﬁcation trees. After an RF is constructed, the similarity measure between two samples can be deﬁned as the number of times a tree predictor places the two samples in the same terminal node. This similarity measure can be used to cluster gene expression data [52]. It was demonstrated that the RF-based clustering of gene proﬁles is superior compared to the standard Euclidean distance measure [53]. Other advanced techniques proposed for clustering gene expression data include the mixture model approach [54], the shrinkage-based similarity procedure [55], the kernel method [56], and bootstrapping analysis [57]. 4.3.5.3 Distance of Gene Expression Proﬁle Clusters There are many ways to measure the distance between gene expression proﬁles and clusters of gene expression proﬁles. The Pearson correlation coefﬁcient and the Euclidean distance are often used for well-normalized microarray data sets. However, microarray gene expression proﬁles contain noise and outliers. Nonparametric distance measures provide a way to avoid these problems. For instance, the Spearman correlation replaces gene expression values with their ranks before measuring the distance. Average linkage, single linkage, and complete linkage are commonly used to measure the distances between clusters of gene expression proﬁles. Average linkage

MICROARRAY DATA ANALYSIS

137

FIGURE 4.15 Cluster distance deﬁnitions. Hollow dots represent data points, and the two circles represent two distinct clusters of data points, while black dots are weighted centers of data points in each cluster. The bottom line illustrates the single linkage method of cluster distance, the top line illustrates the complete linkage method, and the middle line represents the average linkage method.

computes the distances between all pairs of gene expression proﬁles from two clusters and the average of these distances becomes the distance between the clusters. Single linkage deﬁnes the distance between two clusters as the distance between the two closest representatives of these clusters. Complete linkage deﬁnes the distance between two clusters as the distance between the two farthest representatives. The difference between these three deﬁnitions is illustrated in Figure 4.15. 4.3.5.4 Cluster Validation Regardless of the type of clustering, all obtained clusters need to be evaluated for biological validity before proceeding to further analysis. Visual validation is aimed at determining whether there are outliers in clusters or whether the gene expression proﬁles within each cluster are correlated to each other. If a problem is detected by validation, clusters are often reﬁned by adjusting the number of clusters (parameter k), the distance measuring method, or even by repeating the clustering with a different clustering method. Microarray data sets are highly dimensional. It is often difﬁcult to provide a clear view of gene expression proﬁle types within each cluster. By reducing the dimension of the microarray data set to two or three dimensions, analysis can be simpliﬁed and a visual overview of the data can be generated, which may provide useful information on gene expression proﬁle clustering. Such a dimensionality reduction is typically achieved with principal component analysis (PCA). This technique ﬁnds the orthogonal components (also called principal components) of the input vectors and retains two or three orthogonal components with the highest variance. A visual examination of the projected clusters can help determine an appropriate number of distinct clusters for clustering as illustrated in Figure 4.16.

138

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

FIGURE 4.16 Principal component analysis. This scatterplot was obtained by plotting the ﬁrst and the second principal component of the ﬁrst 100 genes in an acute leukemia data set. It illustrates the beneﬁt of PCA for visualizing data. There are apparently two to four clusters (depending on the criteria of separation of clusters), which is valuable information for the choice of parameter k in many clustering algorithms. A possible clustering to two groups of genes is shown as light gray and dark gray points, while black and lighter gray (top right) points can be discarded as outliers.

4.3.6

Biomarker Identiﬁcation

One major challenge of microarray data analysis is sample classiﬁcation. Examples of classiﬁcation include the separation of people with and without CFS, or the classiﬁcation of cancer patients into prespeciﬁed subcategories. Classiﬁer construction includes the selection of the appropriate prediction model and the selection of features. Feature selection is a technique whereby genes with the most useful expression levels for classiﬁcation are selected. Such genes can also be useful as biomarkers that in turn can be used for practical and cost-effective classiﬁcation systems. 4.3.6.1 Classical Feature Selection Methods Forward feature selection is an iterative process. It starts with an empty set of genes and at each iteration step adds the most informative of the remaining genes based on their ability to discriminate different classes of samples. This process is repeated until no further signiﬁcant improvement of classiﬁcation accuracy can be achieved. A reverse procedure, backward feature elimination, is also widely applied. It begins by using all the available genes and continues by dropping the least important genes until no signiﬁcant improvement can be achieved.

MICROARRAY DATA ANALYSIS

139

In the ﬁlter feature selection methods, various statistical measures are used to rank genes by their discriminative powers. Successful measures include using the t-test, the chi-square test, information gain, and the Kruskal–Wallis test. A recently proposed biomarker identiﬁcation approach involves clustering gene expression proﬁles [58]. In such an approach, genes are clustered based on their microarray expression proﬁles. Then, within each cluster, the most representative gene is selected (the representative gene could be the gene closest to the mean or median expression value within the cluster). The representative genes are collected and used as selected features to build a predictor for classiﬁcation of unknown samples. However, selected sets of genes often lack biological justiﬁcation and their size is usually too large for experimental validation. 4.3.6.2 Domain Knowledge-Based Feature Selection A recently proposed feature selection approach exploits the biological knowledge of gene functions as a criterion for selection [59]. The underlying hypothesis for this approach is that the difference between samples lies in a few key gene functions. Genes annotated with those key functions are likely to be very useful for classiﬁcation. To use this observation, a statistical test is applied to microarray data in order to rank genes by their p-values and generate a subset of signiﬁcant genes. Selected genes are compared to the overall population in order to identify the most signiﬁcant function. Only genes associated with the most signiﬁcant function are selected for classiﬁcation. This approach results in a small set of genes that provide high accuracy (see the case study below).

Case Study 4.3: Feature Selection for Classiﬁcation The CFS data set contains 39 test samples from patients clinically diagnosed with CFS and 40 control samples from subjects without CFS (nonfatigue, NF). The objective is to develop a predictor that classiﬁes new subjects either as CFS or NF based on their gene expressions. Each microarray measures 20,160 genes. We ﬁrst used the Kruskal–Wallis test with p-value threshold of 0.05 for the initial gene selection. For each GO term, we count how many genes in the original set of 20,160 genes, as well as how many of the selected, are annotated with it. We then use the hypergeometric test to evaluate whether the representation of this GO term in the selected subset of genes is signiﬁcantly greater than that in the original set of genes. We rank GO terms by their p-values and ﬁnd the most overrepresented (those with smallest p-value) GO term. We narrow the selection of genes to include only the genes that are the most overrepresented GO term. We then select these genes as features for classiﬁcation. Feature selection methods were tested using a leave-one-out cross-validation procedure. The prediction model used in all experiments was an SVM with quadratic kernel k(x, y) = (C + xT y)2 . The Kruskal–Wallis test with a threshold of 0.05 produced the initial selection of 1296 genes. The overall accuracy of prediction with this feature selection method was 53 percent, which is barely better than the 50 percent accuracy of a random predictor. The

140

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

proposed procedure narrowed the selection down to 17 genes. Although the number of features was reduced by almost two orders of magnitude, the overall accuracy of prediction with this smaller feature set improved to 72 percent. The GO term that was most often selected was GO:0006397 (mRNA processing). Interestingly, mRNA processing was veriﬁed by unrelated biological research as very important for CFS diagnosis [60]. We can compare the accuracy of the obtained predictor (72 percent) to the accuracy of a predictor with 17 features with the smallest p-values selected by the Kruskal–Wallis test, which was close to 50 percent; in other words, the predictor was not better than a trivial random predictor.

4.3.7

Conclusions

Microarray data analysis is a signiﬁcant and broad ﬁeld with many unresolved problems. This chapter brieﬂy introduces some of the most commonly used methods for the analysis of microarray data, but many topics still remain. For example, microarray data can be used to construct gene networks, which are made up of links that represent relationships between genes, such as coregulation. Computational models for gene networks include Bayesian networks [61], Boolean networks [62], Petri nets [63], graphical Gaussian models [64], and stochastic process calculi [65]. Microarrays can also be studied in conjunction with other topics, such as microarray-related text mining, microarray resources and database construction, drug discovery, drug response study, and design clinical trials. Several other types of microarrays are used in addition to gene expression microarrays: protein microarrays (including antibody microarrays), single-nucleotide polymorphism (SNP) microarrays, and chemical compound microarrays. Other experimental technologies, such as mass spectrometry, also produce results at a high throughput rate. Methods for the analysis of these various types of biological data have a certain degree of similarity with microarray data analysis. For example, methods used for the identiﬁcation of differentially expressed genes are similar to the methods used for the identiﬁcation of biomarkers in mass spectrometry data. Overall, there are many challenging open topics on analyzing high throughput biological data that can provide research opportunities for the data mining and machine learning community. Progress toward solving these challenges and the future directions of research in this area are discussed at various bioinformatics meetings; these include a specialized International Conference for the Critical Assessment of Microarray Data Analysis (CAMDA) that was established in 2000, and that was aimed at the assessment of the state-of-the-art methods in large-scale biological data mining. CAMDA provided standard data sets and put an emphasis on various challenges of analyzing large-scale biological data: time series cell cycle data analysis [45] and cancer sample classiﬁcation using microarray data [3], functional discovery [42] and drug response [66], microarray data sample variance [67], integration of information from different microarray lung cancer data sets [68–71], the malaria transcriptome monitored by microarray data [4], and integration of different types of high throughput biological data related to CFS.

REFERENCES

141

ACKNOWLEDGMENTS This project is funded in part under a grant with the Pennsylvania Department of Health. The Department speciﬁcally disclaims responsibility for any analyses, interpretations, or conclusions. We thank Samidh Chatterjee, Omkarnath Prabhu, Vladan Radosavljevi´c, Lining Yu, and Jingting Zeng at our laboratory for carefully reading and reviewing this text. In addition, we would like to express special thanks to the external reviewers for their valuable comments on a preliminary manuscript.

REFERENCES 1. Schena M, Shalon D, Davis RW, Brown PO. Quantitative monitoring of gene expression patterns with a complementary DNA microarray. Science 1995;270:467–470. 2. Lockhart DJ, Dong H, Byrne MC, Follettie MT, Gallo MV, Chee MS, Mittmann M, Wang C, Kobayashi M, Horton H, Brown EL. Expression monitoring by hybridization to highdensity oligonucleotide arrays. Nat Biotechnol 1996;14:1675–1680. 3. Golub TR, Slonim DK, Tamayo P, Huard C, Gaasenbeek M, Mesirov JP, Coller H, Loh ML, Downing JR, Caligiuri MA, Bloomﬁeld CD, Lander ES. Molecular classiﬁcation of cancer: class discovery and class prediction by gene expression monitoring. Science 1999;286:531–537. 4. Bozdech Z, Llinas M, Pulliam BL, Wong ED, Zhu J, DeRisi JL. The transcriptome of the intraerythrocytic developmental cycle of Plasmodium falciparum. PLoS Biol 2003;1:E5. 5. Vernon SD, Reeves WC. The challenge of integrating disparate high-content data: epidemiological, clinical and laboratory data collected during an in-hospital study of chronic fatigue syndrome. Pharmacogenomics 2006;7:345–354. 6. Yang YH, Buckley MJ, Speed TP. Analysis of cDNA microarray images. Brief Bioinform 2001;2:341–349. 7. Yap G. Affymetrix, Inc. Pharmacogenomics 2002;3:709–711. 9. Kooperberg C, Fazzio TG, Delrow JJ, Tsukiyama T. Improved background correction for spotted DNA microarrays. J Comput Biol 2002;9:55–66. 9. Cui X, KM, Churchill GA. Transformations for cDNA microarray data. Stat Appl Genet Mol Biol 2003;2:article 4. 10. Troyanskaya O, Cantor M, Sherlock G, Brown P, Hastie T, Tibshirani R, Botstein D, Altman RB. Missing value estimation methods for DNA microarrays. Bioinformatics 2001;17:520–525. 11. Kim H, Golub GH, Park H. Missing value estimation for DNA microarray gene expression data: local least squares imputation. Bioinformatics 2005;21:187–198. 12. Johansson P, Hakkinen J. Improving missing value imputation of microarray data by using spot quality weights. BMC Bioinform 2006;7:306. 13. Tuikkala J, Elo L, Nevalainen OS, Aittokallio T. Improving missing value estimation in microarray data with gene ontology. Bioinformatics 2006;22:566–572. 14. Quackenbush J. Microarray data normalization and transformation. Nat Genet 2002; 32(Suppl):496–501.

142

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

15. Yang YH, Dudoit S, Luu P, Lin DM, Peng V, Ngai J, Speed TP. Normalization for cDNA microarray data: a robust composite method addressing single and multiple slide systematic variation. Nucleic Acids Res 2002;30:e15. 16. Smyth GK, Speed T. Normalization of cDNA microarray data. Methods 2003;31: 265–273. 17. Berger JA, Hautaniemi S, Jarvinen AK, Edgren H, Mitra SK, Astola J. Optimized LOWESS normalization parameter selection for DNA microarray data. BMC Bioinform 2004;5: 194. 18. Colantuoni CHG, Zeger S, Pevsner J. Local mean normalization of microarray element signal intensities across an array surface: quality control and correction of spatially systematic artifacts. Biotechniques 2002;32:1316–1320. 19. Holter NS, Mitra M, Maritan A, Cieplak M, Banavar JR, Fedoroff NV. Fundamental patterns underlying gene expression proﬁles: simplicity from complexity. Proc Natl Acad Sci USA 2000;97:8409–8414. 20. Bolstad BM, Irizarry RA, Astrand M, Speed TP, A comparison of normalization methods for high density oligonucleotide array data based on variance and bias. Bioinformatics 2003;19:185–193. 21. Wolﬁnger RD, Gibson G, Wolﬁnger ED, Bennett L, Hamadeh H, Bushel P, Afshari C, Paules RS. Assessing gene signiﬁcance from cDNA microarray expression data via mixed models. J Comput Biol 2001;8:625–637. 22. Schadt EE, Li C, Ellis B, Wong WH, Feature extraction and normalization algorithms for high-density oligonucleotide gene expression array data. J Cell Biochem Suppl 2001;37:120–125. 23. Irizarry RA, Hobbs B, Collin F, Beazer-Barclay YD, Antonellis KJ, Scherf U, Speed TP. Exploration, normalization, and summaries of high density oligonucleotide array probe level data. Biostatistics 2003;4:249–264. 24. Yu X, Chu TM, Gibson G, Wolﬁnger RD, A mixed model approach to identify yeast transcriptional regulatory motifs via microarray experiments. Stat Appl Genet Mol Biol 2004;3:article22. 25. Ramsey FL, Shafer DW. The Statistical Sleuth: A Course in Methods of Data Analysis. Belmont, CA: Duxbury Press; 1996. 26. Kerr MK, Martin M, Churchill GA, Analysis of variance for gene expression microarray data. J Comput Biol 2000;7:819–837. 27. Pan WA. Comparative review of statistical methods for discovering differentially expressed genes in replicated microarray experiments. Bioinformatics 2002;18:546– 554. 28. Singer JD. Using SAS PROC MIXED to ﬁt multilevel models, hierarchical models, and individual growth models. J Educ Behav Stat 1998;24:323–355. 29. Tusher VG, Tibshirani R, Chu G. Signiﬁcance analysis of microarrays applied to the ionizing radiation response. Proc Natl Acad Sci USA 2001;98:5116– 5121. 30. Thomas JG, Olson JM, Tapscott SJ, Zhao LP. An efﬁcient and robust statistical modeling approach to discover differentially expressed genes using genomic expression proﬁles. Genome Res 2001;11:1227–1236. 31. Efron B, Tibshirani R. Empirical Bayes methods and false discovery rates for microarrays. Genet Epidemiol 2002;23:70–86.

REFERENCES

143

32. Benjamini Y, Hochberg Y. Controlling the false discovery rate: a practical and powerful approach to multiple testing. J R Stat Soc Ser B 1995;57:289–300. 33. Qian HR, Huang S. Comparison of false discovery rate methods in identifying genes with differential expression. Genomics 2005;86:495–503. 34. Ashburner M, Ball CA, Blake JA, Botstein D, Butler H, Cherry JM, Davis AP, Dolinski K, Dwight SS, Eppig JT, Harris MA, Hill DP, Issel-Tarver L, Kasarskis A, Lewis S, Matese JC, Richardson JE, Ringwald M, Rubin GM, Sherlock G. Gene ontology: tool for the uniﬁcation of biology. The Gene Ontology Consortium. Nat Genet 2000;25:25–29. 35. Gene Ontology Consortium. Creating the gene ontology resource: design and implementation. Genome Res 2001;11:1425–1433. 36. Lord PW, Stevens RD, Brass A, Goble CA. Investigating semantic similarity measures across the Gene Ontology: the relationship between sequence and annotation. Bioinformatics 2003;19:1275–1283. 37. Schlicker A, Domingues FS, Rahnenfuhrer J, Lengauer T. A new measure for functional similarity of gene products based on Gene Ontology. BMC Bioinform 2006; 7:302. 38. Rada R, Mili H, Bicknell E, Blettner M. development and application of a metric on semantic nets. IEEE Trans Syst Man Cybernet 1989;19:17–30. 39. Beissbarth T, Speed TP. GOstat: ﬁnd statistically overrepresented Gene Ontologies within a group of genes. Bioinformatics 2004;20:1464–1465. 40. Dennis G, Jr, Sherman BT, Hosack DA, Yang J, Gao W, Lane HC, Lempicki RA. DAVID: Database for annotation, visualization, and integrated discovery. Genome Biol 2003;4:P3. 41. Chu S, DeRisi J, Eisen M, Mulholland J, Botstein D, Brown PO, Herskowitz I. The transcriptional program of sporulation in budding yeast. Science 1998;282:699–705. 42. Hughes TR, Marton MJ, Jones AR, Roberts CJ, Stoughton R, Armour CD, Bennett HA, Coffey E, Dai H, He YD, Kidd MJ, King AM, Meyer MR, Slade D, Lum PY, Stepaniants SB, Shoemaker DD, Gachotte D, Chakraburtty K, Simon J, Bard M, Friend SH. Functional discovery via a compendium of expression proﬁles. Cell 2000;102:109–126. 43. Karaoz U, Murali TM, Letovsky S, Zheng Y, Ding C, Cantor CR, Kasif S. Whole-genome annotation by using evidence integration in functional-linkage networks. Proc Natl Acad Sci USA 2004;101:2888–2893. 44. Eisen MB, Spellman PT, Brown PO, Botstein D. Cluster analysis and display of genomewide expression patterns. Proc Natl Acad Sci USA 1998;95:14863–14868. 45. Spellman PT, Sherlock G, Zhang MQ, Iyer VR, Anders K, Eisen MB, Brown PO, Botstein D, Futcher B. Comprehensive identiﬁcation of cell cycle-regulated genes of the yeast Saccharomyces cerevisiae by microarray hybridization. Mol Biol Cell 1998;9: 3273–3297. 46. Whitﬁeld ML, Sherlock G, Saldanha AJ, Murray JI, Ball CA, Alexander KE, Matese JC, Perou CM, Hurt MM, Brown PO, Botstein D. Identiﬁcation of genes periodically expressed in the human cell cycle and their expression in tumors. Mol Biol Cell 2002;13:1977–2000. 47. Zhou X, Kao MC, Wong WH. Transitive functional annotation by shortest-path analysis of gene expression data. Proc Natl Acad Sci USA 2002;99:12783–12788. 48. Xie H, Vucetic S, Sun H, Hedge P, Obradovic Z. Characterization of gene functional expression proﬁles of Plasmodium falciparum. Proceedings of the 5th Conference on Critical Assessment of Microarray Data Analysis; 2004.

144

ALGORITHMIC METHODS FOR THE ANALYSIS OF GENE EXPRESSION DATA

49. Barutcuoglu Z, Schapire RE, Troyanskaya OG. Hierarchical multi-label prediction of gene function. Bioinformatics 2006;22:830–836. 50. Brown MP, Grundy WN, Lin D, Cristianini N, Sugnet CW, Furey TS, Ares M Jr, Haussler D. Knowledge-based analysis of microarray gene expression data by using support vector machines. Proc Natl Acad Sci USA 2000;97:262–267. 51. Mangiameli P, Chen SK, West D. A comparison of SOM of neural network and hierarchical methods. Eur J Oper Res 1996;93:402–417. 52. Breiman L. Random forests. Mach Learning 2001;45:5–32. 53. Shi T, S D, Belldegrun AS, Palotie A, Horvath S. Tumor classiﬁcation by tissue microarray proﬁling: random forest clustering applied to renal cell carcinoma. Mod Pathol 2005;18:547–557. 54. McLachlan GJ, Bean RW, Peel D. A mixture model-based approach to the clustering of microarray expression data. Bioinformatics 2002;18:413–422. 55. Cherepinsky V, Feng J, Rejali M, Mishra B. Shrinkage-based similarity metric for cluster analysis of microarray data. Proc Natl Acad Sci USA 2003;100:9668–9673. 56. Verri A. A novel kernel method for clustering. IEEE Trans Pattern Anal Mach Intell 2005;27:801–805. 57. Kerr K, Churchill GA. Bootstrapping cluster analysis: access the reliable of conclusions from microarray experiments. Proc Natl Acad Sci USA 2001;98:8961–8965. 58. Au W, Chan K, Wong A, Wang Y. Attribute clustering for grouping, selection, and classiﬁcation of gene expression data. IEEE/ACM Trans Comput Biol Bioinform 2005;2:83–101. 59. Xie H, Obradovic Z, Vucetic S. Mining of microarray, proteomics, and clinical data for improved identiﬁcation of chronic fatigue syndrome. In: Proceedings of the Sixth International Conference for the Critical Assessment of Microarray Data Analysis; 2006. 60. Whistler T, Unger ER, Nisenbaum R, Vernon SD. Integration of gene expression, clinical, and epidemiologic data to characterize chronic fatigue syndrome. J Transl Med 2003;1: 10. 61. Hartemink AJ, Gifford DK, Jaakkola TS, Young RA. Combining location and expression data for principled discovery of genetic regulatory network models. Pac Symp Biocomput 2002;437–449. 62. Akutsu T, Miyano S, Kuhara S. Identiﬁcation of genetic networks from a small number of gene expression patterns under the Boolean network model. Pac Symp Biocomput 1999;17–28. 63. Gambin A, Lasota S, Rutkowski M. Analyzing stationary states of gene regulatory network using Petri nets. In Silico Biol 2006;6:0010. 64. Toh H, Horimoto K. Inference of a genetic network by a combined approach of cluster analysis and graphical Gaussian modeling. Bioinformatics 2002;18:287–297. 65. Golightly A, Wilkinson DJ. Bayesian inference for stochastic kinetic models using a diffusion approximation. Biometrics 2005;61:781–788. 66. Scherf U, Ross DT, Waltham M, Smith LH, Lee JK, Tanabe L, Kohn KW, Reinhold WC, Myers TG, Andrews DT, Scudiero DA, Eisen MB, Sausville EA, Pommier Y, Botstein D, Brown PO, Weinstein JN. A gene expression database for the molecular pharmacology of cancer. Nat Genet 2000;24:236–244. 67. Pritchard CC, Hsu L, Delrow J, Nelson PS. Project normal: deﬁning normal variance in mouse gene expression. Proc Natl Acad Sci USA 2001;98:13266–13271.

REFERENCES

145

68. Wigle DA, Jurisica I, Radulovich N, Pintilie M, Rossant J, Liu N, Lu C, Woodgett J, Seiden I, Johnston M, Keshavjee S, Darling G, Winton T, Breitkreutz BJ, Jorgenson P, Tyers M, Shepherd FA, Tsao MS. Molecular proﬁling of non-small cell lung cancer and correlation with disease-free survival. Cancer Res 2002;62:3005–3008. 69. Beer DG, et al. Gene-expression proﬁles predict survival of patients with lung adenocarcinoma. Nat Med 2002;8:816–824. 70. Garber ME, Troyanskaya OG, Schluens K, Petersen S, Thaesler Z, Pacyna-Gengelbach M, van de Rijn M, Rosen GD, Perou CM, Whyte RI, Altman RB, Brown PO, Botstein D, Petersen I. Diversity of gene expression in adenocarcinoma of the lung. Proc Natl Acad Sci USA 2001;98:13784–13789. 71. Bhattacharjee A, Richards WG, Staunton J, Li C, Monti S, Vasa P, Ladd C, Beheshti J, Bueno R, Gillette M, Loda M, Weber G, Mark EJ, Lander ES, Wong W, Johnson BE, Golub TR, Sugarbaker DJ, Meyerson M. Classiﬁcation of human lung carcinomas by mRNA expression proﬁling reveals distinct adenocarcinoma subclasses. Proc Natl Acad Sci USA 2001;98: 13790–13795.

CHAPTER 5

Algorithms of Reaction–Diffusion Computing ANDREW ADAMATZKY

We give a case study introduction to the novel paradigm of wave-based computing in chemical systems. We show how selected problems and tasks of computational geometry, robotics, and logics can be solved by encoding data in conﬁguration of chemical medium’s disturbances and programming wave dynamics and interaction.

5.1 INTRODUCTION It is usually very difﬁcult, and sometimes impossible, to solve variational problems explicitly in terms of formulas or geometric constructions involving known simple elements. Instead, one is often satisﬁed with merely proving the existence of a solution under certain conditions and afterward investigating properties of the solution. In many cases, when such an existence proof turns to be more or less difﬁcult, it is stimulating to realize the mathematical conditions of the problem by corresponding physical devices, or rather, to consider mathematical problem as an interpretation of a physical phenomenon. The existence of the physical phenomenon then represents the solution of the mathematical problem [16].

In 1941, in their timeless treatise Courant and Robbins [16] discussed one of the “classical examples of nonclassical computing”— an idea of physics-based computation, traced back to 1800s where Plateau experimented with the problem on calculation of the surface of smallest area bounded by a given closed contour in space. We will rephrase this as follows. Given a set of planar points, connect the points by a graph with minimal sum of edge lengths (it is allowed to add more points; however, a number of additional points should be minimal). The solution offered is extraordinarily simple and hence nontrivial. Mark given planar points on a ﬂat surface. Insert pins in the points. Place another sheet on top of the pins. Brieﬂy immerse the device in soap solution. Wait till the soap ﬁlm dries. Record (draw, make a photo) topology of dried soap ﬁlm. This represents minimal Steiner tree spanning given planar points. Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

147

148

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

FIGURE 5.1 Soap computer constructs spanning tree of four points [16].

An example of the computing device is shown in Figure 5.1. Owing to surface tension the soap ﬁlm between the pins, representing points, will try to minimize total surface area. The shrinking can be constrained by a ﬁxed pressure, assuming that the foam ﬁlm is a cross section of a three-dimensional foam. A length-minimizing curve enclosing a ﬁxed-area region consists of circular arcs of positive outward curvature and line segments [41]. Curvature of the arcs is inversely proportional to pressure. By gradually increasing pressure (Fig. 5.2) we transform arcs to straight lines, and thus spanning tree is calculated. In the nineteenth century many of the fundamental theorems of function theory were discovered by Riemann by thinking of simple experiments concerning the ﬂow of electricity in thin metallic sheets [16].

At that time ideas on unconventional, or nature-inspired, computing were ﬂourishing as ever, and Lord Kelvin made his famous differential analyzer, a typical example of a general-purpose analog computer generating functions of the time measure in volts [37]. He wrote in 1876

FIGURE 5.2 Several steps of spanning tree constructions by soap ﬁlm [41].

INTRODUCTION

149

FIGURE 5.3 An electrical machine that computes connectivity of graph edges [50]. It may be possible to conceive that nature generates a computable function of a real variable directly and not necessarily by approximation as in the traditional approach [37].

The main idea of a ﬁeld computing on graphs and networks lies in the application of a voltage to a graph, where edges and nodes are assumed to have certain resistance, and measuring resistance or capacities of the networks. This technique was used, at least implicitly, from the beginning of the century or even early but the earliest publication with the emphasis on the algorithmic part is the paper by Vergis et al. [50]. They solve a well-known (s, t)-connectivity problem by constructing a virtual electrical model of the given graph (Fig. 5.3): Given two vertexes s and t of a graph, decide whether there is a path from s to t. This is solved as follows. Put wires instead of edges and connect them at the nodes. Apply a voltage between the nodes s and t. Measure the current. If near null current is recorded, there is no path between s and t. The method works on the assumption that resistance is proportional only to the length of a wire; therefore, if there is no path between s and t then resistance is nearly inﬁnite high resistance, if there is no path between vs and vt . If lengths of wires grow linearly with the number of graph nodes, the total capacity of the voltage source and total resistance have the upper bound O(|E2 |), which leads to the total size and power consumption O(|E4 |); that is, the electric machine operates polynomial resources [50]. Surface tension, propagating waves, and electricity have been principal “engines” of nature-inspired computers for over two centuries; even so they never were combined together till Kuhnert’s pioneer work on image transformations in light-sensitive Belousov–Zhabotinsky system [27]. A reaction–diffusion computer is a spatially extended chemical system, which processes information using interacting growing patterns, and excitable and diffusive waves. In reaction–diffusion processors, both the data and the results of the computation are encoded as concentration proﬁles of the reagents. The computation is performed via the spreading and interaction of wave fronts. The reaction–diffusion computers are parallel because myriads of their microvolumes update their states simultaneously, and molecules diffuse and react

150

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

in parallel. Liquid-phase chemical media are wet analogs of massive parallel (millions of elementary processors in a small chemical reactor) and locally connected (every microvolume of the medium changes its state depending on the states of its closest neighbors) processors. They have parallel inputs and outputs; for example, optical input is parallel because of the control of initial excitation dynamics by illumination masks while, output is parallel because concentration proﬁle representing results of computation is visualized by indicators. The reaction–diffusion computers are fault tolerant and capable of automatic reconﬁguration, namely if we remove some quantity of the computing substrate, the topology is restored almost immediately. Reaction–diffusion computers are based on three principles of physics-inspired computing. First, physical action measures amount of information: we exploit active processes in nonlinear systems and interpret dynamics of the systems as computation. Second, physical information travels only ﬁnite distance: this means that computation is local and we can assume that the nonlinear medium is a spatial arrangement of elementary processing units connected locally; that is, each unit interacts with closest neighbors. Third, nature is governed by waves and spreading patterns: computation is therefore spatial. Reaction–diffusion computers give us best examples of unconventional computers; their features follow Jonathan Mills’ classiﬁcation of convention versus unconventional [32]: wetware, nonsilicon computing substrate; parallel processing; computation occurring everywhere in substrate space; computation is based on analogies; spatial increase in precision; holistic and spatial programming; visual structure; and implicit error correcting. A theory of reaction–diffusion computing was established and a range of practical applications are outlined in the work by Adamatzky [1]; recent discoveries are published in a collective monograph [5]. The chapter in no way serves as a substitute for these books but rather an introduction to the ﬁeld and a case study of several characteristic examples. The chapter is populated with cellular automaton examples of reaction–diffusion processes. We have chosen cellular automatons to study computation in reaction– diffusion media because cellular automatons can provide just the right fast prototypes of reaction–diffusion models. The examples of “best practice” include models of BZ reactions and other excitable systems [21,31], chemical systems exhibiting Turing patterns [54,56,58], precipitating systems [5], calcium wave dynamics [55], and chemical turbulence [23]. We therefore consider it reasonable to interpret the cellular automaton local update rules in terms of reaction–diffusion chemical systems and reinterpret the cellular automaton rules in novel designs of the chemical laboratory reaction–diffusion computers. Cellular automaton models of reaction–diffusion and excitable media capture essential aspects of the natural media in a computationally tractable form. A cellular automaton is a—in our case two-dimensional—lattice of ﬁnite automatons, or an array of cells. The automatons evolve in a discrete time and take their states from a ﬁnite set. All automatons of the lattice update their states simultaneously. Every automaton calculates its next state depending on the states of its closest neighbors (throughout

COMPUTATIONAL GEOMETRY

151

the chapter we assume every nonedge cell x of a cellular automaton updates its state depending on the states of its eight closest neighbors). The best way to learn riding bicycle is to ride a bicycle. Therefore, instead of wasting time on pointless theoretical constructions, we immediately describe and analyze working reaction–diffusion algorithms for image processing, computational geometry, logical and arithmetical circuits, memory devices, path planning and robot navigation, and control of massive parallel actuators. Just few words of warning—when thinking about chemical algorithms some of you may realize that diffusive and phase waves are pretty slow in physical time. The sluggishness of computation is the only point that may attract criticism to reaction– diffusion chemical computers. There is however a solution—to speed up we are implementing the chemical medium in silicon, microprocessor LSI analogs of reaction–diffusion computers [11]. Further miniaturization of the reaction–diffusion computers can be reached when the system is implemented as a two-dimensional array of single-electron nonlinear oscillators diffusively coupled to each other [12]. Yet another point of developing reaction–diffusion computers is to design embedded controllers for soft-bodied robots, where usage of conventional silicon materials seem to be inappropriate.

5.2 COMPUTATIONAL GEOMETRY In this section we discuss “mechanics” of reaction–diffusion computing on example of plane subdivision. Let P be a nonempty ﬁnite set of planar points. A planar Voronoi diagram of the set P is a partition of the plane into such regions that for any element of P, a region corresponding to a unique point p contains all those points of the plane that are closer to p than to any other node of P. A unique region vor(p) = {z ∈ R2 : d(p, z) < d(p, m)∀m ∈ R2 , m = z} assigned to point p is called a Voronoi cell of the point p. The boundary of the Voronoi cell of a point p is built of segments of bisectors separating pairs of geographically closest points of the given planar set P. A union of all boundaries of the Voronoi cells determines the planar Voronoi diagram: VD(P) = ∪p∈P ∂ vor(p). A variety of Voronoi diagrams and algorithms of their construction can be found in the work by Klein [26]. The basic concept of constructing Voronoi diagrams with reaction-diffusion systems is based on a very simple intuitive technique for detecting the bisector points separating two given points of the set P. If we drop reagents at the two data points, the diffusive waves, or phase waves if computing substrate is active, spread outward from the drops with the same speed. The waves travel the same distance from the sites of origination before they meet one another. The points, where the waves meet, are the bisector points. This idea of a Voronoi diagram computation was originally implemented in cellular automaton models and in experimental parallel chemical processors (see extensive bibliography in the works by Adamatzky et al. [1,5]). Assuming that the computational space is homogeneous and locally connected, and every site (microvolume of the chemical medium or cell of the automaton array) is coupled to its closest neighbors by the same diffusive links, we can easily draw

152

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

a parallel between distance and time, and thus put our wave-based approach into action. In cellular automaton representation of physical reality, cell neighborhood u determines that all processes in the cellular automaton model are constrained to the discrete metric L∞ . So, when studying automaton models we should think rather about discrete Voronoi diagram than its Euclidean representation. Chemical laboratory prototypes of reaction–diffusion computers do approximate continuous Voronoi diagram as we will see further. A discrete Voronoi diagram can be deﬁned on lattices or arrays of cells, for example, a two-dimensional lattice Z2 . The distance d(·, ·) is calculated not in Euclidean but in one of the discrete metrics, for example, L1 and L∞ . A discrete bisector of nodes x and y of Z2 is determined as B(x, y) = {z ∈ Z2 : d(x, z) = d(y, z)}. However, following such deﬁnition we sometimes generate bisectors that ﬁll a quarter of the lattices or produce no bisector at all [1]. If we want the constructed diagrams be closer to the real world, then we could redeﬁne discrete bisector as follows: B(x, y) = {z ∈ Z2 : |d(x, z) − d(y, z)| ≤ 1}. The redeﬁned bisector will comprise edges of Voronoi diagrams constructed in discrete, cellular automaton models of reaction–diffusion and excitable media. Now we will discuss several versions of reaction–diffusion wave-based construction of Voronoi diagrams, from a na¨ıve model, where the number of reagents grow proportionally to the number of data points, to a minimalist implementation with just one reagent and one substrate [1]. Let us start with O(n)-reagent model. In a na¨ıve version of reaction–diffusion computation of a Voronoi diagram, one needs two reagents and a precipitate to mark a bisector separating two points. Therefore, n + 2 reagents, including precipitate and substrate, are required to approximate a Voronoi diagram of n points. When place n unique reagents on n points of the given data set P, waves of these reagents spread around the space and interact with each other where they meet. When at least two different reagents meet at the same or adjacent sites of the space, they react and form a precipitate—sites that contain the precipitate represent edges of the Voronoi cell, and therefore constitute the Voronoi diagram. In “chemical reaction” equations, the idea looks as follows: α and β are different reagents and # is a precipitate: α + β → #. This can be converted to cellular automaton interpretation as follows: ⎧ t t ⎪ ⎨ρ, if x = • and (x) ⊂ {ρ, •}, xt+1 = #, if xt = # and |(x)t /#| > 1, ⎪ ⎩ t x , otherwise, where • is a resting state (cell in this state does not contain any reagents), ρ ∈ R is a reagent from the set R of n reagents, and (x)t = {yt : y ∈ u(x)} characterizes the reagents that are present in the local neighborhood u(x) of the cell x at time step t. The ﬁrst transition of the above rule symbolizes diffusion. A resting cell takes the state ρ if only this reagent is present in the cell’s neighborhood. If there are two different reagents in the cell’s neighborhood, then the cell takes the precipitate state #. Diffusing reagents halt because the formation of precipitate reduces the number of “vacant” resting cells. Precipitate does not diffuse. Cell in state # remains in this

COMPUTATIONAL GEOMETRY

153

FIGURE 5.4 Computation of a Voronoi diagram in a cellular automaton model of a chemical processor with O(n) reagents. Precipitate is shown in black (a) t = 1; (b) t = 3; (c) t = 5; (d) t = 6; (e) t = 7; (f ) t = 8; (g) t = 10; (h) t = 12; (i) t = 15.

indeﬁnitely. An example of a cellular automaton simulation of O(n)-reagent chemical processor is shown in Figure 5.4. The O(n)-reagent model is demonstrative; however, it is computationally inefﬁcient. Clearly, we can reduce number of reagents to four—using map coloring theorems—but preprocessing time will be unfeasibly high. The number of participating reagents can be sufﬁciently reduced to O(1) when the topology of the spreading waves is taken into account [1]. Now we go from one extreme to another and consider a model with just one reagent and a substrate. The reagent α diffuses from sites corresponding two point of a data planar set P. When two diffusing wave fronts meet a superthreshold concentration of reagents, they do not spread further. A cellular automaton model represents this as follows. Every cell has two possible states: resting or substrate state • and reagent state α. If the cell is in state α, it remains in this state indeﬁnitely. If the cell is in state

154

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

• and between one and four of its neighbors are in state α, then the cell takes the state α. Otherwise, the cell remains in the state • — this reﬂects the “superthreshold inhibition” idea. A cell state transition rule is follows: xt+1 =

α, if xt = • and 1 ≤ σ(x)t ≤ 4, xt , otherwise,

where σ(x)t = |y ∈ u(x) : yt = α|. Increasing number of reagents to two (one reagent and one precipitate) would make life easy. A reagent β diffuses on a substrate, from the initial points (drop of reagent) of P, and forms a precipitate in the reaction mβ → α, where 1 ≤ m ≤ 4.

FIGURE 5.5 An example of Voronoi diagram computing in an automaton model of reaction– diffusion medium with one reagent and one substrate. Reactive parts of wave fronts are shown in black. Precipitate is gray and edges of Voronoi diagram are white (a) t = 1; (b) t = 3; (c) t = 5; (d) t = 7; (e) t = 9; (f ) t = 11; (g) t = 13; (h) t = 15; (i) t = 17.

155

COMPUTATIONAL GEOMETRY

FIGURE 5.6 Planar Voronoi diagram computed in (a) cellular automaton and (b) palladium reaction–diffusion chemical processor [5].

Every cell takes three states: • (resting cell, no reagents), α (e.g., colored precipitate), and β (reagent). The cell updates its states by the rule:

xt+1

⎧ t t ⎪ ⎨β, if x = • and 1 ≤ σ(x) ≤ 4, = α, if xt = β and 1 ≤ σ(x)t ≤ 4, ⎪ ⎩ t x , otherwise,

where σ(x)t = |y ∈ u(x) : yt = β|. An example of a Voronoi diagram computed in an automaton model of a reaction– diffusion medium with one reagent and one substrate is shown in Figure 5.5. By increasing number of cell state and enlarging cell neighborhood in cellular automaton model we can produce more realistic—almost perfectly matching outcomes of chemical laboratory experiments—Voronoi diagrams (Fig. 5.6). Let us consider the following model. Cells of the automaton take state from interval [ρ, α], where ρ is a minimum refractory value and α is maximum excitation value; ρ = −2 and α = 5 in our experiments. Cellx’s state √ transitions are strongly determined by normalized local excitation σxt = y∈ux (yt / (|ux |)). Every cell x updates its state at time t + 1, depending on its state xt and state utx of its neighborhood ux —in experiments we used 15 × 15 cell neighborhood—as follows:

xt+1

⎧ α, if xt = 0 and σxt ≥ α, ⎪ ⎪ ⎪ ⎪ t t ⎪ ⎪ ⎨0, if x = 0 and σx < α, = xt + 1, if xt < 0, ⎪ ⎪ ⎪ ⎪xt − 1, if xt > 1, ⎪ ⎪ ⎩ ρ, if xt = 1.

156

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

FIGURE 5.7 Skeleton—internal Voronoi diagram—of planar T-shape constructed in multistate cellular automaton model (a) and chemical laboratory Prussian blue reaction–diffusion processor (b) [10].

This rule represents spreading of “excitation,” or simply phase wave fronts, in computational space, interaction, and annihilation of the wave fronts. To allow the reaction–diffusion computer “memorize” sites of wave collision, we add a precipitate state ptx . Concentration ptx of precipitate at site x at moment t is calculated as ∼ |{y ∈ ux : yt = α}|. pt+1 x As shown in Figure 5.7, the model represents cellular automaton Voronoi diagrams in “unlike phase” with experimental chemical representation of the diagram. Sites of higher concentration of precipitate in cellular automaton conﬁgurations correspond to sites with lowest precipitate concentration in experimental processors.

5.3 LOGICAL UNIVERSALITY Certain families of thin-layer reaction–diffusion chemical media can implement sensible transformation of initial (data) spatial distribution of chemical species concentrations to ﬁnal (result) concentration proﬁle [1,45]. In these reaction–diffusion computers, a computation is realized via spreading and interaction of diffusive or phase waves. Specialized, intended to solve a particular problem, experimental chemical processors implement basic operations of image processing [5,28,39,40], computation of optimal paths [5,9,46], and control of mobile robots [5]. A device is called computationally universal if it implements a functionally complete system of logical gates, for example, a tuple of negation and conjunction, in its space–time dynamics. A number of computationally universal reaction–diffusion devices were implemented: the ﬁndings include logical gates [42,48] and diodes [17,29,34] in BelousovZhabotinsky (BZ) medium, and xor gate in palladium processor [2]. All the known so far experimental prototypes of reaction–diffusion processors exploit interaction of wave fronts in a geometrically constrained chemical medium; that is, the computation is based on a stationary architecture of medium’s inhomogeneities. Constrained by stationary wires and gates, chemical universal processors pose a little computa-

LOGICAL UNIVERSALITY

157

tional novelty and none dynamical reconﬁguration ability because they simply imitate architectures of silicon computing devices. Experimental prototypes of reaction–diffusion processors exploit interaction of wave fronts in a geometrically constrained chemical medium; that is, the computation is based on a stationary architecture of medium’s inhomogeneities. Constrained by stationary wires and gates reaction–diffusion chemical universal processors pose a little computational novelty and no dynamic reconﬁguration ability because they simply imitate architectures of conventional silicon computing devices. To appreciate in full massive parallelism of thin-layer chemical media and to free the chemical processors from limitations of ﬁxed computing architectures, we adopt an unconventional paradigm of architectureless, or collision-based, computing. An architecture-based, or stationary, computation implies that a logical circuit is embedded into the system in such a manner that all elements of the circuit are represented by the system’s stationary states. The architecture is static. If there is any kind of “artiﬁcial” or “natural” compartmentalization, the medium is classiﬁed as an architecture-based computing device. Personal computers, living neural networks, cells, and networks of chemical reactors are typical examples of architecture-based computers. A collision-based, or dynamical, computation employs mobile compact ﬁnite patterns, mobile self-localized excitations or simply localizations, in active nonlinear medium. Essentials of collision-based computing are the following. Information values (e.g., truth values of logical variables) are given by either absence or presence of the localizations or other parameters of the localizations. The localizations travel in space and do computation when they collide with each other. There are no predetermined stationary wires; a trajectory of the traveling pattern is a momentary wire. Almost any part of the medium space can be used as a wire. Localizations can collide anywhere within a space sample; there are no ﬁxed positions at which speciﬁc operations occur, nor location speciﬁed gates with ﬁxed operations. The localizations undergo transformations, form bound states, annihilate, or fuse when they interact with other mobile patterns. Information values of localizations are transformed as a result of collision and thus a computation is implemented [3]. The paradigm of collision-based computing originates from the technique of proving computational universality of game of life [14], conservative logic and billiard ball model [20], and their cellular automaton implementations [30]. Solitons, defects in tubulin microtubules, excitons in Scheibe aggregates, and breather in polymer chains are most frequently considered candidates for a role of information carrier in nature-inspired collision-based computers (see overview in the work by Adamatzky [1]). It is experimentally difﬁcult to reproduce all these artifacts in natural systems; therefore, existence of mobile localizations in an experimentfriendly chemical media would open new horizons for fabrication of collision-based computers. The basis for material implementation of collision-based universality of reaction– diffusion chemical media is discovered by Sendina-Nadal et al. [44]. They experimentally proved the existence of localized excitations—traveling wave fragments that behave like quasiparticles—in photosensitive subexcitable Belousov–Zhabotinsky medium.

158

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

We show how logical circuits can be fabricated in a subexcitable BZ medium via collisions between traveling wave fragments. While implementation of collisionbased logical operations is relatively straightforward [5], more attention should be paid to control of signal propagation in the homogeneous medium. It has been demonstrated that applying light of varying intensity we can control excitation dynamics in Belousov–Zhabotinsky medium [13,22,36], wave velocity [47], and pattern formation [51]. Of particular interest are experimental evidences of light-induced backpropagating waves, wave front splitting, and phase shifting [59]; we can also manipulate medium’s excitability by varying intensity of the medium’s illumination [15]. On the basis of these facts we show how to control signal wave fragments by varying geometric conﬁguration of excitatory and inhibitory segments of impurity reﬂectors. We built our model on a two-variable Oregonator equation [19,49] adapted to a light-sensitive BZ reaction with applied illumination [13]: 1 u−q ∂u 2 = u − u − (fv + φ) + Du ∇ 2 u, ∂t u+q ∂v = u − v, ∂t where variables u and v represent local concentrations of bromous acid (HBrO2 ) and the oxidized form of the catalyst ruthenium (Ru(III)), respectively, sets up a ratio of timescale of variables u and v, q is a scaling parameter depending on reaction rates, f is a stoichiometric coefﬁcient, and φ is a light-induced bromide production rate proportional to intensity of illumination (an excitability parameter—moderate intensity of light will facilitate excitation process, higher intensity will produce excessive quantities of bromide which suppresses the reaction). We assumed that the catalyst is immobilized in a thin layer of gel; therefore, there is no diffusion term for v. To integrate the system we used the Euler method with ﬁve-node Laplacian operator, time step t = 10−3 , and grid point spacing x = 0.15, with the following parameters: φ = φ0 + A/2, A = 0.0011109, φ0 = 0.0766, = 0.03, f = 1.4, and q = 0.002. Chosen parameters correspond to a region of “higher excitability of the subexcitability regime” outlined in the work by Sedina-Nadal et al. [44] (see also how to adjust f and q in the work by Qian and Murray [38]) that supports propagation of sustained wave fragments (Fig. 5.8a). These wave fragments are used as quanta of information in our design of collision-based logical circuits. The waves were initiated by locally disturbing initial concentrations of species; for example, 10 grid sites in a chain are given value u = 1.0 each; this generated two or more localized wave fragments, similarly to counterpropagating waves induced by temporary illumination in experiments [59]. The traveling wave fragments keep their shape for around 4 × 103 –104 steps of simulation (4–10 time units), then decrease in size and vanish. The wave’s lifetime is sufﬁcient, however, to implement logical gates; this also allows us not to worry about “garbage collection” in the computational medium. We model signals by traveling wave fragments [13,44]: a sustainably propagating wave fragment (Fig. 5.8a) represents true value of a logical variable corresponding to the wave’s trajectory (momentarily wire).

LOGICAL UNIVERSALITY

159

FIGURE 5.8 Basic operations with signals. Overlay of images taken every 0.5 time units. Exciting domains of impurities are shown in black; inhibiting domains of impurities are shown in gray. (a) Wave fragment traveling north. (b) Signal branching without impurities: a wave fragment traveling east splits into two wave fragments (traveling southeast and northeast) when it collides with a smaller wave fragment traveling west. (c) Signal branching with impurity: wave fragment traveling west is split by impurity (d) into two waves traveling northwest and southwest. (e) Signal routing (U-turn) with impurities: a wave fragment traveling east is routed north and then west by two impurities. (f ) An impurity reﬂector consists of inhibitory (gray) and excitatory (black) chains of grid sites.

To demonstrate that a physical system is logically universal, it is enough to implement negation and conjunction or disjunction in spatiotemporal dynamics of the system. To realize a fully functional logical circuit, we must also know how to operate input and output signals in the system’s dynamics, namely to implement signal branching and routing; delay can be realized via appropriate routing. We can branch a signal using two techniques. First, we can collide a smaller auxiliary wave to a wave fragment representing the signal, the signal wave will split then into two signals (these daughter waves shrink slightly down to stable size and then travel with constant shape further 4 × 103 time steps of the simulation) and the auxiliary wave will annihilate (Fig. 5.8b). Second, we can temporarily and locally apply illumination impurities on a signal’s way to change properties of the medium and thus cause the signal to split (Fig. 5.8c and d). We must mention, it was already demonstrated in the work by Yoneyama [59], that wave front inﬂuenced by strong illumination (inhibitory segments of the impurity) splits and its ends do not form spirals, as in typical situations of excitable media.

160

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

FIGURE 5.9 Implementation of conservative gate in Belousov–Zhabotinsky system. (a) Elastic co-collision of two wave fragments, one traveling west and the other east. The fragments change directions of their motion to northwest and southeast, respectively, as a result of the collision. (b) Scheme of the gate. In (a), logical variables are represented as x = 1 and y = 1.

A control impurity, or reﬂector, consists of a few segments of sites whose illumination level is slightly above or below overall illumination level of the medium. Combining excitatory and inhibitory segments we can precisely control wave’s trajectory, for example, realize U-turn of a signal (Fig. 5.8e and f). A typical billiard ball model interaction gate [20,30] has two inputs—x and y, and four outputs—xy (ball x moves undisturbed in absence of ball y), xy (ball y moves undisturbed in absence of ball x), and twice xy (balls x and y change their trajectories when collided with each other). Such conservative interaction gate can be implemented via elastic collision of wave fragment see Fig. 5.9. The elastic collision is not particularly common in laboratory prototypes of chemical systems; more often interacting waves either fuse or one of the waves annihilates as a result of the collision with another wave. This leads to nonconservative version

FIGURE 5.10 Two wave fragments undergo angle collision and implement interaction gate x, y → xy, xy, xy. (a) In this example x = 1 and y = 1, both wave fragments are present initially. Overlay of images taken every 0.5 time units. (b) Scheme of the gate. In upper-left and bottom-left corners of (a) we see domains of wave generation two echo wave fragments are also generated; they travel outward gate area and thus do not interfere with computation.

161

MEMORY

of the interaction gate with two inputs and three outputs, that is, just one xy output instead of two. Such collision gate is shown in Figure 5.10. Rich dynamics of subexcitable Belousov-Zhabotinsky medium allows us also to implement complicated logical operations just in a single interaction event (see details in the work by Adamatzky et al. [5]).

5.4 MEMORY Memory in chemical computers can be represented in several following ways. In precipitating systems, any site with precipitate is a memory element. However, they are not rewritable. In “classical” excitable chemical systems, like Belousov–Zhabotinsky dynamics, one can construct memory as a conﬁguration of sources of spiral or target ways. We used this technique to program movement of wheeled robot controlled by onboard chemical reactor with Belouso–Zhabotinsky system [5]. The method has the same drawback as precipitating memory—as soon as reaction space is divided by spiral or target waves, it is quite difﬁcult if not impossible to sensibly move source of the waves. This is only possible with external inhibition or complete reset of the medium. In geometrically constrained excitable chemical medium, as demonstrated in the work by Motoike et al. [33], we can employ old-time techniques of storing information in induction coils and other types of electrical circuits, that is, dynamical memory. A ring with an input channel is prepared from reaction substrate. The ring is broken by a small gap and the input is also separated from the ring with a gap of similar width [33]; the gaps play a role of one-way gates to prevent excitation from spreading backwards. The waves enter the ring via input channel and travel along the ring “indeﬁnitely” (till substrate lasts) [33]. The approach aims to split reaction–diffusion system into many compartments, and thus does not ﬁt our paradigm of computing in uniform medium. In our search for real-life chemical systems exhibiting both mobile and stationary localizations, we discovered a cellular automaton model [53] of an abstract activator– inhibitor reaction–diffusion system, which ideally ﬁts the framework of the collisionbased computing paradigm and reaction–diffusion computing. The phenomenology of the automaton was discussed in detail in our previous work [53]; therefore, in the present paper we draw together the computational properties of the reaction–diffusion cellular hexagonal automaton. The automaton imitates spatiotemporal dynamics of the following reaction equations: A + 6S → A

A+I →I

A + 3I → I

A + 2I → S

2A → I

3A → A

βA → I I → S.

162

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

Each cell of the automaton takes three states—substrate S, activator A, and inhibitor I. Adopting formalism from [7], we represent the cell state transition rule as a matrix M = (mij ), where 0 ≤ i ≤ j ≤ 7, 0 ≤ i + j ≤ 7, and mij ∈ {I, A, S}. The output state of each neighborhood is given by the row index i, the number of neighbors in cell state I, and column index j (the number of neighbors in cell state A). We do not have to count the number of neighbors in cell state S, because it is given by 7 − (i + j). A cell with a neighborhood represented by indexes i and j will update to cell state Mij that can be read off the matrix. In terms of the cell state transition function, this can be presented as follows: xt+1 = Mσ2 (x)t σ1 (x)t , where σi (x)t is a sum of cell x’s neighbors in state i, i = 1, 2, at time step t. The exact matrix structure, which corresponds to matrix M3 in the work by Wuensche and Adamatzky [53], is as follows: ⎧ S ⎪ ⎪ ⎪ S ⎪ ⎪ ⎪ ⎪ S ⎪ ⎪ ⎪ ⎪ ⎨S M= S ⎪ ⎪ S ⎪ ⎪ ⎪ ⎪ S ⎪ ⎪ ⎪ ⎪ ⎪ ⎩S

A I S I S S S

I I I I I I

A I A I A I A I A

I I I

I I

⎫ I⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎬ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎭

.

The cell state transition rule reﬂects the nonlinearity of activator–inhibitor interactions for subthreshold concentrations of the activator. Namely, for small concentration of the inhibitor and for threshold concentrations, the activator is suppressed by the inhibitor, while for critical concentrations of the inhibitor both inhibitor and activator dissociate producing the substrate. In exact words, M01 = A symbolizes the diffusion of activator A, M11 = I represents the suppression of activator A by the inhibitor I, and Mz2 = I (z = 0, · · · , 5) can be interpreted as self-inhibition of the activator in particular concentrations. Mz3 = A (z = 0, . . . , 4) means a sustained excitation under particular concentrations of the activator. Mz0 = S (z = 1, . . . , 7) means that the inhibitor is dissociated in absence of the activator, and that the activator does not diffuse in subthreshold concentrations. And, ﬁnally, Mzp = I, p ≥ 4 is an upper-threshold self-inhibition. Among nontrivial localizations, see full “catalog” in the work by Adamatzky and Wuensche Study [8], found in the medium we selected eaters gliders G4 and G34 , mobile localizations with activator head and inhibitor tail, and eaters E6 , stationary localizations transforming gliders colliding into them, as components of the memory unit. The eater E6 can play the role of a six-bit ﬂip-ﬂop memory device. The substrate sites (bit-down) between inhibitor sites (Fig. 5.11) can be switched to an inhibitor state (bit-up) by a colliding glider. An example of writing one bit of information in E6 is shown in Figure 5.12. Initially, E6 stores no information. We aim to write one bit in the substrate site between the northern and northwestern inhibitor sites (Fig. 5.12a). We

163

MEMORY

(a)

(b)

(c)

(d)

FIGURE 5.11 Localizations in reaction–diffusion hexagonal cellular automaton. Cell with inhibitor I are empty circles, and cells with activator A are black disks. (a) Stationary localization eater E6 , (b), (c) two forms of glider G34 , and (d) glider G4 [8].

generate a glider G34 (Fig. 5.12b and c) traveling west. G34 collides with (or brushes past) the north edge of E6 , resulting in G34 being transformed to a different type of glider, G4 (Fig. 5.12g and h). There is now a record of the collision—evidence that writing was successful. The structure of E6 now has one site (between the northern and northwestern inhibitor sites) changed to an inhibitor state (Fig. 5.12j)—a bit was saved [8]. To read a bit from the E6 memory device with one bit-up (Fig. 5.13a), we collide (or brush past) with glider G34 (Fig. 5.13b). Following the collision, the glider G34 is transformed into a different type of basic glider, G34 (Fig. 5.13g), and the bit is erased (Fig. 5.13j).

(a)

(f)

(b)

(c)

(d)

(e)

(g)

(h)

(i)

(j)

FIGURE 5.12 Write bit [8]. (a) t; (b) t + 1; (c) t + 2; (d) t + 3; (e) t + 4; (f ) t + 5; (g) t + 6; (h) t + 7; (i) t + 8; (j) t + 9.

164

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

(a)

(f)

(b)

(c)

(d)

(e)

(g)

(h)

(i)

(j)

FIGURE 5.13 Read and erase bit [8]. (a) t; (b) t + 5; (c) t + 7; (d) t + 8; (e) t + 9; (f ) t + 10; (g) t + 11; (h) t + 12; (i) t + 13; (j) t + 14.

5.5 PROGRAMMABILITY When developing a coherent theoretical foundation of reaction–diffusion computing in chemical media, one should pay particular attention to issues of programmability. In chemical laboratory, the term programmability means controllability. How real chemical systems can be controlled? The majority of the literature, related to theoretical and experimental studies concerning the controllability of reaction– diffusion medium, deals with the application of an electric ﬁeld. For example, in a thin-layer Belousov–Zhabotinsky reactor stimulated by an electric ﬁeld the following phenomena are observed. The velocity of excitation waves is increased by a negative and decreased by a positive electric ﬁeld. Very high electric ﬁeld, applied across the medium, splits a wave into two waves that move in opposite directions; stabilization and destabilization of wave fronts are also observed (see [5]). The other control parameters may include temperature (e.g., program transitions between periodic and chaotic oscillations), substrate’s structure (controlling formation, annihilation, and propagation of waves), and illumination (inputting data and routing signals in light-sensitive chemical systems). Let us demonstrate a concept of control-based programmability in models of reaction–diffusion processors. First, we show how to adjust reaction rates in chemical medium to make it perform computation of Voronoi diagram over a set of given points. Second, we show how to switch excitable system between specialized-processor and universal-processor modes (see the work by Adamatzky et al. [5] for additional examples and details). Let a cell x of a two-dimensional lattice take four states: resting ◦, excited (+), refractory (−) and precipitate , and update their states in discrete time t depending

165

PROGRAMMABILITY

FIGURE 5.14 Cell state transition diagrams: (a) model of precipitating reaction–diffusion medium and (b) model of excitable system.

on the number σ t (x) of excited neighbors in its eight-cell neighborhood as follows (Fig. 5.14a): A resting cell x becomes excited if 0 < σ t (x) ≤ θ2 and precipitates if θ2 < σ t (x). An excited cell “precipitates” if θ1 < σ t (x) or otherwise becomes refractory. A refractory cell recovers to the resting state unconditionally, and the precipitate cell does not change its state. Initially, we perturb the medium, excite it in several sites, thus inputting data. Waves of excitation are generated, they grow, collide with each other, and annihilate as a result of the collision. They may form a stationary inactive concentration proﬁle of a precipitate, which represents the result of the computation. Thus, we can only k1

k2

be concerned with reactions of precipitation: +→ and ◦ + →, where k1 and k2 are inversely proportional to θ1 and θ2 , respectively. Varying θ1 and θ2 from 1 to 8, and thus changing precipitation rates from the maximum possible to the minimum, we obtain various kinds of precipitate patterns, as shown in Figure 5.15. Precipitate patterns developed for relatively high ranges of reaction rates (3 ≤ θ1 , θ2 ≤ 4) represent discrete Voronoi diagrams (a given “planar” set, represented by sites of initial excitation, is visible in pattern θ1 = θ2 = 3 as white dots inside the Voronoi cells) derived from the set of initially excited sites (see Fig. 5.16a and b). This example demonstrates that by externally controlling precipitation rates we can force the reaction–diffusion medium to compute a Voronoi diagram. When dealing with excitable media excitability is the key parameter for tuning spatiotemporal dynamics. We demonstrated that by varying excitability we can force the medium to exhibit almost all possible types of excitation dynamics [1]. Let each cell of 2D automaton take three states: resting (·), exciting (+), and refractory (−), and update its state depending on number σ+ of excited neighbors in its eight-cell neighborhood (Fig. 5.14a). A cell goes from excited to refractory and from

166

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

FIGURE 5.15 Final conﬁgurations of reaction–diffusion medium for 1 ≤ θ1 ≤ θ2 ≤ 2. Resting sites are black, precipitate is white [4].

refractory to resting states unconditionally, and resting cell excites if σ+ ∈ [θ1 , θ2 ], 1 ≤ θ1 ≤ θ2 ≤ 8. By changing θ1 and θ2 we can move the medium dynamics in a domain of “conventional” excitation waves, useful for image processing and robot navigation [5] (Fig. 5.17a), as well as make it exhibit mobile localized excitations

FIGURE 5.16 Exemplary conﬁgurations of reaction–diffusion medium for (a) θ1 = 3 and θ2 = 3, and (b) θ1 = 4 and θ2 = 3. Resting sites are black, precipitate is white [5].

ROBOT NAVIGATION AND MASSIVE MANIPULATION

167

FIGURE 5.17 Snapshots of space–time excitation dynamics for excitability σ+ ∈ [1, 8] (a) and σ+ ∈ [2, 2] (b).

(Fig. 5.17b), quasiparticles, and discrete analogs of dissipative solitons, employed in collision-based computing [1].

5.6 ROBOT NAVIGATION AND MASSIVE MANIPULATION As we have seen in previous sections, reaction–diffusion chemical systems can solve complex problems and implement logical circuits. Embedded controllers for nontraditional robotics architectures would be yet another potentially huge ﬁeld of application of reaction–diffusion computers. The physicochemical artifacts are well known to be capable of sensible motion. Most famous are Belousov–Zhabotinsky vesicles [24], self-propulsive chemosensitive drops [25,35], and ciliar arrays. Their motion is directional but somewhere lacks sophisticated control mechanisms. At the present stage of reaction–diffusion computing research, it seems to be difﬁcult to provide effective solutions for experimental prototyping of combined sensing, decision making, and actuating. However, as a proof-of-concept we can always consider hybrid “wetware + hardware” systems. For example, to fabricate a chemical controller for robot, we can place a reactor with Belousov–Zhabotinsky solution onboard of a wheeled robot and allow the robot to observer excitation wave dynamics in the reactor. When the medium is stimulated at one point, target waves are formed. The robot becomes aware of the direction toward source of stimulation from the topology of the wave fronts [2,5]. A set of remarkable experiments were undertaken by Hiroshi Yokoi and Ben De Lacy Costello. They built interface between robotic hand and Belousov–Zhabotinsky chemical reactor [57]. Excitation waves propagating in the reactor were sensed by photodiodes, which triggered ﬁnger motion. When the bending ﬁngers touched the chemical medium with their glass nails ﬁlled with colloid silver, circular waves were triggered in the medium [5]. Starting from any initial conﬁguration, the chemical robotic system does always reach a coherent activity mode, where ﬁngers move in

168

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

regular, somewhat melodic patterns, and few generators of target waves govern dynamics of excitation in the reactor [57]. The chemical processors for navigating wheeled robot and for controlling, and actively interacting with, a robotic hand are well discussed in our recent monograph [5]; therefore, we do not go into details in the present chapter. Instead, we concentrate on rather novel ﬁndings on coupling of reaction–diffusion system with massive parallel array of virtual actuators. How a reaction–diffusion medium can manipulate objects? To ﬁnd out we couple a simulated abstract parallel manipulator with an experimental Belousov–Zhabotinsky (BZ) chemical medium, so the excitation dynamics in the chemical system are reﬂected in changing the OFF–ON mode of elementary actuating units. In this case, we convert experimental snapshots of the spatially distributed chemical system to a force vector ﬁeld and then simulate the motion of manipulated objects in the force ﬁeld, thus achieving reaction–diffusion medium controlled actuation. To build an interface between the recordings of space–time snapshots of the excitation dynamics in BZ medium and simulated physical objects, we calculate force ﬁelds generated by mobile excitation patterns and then simulate the behavior of an object in this force ﬁeld. Chemical medium to perform actuation is prepared following the typical receipt1 (see the works by Adamatzky et al. [6] and Field and Winfee [18]), based on a ferroin-catalyzed BZ reaction. A silica gel plate is cut and soaked in a ferroin solution. The gel sheet is placed in a Petri dish and BZ solution is added. Dynamics of the chemical system is recorded at 30-s intervals using a digital camera. The cross-section proﬁle of the BZ wave front recorded on a digital snapshot shows a steep rise of red color values in the pixels at the wave front’s head and a gradual descent in the pixels along the wave front’s tail. Assuming that excitation waves push the object, local force vectors generated at each site—pixel of the digitized image—of the medium should be oriented along local gradients of the red color values. From the digitized snapshot of the BZ medium we extract an array of red components from the snapshot’s pixels and then calculate the projection of a virtual vector force at the pixel. Force ﬁelds generated by the excitation patterns in a BZ system (Fig. 5.18) result in tangential forces being applied to a manipulated object, thus causing translational and rotational motions of the object [6]. Nonlinear medium controlled actuators can be used for sorting and manipulating both small objects, comparable in size to the elementary actuating unit, and larger objects, with lengths of tens or hundreds of actuating units. Therefore, we demonstrate here two types of experiments with BZ-based manipulation of pixel-sized objects and of planar convex shapes. Pixel objects, due to their small size, are subjected to random forces, caused by impurities of the physical medium and imprecision of the actuating units. In this case, no averaging of forces is allowed and the pixel objects themselves sensitively react to a single force vector. Therefore, we adopt the following model of manipulating a

1 Chemical

laboratory experiments are undertaken by Dr. Ben De Lacy Costello (UWE, Bristol, UK).

ROBOT NAVIGATION AND MASSIVE MANIPULATION

169

FIGURE 5.18 Force vector ﬁeld (b) calculated from BZ medium’s image (a) [6].

pixel object: if all force vectors at the eight-pixel neighborhood of the current site of the pixel object are nil, then the pixel object jumps to a randomly chosen neighboring pixel of its neighborhood, otherwise the pixel object is translated by the maximum force vector in its neighborhood. When placed on the simulated manipulating surface, pixel objects move at random in the domains of the resting medium; however, by randomly drifting each pixel object does eventually encounter a domain of coaligned vectors (representing excitation wave front in BZ medium) and is translated along the vectors. An example of several pixel objects transported on a “frozen” snapshot of the chemical medium is shown in Figure 5.19. Trajectories of pixel objects (Fig. 5.19a) show distinctive intermittent modes of random motion separated by modes of directed “jumps” guided by traveling wave fronts. Smoothed trajectories of pixel objects (Fig. 5.19b) demonstrate that despite a very strong chaotic component in manipulation, pixel objects are transported to the sites of the medium where two or more excitation wave fronts meet.

FIGURE 5.19 Examples of manipulating ﬁve pixel objects using the BZ medium: (a) trajectories of pixel objects, (b) jump trajectories of pixel objects recorded every 100th time step. Initial positions of the pixel objects are shown by circles [6].

170

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

The overall speed of pixel object transportation depends on the frequency of wave generations by sources of target waves. As a rule, the higher the frequency, the faster the objects are transported. This is because in parts of the medium spanned by low frequency target waves there are lengthy domains of resting system, where no force vectors are formed. Therefore, pixel-sized object can wander randomly for a long time till climbing next wave front [6]. To calculate the contribution of each force we partitioned the object into fragments, using a square grid, in which each cell of the grid corresponds to one pixel of the image. We assume that the magnitude of the force applied to each fragment above given pixel is proportional to the area of the fragment and is codirectional with a force vector. A momentum of inertia of the whole object with respect to axis normal to the object and passing through the object’s center of mass is calculated from the position of the center of mass and the mass of every fragment. Since the object’s shape and size are constant, it is enough to calculate the moment of inertia only at the beginning of simulation. We are also taking into account principal rotational momentum created by forces and angular acceleration of the object around its center of mass. Therefore, object motion in our case can be sufﬁciently described by coordinates of its center of mass and its rotation at every moment of time [6]. Spatially extended objects follow the general pattern of motion observed for the pixel-sized objects. However, due to integration of many force vectors the motion of planar objects is smoother and less sensitive to the orientation of any particular force vector.

FIGURE 5.20 Manipulating planar object in BZ medium. (a) Right-angled triangle moved by fronts of target waves. (b) Square object moved by fronts of fragmented waves in subexcitable BZ medium. Trajectories of center of mass of the square are shown by the dotted line. Exact orientation of the objects is displayed every 20 steps. Initial position of the object is shown by and the ﬁnal position by ⊗ [6].

SUMMARY

171

Outcome of manipulation depends on the size of the object; with increasing size of the object—due to larger numbers of local vector forces acting on the object—the objects become more controllable by the excitation wave fronts (Fig. 5.20).

5.7 SUMMARY The ﬁeld of reaction–diffusion computing started 20 years ago [27] as a subﬁeld of physics and chemistry dealing with image processing operations in uniform thin-layer excitable chemical media. The basic idea was to apply input data as two-dimensional proﬁle of heterogeneous illumination, then allow excitation waves spread and interact with each other, and then optically record result of the computation. The ﬁrst even reaction–diffusion computers were already massively parallel, with parallel optical inputs and outputs. Later computer engineers entered the ﬁeld and started to exploit traditional techniques—wires were implemented by channels where wave pulses travel, and speciﬁcally shaped junctions acted as logical valves. In this manner, most “famous” chemical computing devices were implemented, including Boolean gates, coincidence detectors, memory units, and more. The upmost idea of reaction– diffusion computation was if not ruined then forced into cul-de-sac of nonclassical computation. The breakthrough happened when paradigms and solutions from the ﬁeld of dynamical, collision-based computing and conservative logic were mapped onto realms of spatially extended chemical systems. The computers became uniform and homogeneous. In several examples we demonstrated that reaction–diffusion chemical systems are capable of solving combinatorial problems with natural parallelism. In spatially distributed chemical processors, the data and the results of the computation are encoded as concentration proﬁles of the chemical species. The computation per se is performed via the spreading and interaction of wave fronts. The reaction–diffusion computers are parallel because the chemical medium’s microvolumes update their states simultaneously, and molecules diffuse and react in parallel. During the last decades, a wide range of experimental prototypes of reaction– diffusion computing devices have been fabricated and applied to solve various problems of computer science, including image processing, pattern recognition, path planning, robot navigation, computational geometry, logical gates in spatially distributed chemical media, and arithmetical and memory units. These important, but scattered across many scientiﬁc ﬁelds, results convince us that reaction–diffusion systems can do a lot. Are they capable enough to be intelligent? Yes, reaction–diffusion systems are smart—showing a state of readiness to respond, able to cope with difﬁcult situations, capable for determining something by mathematical and logical methods—and endowed with capacity to reason. Reaction–diffusion computers allow for massive parallel input of data. Equivalently, reaction–diffusion robots would need no dedicated sensors, each microvolume of the medium, each site of the matrix gel, is sensitive to changes in one or another physical characteristic of the environment. Electric ﬁeld, temperature, and illumination are “sensed”

172

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

by reaction–diffusion devices, and these are three principal parameters in controlling and programming reaction–diffusion robots. Hard computational problems of geometry, image processing, and optimization on graphs are resource efﬁciently solved in reaction–diffusion media due to intrinsic natural parallelism of the problems [1]. In this chapter we demonstrated efﬁciency of reaction–diffusion computers on example of construction of Voronoi diagram. The Voronoi diagram is a subdivision of plane by data planar set. Each point of the data set is represented by a drop of a reagent. The reagent diffuses and produces a color precipitate when reacting with the substrate. When two or more diffusive fronts of the “data” chemical species meet, no precipitate is produced (due to concentrationdependent inhibition). Thus, uncolored domains of the computing medium represent bisectors of the Voronoi diagram. The precipitating chemical processor can also compute a skeleton. The skeleton of a planar shape is computed in the similar manner. A contour of the shape is applied to computing substrate as a disturbance in reagent concentrations. The contour concentration proﬁle induces diffusive waves. A reagent diffusing from the data contour reacts with the substrate and the precipitate is formed. Precipitate is not produced at the sites of diffusive waves’ collision. The uncolored domains correspond to the skeleton of the data shape. To compute a collision-free shortest path in a space with obstacles, we can couple two reaction–diffusion media. Obstacles are represented by local disturbances of concentration proﬁles in one of the media. The disturbances induce circular waves traveling in the medium and approximating a scalar distance-to-obstacle ﬁeld. This ﬁeld is mapped onto the second medium, which calculates a tree of “many-sources-one-destination” shortest paths by spreading wave fronts [5]. There is still no rigorous theory of reaction–diffusion computing, and God knows if one will ever be developed; however, algorithms are intuitively convincing and range of applications is wide, and after all the whole ﬁeld of nature-inspired computing is built on interpretations: Of course, this is only a plausible consideration and not a mathematical proof, since the question still remains whether the mathematical interpretation of the physical event is adequate in a strict sense, or whether it gives only an adequate image of physical reality. Sometimes such experiments, even if performed only in imagination, are convincing even to mathematicians [16].

5.8 ACKNOWLEDGEMENTS Many thanks to Ben De Lacy Costello, who implemented chemical laboratory prototypes of reaction–diffusion computers discussed in the chapter. I am grateful to Andy Wuensche (hexagonal cellular automatons), Hiroshi Yokoi (robotic hand controlled by Belousov–Zhabotinsky reaction), Chris Melhuish (control of robot navigation), Sergey Skachek (massive parallel manipulation), Tetsuya Asai (LSI prototypes of reaction–diffusion computers) and Genaro Martinez (binary-state cellular automatons) for their cooperation. Some pictures, where indicated, where adopted from our

REFERENCES

173

coauthored publications. Special thanks to Ikuko Motoike for correcting the original version of the chapter.

REFERENCES 1. Adamatzky A. Computing in Nonlinear Media and Automata Collectives. Institute of Physics Publishing; 2001. 2. Adamatzky A, De Lacy Costello BPJ. Experimental logical gates in a reaction–diffusion medium: the XOR gate and beyond. Phys Rev E 2002;66:046112. 3. Adamatzky A, editor. Collision Based Computing. Springer; 2003. 4. Adamatzky A. Programming reaction–diffusion computers. In: Unconventional Programming Paradigms. Springer; 2005. 5. Adamatzky A, De Lacy Costello B, Asai T. Reaction-Diffusion Computers. Elsevier; 2005. 6. Adamatzky A, De Lacy Costello B, Skachek S, Melhuish C. Manipulating objects with chemical waves: open loop case of experimental Belousov–Zhabotinsky medium. Phys Lett A 2005. 7. Adamatzky A, Wuensche A, De Lacy Costello B. Glider-based computation in reaction– diffusion hexagonal cellular automata. Chaos, Solitons Fract 2006;27:287–295. 8. Adamatzky A, Wuensche A. Computing in ‘spiral rule’ reaction–diffusion hexagonal cellular automaton. Complex Syst. 2007;16:1–27. 9. Agladze K, Magome N, Aliev R, Yamaguchi T, Yoshikawa K. Finding the optimal path with the aid of chemical wave. Physica D 1997;106:247–254. 10. Asai T, De Lacy Costello B, Adamatzky A. Silicon implementation of a chemical reaction-diffusion processor for computation of Voronoi diagram. Int J Bifurcation Chaos 2005;15(1). 11. Asai T, Kanazawa Y, Hirose T, Amemiya Y. Analog reaction–diffusion chip imitating Belousov–Zhabotinsky reaction with hardware oregonator model. Int J Unconven Comput 2005;1:123–147. 12. Oya T, Asai T, Fukui T, Amemiya Y. Reaction–diffusion systems consisting of singleelectron oscillators. Int J Unconvent Comput 2005;1:179–196. 13. Beato V, Engel H. Pulse propagation in a model for the photosensitive Belousov– Zhabotinsky reaction with external noise. In: Schimansky-Geier L, Abbott D, Neiman A, Van den Broeck C, editors. Noise in Complex Systems and Stochastic Dynamics. Proc SPIE 2003;5114:353–62. 14. Berlekamp ER, Conway JH, Guy RL. Winning Ways for Your Mathematical Plays. Volume 2. Academic Press; 1982. 15. Brandtst¨adter H, Braune M, Schebesch I, Engel H. Experimental study of the dynamics of spiral pairs in light-sensitive Belousov–Zhabotinskii media using an open-gel reactor. Chem Phys Lett 2000;323:145–154. 16. Courant R, Robbins H. What is Mathematics? Oxford University Press; 1941. 17. Dupont C, Agladze K, Krinsky V. Excitable medium with left–right symmetry breaking. Physica A 1998;249:47–52. 18. Field R, Winfree AT. Travelling waves of chemical activity in the Zaikin–Zhabotinsky– Winfree reagent. J Chem Educ 1979; 56:754.

174

ALGORITHMS OF REACTION–DIFFUSION COMPUTING

19. Field RJ, Noyes RM. Oscillations in chemical systems. IV. Limit cycle behavior in a model of a real chemical reaction. J Chem Phys 1974;60:1877–1884. 20. Fredkin F, Toffoli T. Conservative logic. Int J Theor Phys 1982;21:219–253. 21. Gerhardt M, Schuster H, Tyson JJ. A cellular excitable media. Physica D 1990;46:392–415. 22. Grill S, Zykov VS, M¨uller SC. Spiral wave dynamics under pulsatory modulation of excitability. J Phys Chem 1996;100:19082–19088. 23. Hartman H, Tamayo P. Reversible cellular automata and chemical turbulence. Physica D 1990;45:293–306. 24. KItahata H, Aihara R, Magome N, Yoshikawa K. Convective and periodic motion driven by a chemical wave. J Chem Phys 2002;116:5666. 25. Kitahata H, Yoshikawa K. Chemo-mechanical energy transduction through interfacial instability. Physica D 2005;205:283–291. 26. Klein R. Concrete and abstract Voronoi diagrams. Berlin: Springer-Verlag; 1990. 27. Kuhnert L. A new photochemical memory device in a light sensitive active medium. Nature 1986;319:393. 28. Kuhnert L, Agladze KL, Krinsky VI. Image processing using light-sensitive chemical waves. Nature 1989;337:244–247. 29. Kusumi T, Yamaguchi T, Aliev R, Amemiya T, Ohmori T, Hashimoto H, Yoshikawa K. Numerical study on time delay for chemical wave transmission via an inactive gap. Chem Phys Lett 1997;271:355–360. 30. Margolus N. Physics-like models of computation. Physica D 1984;10:81–95. 31. Markus M, Hess B. Isotropic cellular automata for modelling excitable media. Nature 1990;347:56–58. 32. Mills J. The new computer science and its unifying principle: complementarity and unconventional computing. Position Papers. International Workshop on the Grand Challenge in Nonclassical Computation; New York; 2005 Apr 18–19. 33. Motoike IN, Yoshikawa K, Iguchi Y, Nakata S. Real-time memory on an excitable ﬁeld. Phys Rev E 2001;63:036220. 34. Motoike IN, Yoshikawa K. Information operations with multiple pulses on an excitable ﬁeld. Chaos Solitons Fract 2003;17:455–461. 35. Nagai K, Sumino Y, Kitahata H, Yoshikawa K. Mode selection in the spontaneous motion of an alcohol droplets. Phys Rev E 2005;71:065301. 36. Petrov V, Ouyang Q, Swinney HL. Resonant pattern formation in a chemical system. Nature 1997;388:655–657. 37. Pour–El MB. Abstract computability and its relation to the general purpose analog computer (some connections between logic, differential equations and analog computers). Trans Am Math Soc 1974;199:1–28. 38. Qian H, Murray JD. A simple method of parameter space determination for diffusion-driven instability with three species. Appl Math Lett 2001;14:405–411. 39. Rambidi NG. Neural network devices based on reaction–diffusion media: an approach to artiﬁcial retina. Supramol Sci 1998;5:765–767. 40. Rambidi NG, Shamayaev KR, Peshkov GY. Image processing using light-sensitive chemical waves. Phys Lett A 2002;298:375–382. 41. Saltenis V. Simulation of wet ﬁlm evolution and the Euclidean Steiner problem. Informatica 1999;10:457–466.

REFERENCES

175

42. Sielewiesiuk J, Gorecki J. Logical functions of a cross junction of excitable chemical media. J Phys Chem A 2001;105:8189–8195. 43. Schenk CP, Or-Guil M, Bode M, Purwins HG. Interacting pulses in three-component reaction–diffusion systems on two-dimensional domains. Phys Rev Lett 1997;78:3781– 3784. 44. Sedina-Nadal I, Mihaliuk E, Wang J, P´erez-Munuzuri V, Showalter K. Wave propagation in subexcitable media with periodically modulated excitability. Phys Rev Lett 2001;86:1646– 1649. 45. Sienko T, Adamatzky A, Rambidi N, Conrad M, editors. Molecular Computing. The MIT Press; 2003. 46. Steinbock O, Toth A, Showalter K. Navigating complex labyrinths: optimal paths from chemical waves. Science 1995;267:868–871. 47. Schebesch I, Engel H. Wave propagation in heterogeneous excitable media. Phys Rev E 1998;57:3905–3910. 48. T´oth A, Showalter K. Logic gates in excitable media. J Chem Phys 1995;103:2058–2066. 49. Tyson JJ, Fife PC. Target patterns in a realistic model of the Belousov–Zhabotinskii reaction. J Chem Phys 1980;73:2224–2237. 50. Vergis A, Steiglitz K, Dickinson B. The complexity of analog computation. Math Comput Simulat 1986;28:91–113. 51. Wang J. Light-induced pattern formation in the excitable Belousov–Zhabotinsky medium. Chem Phys Lett 2001;339:357–361. 52. Weaire D, Hutzler S, Cox S, Kern N, Alonso MD Drenckhan W. The ﬂuid dynamics of foams. J Phys: Condens Matter 2003;15:S65–S73. 53. Wuensche A, Adamatzky A. On spiral glider-guns in hexagonal cellular automata: activator-inhibitor paradigm. Int J Modern Phys C 2006;17. 54. Yaguma S, Odagiri K, Takatsuka K. Coupled-cellular-automata study on stochastic and pattern-formation dynamics under spatiotemporal ﬂuctuation of temperature. Physica D 2004;197:34–62. 55. Yang X. Computational modelling of nonlinear calcium waves. Appl Math Model 2006;30:200–208. 56. Yang X. Pattern formation in enzyme inhibition and cooperativity with parallel cellular automata. Parallel Comput 2004;30:741–751. 57. Yokoi H, Adamatzky A, De Lacy Costello B, Melhuish C. Excitable chemical medium controlled for a robotic hand: closed loop experiments. Int J Bifurcation Chaos 2004. 58. Young D. A local activator–inhibitor model of vertebrate skin patterns. Math Biosci 1984;72:51. 59. Yoneyama M. Optical modiﬁcation of wave dynamics in a surface layer of the Mn-catalyzed Belousov–Zhabotinsky reaction. Chem Phys Lett 1996;254:191–196.

CHAPTER 6

Data Mining Algorithms I: Clustering DAN A. SIMOVICI

6.1 INTRODUCTION Activities of contemporary society generate enormous amounts of data that are used in decision support processes. Many databases have current volumes in the hundreds of terabytes. An academic estimate [4] puts the volume of data created in 2002 alone at 5 hexabytes (the equivalent of 5 million terabytes). The difﬁculty of analyzing these kinds of data volumes by human operators is clearly insurmountable. This lead to a rather new area of computer science, data mining, whose aim is to develop automatic means of data analysis for discovering new and useful patterns embedded in data. Data mining builds on several disciplines, statistics, artiﬁcial intelligence, databases, visualization techniques, and others, and has crystallized as a distinct discipline in the last decade of the past century. The range of subjects in data mining is very broad. Among the main directions of this branch of computer science, one should mention identiﬁcation of associations between data items, clustering, classiﬁcation, summarization, outlier detection, and so on. The diversity of these preoccupations makes impossible an exhaustive presentation of data mining algorithms in a very limited space. In this chapter, we concentrate on clustering algorithms. This choice will allow us a presentation that is as selfcontained as possible and gives a quite accurate image of the challenges posed by data mining.

6.2 CLUSTERING ALGORITHMS Clustering is the process of grouping together objects that are similar. The groups formed by clustering are referred to as clusters. Similarity between objects that belong to a set S is usually measured using a dissimilarity d : S × S −→ R≥0 that is deﬁnite (see Section 6.3), this means that d(x, y) = 0 if and only if x = y and d(x, y) = d(y, x) Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

177

178

DATA MINING ALGORITHMS I: CLUSTERING

for every x, y ∈ S. Two objects x, y are similar if the value of d(x, y) is small; what “small” means depends on the context of the problem. Clustering can be regarded as a special type of classiﬁcation, where the clusters serve as classes of objects. It is a widely used data mining activity with multiple applications in a variety of scientiﬁc activities ranging from biology and astronomy to economics and sociology. There are several points of view for examining clustering techniques. We follow here the taxonomy of clustering presented in the work by Jain et al. [5]. Clustering may or may not be exclusive, where an exclusive clustering technique yields clusters that are disjoint, while a nonexclusive technique produces overlapping clusters. From an algebraic point of view, an exclusive clustering generates a partition of the set of objects, and most clustering algorithms ﬁt in this category. Clustering may be intrinsic or extrinsic. Intrinsic clustering is an unsupervised activity that is based only on the dissimilarities between the objects to be clustered. Most clustering algorithms fall into this category. Extrinsic clustering relies on information provided by an external source that prescribes, for example, which objects should be clustered together and which should not. Finally, clustering may be hierarchical or partitional. In hierarchical clustering algorithms, a sequence of partitions is constructed. In hierarchical agglomerative algorithms, this sequence is increasing and it begins with the least partition of the set of objects whose blocks consist of single objects; as the clustering progresses, certain clusters are fused together. As a result, an agglomerative clustering is a chain of partitions on the set of objects that begins with the least partition αS of the set of objects S and ends with the largest partition ωS . In a hierarchical divisive algorithm, the sequence of partitions is decreasing. Its ﬁrst member is the one-block partition ωS and each partition is built by subdividing the blocks of the previous partition. A partitional clustering creates a partition of the set of objects whose blocks are the clusters such that objects in a cluster are more similar to each other than to objects that belong to different clusters. A typical representative algorithm is the k-means algorithm and its many extensions. Our presentation is organized around the last dichotomy. We start with a class of hierarchical agglomerative algorithms. This is continued with a discussion of the k-means algorithm, a representative of partitional algorithms. Then, we continue with a discussion of certain limitations of clustering centered around Kleinberg’s impossibility theorem. We conclude with an evaluation of clustering quality.

6.3 BASIC NOTIONS: PARTITIONS AND DISSIMILARITIES Deﬁnition 1 Let S be a nonempty set. A partition of S is a nonempty collection of nonempty subsets of S, π = {Bi |i ∈ I} such that i = j implies Bi ∩ Bj = ∅ and {Bi |i ∈ I} = S. The members of the collection π are the blocks of the partition π. The collection of partitions of a set S is denoted by PART(S).

BASIC NOTIONS: PARTITIONS AND DISSIMILARITIES

179

Example 1 Let S = {a, b, c, d, e} be a set. The following collections of subsets of S are partitions of S: π0 = {{a}, {b}, {c}, {d}, {e}}, π1 = {{a, b}, {c}, {d, e}}, π2 = {{a, c}, {b}, {d, e}}, π3 = {{a, b, c}{d, e}}, π4 = {{a, b, c, d, e}}.

䊐

A partial order relation can be deﬁned on PART(S) by taking π ≤ σ if every block of π is included in some block of σ. It is easy to see that for the partitions deﬁned in Example 1, we have π0 ≤ π1 ≤ π3 ≤ π4 and π0 ≤ π2 ≤ π3 ≤ π4 ; however, we have neither π1 ≤ π2 nor π2 ≤ π1 . The partially ordered set (PART(S), ≤) has as its least element the partition whose blocks are singletons of the form {x}, αS = {{x}|x ∈ S}, and as its largest element the one-block partition ωS = {S}. For the partitions deﬁned in Example 1 we have π0 = αS and π4 = ωS . We refer the reader to the work by Birkhoff [1] for a detailed discussion of the properties of this partial ordered set. To obtain a quantitative expression of the differences that exist between objects we use the notion of dissimilarity. Deﬁnition 2 A dissimilarity on a set S is a function d : S 2 −→ R≥0 satisfying the following conditions: (i) d(x, x) = 0 for all x ∈ S; (ii) d(x, y) = d(y, x) for all x, y ∈ S. The pair (S, d) is a dissimilarity space. The set of dissimilarities deﬁned on a set S is denoted by DS . The notion of dissimilarity can be strengthened in several ways by imposing certain supplementary conditions. A nonexhaustive list of these conditions is given next. 1. 2. 3. 4.

d(x, y) = 0 implies d(x, z) = d(y, z) for every x, y, z ∈ S (evenness); d(x, y) = 0 implies x = y for every x, y (deﬁniteness); d(x, y) ≤ d(x, z) + d(z, y) for every x, y, z (triangular inequality); d(x, y) ≤ max{d(x, z), d(z, y)} for every x, y, z (the ultrametric inequality).

180

DATA MINING ALGORITHMS I: CLUSTERING

The set of deﬁnite dissimilarities on a set S is denoted by DS . Example 2 Consider the mapping d : (Seqn (S))2 −→ R≥0 deﬁned by d(p, q) = |{i|0 ≤ i ≤ n − 1 and p(i) = q(i)}|, for every sequences p, q of length n on the set S. Clearly, d is a dissimilarity that is both even and deﬁnite. Moreover, it satisﬁes the triangular inequality. Indeed, let p, q, r be three sequences of length n on the set S. If p(i) = q(i), then r(i) must be distinct from at least one of p(i) and q(i). Therefore, {i|0 ≤ i ≤ n − 1 and p(i) = q(i)} ⊆ {i|0 ≤ i ≤ n − 1 and p(i) = r(i)} ∪ {i|0 ≤ i ≤ n − 1 and r(i) = q(i)}, which implies the triangular inequality.

䊐

The ultrametric inequality implies the triangular inequality; both the triangular inequality and deﬁniteness imply evenness (see Exercise 10). Deﬁnition 3 A dissimilarity d ∈ DS is 1. a metric, if it satisﬁes the deﬁniteness property and the triangular inequality; 2. an ultrametric, if it satisﬁes the deﬁniteness property and the ultrametric inequality. The set of metrics and the set of ultrametrics on a set S are denoted by MS and US , respectively. If d is a metric or an ultrametric on a set S, then (S, d) is a metric space or an ultrametric space, respectively. Deﬁnition 4 The diameter of a ﬁnite metric space (S, d) is the number diamS,d = max{d(x, y)|x, y ∈ S}. Exercise 10 implies that US ⊆ MS ⊆ DS . Example 3 Let G = (V, E) be a connected graph. Deﬁne the mapping d : V 2 −→ R≥0 by d(x, y) = m, where m is the length of the shortest path that connects x and y. Then, d is a metric. Indeed, we have d(x, y) = 0 if and only if x = y. The symmetry of d is obvious. If p is a shortest path that connects x to z and q is a shortest path that connects z to y, then pq is a path of length d(x, z) + d(z, y) that connects x to y. Therefore, 䊐 d(x, y) ≤ d(x, z) + d(z, y). In this chapter, we shall use frequently the notion of sphere in a metric space.

181

ULTRAMETRIC SPACES

Deﬁnition 5 Let (S, d) be a metric space. The closed sphere centered in x ∈ S of radius r is the set Bd (x, r) = {y ∈ S|d(x, y) ≤ r}. The open sphere centered in x ∈ S of radius r is the set Cd (x, r) = {y ∈ S|d(x, y) < r}. Let d be a dissimilarity and let S(x, y) be the set of all nonnull sequences s = (s1 , . . . , sn ) ∈ Seq(S) such that s1 = x and sn = y. The d-amplitude of s is the number ampd (s) = max{d(si , si+1 )|1 ≤ i ≤ n − 1}. If d is a ultrametric we have d(x, y) ≤ min{ampd (s)|s ∈ S(x, y)} (Exercise 1). Dissimilarities deﬁned on ﬁnite sets can be represented by matrices. If S = {x1 , . . . , xn } is a ﬁnite set and d : S × S −→ R≥0 is a dissimilarity, let Dd ∈ (R≥0 )n×n be the matrix deﬁned by (Dd )ij = d(xi , xj ) for 1 ≤ i, j ≤ n. Clearly, all main diagonal elements of Dd are 0 and the matrix D is symmetric. 6.4 ULTRAMETRIC SPACES Ultrametrics represent a strengthening of the notion of metric, where the triangular inequality is replaced by the stronger ultrametric inequality. They play an important role in studying hierarchical clustering algorithm, which we discuss in Section 6.5. A simple, interesting property of triangles in ultrametric spaces is given next. Theorem 1 Let (S, d) be an ultrametric space. For every x, y, z ∈ S, two of the numbers d(x, y), d(x, z), d(y, z) are equal and the third is not larger than the other two equal numbers. Proof. Let d(x, y) be the least of the numbers d(x, y), d(x, z), d(y, z). We have d(x, z) ≤ max{d(x, y), d(y, z} = d(y, z) and d(y, z) ≤ max{d(x, y), d(x, z)} = d(x, z). Therefore, d(y, z) = d(x, z) and d(x, y) is not larger than the other two. 䊏 Theorem 1 can be paraphrased by saying that in an ultrametric space any triangle is isosceles and the side that is not equal to the other two cannot be longer than these. In an ultrametric space, a closed sphere has all its points as centers. Theorem 2 Let B(x, r) be a closed sphere in the ultrametric space (S, d). If z ∈ B(x, d), then B(x, r) = B(z, r). Moreover, if two closed spheres B(x, r), B(y, r ) space have a point in common, they one of the closed spheres is included in the other. Proof. See Exercise 7. 䊏 Theorem 2 implies S = B(x, diamS,d ) for any point x ∈ S.

182

6.4.1

DATA MINING ALGORITHMS I: CLUSTERING

Construction of Ultrametrics

There is a strong link between ultrametrics deﬁned on a ﬁnite set S and chains of equivalence relations on S (or chains of partitions on S). This is shown in the next statement. Theorem 3 Let S be a ﬁnite set and let d : S × S −→ R≥0 be a function whose range is Ran(d) = {r1 , . . . , rm }, where r1 = 0 such that d(x, y) = 0 if and only if x = y. For u ∈ S and r ∈ R≥0 deﬁne the set Du,r = {x ∈ S|d(u, x) ≤ r}. Deﬁne the collection of sets πri = {D(u, ri )|u ∈ S} for 1 ≤ i ≤ m. The function d is an ultrametric on S if and only if the sequence of collections πr1 , . . . , πrm is an increasing sequence of partitions on S such that πr1 = αS and πrm = ωS . Proof. Suppose that d is an ultrametric on S. Then, the sets of the form D(x, r) are precisely the closed spheres B(x, r). Since x ∈ B(x, r) for x ∈ S, it follows that none of these sets is empty and that x∈S B(x, r) = S. Any two distinct spheres B(x, r), B(y, r) are disjoint by Theorem 2. It is straightforward to see that πr1 ≤ πr2 ≤ · · · ≤ πrm ; that is, this sequence of relations is indeed a chain of equivalences. Conversely, suppose that πr1 , . . . , πrm is an increasing sequence of partitions on S such that πr1 = αS and πrm = ωS , where πri consists of the sets of the form Du,ri for u ∈ S. Since Dx,0 = {x}, it follows that d(x, y) = 0 if and only if x = y. We claim that d(x, y) = min{r|{x, y} ⊆ B ∈ πr }.

(6.1)

= ωS , it is clear that there is a partition such that {x, y} ⊆ Indeed, since B ∈ πri . If x and y belong to the same block of πri , the deﬁnition of πri implies d(x, y) ≤ ri , so d(x, y) ≤ min{r|{x, y} ⊆ B ∈ πr }. This inequality can be easily seen to become an equality since x, y ⊆ B ∈ πd(x,y) . This implies immediately that d is symmetric. To prove that d satisﬁes the ultrametric inequality, let x, y, z be three members of the set S. Let p = max{d(x, z), d(z, y)}. Since {x, z} ⊆ b ∈ πd(x,z) ≤ πp and {z, y} ⊆ B ∈ πd(z,y) ≤ πp , it follows that x, y belong to the same block of the partition πp . Thus, d(x, y) ≤ p = max{d(x, z), d(z, y)}, which proves the triangular inequality for d. 䊏 π rm

6.4.2

π ri

Hierarchies and Ultrametrics

Deﬁnition 6 Let S be a set. A hierarchy on the set S is a collection of sets H ⊆ P(S) that satisﬁes the following conditions: (i) the members of H are nonempty sets; (ii) S ∈ H;

ULTRAMETRIC SPACES

183

(iii) for every x ∈ S we have {x} ∈ H; (iv) if H, H ∈ H and H ∩ H = ∅, then we have either H ⊆ H or H ⊆ H. Example 4 Let S = {s, t, u, v, w, x, y} be a ﬁnite set. It is easy to verify that the family of subsets of S deﬁned by H = {{s}, {t}, {u}, {v}, {w}, {x}, {y}, {s, t, u}, {w, x}, {s, t, u, v}, {w, x, y}, {s, t, u, v, w, x, y}} is a hierarchy on the set S.

䊐

Chains of partitions deﬁned on a set generate hierarchies as we show next. Theorem 4 Let S be a set and let C = (π1 , π2 , . . . , πn ) be an increasing chain of partitions (PART(S), ≤) such that π1 = αS and πn = ωS . Then, the collection HC = n π that consists of the blocks of all partitions in the chain is a hierarchy on S. i i=1 Proof. The blocks of any of the partitions are nonempty sets, so HC satisﬁes the ﬁrst condition of Deﬁnition 6. Note that S ∈ HC because S is the unique block of πn = ωS . Also, since all singletons {x} are blocks of αS = π1 it follows that HC satisﬁes the second and the third conditions of Deﬁnition 6. Finally, let H, H be two sets of HC such that H ∩ H = ∅. Because of this condition it is clear that these two sets cannot be blocks of the same partition. Thus, there exist two partitions πi and πj in the chain such that H ∈ πi and H ∈ πj . Suppose that i < j. Since every block of πj is a union of blocks of πi , H is a union of blocks of πi and H ∩ H = ∅ means that H is one of these blocks. Thus, H ⊆ H . If j > i, we obtain the reverse inclusion. This allows us to conclude that HC is indeed a hierarchy. 䊏 Of course, Theorem 4 could be stated in terms of chains of equivalences; we give this alternative formulation for convenience. Theorem 5 Let S be a ﬁnite set and let (ρ1 , . . . , ρn ) be a chain of equivalence re= θS . Then, the collection of blocks of the lations on S such that ρ1 = ιS and ρn equivalence relations ρr , that is, the set 1≤r≤n S/ρr , is a hierarchy on S. Proof. The proof is a mere restatement of the proof of Theorem 4. 䊏 Deﬁne the relation “≺” on a hierarchy H on S by H ≺ K if H, K ∈ H, H ⊂ K, and there is no set L ∈ H such that H ⊂ L ⊂ K. Lemma 1 Let H be a hierarchy on a ﬁnite set S and let L ∈ H. The collection PL = {H ∈ H|H ≺ L} is a partition of the set L.

184

DATA MINING ALGORITHMS I: CLUSTERING

Proof. We claim that L = PL . Indeed, it is clear that PL ⊆ L. Conversely, suppose that z ∈ L but z ∈ PL . Since {z} ∈ H and there is no K ∈ PL such {z} ∈ PL , which contradicts the assumption that that z ∈ K, it follows that z ∈ PL . This means that L = PL . Let K0 , K1 ∈ PL be two distinct sets. These sets are disjoint since otherwise we would have either K0 ⊂ K1 , or K1 ⊂ K0 , and this would contradict the deﬁnition of PL . 䊏 Theorem 6 Let H be a hierarchy on a set S. The graph of the relation ≺ on H is a tree whose root is S; its leaves are the singletons {x} for every x ∈ S. Proof. Since ≺ is an antisymmetric relation on H it is clear that the graph (H, ≺) is acyclic. Moreover, for each set K ∈ H there is a unique path that joins K to S, so the graph is indeed a rooted tree. 䊏 Deﬁnition 7 Let H be a hierarchy on a set S. A grading function for H is a function h : H −→ R that satisﬁes the following conditions: (i) h({x}) = 0 for every x ∈ S, and (ii) if H, K ∈ H and H ⊂ K, then h(H) < h(K). If h is a grading function for a hierarchy H, the pair (H, h) is a graded hierarchy. Example 5 For the hierarchy H deﬁned in Example 4 on the set S = {s, t, u, v, w, x, y}, the function h : H −→ R given by h({s}) = h({t}) = h({u}) = h({v}) = h({w}) = h({x}) = h({y}) = 0, h({s, t, u}) = 3, h({w, x}) = 4, h({s, t, u, v}) = 5, h({w, x, y}) = 6, h({s, t, u, v, w, x, y}) = 7 is a grading function and the pair (H, h) is a graded hierarchy on S.

䊐

Theorem 4 can be extended to graded hierarchies. Theorem 7 Let S be a ﬁnite set and let C = (π1 , π2 , . . . , πn ) be an increasing chain of partitions (PART(S), ≤) such that π1 = αS and πn = ωS . Consider a function f : {1, . . ., n} −→ R≥0 such that f (1) = 0. The function h : HC −→ R≥0 given by h(K) = f min{j|K ∈ πj } for K ∈ HC is a grading function for the hierarchy HC . Proof. Since {x} ∈ π1 = αS it follows that h({x}) = 0, so h satisﬁes the ﬁrst condition of Deﬁnition 7. Suppose that H, K ∈ HC and H ⊂ K. If = min{j|H ∈ πj }, it is impossible for K to be a block of a partition that precedes π . Therefore, < min{j|K ∈ πj }, so h(H) < h(K), so (HC , h) is indeed a graded hierarchy. 䊏

185

ULTRAMETRIC SPACES

A graded hierarchy deﬁnes an ultrametric as shown next. Theorem 8 Let (H, h) be a graded hierarchy on a ﬁnite set S. Deﬁne the function d : S 2 −→ R as d(x, y) = min{h(U)|U ∈ H and {x, y} ⊆ U} for x, y ∈ S. The mapping d is an ultrametric on S. Proof. Note that for every x, y ∈ S there exists a set H ∈ H such that {x, y} ⊆ H because S ∈ H. It is immediate that d(x, x) = 0. Conversely, suppose that d(x, y) = 0. Then, there exists H ∈ H such that {x, y} ⊆ H and h(H) = 0. If x = y, then {x} ⊂ H; hence 0 = h({x}) < h(H), which contradicts the fact that h(H) = 0. Thus, x = y. The symmetry of d is immediate. To prove the ultrametric inequality, let x, y, z ∈ S and suppose that d(x, y) = p, d(x, z) = q, and d(z, y) = r. There exist H, K, L ∈ H such that {x, y} ⊆ H, h(H) = p, {x, z} ⊆ K, h(K) = q, and {z, y} ⊆ L, h(L) = r. Since K ∩ L = ∅ (because both sets contain z), we have either K ⊆ L or L ⊆ K, so K ∪ L equals either K or L, and in either case, K ∪ L ∈ H. Since {x, y} ⊆ K ∪ L, it follows that d(x, y) ≤ h(K ∪ L) = max{h(K), H(L)} = max{d(x, z), d(z, y)}, which is the ultrametric inequality. 䊏 We refer to the ultrametric d whose existence is shown in Theorem 8 as the ultrametric generated by the graded hierarchy (H, h). Example 6 The values of the ultrametric generated by the graded hierarchy (H, h) on the set S, introduced in Example 5, are given in the following table. d s t u v w x y

s 0 3 3 5 7 7 7

t 3 0 3 5 7 7 7

u 3 3 0 5 7 7 7

v w 5 7 5 7 5 7 0 7 7 0 7 4 7 6

x 7 7 7 7 4 0 6

y 7 7 7 7 6 6 0

䊐

The hierarchy introduced in Theorem 5 that is associated with an ultrametric space can be naturally equipped with a grading function, as shown next. Theorem 9 Let (S, d) be a ﬁnite ultrametric space. There exists a graded hierarchy (H, h) on S such that d is the ultrametric associated to (H, h).

186

DATA MINING ALGORITHMS I: CLUSTERING

Proof. Let H be the collection of equivalence classes of the equivalences ηr = {(x, y) ∈ S 2 |d(x, y) ≤ r} deﬁned by the ultrametric d on the ﬁnite set S, where the index r takes its values in the range Rd of the ultrametric d. Deﬁne h(E) = min{r ∈ Rd |E ∈ S/ηr } for every equivalence class E. It is clear that h({x}) = 0 because {x} is an η0 -equivalence class for every x ∈ S. Let [x]t be the equivalence class of x relative to the equivalence ηt . Suppose that E, E belong to the hierarchy and E ⊂ E . We have E = [x]r and E = [x]s for some x ∈ X. Since E is strictly included in E , there exists z ∈ E − E such that d(x, z) ≤ s and d(x, z) > r. This implies r < s. Therefore, h(E) = min{r ∈ Rd |E ∈ S/ηr } ≤ min{s ∈ Rd |E ∈ S/ηs } = h(E ), which proves that (H, h) is a graded hierarchy. The ultrametric e generated by the graded hierarchy (H, h) is given by e(x, y) = min{h(B)|B ∈ H and {x, y} ⊆ B} = min{r|(x, y) ∈ ηr } = min{r|d(x, y) ≤ r} = d(x, y), for x, y ∈ S; in other words, we have e = d. 䊏 Example 7 Starting from the ultrametric on the set S = {s, t, u, v, w, x, y} deﬁned by the table given in Example 6, we obtain the following quotient sets: Values of r [0, 3) [3, 4) [4, 5) [5, 6) [6, 7) [7, ∞)

S/ηr {s}, {t}, {u}, {v}, {w}, {x}, {y} {s, t, u}, {v}, {w}, {x}, {y} {s, t, u}, {v}, {w, x}, {y} {s, t, u, v}, {w, x}, {y} {s, t, u, v}, {w, x, y} {s, t, u, v, w, x, y}

䊐

We shall draw the tree of a graded hierarchy (H, h) using a special representation known as a dendrogram. In a dendrogram, an interior vertex K of the tree is represented by a horizontal line drawn at the height h(K). For example, the dendrogram of the graded hierarchy of Example 5 is shown in Figure 6.1. As we saw in Theorem 8, the value d(x, y) of the ultrametric d generated by a hierarchy H is the smallest height of a set of a hierarchy that contains both x and y. This allows us to “read” the value of the ultrametric generated by H directly from the dendrogram of the hierarchy. Example 8 For the graded hierarchy of Example 5, the ultrametric extracted from Figure 6.1 is clearly the same as the one that was obtained in Example 6. 䊐

187

ULTRAMETRIC SPACES

FIGURE 6.1 Dendrogram of graded hierarchy of Example 5.

6.4.3

The Poset of Ultrametrics

Let S be a set. Recall that we denoted the set of dissimilarities by DS . Deﬁne a partial order ≤ on DS by d ≤ d if d(x, y) ≤ d (x, y) for every x, y ∈ S. It is easy to verify that (DS , ≤) is a poset. Note that US , the set of ultrametrics on S, is a subset of DS . Theorem 10 Let d be a dissimilarity on a set S and let Ud be the set of ultrametrics: Ud = {e ∈ US |e ≤ d}. The set Ud has a largest element in the poset (DS , ≤). Proof. Note that the set Ud is nonempty because the zero dissimilarity d0 given by d0 (x, y) = 0 for every x, y ∈ S is an ultrametric and d0 ≤ d. Since the set {e(x, y)|e ∈ Ud } has d(x, y) as an upper bound, it is possible to deﬁne the mapping e1 : S 2 −→ R≥0 as e1 (x, y) = sup{e(x, y)|e ∈ Ud } for x, y ∈ S. It is clear that e ≤ e1 for every ultrametric e. We claim that e1 is an ultrametric on S. We prove only that e1 satisﬁes the ultrametric inequality. Suppose that there exist x, y, z ∈ S such that e1 violates the ultrametric inequality, that is max{e1 (x, z), e1 (z, y)} < e1 (x, y). This is equivalent to sup{e(x, y)|e ∈ Ud } > max{sup{e(x, z)|e ∈ Ud }, sup{e(z, y)|e ∈ Ud }}. Thus, there exists eˆ ∈ Ud such that eˆ (x, y) > sup{e(x, z)|e ∈ Ud }, eˆ (x, y) > sup{e(z, y)|e ∈ Ud }.

188

DATA MINING ALGORITHMS I: CLUSTERING

FIGURE 6.2 Two ultrametrics on the set {x, y, z}.

In particular, eˆ (x, y) > eˆ (x, z) and eˆ (x, y) > eˆ (z, y), which contradicts the fact that eˆ is an ultrametric. 䊏 The ultrametric deﬁned by Theorem 10 is known as the maximal subdominant ultrametric for the dissimilarity d. The situation is not symmetric with respect to the inﬁmum of a set of ultrametrics because, in general, the inﬁmum of a set of ultrametrics is not necessarily an ultrametric. For example, consider a three-element set S = {x, y, z}, four distinct nonnegative numbers a, b, c, d such that a > b > c > d, and the ultrametrics d and d deﬁned by the triangles shown in Figure 6.2a and b, respectively. The dissimilarity d0 deﬁned by d0 (u, v) = min{d(u, v), d (u, v)} for u, v ∈ S is given by d0 (x, y) = b, d0 (y, z) = d, and d0 (x, z) = c, and d0 is clearly not an ultrametric because the triangle xyz is not isosceles. In the sequel, we give an algorithm for computing the maximal subdominant ultrametric for a dissimilarity deﬁned on a ﬁnite set S. We will deﬁne inductively an increasing sequence of partitions π1 ≺ π2 ≺ · · · and a sequence of dissimilarities d1 , d2 , . . . on the sets of blocks of π1 , π2 , . . ., respectively. For the initial phase, π1 = αS and d1 ({x}, {y}) = d(x, y) for x, y ∈ S. Suppose that di is deﬁned on πi . If B, C ∈ πi is a pair of blocks such that di (B, C) has the smallest value, deﬁne the partition πi+1 by πi+1 = (πi − {B, C}) ∪ {B ∪ C}. In other words, to obtain πi+1 we replace two of the closest blocks B, C of πi (in terms of di ) with new block B ∪ C. Clearly, πi ≺ πi+1 in PART(S) for i ≥ 1. Note that the collection of blocks of the partitions πi form a hierarchy Hd on the set S. The dissimilarity di+1 is given by di+1 (U, V ) = min{d(x, y)|x ∈ U, y ∈ V } for U, V ∈ πi+1 .

(6.2)

189

ULTRAMETRIC SPACES

We introduce a grading function hd on the hierarchy deﬁned by this chain of partitions starting from the dissimilarity d. The deﬁnition is done for the blocks of the partitions πi by induction on i. For i = 1 the blocks of the partition π1 are singletons; in this case we deﬁne hd ({x}) = 0 for x ∈ S. Suppose that hd is deﬁned on the blocks of πi and let D be the block of πi+1 that is generated by fusing the blocks B, C of πi . All other blocks of πi+1 coincide with the blocks of πi . The value of the function hd for the new block D is given by hd (D) = min{d(x, y)|x ∈ B, y ∈ C}. It is clear that hd satisﬁes the ﬁrst condition of Deﬁnition 7. For a set U of Hd deﬁne pU = min{i|U ∈ πi } and qU = max{i|U ∈ πi }. To verify the second condition of Deﬁnition 7, let H, K ∈ Hd such that H ⊂ K. It is clear that qH ≤ pK . The construction of the sequence of partitions implies that there are H0 , H1 ∈ πpH −1 and K0 , K1 ∈ πpK −1 such that H = H0 ∪ H1 and K = K0 ∪ K1 . Therefore, hd (H) = min{d(x, y)|x ∈ H0 , y ∈ H1 }, hd (K) = min{d(x, y)|x ∈ K0 , y ∈ K1 }. Since H0 , H1 have been fused (to produce the partition πpH ) before K0 , K1 (to produce the partition πpK ), it follows that hd (H) < hd (K). By Theorem 8 the graded hierarchy (Hd , hd ) deﬁnes an ultrametric; we denote this ultrametric by e and we will prove that e is the maximal subdominant ultrametric for d. Recall that e is given by e(x, y) = min{hd (W)|{x, y} ⊆ W}, and that hd (W) is the least value of d(u, v) such that u ∈ U, v ∈ V if W ∈ πpW is obtained by fusing the blocks U and V of πpW −1 . The deﬁnition of e(x, y) implies that we have neither {x, y} ⊆ U nor {x, y} ⊆ V . Thus, we have either x ∈ U and y ∈ V or x ∈ V and y ∈ U. Thus, e(x, y) ≤ d(x, y). We now prove that e(x, y) = min{ampd (s)|s ∈ S(x, y)}, for x, y ∈ S. Let D be the minimal set in Hd that includes {x, y}. Then, D = B ∪ C, where B, C are two disjoint sets of Hd such that x ∈ B and y ∈ C. If s is a sequence included in D, then there are two consecutive components of s, sk , sk+1 such that sk ∈ B and sk+1 ∈ C. This implies e(x, y) = min{d(u, v)|u ∈ B, v ∈ C} ≤ d(sk , sk+1 ) ≤ ampd (s).

190

DATA MINING ALGORITHMS I: CLUSTERING

If s is not included in D, let sq , sq+1 be two consecutive components of s such that sq ∈ D and sq+1 ∈ D. Let E be the smallest set of Hd that includes {sq , sq+1 }. Note that D ⊆ E (because sk ∈ D ∩ E), and therefore, hd (D) ≤ hd (E). If E is obtained as the union of two disjoint sets E , E of Hd such that sk ∈ E and sk+1 ∈ E , we have D ⊆ E . Consequently, hd (E) = min{d(u, v)|u ∈ E , v ∈ E } ≤ d(sk , sk+1 ), which implies e(x, y) = hd (D) ≤ hd (E) ≤ d(sk , sk+1 ) ≤ ampd (s). Therefore, we conclude that e(x, y) ≤ ampd (s) for every s ∈ S(x, y). We show now that there is a sequence w ∈ S(x, y) such that e(x, y) ≥ ampd (w), which implies the equality e(x, y) = ampd (w). To this end, we prove that for every D ∈ πk ⊆ Hd there exists w ∈ S(x, y) such that ampd (w) ≤ hd (D). The argument is by induction on k. For k = 1, the statement obviously holds. Suppose that it holds for 1, . . . , k − 1 and let D ∈ πk . The set D belongs to πk−1 or D is obtained by fusing the blocks B, C of πk−1 . In the ﬁrst case, the statement holds by inductive hypothesis. The second case has several subcases: (i) If {x, y} ⊆ B, then by inductive hypothesis, there exists a sequence u ∈ S(x, y) such that ampd (u) ≤ hd (B) ≤ hd (D) = e(x, y). (ii) The case {x, y} ⊆ C is similar to the ﬁrst case. (iii) If x ∈ B and y ∈ C, there exist u, v ∈ D such that d(u, v) = hd (D). By the inductive hypothesis, there is a sequence u ∈ S(x, u) such that ampd (u) ≤ hd (B) and there is a sequence v ∈ S(v, y) such that ampd (v) ≤ hd (C). This allows us to consider the sequence w obtained by concatenating the sequences u, (u, v), v; clearly, we have w ∈ S(x, y) and ampd (w) = max{ampd (u), d(u, v), ampd (v)} ≤ hd (D). To complete the argument we need to show that if e is an other ultrametric such that e(x, y) ≤ e (x, y) ≤ d(x, y), then e(x, y) = e (x, y) for every x, y ∈ S. By the previous argument there exists a sequence s = (s0 , . . . , sn ) ∈ S(x, y) such that ampd (s) = e(x, y). Since e (x, y) ≤ d(x, y) for every x, y ∈ S, it follows that e (x, y) ≤ ampd (s) = e(x, y). Thus, e(x, y) = e (x, y) for every x, y ∈ S, which means that e = e . This concludes our argument.

6.5 HIERARCHICAL CLUSTERING Hierarchical clustering is a recursive process that begins with a metric space of objects (S, d) and results in a chain of partitions of the set of objects. In each of the partitions,

191

HIERARCHICAL CLUSTERING

similar objects belong to the same block and objects that belong to distinct blocks tend to be dissimilar. In the agglomerative hierarchical clustering, the construction of this chain begins with the unit partition π1 = αS . If the partition constructed at step k is k }, πk = {U1k , . . . , Um k

then two distinct blocks Upk and Uqk of this partition are selected using a selection criterion. These blocks are fused and a new partition k k k k , Up+1 , . . . , Uq−1 , Uq+1 , . . . , Upk ∪ Uqk } πk+1 = {U1k , . . . , Up−1

is formed. Clearly, we have πk ≺ πk+1 . The process must end because the poset (PART(S), ≤) is of ﬁnite height. The algorithm halts when the one-block partition ωS is reached. As we saw in Theorem 4, the chain of partitions π1 , π2 , . . . generates a hierarchy on the set S. Therefore, all tools developed for hierarchies, including the notion of dendrogram, can be used for hierarchical algorithms. When data to be clustered is numerical, that is, when S ⊆ Rn , we can deﬁne the centroid of a nonempty subset U of S as cU =

1 {o|o ∈ U}. |U|

If π = {U1 , . . . , Um } is a partition of S, then the sum of the squared errors of π is the number sse(π) =

m

{d 2 (o, cUi )|o ∈ Ui },

(6.3)

i=1

where d is the Euclidean distance in Rn . If two blocks U, V of a partition π are fused into a new block W to yield a new partition π that covers π, then the variation of the sum of squared errors is given by sse(π ) − sse(π) =

{d 2 (o, cW )|o ∈ U ∩ V } − {d 2 (o, cU )|o ∈ U} − {d 2 (o, cV )|o ∈ V }.

The centroid of the new cluster W is given by cW = =

1 {o|o ∈ W} |W| |U| |V | cU + cV . |W| |W|

192

DATA MINING ALGORITHMS I: CLUSTERING

This allows us to evaluate the increase in the sum of squared errors: {d 2 (o, cW )|o ∈ U ∪ V } − {d 2 (o, cU )|o ∈ U} − {d 2 (o, cV )|o ∈ V } = {d 2 (o, cW ) − d 2 (o, cU )|o ∈ U} + {d 2 (o, cW ) − d 2 (o, cV )|o ∈ V }.

sse(π ) − sse(π) =

Observe that {d 2 (o, cW ) − d 2 (o, cU )|o ∈ U} ((o − cW )(o − cW ) − (o − cU )(o − cU )) = o∈U

= |U|(c2W − c2U ) + 2(cU − cW )

o

o∈U

= |U|(c2W − c2U ) + 2|U|(cU − cW )cU = (cW − cU ) (|U|(cW + cU ) − 2|U|cU ) = |U|(cW − cU )2 . Using the equality cW − cU = |U|/|W|cU + |V |/|W|cV − cU = |V |/|W| (cV −cU ), we obtain {d 2 (o, cW ) − d 2 (o, cU )|o ∈ U} = |U||V |2 /|W|2 (cV − cU )2 . Similarly, we have

{d 2 (o, cW ) − d 2 (o, cV )|o ∈ V } =

|U|2 |V | (cV − cU )2 , |W|2

so sse(π ) − sse(π) =

|U||V | (cV − cU )2 . |W|

(6.4)

The dissimilarity between two clusters U, V can be deﬁned using one of the following real-valued, two-argument functions deﬁned on the set of subsets of S: sl(U, V ) = min{d(u, v)|u ∈ U, v ∈ V }; cl(U, V ) = max{d(u, v)|u ∈ U, v ∈ V }; {d(u, v)|u ∈ U, v ∈ V } gav(U, V ) = ; |U| · |V |

193

HIERARCHICAL CLUSTERING

cen(U, V ) = (cU − cV )2 ; ward(U, V ) =

|U||V | (cV − cU )2 . |U| + |V |

The names of the functions sl, cl, gav, and cen deﬁned above are acronyms of the terms “single link,” “complete link,” “group average,” and “centroid,” respectively. They are linked to variants of the hierarchical clustering algorithms that we discuss in later. Note that in the case of the ward function the value equals the increase in the sum of the square errors when the clusters U, V are replaced with their union. The speciﬁc selection criterion for fusing blocks deﬁnes the clustering algorithm. All algorithms store the dissimilarities between the current clusters πk = k } in a m × m matrix Dk = (d k ), where d k is the dissimilarity be{U1k , . . . , Um k k ij ij k tween the clusters Uik and Ujk . As new clusters are created by merging two existing clusters, the distance matrix must be adjusted to reﬂect the dissimilarities between the new cluster and existing clusters. The general form of the algorithm is matrix agglomerative clustering { compute the initial dissimilarity matrix D1 ; k = 1; while (πk contains more than one block) do merge a pair of two of the closest clusters; k + +; compute the dissimilarity matrix Dk ; endwhile; } Next, we show the computation of the dissimilarity between a new cluster and existing clusters. Theorem 11 Let U, V be two clusters of the clustering π that are joined into a new cluster W. Then, if Q ∈ π − {U, V } we have ( ( ( ( sl(W, Q) = 21 sl(U, Q) + 21 sl(V, Q) − 21 (sl(U, Q) − sl(V, Q)(; ( ( ( ( cl(W, Q) = 21 cl(U, Q) + 21 cl(V, Q) + 21 (cl(U, Q) − cl(V, Q)(; gav(W, Q) =

|U| |V | gav(U, Q) + gav(V, Q); |U| + |V | |U| + |V |

cen(W, Q) =

|U| |V | |U||V | cen(U, Q) + cen(V, Q) − cen(U, V ); |U| + |V | |U| + |V | (|U| + |V |)2

194

DATA MINING ALGORITHMS I: CLUSTERING

ward(W, Q) =

|V | + |Q| |U| + |Q| ward(U, Q) + ward(V, Q) |U| + |V | + |Q| |U| + |V | + |Q| −

|Q| ward(U, V ). |U| + |V | + |Q|

Proof. The ﬁrst two equalities follow from the fact that min{a, b} = 21 (a + b) − 21 |a − b|, max{a, b} = 21 (a + b) + 21 |a − b|, for every a, b ∈ R. For the third equality, we have {d(w, q)|w ∈ W, q ∈ Q} gav(W, Q) = |W| · |Q| {d(u, q)|u ∈ U, q ∈ Q} {d(v, q)|v ∈ V, q ∈ Q} = + |W| · |Q| |W| · |Q| |U| {d(u, q)|u ∈ U, q ∈ Q} |V | {d(v, q)|v ∈ V, q ∈ Q} = + |W| |U| · |Q| |W| |V | · |Q| =

|U| |V | gav(U, Q) + gav(V, Q). |U| + |V | |U| + |V |

The equality involving the function cen is immediate. The last equality can be easily translated into 2 |Q||W| cQ − cW |Q| + |W| =

2 |U||Q| |U| + |Q| cQ − cU |U| + |V | + |Q| |U| + |Q| 2 |V ||Q| |V | + |Q| cQ − cV + |U| + |V | + |Q| |V | + |Q| −

|U||V | |Q| (cV − cU )2 , |U| + |V | + |Q| |U| + |V |

which can be veriﬁed replacing |W| = |U| + |V | and cW = |U|/|W|cU + |V |/ |W|cV . 䊏. The equalities contained by Theorem 11 are often presented as a single equality involving several coefﬁcients. Corollary 1 (The Lance–Williams formula) Let U, V be two clusters of the clustering π that are joined into a new cluster W. Then, if Q ∈ π − {U, V } the dissimilarity

195

HIERARCHICAL CLUSTERING

between W and Q can be expressed as d(W, Q) = aU d(U, Q) + aV d(V, Q) + bd(U, V ) + c|d(U, Q) − d(V, Q)|, where the coefﬁcients aU , aV , b, c are given by the following table. Function sl cl gav cen ward

aU 1/2 1/2 |U|/(|U| + |V |) |U|/(|U| + |V |) |U| + |Q|(|U| + |V | + |Q|)

aV 1/2 1/2 |V |/|U| + |V | |V |/|U| + |V | |V | + |Q|/|U| + |V | + |Q|

b 0 0 0 −(|U||V |(|U| + |V |)2 ) −(|Q||U| + |V | + |Q|)

c −(1/2) 1/2 0 0 0

Proof. This statement is an immediate consequence of Theorem 9. 䊏 The variant of the algorithm that makes use of the function sl is known as the single-link clustering. It tends to favor elongated clusters. Example 9 We use single-link clustering for the data set shown in Figure 6.3, S = {o1 , . . . , o7 }, that consists of seven objects. The distances between the objects of S are speciﬁed by the 7 × 7 matrix √ √ √ ⎞ √ √ ⎛ 0 1 32 √61 √58 √5 √20 2 ⎜ √1 √0 √13 √5 √50 √45 ⎟ ⎟ ⎜ 0 5 13 √32 √29 ⎟ ⎜√ 5 √ 2 √ ⎟ ⎜ 0 2 . D1 = ⎜ √20 √13 √ 5 √13 √10 ⎟ ⎟ ⎜ 0 5 10 ⎟ ⎜ √32 √ 5 √13 √2 √ √ ⎠ ⎝ 5 √0 √61 √50 √32 √13 √ 5 58 45 29 10 10 5 0 Let us apply the hierarchical clustering algorithm using the single-link variant to the set S. Initially, the clustering is

FIGURE 6.3 Set of seven points in R . 2

196

DATA MINING ALGORITHMS I: CLUSTERING

π1 = {{o1 }, {o2 }, {o3 }, {o4 }, {o5 }, {o6 }, {o7 }}. The closest clusters are {o1 }, {o2 }; these clusters are fused into the cluster {o1 , o2 }, the new partition is π2 = {{o1 , o2 }, {o3 }, {o4 }, {o5 }, {o6 }, {o7 }}, and the matrix of dissimilarities becomes the 6 × 6 matrix √ √ √ ⎛ 2 √0 √13 √5 √50 5 13 0 ⎜√ 2 √ √32 ⎜ 5 0 2 13 ⎜ √13 √ D2 = ⎜ 13 2 0 5 ⎜ √5 √ √ √ ⎝ 50 32 13 5 0 √ √ √ √ √ 45 29 10 10 5

√ ⎞ √45 √29 ⎟ ⎟ √10 ⎟ ⎟. √10 ⎟ ⎠ 5 0

Next, the closest clusters are {o1 , o2 } and {o3 }. These clusters are fused into the cluster {o1 , o2 , o3 } and the new 5 × 5 matrix is √ √ √ √ ⎞ ⎛ 5 13 √32 √29 √0 0 2 ⎜√ 5 √13 √10 ⎟ ⎟ ⎜ 0 5 , D3 = ⎜ √13 √2 √ √10 ⎟ ⎠ ⎝ 32 13 5 0 5 √ √ √ √ 29 10 10 5 0 which corresponds to the partition π3 = {{o1 , o2 , o3 }, {o4 }, {o5 }, {o6 }, {o7 }}. Next, the closest clusters are {o4 } and {o5 }. Fusing these yields the partition π4 = {{o1 , o2 , o3 }, {o4 , o5 }, {o6 }, {o7 }} and the 4 × 4 matrix ⎛

√0 5 ⎜ D4 = ⎝ √ 32 √ 29

√ 5 0 √ √5 10

√ √32 5 0 √ 5

√ ⎞ √29 √10 ⎟ ⎠. 5 0

with {o4 , o5 }, or {o4 , o5 } with We have two choices now: we could fuse {o1 , o2 , o3 } √ {o6 } since in either case the intercluster dissimilarity is 5. We choose the ﬁrst option and we form the cluster {o1 , o2 , o3 , o4 , o5 }. Now the partition is π5 = {{o1 , o2 , o3 , o4 , o5 }, {o6 }, {o7 }}

197

HIERARCHICAL CLUSTERING

FIGURE 6.4 Elongated cluster produced by the single-link algorithm.

and the matrix is D5 =

√0 √5 10

√

5 0 √ 5

√ √10 5 . 0

Observe that the large cluster formed so far has an elongated shape (see Fig. 6.4); this is typical for single-link variant of the algorithm. Fusing now {o1 , o2 , o3 , o4 , o5 } with {o6 } gives the two-block partition π6 = {{o1 , o2 , o3 , o4 , o5 , o6 }, {o7 }} and the 2 × 2 matrix

D = 6

√0 5

√ 5 . 0

In the ﬁnal step, the two clusters are fused and the algorithm stops. The dendrogram of the hierarchy produced by the algorithm is given in 䊐 Figure 6.5. The variant of the algorithm that uses the function cl is known as the complete-link clustering. It tends to favor globular clusters.

FIGURE 6.5 Dendrogram of single-link clustering.

198

DATA MINING ALGORITHMS I: CLUSTERING

Example 10 Now we apply the complete-link algorithm to the set S considered in Example 9. It is easy to see that the initial two partitions and the initial matrix are the same as for the single-link algorithm. However, after creating the ﬁrst cluster {o1 , o2 }, the distance matrices begin to differ. The next matrix is √ √ ⎞ √ √ √ ⎛ 5 √20 √32 √61 √58 √0 5 13 √32 √29 ⎟ ⎜√ 5 √0 ⎜ ⎟ 20 5 0 2 ⎜ √13 √10 ⎟ √ D2 = ⎜ √ ⎟, 5 ⎜ √32 √13 √2 √0 √10 ⎟ ⎝ ⎠ 5 √61 √32 √13 √ 5 √0 58 29 10 10 5 0 which shows that the closest clusters are now {o4 } and {o5 }. Thus, π3 = {{o1 , o2 }, {o3 }, {o4 , o5 }, {o6 }, {o7 }} and the new matrix is √ 5 0 √ √13 √32 29

⎛

√0 ⎜√ 5 ⎜ D3 = ⎜ √32 ⎝ √61 58

√ √32 13 0 √ √13 10

√ √61 √32 10 0 √ 5

√ ⎞ √58 √29 ⎟ ⎟ . √10 ⎟ ⎠ 5 0

Now there are two pairs of clusters that correspond to the minimal value in D3 : {o1 , o2 }, {o3 } and {o6 }, {o7 }; if we merge the last pair we get the partition π4 = {{o1 , o2 }, {o3 }, {o4 , o5 }, {o6 , o7 }} and the matrix ⎛

√0 ⎜ √32 4 D =⎝ √61 58

√ 32 0 √ √13 10

√ √61 13 √0 5

√ ⎞ √58 √10 ⎟ ⎠. 5 0

Next, the closest clusters are {o1 , o2 }, {o3 }. Merging those clusters will result in the partition π5 = {{o1 , o2 , o3 }, {o4 , o5 }, {o6 , o7 }} and the matrix D5 =

√0 √32 61

√ 32 0 √ 13

√ √61 13 . 0

The current clustering is shown in Figure 6.6. Observe that in the case of the completelink method clusters that appear early tend to enclose objects that are closed in the sense of the distance.

199

HIERARCHICAL CLUSTERING

FIGURE 6.6 Partial clustering obtained by complete-link method.

Now the closest clusters are {o4 , o5 } and {o6 , o7 }. Merging those clusters will give the partition π5 = {{o1 , o2 , o3 }, {o4 , o5 , o6 , o7 }} and the matrix D = 6

√0 61

√

61 0

.

The dendrogram of the resulting clustering is given in Figure 6.7.

䊐

The group average method that makes use of the gav function is an intermediate approach between the single-link and the complete-link method. What the methods mentioned so far have in common is the monotonicity property expressed by the following statement.

FIGURE 6.7 Dendrogram of complete-link clustering.

200

DATA MINING ALGORITHMS I: CLUSTERING

Theorem 12 Let (S, d) be ﬁnite metric space and let D1 , . . . , Dm be the sequence of matrices constructed by any of the ﬁrst three hierarchical methods (single, complete, or average link), where m = |S|. If μi is the smallest entry of the matrix Di for 1 ≤ i ≤ m, then μ1 ≤ μ2 ≤ · · · ≤ μm . In other words, the dissimilarity between clusters that are merged at each step is nondecreasing. Proof. Suppose that the matrix Dj+1 is obtained from the matrix Dj by merging the clusters Cp and Cq that correspond to the lines p, q and to columns p, q of Dj . This happens because dpq = dqp is one of the minimal elements of the matrix Dj . Then, these lines and columns are replaced with a line and column that corresponds to the new cluster Cr and to the dissimilarities between this new cluster and the previous j+1 clusters Ci , where i = p, q. The elements drh of the new line (and column) are obj j j j j j tained either as min{dph , dqh }, max{dph , dqh }, or as (|Cp |/|Cr |)dph + (|Cq |/|Cr |)dqh , for the single-link, complete-link, or group average methods, respectively. In any of j+1 these case, it is not possible to obtain a value for drh that is less than the minimal value of an element of Dj . 䊏 The last two methods captured by the Lance–Williams formula are, respectively, the centroid method and the Ward method of clustering. As we observed before, formula (6.4) shows that the dissimilarity of two cluster in the case of Ward’s method equals the increase in the sum of the squared errors that results when the clusters are merged. The centroid method adopts the distance between the centroids as the distance between the corresponding clusters. Either method lacks the monotonicity properties. To evaluate the space and time complexity of hierarchical clustering note that the algorithm must handle the matrix of the dissimilarities between objects and this is a symmetric n × n matrix having all elements on its main diagonal equal to 0; in other words, the algorithm needs to store (n(n − 1)/2) numbers. To keep track of the clusters, an extra space that does not exceed n − 1 is required. Thus, the total space required is O(n2 ). The time complexity of agglomerative clustering algorithms has been evaluated in the work by Kurita [9]; the proposed implementation requires a heap that contains the pairwise distances between clusters and therefore has a size of n2 . The pseudocode of this algorithm is generic agglomerative algorithm { construct a heap H of size n2 for inter-cluster dissimilarities; while the number of clusters is larger than 1 do get the nearest pairs of clusters Cp , Cq that correspond to H[0]; reduce the number of clusters by 1 through merging Cp and Cq ; update the heap to reﬂect the revised distances and remove unnecessary elements;

201

HIERARCHICAL CLUSTERING

endwhile; } Note that the while loop is performed n times as each execution reduces the number of clusters by 1. The initial construction of the heap requires a time of O(n2 log n2 ) = O(n2 log n). Then, each of operations inside the loop requires no more than O(log n2 ) = O(log n) (because the heap has size n2 ). Thus, we conclude that the time complexity is O(n2 log n). There exists an interesting link between the single-link clustering algorithm and the subdominant ultrametric of a dissimilarity, which we examined in Section 6.4.3. To construct the subdominant ultrametric for a dissimilarity dissimilarity space (S, d), we built an increasing chain of partitions π1 , π2 , . . . of S (where π1 = αS ) and a sequence of dissimilarities d1 , d2 , . . . (where d1 = d) on the sets of blocks of π1 , π2 , . . ., respectively. We claim that this sequence of partitions π1 , π2 , . . . coincides with the sequence of partitions π1 , π2 , . . ., and that the sequence of dissimilarities d1 , d2 , . . . coincides with the sequences of dissimilarities d 1 , d 2 , . . . deﬁned by the matrices Di constructed by the single-link algorithm. This is clearly the case for i = 1. Suppose that the statement is true for i. The partition πi+1 is obtained from πi by fusing the blocks B, C of π such that di (B, C) has the smallest value, that is, πi+1 = (πi − {B, C}) ∪ {B ∪ C}. Since this is exactly how the partition πi+1 is constructed from πi , it follows that πi+1 = πi+1 . The inductive hypothesis implies that d i (U, V ) = di (U, V ) = min{d(u, v)|u ∈ U, v ∈ V } for all U, V ∈ πi . Since the dissimilarity di+1 is di+1 (U, V ) = min{d(u, v)|u ∈ U, u ∈ V } for every pair of blocks U, V of πi+1 , it is clear that di+1 (U, V ) = di (U, V ) = d i (U, V ) = d i+1 (U, V ) when neither U nor V equal the block B ∪ C. Then, di+1 (B ∪ C, W) = min{d(t, w)|t ∈ B ∪ C, w ∈ W} = min{min{d(b, w)|b ∈ B, w ∈ W}, min{d(c, w)|c ∈ C, w ∈ W}} = min{di (B, W), di (C, W)} = min{d i (B, W), d i (C, W)} = d i+1 (B ∪ C, W). Thus, di+1 = d i+1 . Let x, y be a pair of elements of S. The value of the subdominant ultrametric is given by e(x, y) = min{hd (W)|W ∈ Hd and {x, y} ⊆ W}.

202

DATA MINING ALGORITHMS I: CLUSTERING

This is the height of W in the dendrogram of the single-link clustering, and therefore, the subdominant ultrametric can be read directly from this dendrogram. Example 11 The subdominant ultrametric of the Euclidean metric considered in Example 9 is given by the following table. e(oi , oj )

o1

o2

o1 o2 o3 o4 o5 o6 o7

0 √1 2 √2 √5 √5 5

1 0 √ √2 √5 √5 √5 5

o3 √ √2 2 √0 √5 √5 √5 5

o4 √2 √5 5 √0 √5 √5 5

o5 o6 √ √ √5 √5 √5 √5 √5 √5 5 √5 5 √0 √5 √0 5 5

o7 √ √5 √5 √5 √5 √5 5 0

䊐

6.6 THE k-MEANS ALGORITHM The k-means algorithm is a partitional algorithm that requires the speciﬁcation of the number of clusters k as an input. The set of objects to be clustered S = {o1 , . . . , on } is a subset of Rm . Due to its simplicity and its many implementations, it is a very popular algorithm despite this requirement. The k-means algorithm begins with a randomly chosen collection of k points c1 , . . . , ck in Rm called centroids. An initial partition of the set S of objects is computed by assigning each object oi to its closest centroid cj . Let Uj be the set of points assigned to the centroid cj . The assignments of objects to centroids are expressed by a matrix (bij ), where bij =

1 if oi ∈ Uj , 0 otherwise.

Since each object is assigned to exactly one cluster, we have kj=1 bij = 1. On the contrary, ni=1 bij equals the number of objects assigned to the centroid cj . After these assignments, expressed by the matrix (bij ), the centroids cj must be recomputed using the formula n bij oi c = i=1 n i=1 bij j

(6.5)

for 1 ≤ j ≤ k. The sum of squared errors of a partition π = {U1 , . . . , Uk } of a set of objects S was deﬁned in equality (6.3) as

203

THE k-MEANS ALGORITHM

k

sse(π) =

d 2 (o, cj ),

j=1 o∈Uj

where cj is the centroid of Uj for 1 ≤ j ≤ k. The error of such an assignment is the sum of squared errors of the partition π = {U1 , . . . , Uk } deﬁned as sse(π) =

k n

bij ||oi − cj ||2

i=1 j=1

=

k n

bij

i=1 j=1

m

oip − cpj

2

.

p=1

The mk necessary conditions for a local minimum of this function, ∂sse(π) j

∂cp

=

n

bij −2(oip − cpj ) = 0

i=1

for 1 ≤ p ≤ m and 1 ≤ j ≤ k, can be written as n

bij oip =

i=1

n

bij cpj = cpj

i=1

n

bij ,

i=1

or as n

cpj

i=1 = n

bij oip

i=1 bij

for 1 ≤ p ≤ m. In vectorial form, these conditions amount to n bij oi , cj = i=1 n i=1 bij which is exactly formula (6.5) that is used to update the centroids. Thus, the choice of the centroids can be justiﬁed by the goal of obtaining local minima of the sum of squared errors of the clusterings. Since we have new centroids, objects must be reassigned, which means that the values of bij must be recomputed, which, in turn, will affect the values of the centroids, and so on. The halting criterion of the algorithm depends on particular implementations and it may involve

204

DATA MINING ALGORITHMS I: CLUSTERING

(i) performing a certain number of iterations; (ii) lowering the sum of squared errors sse(π) below a certain limit; (iii) the current partition coincides with the previous partition. This variant of the k-means algorithm is known as Forgy’s algorithm: k means forgy{ obtain a randomly chosen collection of k points c1 , . . . , ck in Rn ; assign each object oi to the closest centroid cj ; let π = {U1 , . . . , Uk } be the partition deﬁned by c1 , . . . , ck ; recompute the centroids of the clusters U1 , . . . , Uk ; while (halting criterion is not met) do compute the new value of the partition π using the current centroids; recompute the centroids of the blocks of π; endwhile } The popularity of the k-means algorithm stems on its simplicity and its low time complexity that is O(kn), where n is the number of objects to be clustered and is the number of iterations that the algorithm is performing. Another variant of the k-means algorithm redistributes objects to clusters based on the effect of such a reassignment on the objective function. If sse(π) decreases, the object is moved and the two centroids of the affected clusters are recomputed. This variant is carefully analyzed in the work by Berkin and Becher [3]. 6.7 THE PAM ALGORITHM Another algorithm named PAM (an acronym of partition around medoids) developed by Kaufman and Rousseeuw [7] also requires as an input parameter the number k of clusters to be extracted. The k clusters are determined based on a representative object from each cluster called the medoid of the cluster. The medoid is intended to have the most central position in the cluster relative to all other members of the cluster. Once medoids are selected, each remaining object o is assigned to a cluster represented by a medoid oi if the dissimilarity d(o, oi ) is minimal. In the second phase, swapping objects and existing medoids are considered. The cost of a swap is deﬁned with the intention of penalizing swaps that diminish the centrality of the medoids in the clusters. Swapping continues as long as useful swaps (i.e., swaps with negative costs) can be found. PAM begins with a set of objects S, where |S| = n, a dissimilarity n × n matrix D, and a prescribed number of clusters k. The dij entry of the matrix D is the dissimilarity

205

THE PAM ALGORITHM

d(oi , oj ) between the objects oi and oj . PAM is more robust than Forgy’s variant of k-clustering because it minimizes the sum of the dissimilarities instead of the sum of the squared errors. The algorithm has two distinct phases: the building phase and the swapping phase. The building phase aims to construct a set L of selected objects, L ⊆ S. The set or remaining objects is denoted by R; clearly, R = S − L. We begin by determining the most centrally located object. The quantities Qi = nj=1 dij are computed starting from the matrix D. The most central object oq is the determined by q = arg mini Qi . The set L is initialized as L = {oq }. Suppose now that we have constructed a set of L of selected objects and |L| < k. We need to add a new selected object to the set L. To do this, we need to examine all objects that have not been included in L so far, that is, all objects in R. The selection is determined by a merit function M : R −→ N. To compute the merit M(o) of an object o ∈ R, we scan all objects in R distinct from o. Let o ∈ R − {o} be such an object. If d(o, o ) < d(L, o ), then adding o to L could beneﬁt the clustering (from the point of view of o ) because d(L, o ) will diminish. The potential beneﬁt is d(o , L) − d(o, o ). Of course, if d(o, o ) ≥ d(L, o ) no such beneﬁt exists (from the point of view of o ). Thus, we compute the merit of o as M(o) =

max{D(L, o ) − d(o, o ), 0}.

o ∈R−{o}

We add to L the unselected object o that has the largest merit value. The building phase halts when |L| = k. The objects in set L are the potential medoids of the k clusters that we seek to build. The second phase of the algorithm aims to improve the clustering by considering the merit of swaps between selected and unselected objects. So, assume now that oi is a selected object, oi ∈ L, and oh is an unselected object, oh ∈ R = S − L. We need to determine the cost C(oi , oh ) of swapping oi and oh . Let oj be an arbitrary unselected object. The contribution cihj of oj to the cost of the swap between oi and oh is deﬁned as follows: 1. If d(oi , oj ) and d(oh , oj ) are greater than d(o, oj ) for any o ∈ L − {oi }, then cihj = 0. 2. If d(oi , oj ) = d(L, oj ), then two cases must be considered depending on the distance e(oj ) from ej to the second closest object of S. (a) If d(oh , oj ) < e(oj ), then cihj = d(oh , oj ) − d(S, oj ). (b) If d(oh , oj ) ≥ e(oj ), then cihj = e(oj ) − d(S, oj ). In either of these two subcases, we have

206

DATA MINING ALGORITHMS I: CLUSTERING

cihj = min{d(oh , oj ), ej } − d(oi , oj ). 3. If d(oi , oj ) > d(L, oj ) (i.e., oj is more distant from oi than from at least one other selected object) and d(oh , oj ) < d(L, oj ) (which means that oj is closer to oh than to any selected object), then cihj = d(oh , oj ) − d(S, oj ). The cost of the swap is C(oi , oh ) = oj ∈R cihj . The pair that minimizes C(oi , oj ) is selected. If C(oi , oj ) < 0, then the swap is carried out. All potential swaps are considered. The algorithm halts when no useful swap exists, that is, no swap with negative cost can be found. The pseudocode of the algorithm is k means PAM{ construct the set L of k medoids; repeat compute the costs C(oi , oh ) for oi ∈ L and oh ∈ R; select the pair (oi , oh ) that corresponds to the minimum m = C(oi , oh ); until (m > 0); } Note that inside the loop repeat . . . until there are l(n − l) pairs of objects to be examined and for each pair we need to involve n − l nonselected objects. Thus, one 2 execution of the loop requires O(l(n − l) ) and the total execution may require up to n−l 2 4 O l=1 l(n − l) , which is O(n ). Thus, the usefulness of PAM is limited to rather small data set (no more than a few hundred objects).

6.8 LIMITATIONS OF CLUSTERING As we stated before, an exclusive clustering of a set of objects S is a partition of S whose blocks are the clusters. A clustering method starts with a deﬁnite dissimilarity on S and generates a clustering. This is formalized in the next deﬁnition. Deﬁnition 8 Let S be a set of objects and let DS be the set of deﬁnite dissimilarities that can be deﬁned on S. A clustering function on S is a mapping f : DS −→ PART(S). Example 12 Let g : R≥0 −→ R≥0 be a continuous, nondecreasing, and unbounded function and let S ⊆ Rn be a ﬁnite subset of Rn . For k ∈ N and k ≥ 2, deﬁne a (g, k)-clustering function as follows. g Begin by selecting a set T of k points from S such that the function d (T ) = x∈S g(d(x, T )) is minimized. Here d(x, T ) = min{d(x, t)|t ∈ T }. Then, deﬁne a

LIMITATIONS OF CLUSTERING

207

partition of S into k clusters by assigning each point to the point in T that is the closest and breaking the ties using a ﬁxed (but otherwise arbitrary) order on the set of points. The clustering function deﬁned by (d, g), denoted by f g maps d to this partition. The k-median clustering function is obtained by choosing g(x) = x for x ∈ R≥0 ; 䊐 the k-means clustering function is obtained by taking g(x) = x2 for x ∈ R≥0 . Deﬁnition 9 Let κ be a partition of S and let d, d ∈ DS . The deﬁnite dissimilarity d is a κ-transformation of d if the following conditions are satisﬁed: (i) If x ≡κ y, then d (x, y) ≤ d(x, y); (ii) If x ≡κ y, then d (x, y) > d(x, y). In other words, d is a κ-transformation of d if for two objects that belong to the same κ-cluster d (x, y) is smaller than d(x, y), while for two objects that belong to two distinct clusters d (x, y) is larger than d(x, y). Next, we consider three desirable properties of a clustering function. Deﬁnition 10 Let S be a set and let f : DS −→ PART(S) be a clustering function. The function f is (i) scale invariant, if for every d ∈ DS and every α > 0 we have f (d) = f (αd); (ii) rich, if Ran(f ) = PART(S); (iii) consistent, if for every d, d ∈ DS and κ ∈ PART(S) such that f (d) = κ and d is a κ-transformation of d we have f (d ) = κ, Unfortunately, as we shall see in Theorem 14, established in the work by Kleinburg [8], there is no clustering function that enjoys all three properties. The following deﬁnition will be used in the proof of Lemma 2. Deﬁnition 11 A dissimilarity d ∈ DS is (a, b)-conformant to a clustering κ if x ≡κ y implies d(x, y) ≤ a and x ≡κ y implies d(x, y) ≥ b. A dissimilarity is conformant to a clustering κ if it is (a, b)-conformant to κ for some pair of numbers (a, b). Note that if d is a κ-transformation of d, and d is (a, b)-conformant to κ, then d is also (a, b)-conformant to κ. Deﬁnition 12 Let κ ∈ PART(S) be a partition on S and f be a clustering function on S. A pair of positive numbers (a, b) is κ-forcing with respect to f if for every d ∈ DS that is (a, b)-conformant to κ we have f (d) = κ. Lemma 2 If f is a consistent clustering function on a set S, then for any partition κ ∈ Ran(f ) there exist a, b ∈ R>0 such that the pair (a, b) is κ-forcing.

208

DATA MINING ALGORITHMS I: CLUSTERING

Proof. For κ ∈ Ran(f ) there exists d ∈ DS such that f (d) = κ. Deﬁne the numbers aκ,d = min{d(x, y)|x = y, x ≡κ y}, bκ,d = max{d(x, y)|x ≡κ y}. In other words, aκ,d is the smallest d value for two distinct objects that belong to the same κ-cluster, and bκ,d is the largest d value for two objects that belong to different κ-clusters. Let (a, b) a pair of positive numbers such that a ≤ aκ,d and b ≥ bκ,d . If d is a deﬁnite dissimilarity that is (a, b)-conformant to κ, then x ≡κ y implies d (x, y) ≤ a ≤ aκ,d ≤ d(x, y) and x ≡κ y implies d (x, y) ≥ b > bκ,d > d(x, y), so d is a κtransformation of d. By the consistency property of f , we have f (d ) = κ. This implies that (a, b) is κ-forcing. 䊏 Theorem 13 If f is a scale-invariant and consistent clustering function on a set S, then its range is an antichain in poset (PART(S), ≤). Proof. This statement is equivalent to saying that for any scale-invariant and consistent clustering function no two distinct partitions of S that are values of f are comparable. Suppose that there are two clusterings, κ0 and κ1 , in the range of a scale-invariant and consistent clustering such that κ0 < κ1 . Let (ai , bi ) be a κi -forcing pair for i = 0, 1, where a0 < b0 and a1 < b1 . Let a2 be a number such that a2 ≤ a1 and choose such that 0<<

a0 a2 . b0

By Exercise 3 construct a distance d such that: 1. for any points x, y that belong to the same block of π0 , d(x, y) ≤ ; 2. for points that belong to the same cluster of π1 , but not to the same cluster of π0 , a2 ≤ d(x, y) ≤ a1 ; 3. for points that do not belong to the same cluster of π1 , d(x, y) ≥ b1 . The distance d is (a1 , b1 )-conformant to π1 and so we have f (d) = π1 . Take α = b0 /a2 , and deﬁne d = αd. Since f is scale invariant, we have f (d ) = f (d) = π1 . Note that for points x, y that belong to the same cluster of κ0 we have d (x, y) ≤

b0 < a0 , a2

while for points x, y that do not belong to the same cluster of κ0 we have d (x, y) ≥

a2 b0 ≥ b0 . a2

209

LIMITATIONS OF CLUSTERING

Thus, d is (a0 , b0 )-conformant to κ0 , and so we must have f (d ) = κ0 . Since κ0 = κ1 , this is a contradiction. 䊏 Theorem 14 (Kleinberg’s impossibility theorem) If |S| ≥ 2, there is no clustering function that is scale invariant, rich, and consistent. Proof. If S contains at least two elements than the poset (PART(S), ≤) is not an antichain. Therefore, this statement is a direct consequence of Theorem 13. 䊏 Theorem 15 For every antichain A of the poset (PART(S), ≤) there exists a clustering function f that is scale invariant and consistent such that Ran(f ) = A. Proof. Suppose that A contains more than one partition. We deﬁne f (d) as the ﬁrst partition π ∈ A (in some arbitrary but ﬁxed order) that minimizes the quantity: d (π) = d(x, y). x≡π y

Note that αd = αd . Therefore, f is scale invariant. We need to prove that every partition of A is in the range of f . For a partition ρ ∈ A deﬁne d such that d(x, y) < 1/|S|3 if x ≡ρ y and d(x, y) ≥ 1 otherwise. Observe that d (ρ) < 1. Suppose that d (θ) < 1. The deﬁnition of d means that d (θ) = d(x, y) < 1, x≡θ y

so for all pairs (x, y) ∈≡θ we have d(x, y) < 1/|S|3 , which means that x ≡ρ y. Therefore, we have π < ρ. Since A is an antichain, it follows that ρ must minimize d over all partitions of A, and consequently, f (d) = ρ. To verify the consistency of f suppose that f (d) = π and let d be a πtransformation of d. For σ ∈ PART(S) deﬁne δ(σ) as d (σ) − d (σ). For σ ∈ A we have δ(σ) = (d(x, y) − d (x, y)) x≡σ y

≤

(d(x, y) − d (x, y))

x ≡σ y and x ≡π y

(only terms corresponding to pairs in the same cluster are nonnegative) ≤ δ(π) (every term corresponding to a pair in the same cluster is nonnegative).

210

DATA MINING ALGORITHMS I: CLUSTERING

Consequently, d (σ) − d (σ) ≤ d (π) − d (π), or d (σ) − d (π) ≤ d (σ) − d (π). Thus, if π minimizes d (π), then d (σ) − d (π) ≥ 0 for every σ ∈ A, and therefore, d (σ) − d (π) ≥ 0, which means that π also minimizes d (π). This implies f (d ) = π, which shows that f is consistent. 䊏 Example 13 It is possible to show that for k ≥ 2 and for sufﬁciently large sets of objects the clustering function f g introduced in Example 12 is not consistent. Suppose that κ = {C1 , C2 , . . . , Ck } is a partition of S and d is a deﬁnite dissimilarity on S such that d(x, y) = ri if x = y and {x, y} ⊆ Ci for some 1 ≤ i ≤ k and d(x, y) = r + a if x and y belong to two distinct blocks of κ, where r = max{ri |1 ≤ i ≤ k} and a > 0. Suppose that T is a set of k members of S. Then, the value of g(d(x, T )) is g(r) if the closest member of T is in the same block as x and is g(r + a) otherwise. This g means that the smallest value of d (T ) = x∈Ci g(d(x, T )) is obtained when each g block Ci contains a member ti of T for 1 ≤ i ≤ k and the actual value is d (T ) = k 2 2 i=1 (|Ci | − 1)r = (|S| − k)r . Consider now a partition κ = {C1 , C1 , C2 , . . . , Ck }, where C1 = C1 ∪ C1 , so κ < κ. Choose r to be a positive number such that r < r and deﬁne the dissimilarity d on S such that d (x, y) = r if x = y and x ≡κ y and d (x, y) = d(x, y) g otherwise. Clearly, d is a κ-transformation of d. The minimal value for d (T ) will be achieved when T consists of k + 1 points, one in each of the block of κ ; as a result, the value of the clustering function for d will be κ = κ, which shows that no 䊐 clustering function obtained by this technique is consistent.

6.9 CLUSTERING QUALITY There are two general approaches for evaluating the quality of a clustering: unsupervised evaluation that measures the cluster cohesion and the separation between clusters and supervised evaluation that measures the extent to which the clustering we analyze matches a partition of the set of objects that is speciﬁed by an external labeling of the objects. 6.9.1

Object Silhouettes

The silhouette method is an unsupervised method for evaluation of clusterings that computes certain coefﬁcients for each object. The set of these coefﬁcients allows an evaluation of the quality of the clustering. Let O = {u1 , . . . , un } be a collection of objects, d : O × O −→ R+ be a dissimilarity on O, and let κ : O −→ {C1 , . . . , Ck } be a clustering function.

211

CLUSTERING QUALITY

Suppose that κ(ui ) = C . The (κ, d)-average dissimilarity is the function ak,d : O −→ R given by aκ,d (ui ) =

{d(ui , u)|κ(u) = κ(ui ) and u = ui } , |κ(ui )|

that is, the average dissimilarity of ui to all objects of κ(ui ), the cluster to which ui is assigned. For a cluster C and an object ui let d(ui , C) =

{d(ui , u)|κ(u) = C} |C|

be the average dissimilarity between ui and the objects of the cluster C. Deﬁnition 13 Let κ : O −→ {C1 , . . . , Ck } be a clustering function. A neighbor of ui is a cluster C = κ(ui ) for which d(ui , C) is minimal. In other words, a neighbor of an object ui is “the second best choice” for a cluster for ui . Let b : O −→ R be the function deﬁned by bκ,d (ui ) = min{d(ui , C)|C = κ(ui )}. If κ and d are clear from context, we shall simply write a(ui ) and b(ui ) instead of aκ,d (ui ) and bκ,d (ui ), respectively. Deﬁnition 14 The silhouette of the object ui for which |κ(ui )| ≥ 2 is the number sil(ui ) given by ⎧ a(ui ) ⎪ ⎪ 1− if a(ui ) < b(ui ) ⎪ ⎪ b(u i) ⎨ if a(ui ) = b(ui ) sil(ui ) = 0 ⎪ ⎪ ⎪ b(ui ) ⎪ ⎩ − 1 if a(ui ) > b(ui ). a(ui ) Equivalently, we have sil(ui ) = for ui ∈ O. If κ(ui ) = 1, then s(ui ) = 0.

b(ui ) − a(ui ) max{a(ui ), b(ui )}

212

DATA MINING ALGORITHMS I: CLUSTERING

Observe that −1 ≤ sil(ui ) ≤ 1. When sil(ui ) is close to 1, this means that a(ui ) is much smaller than b(ui ) and we may conclude that ui is well classiﬁed. When sil(ui ) is near 0, it is not clear which is the best cluster for ui . Finally, if sil(ui ) is close to −1, the average distance from u to its neighbor(s) is much smaller than the average distance between ui and other objects that belong to the same cluster κ(ui ). In this case, it is clear that ui is poorly classiﬁed. Deﬁnition 15 Let average silhouette width of a cluster C is {sil(u)|u ∈ C} sil(C) = . |C| The average silhouette width of a clustering κ is {sil(u)|u ∈ O} sil(κ) = . |O| The silhouette of a clustering can be used for determining the “optimal” number of clusters. If the silhouette of the clustering is above 0.7, we have a strong clustering. 6.9.2

Supervised Evaluation

Suppose that we intend to evaluate the accuracy of a clustering algorithm A on a set of objects S relative to a collection of classes on S that forms a partition σ of S. In other words, we wish to determine the extent to which the clustering produced by A coincides with the partition determined by the classes. If the set S is large, the evaluation can be performed by extracting a random sample T from S, applying A to T , and then comparing the clustering partition of T computed by A and the partition of T into the preexisting classes. Let κ = {C1 , . . . , Cm } be the clustering partition of T and let σ = {K1 , . . . , Kn } be the partition of T of classes. The evaluation is helped by n × m matrix Q, where qij = |Ci ∩ Kj | named the confusion matrix. We can use distances associated with the generalized entropy, dβ (κ, σ), to evaluate the distinction between these partitions. This was already observed by Rand [11], who proposed as a measure the cardinality of the symmetric difference of the sets of pairs of objects that belong to the equivalences that correspond to the two partitions. Frequently, one uses the conditional entropy H(σ|κ) =

m |Ci | i=1

|T |

H(σCi ) =

m n |Ci | |Ci ∩ Kj | i=1

|T |

j=1

|Ci |

log2

|Ci ∩ Kj | |Ci |

to evaluate the “purity” of the clusters Ci relative to the classes K1 , . . . , Kn . Low values of this number indicate a high degree of purity. Some authors [14] deﬁne the purity of a cluster Ci as a as pur σ (Ci ) = maxj |Ci ∩ Kj |/|Ci | and the purity of the clustering κ relative to σ as

213

FURTHER READINGS

purσ (κ) =

n |Ci | i=1

|T |

purσ (Ci ).

Larger values of the purity indicate better clusterings (from the point of view of the matching with the class partition of the set of objects). Example 14 Suppose that a set of 1000 objects consists of three classes of objects K1 , K2 , K3 , where |K1 | = 500, |K2 | = 300, and |K1 | = 200. Two clustering algorithms A and A yield the clusterings κ = {C1 , C2 , C3 } and κ = {C1 , C2 , C3 } and the confusion matrices Q and Q , respectively:

C1 C2 C3

K1 400 60 40

K2 0 200 100

K3 25 75 100

and

C1 C2 C3

K1 60 400 40

K2 0 50 250

K3 180 0 20

The distances d2 (κ, σ) and d2 (κ , σ) are 0.5218 and 0.4204 suggesting that the clustering κ produced by the second algorithm is closer to the partition in classes. As expected, the purity of the ﬁrst clustering, 0.7, is smaller than the purity of the 䊐 second clustering, 0.83. Another measure of clustering quality proposed in the work by Ray and Turi [12] applies to objects in Rn and can be applied, for example, to the clustering that results from the k-means method, the validity of clustering. Let π = {U1 , . . . , Uk } be a clustering of N objects, c1 , . . . , ck the centroids of the clusters, then the clustering validity is val(π) =

sse(π) . N mini

The variety of clustering algorithms is very impressive and it is very helpful to the reader to consult two excellent surveys of clustering algorithms [2,5] before exploring in depth this domain.

6.10 FURTHER READINGS Several general introductions in data mining [13,14] provide excellent references for clustering algorithms. Basic reference books for clustering algorithms are authored by Jain and Dubes [6] and Kaufmann and Rousseeuw [7]. Recent surveys such as those by Berkhin [2] and Jain et al. [5] allow the reader to get familiar with current issues in clustering.

214

DATA MINING ALGORITHMS I: CLUSTERING

6.11 EXERCISES 1. Let d be a ultrametric and let S(x, y) be the set of all non-null sequences s = (s1 , . . . , sn ) ∈ Seq(S) such that s1 = x and sn = y. If d is a ultrametric prove that d(x, y) ≤ min{ampd (s)|s ∈ S(x, y)} (Exercise 1). 2. Let S be a set, π be a partition of S, and let a, b be two numbers such that a < b. Prove that the mapping d : S 2 −→ R≥0 given by d(x, x) = 0 for x ∈ S, d(x, y) = a if x = y and {x, y} ⊆ B for some block B of π and d(x, y) = b, otherwise is an ultrametric on S. 3. Prove the following extension of the statement from Exercise 2. Let S be a set, π0 < π1 < · · · < πk−1 be a chain of partitions on S, and let a0 < a1 . . . < ak−1 < ak be a chain of positive reals. Prove that the mapping d : S 2 −→ R≥0 given by

d(x, y) =

⎧ 0 ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪a0 ⎨

if x = y if x = y and x ≡π0 y .. .. . . if x ≡πk−2 y and x ≡πk−1 y

⎪ ⎪ ⎪ ⎪ ⎪ ⎪ak−1 ⎪ ⎩ ak if x ≡πk−1 y

is an ultrametric on S. 4. Let f : R≥0 −→ R≥0 be a function that satisﬁes the following conditions: (a) f (x) = 0 if and only if x = 0; (b) f is monotonic on R≥0 , that is, x ≤ y implies f (x) ≤ f (y) for x, y ∈ R≥0 ; (c) f is subadditive on R≥0 , that is, f (x + y) ≤ f (x) + f (y) for x, y ∈ R≥0 . (c) Prove that if d is a metric on a set S, then fd is also a metric on S. √ (d) Prove that if d is a metric on S, the d and d/1 + d are also metrics on S; what can be said about d 2 ? 5. A function F : R ≥ 0 −→ R is convex if for every s, t ∈ R≥0 and a ∈ [0, 1] we have F (as + (1 − a)t) ≤ aF (s) + (1 − 1)F (t). (a) Prove that if F (0) = 0, F is monotonic and convex, then F is subadditive. (b) Prove that if f is a metric on the set S, then the function given by d (x, y) = 1 − e−kd(x,y) , where k is a positive constant and x, y ∈ S is also a metric on S. This metric is known as the Schoenberg transform of d. 6. Let S be a ﬁnite set and let d : S 2 −→ R≥0 be a dissimilarity. Prove that there exists a ∈ R≥0 such that the dissimilarity da deﬁned by da (x, y) = (d(x, y))a satisﬁes the triangular inequality.

215

EXERCISES

Hint: Observe that lima→0 da (x, y) is a dissimilarity that satisﬁes the triangular inequality. 7. Prove Theorem 2. 8. Let (S, d) be a ﬁnite metric space. Prove that the functions D, E : P(S)2 −→ R deﬁned by D(U, V ) = max{d(u, v)|u ∈ U, v ∈ V } 1 E(U, V ) = {d(u, v)|u ∈ U, v ∈ V } |U| · |V | for U, V ∈ P(S) are metrics on P(S). 9. Prove that if we replace max by min in Exercise 8, then the resulting function F : P(S)2 −→ R deﬁned by D(U, V ) = min{d(u, v)|u ∈ U, v ∈ V }

10.

11.

12.

13.

14.

for U, V ∈ P(S) is not a metric on P(S), in general. Prove that the ultrametric inequality implies the triangular inequality; also, show that both the triangular inequality and deﬁniteness imply evenness for an ultrametric. Let (T , v0 ) be a ﬁnite rooted tree, V be the set of vertices of the tree T , and let S be a ﬁnite, nonempty set such that the rooted tree (T , v0 ) has |S| leaves. Consider a function M : V −→ P(S) deﬁned as follows: (a) the tree T has |S| leaves and each for each leaf v the set M(v) is a distinct singleton of S; (b) if an interior vertex v of the tree has the descendants v1 , v2 , . . . , vn , then M(v) = ni=1 M(vi ). Prove that the collection of sets {M(v)|v ∈ V } is a hierarchy on S. Apply hierarchical clustering to the data set given in Example 9 using the average-link method, the centroid method and the Ward method. Compare the shapes of the clusters that are formed during the aggregation process. Draw the dendrograms of the clusterings. Using a random number generator produce h sets of points in Rn normally distributed around h given points in Rn . Use k-means to cluster these points with several values for k and compare the quality of the resulting clusterings. A variant of the k-means clustering introduced in the work by Stainbach [13] is the bisecting k-means algorithm described below. The parameters are S, the set of objects to be clustered; k, the desired number of clusters; and nt, the number of trial bisections. bisecting k-means{ set of clusters = {S}; while (|set of clusters| < k)

216

DATA MINING ALGORITHMS I: CLUSTERING

extract a cluster C from the set of clusters; k = 0; for i = 1 to nt do let C0i , C1i be the two clusters obtained from C by bisecting C using standard k-means (k = 2); if (i = 1) then s = sse({C0i , C1i }); if (sse({C0i , C1i }) ≤ s) then k = i; s = sse({C0i , C1i }); endif; endfor; add C0k , C1k to set of clusters; endwhile } The cluster C that is bisected may be the largest cluster, or the cluster having the largest sse. Evaluate the time performance of bisecting k-means compared with the standard k-means and with some variant of a hierarchical clustering. 15. One of the issues that the k-means algorithm must confront is that the number of clusters k must be provided as an input parameter. Using clustering validity design an algorithm that identiﬁes local maxima of validity (as a function of k) to provide a basis for a good choice of k. For a solution that applies to image segmentation, see the work by Ray and Turi.

REFERENCES 1. Birkhoff G. Lattice Theory. 3rd ed. Providence, RI: American Mathematical Society; 1967. 2. Berkhin P. A survey of clustering data mining techniques. In: Kogan J, Nicholas C, Teboulle M, editors, Grouping Multidimensional Data—Recent Advances in Clustering. Berlin: Springer-Verlag; 2006. p 25–72. 3. Berkhin P, Becher J. Learning simple relations: theory and applications. Proceedings of the 2nd SIAM International Conference on Data Mining; Arlington, VA; 2002. 4. http://www2.sims.berkeley.edu/research/projects/how-much-info/ 5. Jain AK, Murty MN, Flynn PJ. Data clustering: a review. ACM Comput Surv 1999;31:264– 323. 6. Jain AK, Dubes RC. Algorithms for Clustering Data. Englewood Cliffs: Prentice Hall; 1988. 7. Kaufman L, Rousseeuw PJ. Finding Groups in Data — An Introduction to Cluster Analysis. New York: Wiley-Interscience; 1990. 8. Kleinberg J. An impossibility theorem for clustering. Proceedings of the 16th Conference on Neural Information Processing Systems; 2002.

REFERENCES

217

9. Kurita T. An efﬁcient agglomerative clustering algorithm using a heap. Pattern Recogn 1991;24:205–209. 10. Ng RN, Han J. Efﬁcient and effective clustering methods for spatial data mining. Proceedings of the 20th VLDB Conference; Santiago, Chile; 1994. p 144–155. 11. Rand WM. Objective criteria for the evaluation of clustering methods. J Am Stat Assoc 1971;61:846–850. 12. Ray S, Turi R. Determination of number of clusters in k-means clustering in colour image segmentation. Proceedings of the 4th International Conference on Advances in Pattern Recognition and Digital Technology; Calcutta, India. New Delhi, India: Narosa Publishing House. p 137–143. 13. Steinbach M, Karypis G, Kumar V. A comparison of document clustering techniques. KDD Workshop on Text Mining; 2000. 14. Tan PN, Steinbach M, Kumar V. Introduction to Data Mining. Reading, MA: AddisonWesley; 2005.

CHAPTER 7

Data Mining Algorithms II: Frequent Item Sets DAN A. SIMOVICI

7.1 INTRODUCTION Association rules have received a lot of attention in data mining due to their many applications in marketing, advertising, inventory control, and many other areas. The area of data mining has been initiated in the seminal paper [5]. A typical supermarket may well have several thousand items on its shelves. Clearly, the number of subsets of the set of items is immense. Even though a purchase by a customer involves a small subset of this set of items, the number of such subsets subsets T having no more than is very large. In principle, there are 5i=1 10000 i 5 elements of a set that has 10,000 items and this is indeed a large number! The supermarket is interested in identifying associations between item sets; for example, it may be interested to know how many of the customers who bought bread and cheese also bought milk. This knowledge is important because if it turns out that many of the customers who bought bread and cheese also bought milk, the supermarket will place milk physically close to bread and cheese in order to stimulate the sales of milk. Of course, such a piece of knowledge is especially interesting when there is a substantial number of customers who buy all three items and a large fraction of those individuals who buy bread and cheese also buy milk. Informally, if this is the case, we shall say that we have identiﬁed the association rule bread cheese → milk. Two numbers will play a role in evaluating such a rule: Nbcm /N and Nbcm /Nbc . Here, N is the total number of purchases, Nbcm denotes the number of transactions involving bread, cheese, and milk, and Nbc gives the number of transactions involving bread and cheese. The ﬁrst number is known as the support of the association rule; the second is its conﬁdence and approximates the probability that a customer who bought bread and cheese will buy milk. Thus, identifying association rules requires the capability to identify item sets that occur in large sets of transactions; these are the frequent item sets. Identifying association rules amounts essentially to ﬁnding frequent item sets. If Nbcm is

Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

219

220

DATA MINING ALGORITHMS II: FREQUENT ITEM SETS

large, then Nbc is larger still. We formalize this problem and explore its algorithmic aspects. 7.2 FREQUENT ITEM SETS Suppose that I is a ﬁnite set; we refer to the elements of I as items. Deﬁnition 1 A transaction data set over I is a function T : {1, . . . , n} −→ P(I). The set T (k) is the kth transaction of T . The numbers 1, . . . , n are the transaction identiﬁers (tids). An example of a transaction set is the set of items present in the shopping cart of a consumer who completed a purchase in a store. Example 1 The table below describes a transaction data set over the set of over-thecounter medicines in a drugstore. Transactions

Content

T (1) T (2) T (3) T (4) T (5) T (6) T (7)

{Aspirin, Vitamin C} {Aspirin, Sudafed} {Tylenol} {Aspirin, Vitamin C, Sudafed} {Tylenol, Cepacol} {Aspirin, Cepacol} {Aspirin, Vitamin C}

The same data set can be presented as a 0/1 table as follows:

T (1) T (2) T (3) T (4) T (5) T (6) T (7)

Aspirin

Vitamin C

Sudafed

Tylenol

Cepacol

1 1 0 1 1 1 1

1 0 0 1 0 0 1

0 1 0 1 0 0 0

0 0 1 0 0 0 0

0 0 0 0 1 1 0

The entry in the row T (k) and the column ij is set to 1 if ij ∈ T (k); otherwise, it is set to 0. 䊐 Example 1 shows that we have the option of two equivalent frameworks for studying frequent item sets: tables or transaction item sets.

221

FREQUENT ITEM SETS

Given a transaction data set T on the set I, we would like to determine those subsets of I that occur often enough as values of T . Deﬁnition 2 Let T : {1, . . . , n} −→ P(I) be a transaction data set over a set of items I. The support count of a subset K of the set of items I in T is the number suppcountT (K) given by suppcountT (K) = |{k|1 ≤ k ≤ n and K ⊆ T (k)}|. The support of an item set K is the number suppT (K) =

suppcountT (K) . n

Example 2 For the transaction data set T considered in Example 1 we have suppcountT ({Aspirin, VitaminC}) = 3, because {Aspirin, Vitamin C} is a subset of three of the sets T (k). Therefore, 䊐 suppT ({Aspirin, Vitamin C}) = 37 . To simplify our notation we will denote item sets by the sequence of their elements. For instance, a set {a, b, c} will be denoted from now on by abc. Example 3 Let I = {i1 , i2 , i3 , i4 } be a collection of items. Consider the transaction data set T given by T (1) = i1 i2 , T (2) = i1 i3 , T (3) = i1 i2 i4 , T (4) = i1 i3 i4 , T (5) = i1 i2 , T (6) = i3 i4 . Thus, the support count of the item set i1 i2 is 3; similarly, the support count of the 䊐 item set i1 i3 is 2. Therefore, suppT (i1 i2 ) = 21 and suppT (i1 i3 ) = 13 . The following rather straightforward statement is fundamental for the study of frequent item sets. Theorem 1 Let T : {1, . . . , n} −→ P(I) be a transaction data set over a set of items I. If K and K are two item sets, then K ⊆ K implies suppT (K ) ≥ suppT (K).

222

DATA MINING ALGORITHMS II: FREQUENT ITEM SETS

FIGURE 7.1 The Rymon tree of P({i1 , i2 , i3 }).

Proof. Note that every transaction that contains K also contains K . The statement follows immediately. 䊏 If we seek those item sets that enjoy a minimum support level relative to a transaction data set T , then it is natural to start the process with the smallest nonempty item sets. Deﬁnition 3 An item set K is μ-frequent relatively to the transaction data set T if suppT (K) ≥ μ. μ We denote by FT the collection of all μ-frequent item sets relative to the transaction μ data set T , and by FT,r the collection of μ-frequent item sets that contain r items for r ≥ 1. Note that μ

FT =

/

μ

FT,r .

r≥1

If μ and T are clear from the context, then we may omit either or both adornments from this notation. Let I = {i1 , . . . , in } be an item set that contains n elements. We use a graphical representation of P(I), the set of subsets of I, known as the Rymon tree. The root of the tree is ∅. A vertex K = ip1 · · · ipk with ip1 < ip2 < · · · < ipk has n − ipk children K ∪ {j}, where ipk < j ≤ n. We shall denote this tree by RI . Example 4 Let I = {i1 , i2 , i3 }. The Rymon tree RI is shown in Figure 7.1.

䊐

Let Sr be the collection of item sets that have r elements. The next theorem suggests a technique for generating Sr+1 starting from Sr . Theorem 2 Let RI be the Rymon tree of the set of subsets of I = {i1 , . . . , in }. If W ∈ Sr+1 , where r ≥ 2, then there exists a unique pair of distinct sets U, V ∈ Sr that has a common immediate ancestor T ∈ Sr−1 in RI such that U ∩ V ∈ Sr−1 and W = U ∪ V.

223

FREQUENT ITEM SETS

FIGURE 7.2 Rymon tree for P({i1 , i2 , i3 , i4 }).

Proof. Let u, v be the largest and the second largest subscript of an item that occurs in W, respectively. Consider the sets U = W − {u} and V = W − {v}. Both sets belong to Sr . Moreover, Z = U ∩ V belongs to Sr−1 because it consists of the ﬁrst r − 1 elements of W. Note that both U and V are descendants of Z and that U ∪ V = W. The pair (U, V ) is unique. Indeed, suppose that W can be obtained in the same manner from another pair of distinct sets U , V ∈ Sr , such that U , V are immediate descendants of a set Z ∈ Sr−1 . The deﬁnition of the Rymon tree RI implies that U = Z ∪ {im } and V = Z ∪ {iq }, where the letters in Z are indexed by number smaller than min{m, q}. Then, Z consists of the ﬁrst r − 1 symbols of W, so Z = Z. If m < q, then m is the second highest index of a symbol in W and q is the highest index of a symbol in W, so U = U and V = V . 䊏 Example 5 Consider the Rymon tree of the collection P({i1 , i2 , i3 , i4 ) shown in Figure 7.2. The set i1 i3 i4 is the union of the sets i1 i3 and i1 i4 that have the common ancestor i1 . 䊐 μ

Next we discuss an algorithm that allows us to compute the collection FT of all μ-frequent item sets for a transaction data set T . The algorithm is known as the Apriori algorithm. μ We begin with the procedure apriori gen that starts with the collection FT,k of frequent item sets for the transaction data set T that contain k elements and generates μ a collection Ck+1 of sets of items that contains FT,k+1 , the collection the frequent item sets that have k + 1 elements. The justiﬁcation of this procedure is based on the next statement. Theorem 3 Let T be a transaction data set over a set of items I and let k ∈ N such that k > 1. If W is a μ-frequent item set and |W| = k + 1, then there exist a μ-frequent item set Z and two items im and iq such that |Z| = k − 1, Z ⊆ W, W = Z ∪ {im , iq } and both Z ∪ {im } and Z ∪ {iq } are μ-frequent item sets.

224

DATA MINING ALGORITHMS II: FREQUENT ITEM SETS

Proof. If W is an item set such that |W| = k + 1, then we already know that W is the union of two subsets U, V of I such that |U| = |V | = k and that Z = U ∩ V has k − 1 elements. Since W is a μ-frequent item set and Z, U, V are subsets of W, it follows that each of these sets is also a μ-frequent item set. 䊏 Note that the reciprocal statement of Theorem 3 is not true, as the next example shows. Example 6 Let T be the transaction data set introduced in Example 3. Note that both i1 i2 and i1 i3 are 13 -frequent item sets; however, suppT (i1 i2 i3 ) = 0, so i1 i2 i3 fails to be a 13 -frequent item set.

䊐

The procedure apriori gen mentioned above is introduced next. This procedure starts with the collection of item sets FT,k and produces a collection of item sets CT,k+1 that includes the collection of item sets FT,k+1 of frequent item sets having k + 1 elements. μ

apriori gen(μ, FT,k ){ μ CT,k+1 = ∅; μ for each L, M ∈ FT,k such that μ L = M and L ∩ M ∈ FT,k−1 do begin μ add L ∪ M to CT,k+1 ; μ remove all sets K in CT,k+1 where there is a subset of K containing k elements μ that does not belong to FT,k ; end } Note that in apriori gen no access to the transaction data set is needed. The Apriori algorithm is introduced next. The algorithm operates on “levels.” Each μ level k consists of a collection CT,k of candidate item sets of μ-frequent item sets. μ To build the initial collection of candidate item sets CT,1 , every single item set is μ considered for membership in CT,1 . The initial set of frequent item set consists of those singletons that pass the minimal support test. The algorithm alternates between a candidate generation phase (accomplished by using apriori gen) and an evaluation phase, which involves a data set scan and is, therefore, the most expensive component of the algorithm. Apriori(T, μ){ μ CT,1 = {{i}|i ∈ I}; i = 1; μ while (CT,i = ∅) do /* evaluation phase */

225

FREQUENT ITEM SETS

μ

μ

FT,i = {L ∈ CT,i |suppT (L) ≥ μ}; /* candidate generation */ μ μ CT,i+1 = apriori gen(FT,i ); i + +; endwhile; μ μ output FT = j

}

Example 7 Let T be the data set given by Transactions

i1

i2

i3

i4

i5

T (1) T (2) T (3) T (4) T (5) T (6) T (7) T (8)

1 0 1 1 0 1 1 0

1 1 0 0 1 1 1 1

0 1 0 0 1 1 1 1

0 0 0 0 0 1 0 1

0 0 1 1 1 1 0 1

The support counts of various subsets of I = {i1 , . . . , i5 } are given below: i1 5

i2

i3

i4

i5

6

5

2

5

i1 i2

i1 i3

i1 i4

i1 i5

i2 i3

i2 i4

i2 i5

i3 i4

i3 i5

i4 i5

3

2

1

3

5

2

3

2

3

2

i1 i2 i3 i1 i2 i4 i1 i2 i5 i1 i3 i4 i1 i3 i5 i1 i4 i5 i2 i3 i4 i2 i3 i5 i2 i4 i5 i3 i4 i5 2 1 i1 i2 i3 i4 1

1

1

1

1

2

3

2

2

i1 i2 i3 i5

i1 i2 i4 i5

i1 i3 i4 i5

i2 i3 i4 i5

1

1

1

2

i1 i2 i3 i4 i5 0 μ

Starting with μ = 0.25 and with FT,0 = {∅}, the Apriori algorithm computes the following sequence of sets: μ

CT,1 = {i1 , i2 , i3 , i4 , i5 }, μ

FT,1 = {i1 , i2 , i3 , i4 , i5 }, μ

CT,2 = {i1 i2 , i1 i3 , i1 i4 , i1 i5 , i2 i3 , i2 i4 , i2 i5 , i3 i4 , i3 i5 , i4 i5 }, μ

FT,2 = {i1 i2 , i1 i3 , i1 i5 , i2 i3 , i2 i4 , i2 i5 , i3 i4 , i3 i5 , i4 i5 },

226

DATA MINING ALGORITHMS II: FREQUENT ITEM SETS

μ

CT,3 = {i1 i2 i3 , i1 i2 i5 , i1 i3 i5 , i2 i3 i4 , i2 i3 i5 , i2 i4 i5 , i3 i4 i5 }, μ

FT,3 = {i1 i2 i3 , i2 i3 i4 , i2 i3 i5 , i2 i4 i5 , i3 i4 i5 }, μ

CT,4 = {i2 i3 i4 i5 }, μ

FT,4 = {i2 i3 i4 i5 }, μ

CT,5 = ∅. Thus, the algorithm will output the collection: μ

FT =

4 /

μ

FT,i

i=1

= {i1 , i2 , i3 , i4 , i5 , i1 i2 , i1 i3 , i1 i5 , i2 i3 , i2 i4 , i2 i5 , i3 i4 , i3 i5 , i4 i5 , i1 i2 i3 , i2 i3 i4 , i2 i3 i5 , i2 i4 i5 , i3 i4 i5 , i2 i3 i4 i5 }. 䊐

Let I be a set of items and T : {1, . . . , n} −→ P(I) be a transaction data set. Denote by D the set of transaction identiﬁers, D = {1, . . . , n}. The functions itemsT : P(D) −→ P(I) and tidsT : P(I) −→ P(D) are deﬁned by itemsT (E) =

0

{T (k)|k ∈ E},

tidsT (H) = {k ∈ D|H ⊆ T (k)} for every E ∈ P(D) and every H ∈ P(I). Note that suppcountT (H) = |tidsT (H)| for every item set H ∈ P(I). The next statement shows that the mappings itemsT and tidsT form a Galois connection between the partial ordered sets P(D) and P(I) (see the works by Birkhoff [7] and Ganter and Wille [10] for this concept and related results). The use of Galois connections in data mining was initiated in the work by Pasquier et al. [15] and continued in the work by Zaki [19]. Theorem 4 1. 2. 3. 4.

Let T : {1, . . . , n} −→ P(I) be a transaction data set. We have

if E ⊆ E , then itemsT (E ) ⊆ itemsT (E), if H ⊆ H , then tidsT (H ) ⊆ tidsT (H), E ⊆ tidsT (itemsT (E)), and H ⊆ itemsT (tidsT (H)),

for every E, E ∈ P(D) and every H, H ∈ P(I).

227

FREQUENT ITEM SETS

Proof. The ﬁrst two parts of the theorem follow immediately from the deﬁnitions of the functions itemsT and tidsT . To prove part (iii) let k ∈ E be a transaction identiﬁer. Then, the item set T (e) includes itemsT (E), by the deﬁnition of itemsT (E). By part (ii), tidsT (T (e)) ⊆ tidsT (itemsT (E)). Since e ∈ tidsT (T (e)) it follows that e ∈ tidsT (itemsT (E)), so E ⊆ tidsT (itemsT (E)). The argument for part (iv) is similar. 䊏 Corollary 1 Let T : D −→ P(I) be a transaction data set and let I : P(I) −→ P(I) and D : P(D) −→ P(D) be deﬁned by I(H) = itemsT (tidsT (H)) for H ∈ P(I) and D(E) = tidsT (itemsT (E)) for E ∈ P(D). Then, I and D are closure operators on I and D, respectively. Proof. Let H, H be two subsets of I such that H ⊆ H . By part (ii) of Theorem 4 we have tidsT (H ) ⊆ tidsT (H); part (i) of the same theorem yields I(H) = itemsT (tidsT (H)) ⊆ itemsT (tidsT (H )) = I(H ), so I is monotonic. The proof of monotonicity for D is similar. Since E ⊆ tidsT (itemsT (E)), by part (i) of Theorem 4 we have itemsT (tidsT (itemsT (E))) ⊆ itemsT (E). On the contrary, by the expansiveness of I we can write itemsT (E) ⊆ itemsT (tidsT (itemsT (E))), which implies the equality itemsT (tidsT (itemsT (E))) = itemsT (E)

(7.1)

for every E ∈ P(D). This, in turn means that tidsT (itemsT (tidsT (itemsT (E)))) = tidsT (itemsT (E)), which proves that D is idempotent. The proof for the idempotency of I makes use of the equality tidsT (itemsT (tidsT (H))) = tidsT (H)

(7.2)

and is similar; we omit it. 䊏 Closed sets of items, that is, sets of items H such that H = I(H), can be characterized as follows: Theorem 5 Let T : {1, . . . , n} −→ P(I) be a transaction data set. A set of items H is closed if and only if for every set L ∈ P(I) such that H ⊂ L, we have suppT (H) > suppT (L).

228

DATA MINING ALGORITHMS II: FREQUENT ITEM SETS

Proof. Suppose that for every superset L of H we have suppT (H) > suppT (L) and that H is not a closed set of items. Therefore, the set I(H) = itemsT (tidsT (H)) is a superset of H, and consequently suppcountT (H) > suppcountT (itemsT (tidsT (H))). Since suppcountT (itemsT (tidsT (H))) = |tidsT (itemsT (tidsT (H)))| = |tidsT (H)|, this leads to a contradiction. Thus, H must be closed. Conversely, suppose that H is a closed set of items, that is H = I(H) = itemsT (tidsT (H)) and let L be a strict superset of H. Suppose that suppT (L) = suppT (H). This means that |tidsT (L)| = |tidsT (H)|. Since H = itemsT (tidsT (H)) ⊂ L, it follows that tidsT (L) ⊆ tidsT (itemsT (tidsT (H))) = tidsT (H), which implies the equality tidsT (L) = tidsT (itemsT (tidsT (H))) because the sets tidsT (L) and tidsT (H) have the same number of elements. Thus, by equality (7.1), tidsT (L) = tidsT (H). In turn, this yields H = itemsT (tidsT (H)) = itemsT (tidsT (L)) ⊇ L, which contradicts the initial assumption H ⊂ L. 䊏 Theorem 6 For any transaction data set T : {1, . . . , n} −→ P(I) and set of items L we have suppT (L) = suppT (I(L)). In other words, the support of an item set in T equals the support of its closure. Proof. Equality (7.2) implies that tidsT (I(L)) = tidsT (itemsT (tidsT (L))) = tidsT (L). Since suppcountT (H) = |tidsT (H)| for every item set H, it follows that suppcountT (I(L)) = suppcountT (L). 䊏 A special class of subsets of closed sets is helpful for obtaining a concise representation of μ-frequent item sets. Deﬁnition 4 A μ-maximal frequent item set is a μ-frequent item set that is closed. Thus, once the μ-maximal frequent item sets have been identiﬁed, then all frequent item sets can be obtained as subsets of these sets. Several improvements of the standard Apriori algorithm are very interesting to explore. Park et al. [14] hash tables used for substantially decreasing the sizes of the candidate sets. In a different direction, an algorithm that picks a random sample from

229

ASSOCIATION RULES

a transaction data set, detects association rules satisﬁed in this sample, and veriﬁes the results on the remaining transactions has been proposed in the work by Toivonen [18].

7.3 ASSOCIATION RULES Deﬁnition 5 An association rule on an item set I is a pair of nonempty disjoint item sets (X, Y ). rules on I. Indeed, Note that if |I| = n, then there exist 3n − 2n+1 + 1association suppose that the set X contains k elements; there are nk ways of choosing X. Once X is chosen, Y can be chosen among the remaining 2n−k − 1 nonempty subsets of I − X. In other words, the number of association rules is n n k=1

k

(2

n−k

n n n n−k n − 1) = − 2 . k k k=1

k=1

By taking x = 2 in the equality n n n−k (1 + x) = x , k n

k=0

we obtain n n n−k = 3n − 2n . 2 k k=1

Since nk=1 nk = 2n − 1, we obtain immediately the desired equality. The number of association rules can be quite considerable even for small values of n. For example, for n = 10 we have 310 − 211 + 1 = 57, 002 association rules. An association rule (X, Y ) is denoted by X ⇒ Y . The support of X ⇒ Y is the number suppT (XY ). The conﬁdence of X ⇒ Y is the number conf T (X ⇒ Y ) =

suppT (XY ) . suppT (X)

Deﬁnition 6 An association rule holds in a transaction data set T with support μ and conﬁdence c if suppT (XY ) ≥ μ and conf T (X ⇒ Y ) ≥ c. Once a μ-frequent item set Z is identiﬁed, we need to examine the support levels of the subsets X of Z to ensure that an association rule of the form X ⇒ Z − X has a sufﬁcient level of conﬁdence, conf T (X ⇒ Z − X) = μ/suppT (X). Observe that suppT (X) ≥ μ because X is a subset of Z. To obtain a high level of conﬁdence for X ⇒ Z − X, the support of X must be as small as possible.

230

DATA MINING ALGORITHMS II: FREQUENT ITEM SETS

Clearly, if X ⇒ Z − X does not meet the level of conﬁdence, then it is pointless to look rules of the form X ⇒ Z − X among the subsets X of X. Example 8 Let T be the transaction data set introduced in Example 7. We saw that the item set L = i2 i3 i4 i5 has the support count equal to 2, and therefore, suppT (L) = 0.25. This allows us to obtain the following association rules having three item sets in their antecedent, which are subsets of L. Rule

suppcountT (X)

conf T (X ⇒ Y )

i2 i3 i4 ⇒ i5 i2 i3 i5 ⇒ i4 i2 i4 i5 ⇒ i3 i3 i4 i5 ⇒ i2

2 3 2 2

1 2 3

1 1

Note that i2 i3 i4 ⇒ i5 , i2 i4 i5 ⇒ i3 , and i3 i4 i5 ⇒ i2 have 100 percent conﬁdence. We refer to such rules as exact association rules. The rule i2 i3 i5 ⇒ i4 has conﬁdence ( 23 ). It is clear that the conﬁdence of rules of the form U ⇒ V with U ⊆ i2 i3 i5 and UV = L will be lower than ( 23 ) since suppT (U) is at least 3. Indeed, the possible rules of this form are Rule

suppcountT (X)

conf T (X ⇒ Y )

i2 i3 ⇒ i4 i5

5

i2 i5 ⇒ i3 i4

3

i3 i5 ⇒ i2 i4

3

i2 ⇒ i3 i4 i5

6

i3 ⇒ i2 i4 i5

5

i5 ⇒ i2 i3 i4

5

2 5 2 3 2 3 2 6 2 5 2 5

Obviously, if we seek association rules having a conﬁdence larger than 23 no such rule U ⇒ V can be found such that U is a subset of i2 i3 i5 . Suppose, for example, that we seek association rules U ⇒ V that have a minimal conﬁdence of 80 percent. We need to examine subsets U of the other sets: i2 i3 i4 , i2 i4 i5 , or i3 i4 i5 , which are not subsets of i2 i3 i5 (since the subsets of i2 i3 i5 cannot yield levels of conﬁdence higher than 23 . There are ﬁve such sets. Rule

suppcountT (X)

conf T (X ⇒ Y )

i2 i4 ⇒ i3 i5 i3 i4 ⇒ i2 i5 i4 i5 ⇒ i2 i3 i3 i4 ⇒ i2 i5 i4 ⇒ i2 i3 i5

2 2 2 2 2

1 1 1 1 1

Indeed, all these sets yield exact rules, that is, rules having 100 percent conﬁdence. 䊐

LEVELWISE ALGORITHMS AND POSETS

231

Many transaction data sets produce huge number of frequent item sets, and therefore, huge number of association rules particularly when the levels of support and conﬁdence required are relatively low. Moreover, it is well known (see the work by Tan et al. [17]) that limiting the analysis of association rules to the support/conﬁdence framework can lead to dubious conclusions. The data mining literature contains many references that attempt to derive interestingness measures for association rules in order to focus data analysis of those rules that may be more relevant (see, other works [4,6,8,11,12,16]).

7.4 LEVELWISE ALGORITHMS AND POSETS The focus of this section is the levelwise algorithms, a powerful and elegant generalization of the Apriori algorithm that was introduced in the work by Mannila and Toivonen [13]. Let (P, ≤) be a partially ordered set and let Q be a subset of P. Deﬁnition 7 The border of Q is the set BD(Q) = {p ∈ P|u < p implies u ∈ Q and p < v implies v ∈ Q}. The positive border of Q is the set BD+ (Q) = BD(Q) ∩ Q, while the negative border of Q is BD− (Q) = BD(Q) − Q. Clearly, we have BD(Q) = BD+ (Q) ∪ BD− (Q). An alternative terminology exists that makes use of the terms generalization and specialization. If r, p ∈ P and r < p, then we say that r is a generalization of p, or that p is a specialization of r. Thus, the border of a set Q consists of those elements p of P such that all their generalizations are in Q and none of their specializations is in Q. Theorem 7 Let (P, ≤) be a partially ordered set. If Q, Q are two disjoint subsets of P, then BD(Q ∪ Q ) ⊆ BD(Q) ∪ BD(Q ). Proof. Let p ∈ BD(Q ∪ Q ). Suppose that u < p, so u ∈ Q ∪ Q . Since Q and Q are disjoint we have either u ∈ Q or u ∈ Q . On the contrary, if p < v, then v ∈ Q ∪ Q , so v ∈ Q and v ∈ Q . Thus, we have p ∈ BD(Q) ∪ BD(Q ). 䊏

232

DATA MINING ALGORITHMS II: FREQUENT ITEM SETS

The notion of a hereditary subset of a poset is an immediate generalization of the notion of hereditary family of sets. Deﬁnition 8 A subset Q of a poset (P, ≤) is said to be hereditary if p ∈ Q and r ≤ p imply r ∈ Q. Theorem 8 If Q be a hereditary subset of a poset (P, ≤), then the positive and the negative borders of Q are given by BD+ (Q) = {p ∈ Q|p < v implies v ∈ Q} and

BD− (Q) = {p ∈ P − Q|u < p implies u ∈ Q},

respectively. Proof. Let t be an element of the positive border BD+ (Q) = BD(Q) ∩ Q. We have t ∈ Q and t < v implies v ∈ Q, because t ∈ BD(Q). Conversely, suppose that t is an element of Q such that t < v implies v ∈ Q. Since Q is hereditary, u < t implies u ∈ Q, so t ∈ BD(Q). Therefore, t ∈ BD(Q) ∩ Q = BD+ (Q). Let now s be an element of the negative border of Q, that is, s ∈ BD(Q) − Q. We have immediately s ∈ P − Q. If u < s, then u ∈ Q, because Q is hereditary. Thus, BD− (Q) ⊆ {p ∈ P − Q|u < p implies u ∈ Q}. Conversely, suppose that s ∈ P − Q and u < s implies u ∈ Q. If s < v, then v cannot belong to Q because this would entail s ∈ Q due to the hereditary property of Q. Consequently, s ∈ BD(Q), and so, s ∈ BD(Q) − Q = BD− (Q). 䊏 Theorem 8 can be paraphrased by saying that for a hereditary subset Q of P the positive border consists of the maximal elements of Q, while the negative border of Q consists of the minimal elements of P − Q. Note that if Q, Q are two hereditary subsets of P and BD+ (Q) = BD+ (Q ), then Q = Q . Indeed, if z ∈ P, one of the following two cases may occur: 1. If z is not a maximal element of Q, then there is a maximal element w of Q such that z < w. Since w ∈ BD+ (Q) = BD+ (Q ), it follows that w ∈ Q ; hence z ∈ Q , because Q is hereditary. 2. If z is a maximal element of Q, then z ∈ BD+ (Q) = BD+ (Q ); hence z ∈ Q . In either case z ∈ Q , so Q ⊆ Q . The reverse inclusion can be proven in a similar way, so Q = Q . Similarly, we can show that for two hereditary collections Q, Q of subsets of I, BD− (Q) = BD− (Q ) implies Q = Q . Indeed, suppose that z ∈ Q − Q . Since z ∈ Q , there exists a minimal element v such that v ∈ Q and each of its lower bounds is in Q . Since v belongs to the negative border BD− (Q ), it follows that

233

LEVELWISE ALGORITHMS AND POSETS

v ∈ BD− (Q). This leads to a contradiction because z ∈ Q and v (for which we have v < z) does not, thereby contradicting the fact that Q is a hereditary subset. Since no such z may exist, it follows that Q ⊆ Q . The reverse inclusion can be shown in the same manner. Deﬁnition 9 Let D be a relational database, SD be the set of states of D, and let (B, ≤, h) be a ranked poset, referred to as the ranked poset of objects. A query is a function q : SD × B −→ {0, 1} such that D ∈ SD , b ≤ b , and q(D, b ) = 1 imply q(D, b) = 1. Deﬁnition 9 is meant to capture the framework of the Apriori algorithm for identiﬁcation of frequent item sets. As shown in the work by Mannila and Toivonen [13], this framework can capture many other situations. Example 9 Let D be a database that contains a tabular variable (T, H) and let θ = (T, H, ρ) be the table that is the current value of (T, H) contained by the current state D of D. The graded poset (B, ≤, h) is (P(H), ⊆, h), where h(X) = |X|. Given a number μ, the query is deﬁned by q(D, K) =

1 if suppT (K) ≤ μ, 0 otherwise.

Since K ⊆ K implies suppT (K ) ≤ suppT (K), it follows that q satisﬁes the condition of Deﬁnition 9. Example 10 As in Example 9, let D be a database that contains a tabular variable (T, H), and let θ = (T, H, ρ) be the table that is the current value of (T, H) contained by the current state D of D. The graded poset (P(H), ⊇, g) is the dual of the graded poset considered in Example 9, where g(K) = |H| − |K|. If L is a set of attributes the function qL is deﬁned by qL (D, K) =

1 if K → L holds in θ, 0 otherwise.

Note that if K ⊆ K and D satisﬁes the functional dependency K → L, then D 䊐 satisﬁes K → L. Thus, q is a query in the sense of Deﬁnition 9. Deﬁnition 10 The set of interesting objects for the state D of the database and the query q is given by INT(D, q) = {b ∈ B| q(D, b) = 1}.

234

DATA MINING ALGORITHMS II: FREQUENT ITEM SETS

Note that the set of interesting objects is a hereditary set (B, ≤). Indeed, if b ∈ INT(D, q) and c ≤ b, then c ∈ INT(D, q), according to Deﬁnition 9. Thus, BD+ (INT(D, q)) = {b ∈ INT(D, q) |b < v implies v ∈ INT(D, q)}, BD− (INT(D, q)) = {b ∈ B − INT(D, q) |u < b implies u ∈ INT(D, q)}. In other words, BD+ (INT(D, q)) is the set of maximal objects that are interesting, while BD− (INT(D, q)) is the set of minimal objects that are not interesting. Next, we discuss a general algorithm that seeks to compute the set of interesting objects for a database state. The algorithm is known as the levelwise algorithm because it identiﬁes these objects by scanning successively the levels of the graded poset of objects. If L0 , L1 , . . . are the levels of the graded poset (B, ≤, h), then the algorithm begins by examining all objects located on the initial level. The set of interesting objects located on the level Li is denoted by Fi ; for each level Li the computation of Fi is preceded by a computation of the set of potentially interesting objects Ci referred to as the set of candidate objects. The ﬁrst set of candidate objects C1 coincides with the level Li . Only the interesting objects on this level are retained for the set F1 . The next set of candidate objects Ci+1 is constructed by examining the level Li+1 and keeping those objects b having all their subobjects c in the interesting sets of the previous levels. Generic levelwise algorithm(D, (B, ≤, h), q){ C1 = L1 ; i = 1; while (Ci = ∅) do /* evaluation phase */ Fi = {b ∈ Ci |q(D, b) = 1}; /* candidate generation */ Ci+1 = {b ∈ Li+1 |c < b implies c ∈ j≤i Fj } − j≤i Cj i + +; endwhile; output j

䊐

235

FURTHER READINGS

Example 12 In Example 10, we deﬁned the grading query qL as qL (D, K) =

1 if K → L holds in θ, 0 otherwise.

for K ∈ P(H). The levelwise algorithm allows us to identify those subsets K such that a table θ = (T, H, ρ) satisﬁes the functional dependency K → L. The ﬁrst level consists of all subsets K of H that have |H| − 1 attributes. There are, of course, |H| − 1 such subsets and the set F1 will contain all these sets such that K → H is satisﬁed. Successive levels contain sets that have fewer and fewer attributes. Level Li contains sets that have |H| − i attributes. The algorithm will go through the while loop at most 1 + |H − K|, where K is 䊐 the smallest set such that K → L holds. Observe that the computation of Ci+1 in the generic levelwise algorithm, ⎫ ⎧ ⎨ / ⎬ / Fj − Cj Ci+1 = b ∈ Li+1 | c < b implies c ∈ ⎭ ⎩ j≤i

can be written as

⎛ Ci+1 = BD− ⎝

/

j≤i

⎞ Fj ⎠ −

/

j≤i

Cj .

j≤i

This shows that the set of candidate objects at level Li+1 is the negative border of the interesting sets located on lower level excluding those objects that have been already evaluated. The most expensive component of the levelwise algorithm is the evaluation of q(D, b) since this requires a scan of the database state D. Clearly, we need to evaluate this function for each candidate element, so we will require | i=1 Ci | evaluations, where is the number of levels that are scanned. Some of these evaluations will result in including the evaluated object b in the set Fi . Objects that will not be included in INT (D, q) are such that any of their generalizations are in INT (D, q), even though they fail to belong to this set. They belong to BD− (INT (D, q)). Thus, the levelwise algorithm performs |INT (D, q)| + |BD− (INT (D, q))| evaluations of q(D, b). Exercises 5–8 are reformulations of results obtained in the work by Mannila and Toivonen [13].

7.5 FURTHER READINGS In addition to general data mining references [17], the reader should consult [1], a monograph dedicated to frequent item sets and association rules. Seminal work in this

236

DATA MINING ALGORITHMS II: FREQUENT ITEM SETS

area, in addition to the original paper [5], has been done by Mannila and Toivonen [13] and by Zaki [19]; these references and others, such as [2] and [3], lead to an interesting and rewarding journey through the data mining literature. An alternative method for detecting frequent item sets based on a very interesting condensed representation of the data set was developed by Han et al. [9].

7.6 EXERCISES 1. Let I = {a, b, c, d} be a set of items and let T be a transaction data set deﬁned by T (1) = abc, T (2) = abd, T (3) = acd, T (4) = bcd, T (5) = ab. (a)Find item sets whose support it at least 0.25. (b)Find association rules having support at least 0.25 and a conﬁdence at least 0.75. 2. Let I = i1 i2 i3 i4 i5 be a set of items. Find the 0.6-frequent item sets of the transaction data set T over I deﬁned by T (1) = i1

T (6) = i1 i2 i4

T (2) = i1 i2

T (7) = i1 i2 i5

T (3) = i1 i2 i3 T (8) = i2 i3 i4 T (4) = i2 i3

T (9) = i2 i3 i5

T (5) = i2 i3 i4 T (10) = i3 i4 i5 Also, determine all rules whose conﬁdence is at least 0.75. 3. Let T be a transaction data set T over an item set I, T : {1, . . . , n} −→ P(I). Deﬁne the bit sequence of an item set X as sequence bX = (b1 , . . . , bn ) ∈ Seqn ({0, 1}), where bi =

1 if X ⊆ T (i), 0 otherwise,

for 1 ≤ i ≤ n. √ For b ∈ Seqn ({0, 1}) the number |{i|1 ≤ i ≤ n, bi = 1}| is denoted by b. The distance between the sequences b, c is deﬁned as b ⊕ c. Prove that

237

EXERCISES

(a) bX∪Y = bX ∧ bY for every X, Y ∈ P(I); (b) bK⊕L = bL ⊕ bK , where K ⊕ L is the symmetric difference of the item sets K and L; √ (c) | suppT (K) − suppT (L)| ≤ d(bK , bL )/ |T |. 4. For a transaction data set T over an item set I = {i1 , . . . , in }, T : {1, . . . , n} −→ P(I) and a number h, 1 ≤ h ≤ n, deﬁne the number νT (h) by νT (h) = 2n−1 bn + · · · + 2b2 + b1 , where 1 0

bk =

if ik ∈ T (h), otherwise,

for 1 ≤ k ≤ n. Prove that ik ∈ T (h) if and only if the result of the integer division νT (h)/k is an odd number. Suppose that the tabular variables of a database D are (T1 , H1 ), . . . , (Tp , Hp ). An inclusion dependency is an expression of the form Ti [K] ⊆ Tj [L], where K ⊆ Hi and L ⊆ Hj for some i, j, where 1 ≤ i, j ≤ p are two sets of attributes having the same cardinality. Denote by IDD the set of inclusion dependences of D. Let D ∈ SD be a state of the database D, φ = Ti [K] ⊆ Tj [L] be an inclusion dependency and let θi = (Ti , Hi , ρi ), θj = (Tj , Hj , ρj ) be the tables that correspond to the tabular variables (Ti , Hi ) and (Tj , Hj ) in D. The inclusion dependency φ is satisﬁed in the state D of D if for every tuple t ∈ ρi there is a tuple s ∈ ρj such that t[K] = s[L]. 5. For φ = Ti [K] ⊆ Tj [L] and ψ = Td [K ] ⊆ Te [L ] deﬁne the relation φ ≤ ψ if d = i, e = j, K ⊆ K , and H ⊆ H . Prove that “≤” is a partial order on IDD . 6. Prove that the triple (IDD , ≤, h) is a graded poset, where h(Ti [K] ⊆ Tj [L]) = |K|. 7. Prove that the function q : SD × IDD −→ {0, 1} deﬁned by q(D, φ) =

1 0

if φ is satisﬁed in D, otherwise

is a query (as in Deﬁnition 9). 8. Specialize the generic levelwise algorithm to an algorithm that retrieves all inclusion dependences satisﬁed by a database state. Let T : {1, . . . , n} −→ P(D) be a transaction data set over an item set D. The contingency matrix of two item sets X, Y is the 2 × 2 matrix: m11 m10 MXY = , m01 m00

238

DATA MINING ALGORITHMS II: FREQUENT ITEM SETS

where m11 = |{k|X ⊆ T (k) and Y ⊆ T (k)}|, m10 = |{k|X ⊆ T (k) and Y ⊆ T (k)}|, m01 = |{k|X ⊆ T (k) and Y ⊆ T (k)}|, m00 = |{k|X ⊆ T (k) and Y ⊆ T (k)}|. Also, let m1· = m11 + m10 and m·1 = m11 + m01 . 9. Let X ⇒ Y be an association rule. Prove that suppT (X ⇒ Y ) =

m11 + m10 n

and

conf T (X ⇒ Y ) =

m11 . m11 + m10

Which signiﬁcance has the number m10 for X ⇒ Y ? 10. Let T : {1, . . . , n} −→ P(I) be a transaction data set over a set of items I and let π be a partition of the set {1, . . . , n} of transaction identiﬁers, π = {B1 , . . . , Bp }. Let ni = |Bi | for 1 ≤ i ≤ p. A partitioning of T is a sequence T1 , . . . , Tp of transaction data sets over I such that Ti : {1, . . . , ni } −→ P(I) is deﬁned by Ti () = T (k ), where Bi = {k1 , . . . , kni } for 1 ≤ i ≤ p. Intuitively, this corresponds to splitting horizontally the table of T into p tables that contain n1 , . . . , np consecutive rows, respectively. Let K be an item set. Prove that if suppT (K) ≥ μ, there exists j, 1 ≤ j ≤ p, such that suppTj (K) ≥ μ. Give an example to show that the reverse implication does not hold; in other words, give an example of a transaction data set T , a partitioning T1 , . . . , Tp of T , and an item set K such that K is μ-frequent in some Ti but not in T . 11. Piatetsky-Shapiro [16] formulated three principles that a rule interestingness measure R should satisfy: (a)R(X ⇒ Y ) = 0 if m11 = m1 m1 /n; (b)R(X → Y ) increases with m11 when other parameters are ﬁxed; (c)R(X → Y ) decreases with m·1 and with m1· when other parameters are ﬁxed. The lift of a rule X ⇒ Y is the number lift(X ⇒ Y ) = (nm11 )/(m1 m1 ). The PS measure is PS(X → Y ) = m11 − (m1 m1 )/(n). Do lift and PS satisfy PiatetskyShapiro’s principles? Give examples of interestingness measures that satisfy these principles.

REFERENCES 1. Adamo JM. Data Mining for Association Rules and Sequential Patterns. New York: Springer-Verlag; 2001.

REFERENCES

239

2. Agarwal RC, Aggarwal CC, Prasad VVV. A tree projection algorithm for generation of frequent item sets. J Parallel Distrib Comput 2001;61(3):350–371. 3. Agarwal RC, Aggarwal CC, Prasad VVV. Depth ﬁrst generation of long patterns. Proceedings of Knowledge Discovery and Data Mining; 2000. p 108–118. 4. Aggarwal CC, and Yu PS. Mining associations with the collective strength approach. IEEE Trans. Knowledge Data Eng 2001;13(6):863–873. 5. Agrawal R, Imielinski T, Swami A. Mining association rules between sets of items in very large databases. Proceedings of the ACM SIGMOD Conference on Management of Data; 1993. p 207–216. 6. Bayardo R, Agrawal R. Mining the most interesting rules. Proceedings of the 5th KDD. San Diego; 1999. p 145–153. 7. Birkhoff G. Lattice Theory. 3rd ed. Providence, RI: American Mathematical Society; 1967. 8. Brin S, Motwani R, Silverstein C. Beyond market baskets: generalizing association rules to correlations. Proceedings of ICMD; 1997. p 255–264. 9. Han J, Pei J, Yin Y. Mining frequent patterns without candidate generation. Proceedings of the ACM–SIGMOD International Conference on Management of Data; Dallas; 2000. p 1–12. 10. Ganter B, Wille R. Formal Concept Analysis. Berlin: Springer-Verlag; 1999. 11. Hilderman R, Hamilton H. Knowledge discovery and interestingness measures: a survey. Technical Report No. CS 99-04. Department of Computer Science, University of Regina; October 1999. 12. Jaroszewicz S, Simovici D. Interestingness of frequent item sets using Bayesian networks as background knowledge. Proceedings of the 10th KDD International Conference; Seattle; 2004. p 178–186. 13. Mannila H, Toivonen H. Levelwise search and borders of theories in knowledge discovery. TR C-1997-8. Helsinki, Finland: University of Helsinki; 1997. 14. Park JS, Chen MS, Yu PS. An Effective Hash based algorithm for mining association rules. Proceedings of the 1995 ACM SIGMOD International Conference on Management of Data; San Jose, CA; 1995. p 175–186. 15. Pasquier N, Bastide Y, Taouil R, Lakhal L. Discovering Frequent Closed Itemsets for Association Rules. Lecture Notes in Computer Science. Volume 1540. New York: SpringerVerlag; 1999. p 398–416. 16. Piatetsky-Shapiro G. Discovery, analysis and presentation of strong rules. In: PiatetskyShapiro G, Frawley W, editors. Knowledge Discovery in Databases. Cambridge, MA: MIT Press; 1991. p 229–248. 17. Tan PN, Steinbach M, Kumar V. Introduction to Data Mining. Reading, MA: AddisonWesley; 2005. 18. Toivonen H. Sampling large databases for association rules. Proceedings of the 22nd VLDB Conference; Mumbai, India; 1996. p 134–145. 19. Zaki MJ. Mining non-redundant association rules. Data Mining Knowledge Discov 2004;9:223–248.

CHAPTER 8

Algorithms for Data Streams CAMIL DEMETRESCU and IRENE FINOCCHI

8.1 INTRODUCTION Efﬁcient processing over massive data sets has taken an increased importance in the last few decades due to the growing availability of large volumes of data in a variety of applications in computational sciences. In particular, monitoring huge and rapidly changing streams of data that arrive online has emerged as an important data management problem: Relevant applications include analyzing network trafﬁc, online auctions, transaction logs, telephone call records, automated bank machine operations, and atmospheric and astronomical events. For these reasons, the streaming model has recently received a lot of attention. This model differs from computation over traditional stored data sets since algorithms must process their input by making one or a small number of passes over it, using only a limited amount of working memory. The streaming model applies to settings where the size of the input far exceeds the size of the main memory available and the only feasible access to the data is by making one or more passes over it. Typical streaming algorithms use space at most polylogarithmic in the length of the input stream and must have fast update and query times. Using sublinear space motivates the design for summary data structures with small memory footprints, also known as synopses [34]. Queries are answered using information provided by these synopses, and it may be impossible to produce an exact answer. The challenge is thus to produce high quality approximate answers, that is, answers with conﬁdence bounds on the possible error: Accuracy guarantees are typically made in terms of a pair of user-speciﬁed parameters, ε and δ, meaning that the error in answering a query is within a factor of 1 + ε of the true answer with probability at least 1 − δ. The space and update time will depend on these parameters and the goal is to limit this dependence as much as possible. Major progress has been achieved in the last 10 years in the design of streaming algorithms for several fundamental data sketching and statistics problems, for which several different synopses have been proposed. Examples include number of distinct

Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

241

242

ALGORITHMS FOR DATA STREAMS

items, frequency moments, L1 and L2 norms of vectors, inner products, frequent items, heavy hitters, quantiles, histograms, and wavelets. Recently, progress has been achieved for other problem classes, including computational geometry (e.g., clustering and minimum spanning trees) and graphs (e.g., triangle counting and spanners). At the same time, there has been a ﬂurry of activity in proving impossibility results, devising interesting lower bound techniques, and establishing important complementary results. This chapter is intended as an overview of this rapidly evolving area. The chapter is not meant to be comprehensive, but rather aims at providing an outline of the main techniques used for designing algorithms or for proving lower bounds. We refer the interested reader to the works by Babcock et al. [7], Gibbons and Matias [34] and Muthukrishnan [57] for an extensive discussion of problems and results not mentioned here. 8.1.1

Applications

As observed before, the primary application of data stream algorithms is to monitor continuously huge and rapidly changing streams of data in order to support exploratory analyses and to detect correlations, rare events, fraud, intrusion, and unusual or anomalous activities. Such streams of data may be, for example, performance measurements in trafﬁc management, all detail records in telecommunications, transactions in retail chains, ATM operations in banks, bids in online auctions, log records generated by Web Servers, or sensor network data. In all these cases, the volumes of data are huge (several terabytes or even petabytes), and records arrive at a rapid rate. Other relevant applications for data stream processing are related, for example, to processing massive ﬁles on secondary storage and to monitoring the contents of large databases or data warehouse environments. In this section, we highlight some typical needs that arise in these contexts. 8.1.1.1 Network Management Perhaps the most prominent application is related to network management. This involves monitoring and conﬁguring network hardware and software to ensure smooth operations. Consider, for example, trafﬁc analysis in the Internet. Here, as IP packets ﬂow through the routers, we would like to monitor link bandwidth usage, to estimate trafﬁc demands, to detect faults, congestion, and usage patterns. Typical queries that we would be able to answer are thus the following. How many IP addresses used a given link in a certain period of time? How many bytes were sent between a pair of IP addresses? Which are the top 100 IP addresses in terms of trafﬁc? What is the average duration of an IP session? Which sessions transmitted more than 1000 bytes? Which IP addresses are involved in more than 1000 sessions? All these queries are heavily motivated by trafﬁc analysis, fraud detection, and security. To get a rough estimate of the amount of data that need to be analyzed to answer one such query, consider that each router can forward up to 1 billion packets per hour, and each Internet Service Provider may have many hundreds of routers: thus, many terabytes of data per hour need to be processed. These data arrive at a rapid rate, and

INTRODUCTION

243

we therefore need algorithms to mine patterns, process queries, and compute statistics on such data streams in almost real time. 8.1.1.2 Database Monitoring Many commercial database systems have a query optimizer used for estimating the cost of complex queries. Consider, for example, a large database that undergoes transactions (including updates). Upon the arrival of a complex query q, the optimizer may run some simple queries in order to decide an optimal query plan for q: In particular, a principled choice of an execution plan by the optimizer depends heavily on the availability of statistical summaries such as histograms, the number of distinct values in a column for the tables referenced in a query, or the number of items that satisfy a given predicate. The optimizer uses this information to decide between alternative query plans and to optimize the use of resources in multiprocessor environments. The accuracy of the statistical summaries greatly impacts the ability to generate good plans for complex SQL queries. The summaries, however, must be computed quickly: In particular, examining the entire database is typically regarded as prohibitive. 8.1.1.3 Online Auctions During the last few years, online implementations of auctions have become a reality, thanks to the Internet and to the wide use of computermediated communication technologies. In an online auction system, people register to the system, open auctions for individual items at any time, and then submit continuously items for auction and bids for items. Statistical estimation of auction data is thus very important for identifying items of interest to vendors and purchasers, and for analyzing economic trends. Typical queries may require to convert the prices of incoming bids between different currencies, to select all bids of a speciﬁed set of items, to maintain a table of the currently open auctions, to select the items with the most bids in a speciﬁed time interval, to maintain the average selling price over the items sold by each seller, to return the highest bid in a given period of time, or to monitor the average closing price (i.e., the price of the maximum bid, or the starting price of the auction in case there were no bids) across items in each category. 8.1.1.4 Sequential Disk Accesses In modern computing platforms, the access times to main memory and disk vary by several orders of magnitude. Hence, when the data reside on disk, it is much more important to minimize the number of I/Os (i.e., the number of disk accesses) than the CPU computation time as it is done in traditional algorithms theory. Many ad hoc algorithmic techniques have been proposed in the external memory model for minimizing the number of I/Os during a computation (see, e.g., the work by Vitter [64]). Due to the high sequential access rates of modern disks, streaming algorithms can also be effectively deployed for processing massive ﬁles on secondary storage, providing new insights into the solution of several computational problems in external memory. In many applications managing massive data sets, using secondary and tertiary storage devices is indeed a practical and economical way to store and move data: such large and slow external memories, however, are best optimized for sequential

244

ALGORITHMS FOR DATA STREAMS

access, and thus naturally produce huge streams of data that need to be processed in a small number of sequential passes. Typical examples include data access to database systems [39] and analysis of Internet archives stored on tape [43]. The streaming algorithms designed with these applications in mind may have a greater ﬂexibility: Indeed, the rate at which data are processed can be adjusted, data can be processed in chunks, and more powerful processing primitives (e.g., sorting) may be available. 8.1.2

Overview of the Literature

The problem of computing in a small number of passes over the data appears already in papers from the late 1970s. Morris, for instance, addressed the problem of keeping approximate counts of large numbers [55]. Munro and Paterson [56] studied the space required for selection when at most P passes over the data can be performed, giving almost matching upper and lower bounds as a function of P and of the input size. The paper by Alon et al. [5,6], awarded in 2005 with the G¨odel Prize for outstanding papers in the area of theoretical computer science, provided the foundations of the ﬁeld of streaming and sketching algorithms. This seminal work introduced the novel technique of designing small randomized linear projections that allow the approximation (to user speciﬁed precision) of the frequency moments of a data set and other quantities of interest. The computation of frequency moments is now fully understood, with almost matching (up to polylogarithmic factors) upper bounds [12,20,47] and lower bounds [9,14,46,62]. Namely, Indyk and Woodruff [47] presented the ﬁrst ˜ 1−2/k ). A simpler algorithm for estimating the kth frequency moment using space O(n one-pass algorithm is described in [12]. Since 1996, many fundamental data statistics problems have been efﬁciently solved in streaming models. For instance, the computation of frequent items is particularly relevant in network monitoring applications and has been addressed, for example, in many other works [1,16,22,23,51,54]. A plethora of other problems have been studied in the last few years, designing solutions that hinge upon many different and interesting techniques. Among them, we recall sampling, probabilistic counting, combinatorial group testing, core sets, dimensionality reduction, and tree-based methods. We will provide examples of application of some of these techniques in Section 8.3. An extensive bibliography can be found in the work by Muthukrishnan [57]. The development of advanced techniques made it possible to solve progressively more complex problems, including the computation of histograms, quantiles, norms, as well as geometric and graph problems. Histograms capture the distribution of values in a data set by grouping values into buckets and maintaining suitable summary statistics for each bucket. Different kinds of histograms exist: for example, in an equidepth histogram the number of values falling into each bucket is uniform across all buckets. The problem of computing these histograms is strictly related to the problem of maintaining the quantiles for the data set: quantiles represent indeed the bucket boundaries. These problems have been addressed, for example, in many other works [18,36,37,40,41,56,58,59]. Wavelets are also widely used to provide summarized representations of data: works on computing wavelet coefﬁcients in data stream models include [4,37,38,60].

INTRODUCTION

245

A few fundamental works consider problems related to norm estimation, for example, dominance norms and Lp sums [21,44]. In particular, Indyk pioneered the design of sketches based on random variables drawn from stable distributions (which are known to exist) and applied this idea to the problem of estimating Lp sums [44]. Geometric problems have also been the subject of much recent research in the streaming model [31,32,45]. In particular, clustering problems received special attention: given a set of points with a distance function deﬁned on them, the goal is to ﬁnd a clustering solution (a partition into clusters) that optimizes a certain objective function. Classical objective functions include minimizing the sum of distances of points to their closest median (k-median) or minimizing the maximum distance of a point to its closest center (k-center). Streaming algorithms for such problem are presented, for example, in the works by Charikar [17] and Guha et al. [42]. Differently from most data statistics problems, where O(1) passes and polylogarithmic working space have been proven to be enough to ﬁnd approximate solutions, many classical graph problems seem to be far from being solved within similar bounds: for many classical graph problems, linear lower bounds on the space × passes product are indeed known [43]. A notable exception is related to counting triangles in graphs, as discussed in the works by Bar-Yossef et al. [10], Buriol et al. [13], and Jowhari and Ghodsi [49]. Some recent papers show that several graph problems can be solved with one or few passes in the semi-streaming model [26–28,53] where the working memory size is O(n · polylog n) for an input graph with n vertices: in other words, akin to semi-external memory models [2,64] there is enough space to store vertices, but not edges of the graph. Other works, such as [3,25,61], consider the design of streaming algorithms for graph problems when the model allows more powerful primitives for accessing stream data (e.g., use of intermediate temporary streams and sorting). 8.1.3

Chapter Outline

This chapter is organized as follows. In Section 8.2 we describe the most common data stream models: such models differ in the interpretation of the data on the stream (each item can either be a value itself or indicate an update to a value) and in the primitives available for accessing and processing stream items. In Section 8.3 we focus on techniques for proving upper bounds: we describe some mathematical and algorithmic tools that have proven to be useful in the construction of synopsis data structures (including randomization, sampling, hashing, and probabilistic counting) and we ﬁrst show how these techniques can be applied to classical data statistics problems. We then move to consider graph problems as well as techniques useful in streaming models that provide more powerful primitives for accessing stream data in a nonlocal fashion (e.g., simulations of parallel algorithms). In Section 8.4 we address some lower bound techniques for streaming problems, using the computation of the number of distinct items in a data stream as a running example: we explore the use of reductions of problems in communication complexity to streaming problems,

246

ALGORITHMS FOR DATA STREAMS

and we discuss the use of randomization and approximation in the design of efﬁcient synopses. In Section 8.5 we summarize our contribution. 8.2 DATA STREAM MODELS A variety of models exist for data stream processing: the differences depend on how stream data should be interpreted and which primitives are available for accessing stream items. In this section we overview the main features of the most commonly used models. 8.2.1

Classical Streaming

In classical data streaming [5,43,56,57], input data are accessed sequentially in the form of a data stream = x1 , ..., xn and need to be processed using a working memory that is small compared to the length n of the stream. The main parameters of the model are the number p of sequential passes over the data, the size s of the working memory, and the per-item processing time. All of them should be kept small: typically, one strives for one pass and polylogarithmic space, but this is not a requirement of the model. There exist at least three variants of classical streaming, dubbed (in increasing order of generality) time series, cash register, and turnstile [57]. Indeed, we can think of stream items x1 , ..., xn as describing an underlying signal A, that is, a one-dimensional function over the reals. In the time series model, each stream item xi represents the ith value of the underlying signal, that is, xi = A[i]. In the other models, each stream item xi represents an update of the signal: namely, xi can be thought of as a pair (j, Ui ), meaning that the jth value of the underlying signal must be changed by the quantity Ui , that is, Ai [j] = Ai−1 [j] + Ui . The partially dynamic scenario in which the signal can be only incremented, that is, Ui ≥ 0, corresponds to the cash register model, while the fully dynamic case yields the turnstile model. 8.2.2

Semi-Streaming

Despite the heavy restrictions of classical data streaming, we will see in Section 8.3 that major success has been achieved for several data sketching and statistics problems, where O(1) passes and polylogarithmic working space have been proven to be enough to ﬁnd approximate solutions. On the contrary, there exist many natural problems (including most problems on graphs) for which linear lower bounds on p × s are known, even using randomization and approximation: these problems cannot be thus solved within similar polylogarithmic bounds. Some recent papers [27,28,53] have therefore relaxed the polylog space requirements considering a semi-streaming model, where the working memory size is O(n · polylog n) for an input graph with n vertices: in other words, akin to semi-external memory models [2,64], there is enough space to store vertices, but not edges of the graph. We will see in Section 8.3.3 that some complex graph problems can be solved in semi-streaming, including spanners, matching, and diameter estimation.

ALGORITHM DESIGN TECHNIQUES

8.2.3

247

Streaming with a Sorting Primitive

Motivated by technological factors, some authors have recently started to investigate the computational power of even less restrictive streaming models. Today’s computing platforms are equipped with large and inexpensive disks highly optimized for sequential read/write access to data, and among the primitives that can efﬁciently access data in a nonlocal fashion, sorting is perhaps the most optimized and well understood. These considerations have led to introduce the stream-sort model [3,61]. This model extends classical streaming in two ways: the ability to write intermediate temporary streams and the ability to reorder them at each pass for free. A stream-sort algorithm alternates streaming and sorting passes: a streaming pass, while reading data from the input stream and processing them in the working memory, produces items that are sequentially appended to an output stream; a sorting pass consists of reordering the input stream according to some (global) partial order and producing the sorted stream as output. Streams are pipelined in such a way that the output stream produced during pass i is used as input stream at pass i + 1. We will see in Section 8.3.4 that the combined use of intermediate temporary streams and of a sorting primitive yields enough power to solve efﬁciently (within polylogarithmic passes and memory) a variety of graph problems that cannot be solved in classical streaming. Even without sorting, the model is powerful enough for achieving space–passes trade-offs [25] for graph problems for which no sublinear memory algorithm is known in classical streaming.

8.3 ALGORITHM DESIGN TECHNIQUES Since data streams are potentially unbounded in size, when the amount of computation memory is bounded it may be impossible to produce an exact answer. In this case, the challenge is to produce high quality approximate answers, that is, answers with conﬁdence bounds on the possible error. The typical approach is to maintain a “lossy” summary of the data stream by building up a synopsis data structure with memory footprint substantially smaller than the length of the stream. In this section we describe some mathematical and algorithmic techniques that have proven to be useful in the construction of such synopsis data structures. Besides the ones considered in this chapter, many other interesting techniques have been proposed: the interested reader can ﬁnd pointers to relevant works in Section 8.1.2. Rather than being comprehensive, our aim is to present a small amount of results in sufﬁcient detail that the reader can get a feeling of some common techniques used in the ﬁeld. The most natural approach to designing streaming algorithms is perhaps to maintain a small sample of the data stream: if the sample captures well the essential characteristics of the entire data set with respect to a speciﬁc problem, evaluating a query over the sample may provide reliable approximation guarantees for that problem. In Section 8.3.1 we discuss how to maintain a bounded size sample of a (possibly unbounded) data stream and describe applications of sampling to the problem of ﬁnding frequent items in a data stream.

248

ALGORITHMS FOR DATA STREAMS

Useful randomized synopses can also be constructed hinging upon hashing techniques. In Section 8.3.2 we address the design of hash-based sketches for estimating the number of distinct items in a data stream. We also discuss the main ideas behind the design of randomized sketches for the more general problem of estimating the frequency moments of a data set: the seminal paper by Alon et al. [5] introduced the technique of designing small randomized linear projections that summarize large amounts of data and allow frequency moments and other quantities of interest to be approximated to user-speciﬁed precision. As quoted from the G¨odel Award Prize ceremony, this paper “set the pattern for a rapidly growing body of work, both theoretical and applied, creating the now burgeoning ﬁelds of streaming and sketching algorithms.” Sections 8.3.3 and 8.3.4 are mainly devoted to the semi-streaming and stream-sort models. In Section 8.3.3 we focus on techniques that can be applied to solve complex ˜ space. In Section 8.3.4, ﬁnally, we analyze graph problems in O(1) passes and O(n) the use of more powerful primitives for accessing stream data, showing that sorting yields enough power to solve efﬁciently a variety of problems for which efﬁcient solutions in classical streaming cannot be achieved. 8.3.1

Sampling

A small random sample S of the data often captures certain characteristics of the entire data set. If this is the case, the sample can be maintained in memory and queries can be answered over the sample. In order to use sampling techniques in a data stream context, we ﬁrst need to address the problem of maintaining a sample of a speciﬁed size over a possibly unbounded stream of data that arrive online. Note that simple coin tossing is not possible in streaming applications, as the sample size would be unbounded. The standard solution is to use Vitter’s reservoir sampling [63] that we describe in the following Sections. 8.3.1.1 Reservoir Sampling This technique dates back to the 1980s [63]. Given a stream of n items that arrive online, at any instant of time reservoir sampling guarantees to maintain a uniform random sample S of ﬁxed size m of the part of stream observed up to that time. Let us ﬁrst consider the following natural sampling procedure. At the beginning, add to S the ﬁrst m items of the stream. Upon seeing the stream item xt at time t, add xt to S with probability m/t. If xt is added, evict a random item from S (other than xt ). It is easy to see that at each time |S| = m as desired. The next theorem proves that, at each time, S is actually a uniform random sample of the stream observed so far. Theorem 1 [63] Let S be a sample of size m maintained over a stream = x1 , ..., xn by the above algorithm. Then, at any time t and for each i ≤ t, the probability that xi ∈ S is m/t.

ALGORITHM DESIGN TECHNIQUES

249

Proof. We use induction on t. The base step is trivial. Let us thus assume that the claim is true up to time; t that is, by inductive hypothesis Pr[xi ∈ S] = m/t for each i ≤ t. We now examine how S can change at time t + 1, when item xt+1 is considered for addition. Consider any item xi with i < t + 1. If xt+1 is not added to S (this happens with probability 1 − m/(t + 1)), then xi has the same probability of being in S of the previous step (i.e., m/t). If xt+1 is added to S (this happens with probability m/(t + 1)), then xi has a probability of being in S equal to (m/t)(1 − 1/m), since it must have been in S at the previous step and must not be evicted at the current step. Thus, for each i ≤ t, at time t + 1 we have Pr[xi ∈ S] =

1 2 m m m 1 m m + 1− = . 1− t+1 t t+1 t m t+1

The fact that xt+1 is added to S with probability m/(t + 1) concludes the proof. 䊏 Instead of ﬂipping a coin for each element (that requires to generate n random values), the reservoir sampling algorithm randomly generates the number of elements to be skipped before the next element is added to S. Special care is taken to generate these skip numbers, so as to guarantee the same properties that we discussed in Theorem 1 for the na¨ıve coin-tossing approach. The implementation based on skip numbers has the advantage that the number of random values to be generated is the same as the number of updates of the sample S. We refer to the work by Vitter [63] for the details and the analysis of this implementation. We remark that reservoir sampling works well for insert and updates of the incoming data, but runs into difﬁculties if the data contain deletions. In many applications, however, the timeliness of data is important, since outdated items expire and should be no longer used when answering queries. Other sampling techniques have been proposed that address this issue: see, for example, [8,35,52] and the references therein. Another limitation of reservoir sampling derives from the fact that the stream may contain duplicates, and any value occurring frequently in the sample is a wasteful use of the available space: concise sampling overcomes this limitation representing elements in the sample by pairs (value, count). As described by Gibbons and Matias [33], this natural idea can be used to compress the samples and allows it to solve, for example, the top-k problem, where the k most frequent items need to be identiﬁed. In the rest of this section, we provide a concrete example of how sampling can be effectively applied to certain nontrivial streaming problems. However, as we will see in Section 8.4, there also exist classes of problems for which sampling-based approaches are not effective, unless using a prohibitive (almost linear) amount of memory. 8.3.1.2 An Application of Sampling: Frequent Items Following an approach proposed by Manku and Motwani [51], we will now show how to use sampling to address the problem of identifying frequent items in a data stream, that is, items whose frequency exceeds a user-speciﬁed threshold. Intuitively, it should be possible to estimate frequent items by a good sample. The algorithm that we discuss, dubbed

250

ALGORITHMS FOR DATA STREAMS

sticky sampling [51], supports this intuition. The algorithm accepts two user-speciﬁed thresholds: a frequency threshold ϕ ∈ (0, 1), and an error parameter ε ∈ (0, 1) such that ε < ϕ. Let be a stream of n items x1 , ..., xn . The goal is to report all the items whose frequency is at least ϕ n (i.e., there must be no false negatives) no item with frequency smaller than (ϕ − ε)n. We will denote by f (x) the true frequency of an item x, and by fe (x) the frequency estimated by sticky sampling. The algorithm also guarantees small error in individual frequencies; that is, the estimated frequency is less than the true frequency by at most ε n. The algorithm is randomized, and in order to meet the two goals with probability at least 1 − δ, for a user-speciﬁed probability of failure δ ∈ (0, 1), it maintains a sample with expected size 2ε−1 log(ϕ−1 δ−1 ) = 2t. Note that the space is independent of the stream length n. The sample S is a set of pairs of the form (x, fe (x)). In order to handle potentially unbounded streams, the sampling rate r is not ﬁxed, but is adjusted so that the probability 1/r of sampling a stream item decreases as more and more items are considered. Initially, S is empty and r = 1. For each stream item x, if x ∈ S, then fe (x) is increased by 1. Otherwise, x is sampled with rate r, that is, with probability 1/r: if x is sampled, the pair (x, 1) is added to S, otherwise we ignore x and move to the next stream item. After sampling with rate r = 1 the ﬁrst 2t items, the sampling rate increases geometrically as follows: the next 2t items are sampled with rate r = 2, the next 4t items with rate r = 4, the next 8t items with rate r = 8, and so on. Whenever the sampling rate changes, the estimated frequencies of sample items are adjusted so as to keep them consistent with the new sampling rate: for each (x, fe (x)) ∈ S, we repeatedly toss an unbiased coin until the coin toss is successful, decreasing fe (x) by 1 for each unsuccessful toss. We evict (x, fe (x)) from S if fe (x) becomes 0 during this process. Effectively, after each sampling rate doubling, S is transformed to exactly the state it would have been in, if the new rate had been used from the beginning. Upon a frequency items query, the algorithm returns all sample items whose estimated frequency is at least (ϕ − ε)n. The following technical lemma will be useful in the analysis of sticky sampling. Although pretty straightforward, we report the proof for the sake of completeness. Lemma 1 Let r ≥ 2 and let n be the number of stream items considered when the sampling rate is r. Then 1/r ≥ t/n, where t = ε−1 log(ϕ−1 δ−1 ). Proof. It can be easily proved by induction on r that n = rt at the beginning of the phase in which sampling rate r is used. The base step, for r = 2, is trivial: at the beginning S contains exactly 2t elements by construction. During the phase with sampling rate r, as far as the algorithm works, rt new stream elements are considered; thus, when the sampling rate doubles at the end of the phase, we have n = 2rt, as needed to prove the induction step. This implies that during any phase it must be n ≥ rt, which proves the claim. 䊏

251

ALGORITHM DESIGN TECHNIQUES

We can now prove that sticky sampling meets the goals in the deﬁnition of the frequent items problem with probability at least 1 − δ using space independent of n. Theorem 2 [51] For any ε, ϕ, δ ∈ (0, 1), with ε < ϕ, sticky sampling solves the frequent items problems with probability at least 1 − δ using a sample of expected size (2/ε) log(ϕ−1 δ−1 ). Proof. We ﬁrst note that the estimated frequency of a sample element x is an underestimate of the true frequency, that is, fe (x) ≤ f (x). Thus, if the true frequency is smaller than (ϕ − ε)n, the algorithm will not return x, since it must also be fe (x) < (ϕ − ε)n. We now prove that there are no false negatives with probability ≥ 1 − δ. Let k be the number of elements with frequency at least ϕ, and let y1 , ..., yk be those elements. Clearly, it must be k ≤ 1/ϕ. There are no false negatives if and only if all the elements y1 , ..., yk are returned by the algorithm. We now study the probability of the complementary event, proving that it is upper bounded by δ. Pr[∃ false negative] ≤

k

Pr[yi is not returned] =

i=1

k

Pr[fe (yi ) < (ϕ − ε)n].

i=1

Since f (yi ) ≥ ϕ n by deﬁnition of yi , we have fe (yi ) < (ϕ − ε)n if and only if the estimated frequency of yi is underestimated by at least n. Any error in the estimated frequency of an element corresponds to a sequence of unsuccessful coin tosses during the ﬁrst occurrences of the element. The length of this sequence exceeds ε n with probability

1 1− r

ε n

t ε n ≤ 1− ≤ e−t ε , n

where the ﬁrst inequality follows from Lemma 1. Hence, Pr[∃ false negative] ≤ k e−t ε ≤

e−t ε =δ ϕ

by deﬁnition of t. This proves that the algorithm is correct with probability ≥ 1 − δ. It remains to discuss the space usage. The number of stream elements considered at the end of the phase in which sampling rate r is used must be at most 2rt (see the proof of Lemma 1 for details). The algorithm behaves as if each element was sampled with probability 1/r: the expected number of sampled elements is therefore 2t. 䊏 Manku and Motwani also provide a deterministic algorithm for estimating frequent items: this algorithm guarantees no false negatives and returns no false positives with true frequency smaller than (ϕ − ε)n [51]. However, the price paid for being deterministic is that the space usage increases to O((1/ε) log(ε n)). Other works that describe different techniques for tracking frequent items are, for example, Refs. 1,16,22,23,54.

252

8.3.2

ALGORITHMS FOR DATA STREAMS

Sketches

In this section we exemplify the use of sketches as randomized estimators of the frequency moments of a data stream. Let = x1 , ..., xn be a stream of n values taken from a universe U of size u, and let fi , for i ∈ U, be the frequency (number of occurrences) of value i in , that is, fi = |{j : xj = i}|. The kth frequency moment Fk of is deﬁned as Fk =

fik .

i∈U

Frequency moments represent useful statistical information on a data set and are widely used in database applications. In particular, F0 and F1 represent the number of distinct values in the data stream and the length of the stream, respectively. F2 , also known as Gini’s index, provides valuable information about the skew of the data. F∞ , ﬁnally, is related to the maximum frequency element in the data stream, that is, maxi∈U fi . 8.3.2.1 Probabilistic Counting We begin our discussion from the estimation of F0 . The problem of counting the number of distinct values in a data set using small space has been studied since the early 1980s by Flajolet and Martin [29,30], who proposed a hash-based probabilistic counter. We ﬁrst note that a na¨ıve approach to compute the exact value of F0 would use a counter c(i) for each value i of the universe U, and would therefore require O(1) processing time per item, but linear space. The probabilistic counter of Flajolet and Martin [29,30] relies on hash functions to ﬁnd a good approximation of F0 using only O(log u) bits of memory, where u is the size of the universe U. The counter consists of an array C of log u bits. Each stream item is mapped to one of the log u bits by means of the combination of two functions h and t. The hash function h : U → [0, u − 1] is drawn from a set of strongly 2-universal hash functions: it transforms values of the universe into integers sufﬁciently uniformly distributed over the set of binary strings of length log u. The function t, for any integer i, gives the number t(i) of trailing zeros in the binary representation of i. Updates and queries work as follows: Counter update: Upon seeing a stream value x, set C[t(h(x))] to 1. Distinct values query: Let R be the position of the rightmost 1 in the counter C, with 1 ≤ R ≤ log u. Return 2R . Notice that all stream items by the same value will repeatedly set the same counter bit to 1. Intuitively, the fact that h distributes items uniformly over [0, u − 1] and the use of function t guarantee that counter bits are selected in accordance with a geometric distribution; that is, 1/2 of the universe items will be mapped to the ﬁrst counter bit, 1/4 will be mapped to the second counter bit, and so on. Thus, it seems reasonable to expect that the ﬁrst log F0 counter bits will be set to 1 when the stream contains

253

ALGORITHM DESIGN TECHNIQUES

F0 distinct items: this suggests that R, as deﬁned above, yields a good approximation for F0 . We will now give a more formal analysis. We will denote by Zj the number of distinct stream items that are mapped (by the composition of functions t and h) to a position ≥ j. Thus, R is the maximum j such that Zj > 0. Lemma 2 Let Zj be the number of distinct stream items x for which t(h(x)) ≥ j. Then, E[Zj ] = F0 /2j and Var[Zj ] < E[Zj ]. Proof. Let Wx be an indicator random variable whose value is 1 if and only if t(h(x)) ≥ j. Then, by deﬁnition of Zj , Zj =

Wx .

(8.1)

x∈U∩

Note that |U ∩ | = F0 . We now study the probability that Wx = 1. It is not difﬁcult to see that the number of binary strings of length log u that have exactly j trailing zeros, for 0 ≤ j < log u, is 2log u−(j+1) . Thus, the number of strings that have at log u−1 log u−(i+1) least j trailing zeros is 1 + i=j 2 = 2log u−j . Since h distributes items uniformly over [0, u − 1], we have that Pr[Wx = 1] = Pr[t(h(x)) ≥ j] =

2log u−j = 2−j . u

Hence, E[Wx ] = 2−j and Var[Wx ] = E[Wx2 ] − E[Wx ]2 = 2−j − 2−2j = 2−j (1 − 2−j ). We are now ready to compute E[Zj ] and Var[Zj ]. By (8.1) and by linearity of expectation we have 1 1 F0 = j. E[Zj ] = F0 · 1 · j + 0 · 1 − j 2 2 2 Due to pairwise independence (guaranteed by the choice of the hash function h) we have Var[Wx + Wy ] = Var[Wx ] + Var[Wy ] for any x, y ∈ U ∩ and thus Var[Zj ] =

x∈U∩

Var[Wx ] =

F0 2j

1−

1 2j

< F0 2j = E[Zj ].

This concludes the proof. 䊏 Theorem 3 [5,29,30] Let F0 be the exact number of distinct values and let 2R be the output of the probabilistic counter to a distinct values query. For any c > 2, the probability that 2R is not between F0 /c and c F0 is at most 2/c. Proof. Let us ﬁrst study the probability that the algorithm overestimates F0 by a factor of c. We begin by noticing that Zj takes only nonnegative values, and thus we

254

ALGORITHMS FOR DATA STREAMS

can apply Markov’s inequality to estimate the probability that Zj ≥ 1, obtaining Pr[Zj ≥ 1] ≤

F0 E[Zj ] = j, 1 2

(8.2)

where the equality is by Lemma 2. If the algorithm overestimates F0 by a factor of c, then it must exist an index j such that C[j] = 1 and 2j /F0 > c (i.e., j > log2 (c F0 )). By deﬁnition of Zj , this implies Zlog2 (c F0 ) ≥ 1. Thus, Pr[∃j : C[j] = 1 and 2j /F0 > c ] ≤ Pr[ Zlog2 (c F0 ) ≥ 1 ] ≤

F0 1 = , c 2log2 (c F0 )

where the last inequality follows from (8.2). The probability that the algorithm overestimates F0 by a factor of c is therefore at most 1/c. Let us now study the probability that the algorithm underestimates F0 by a factor of 1/c. Symmetrically to the previous case, we begin by estimating the probability that Zj = 0. Since Zj takes only nonnegative values, we have Pr[ Zj = 0 ] = Pr[ |Zj − E[Zj ]| ≥ E[Zj ] ] ≤

2j Var[Zj ] 1 = < 2 E[Zj ] E[Zj ] F0

(8.3)

using Chebyshev inequality and Lemma 2. If the algorithm underestimates F0 by a factor of 1/c, then there must exist an index j such that 2j < F0 /c (i.e., j < log2 (F0 /c)) and C[p] = 0 for all positions p ≥ j. By deﬁnition of Zj , this implies Zlog2 (F0 /c) = 0, and with reasonings similar to the previous case and by using (8.3), we obtain that the probability that the algorithm underestimates F0 by a factor of 1/c is at most 2log2 (F0 /c) /F0 = 1/c. The upper bounds on the probabilities of overestimates and underestimates imply that the probability that 2R is not between F0 /c and c F0 is at most 2/c. 䊏 The probabilistic counter of Flajolet and Martin [29,30] assumes the existence of hash functions with some ideal random properties. This assumption has been more recently relaxed by Alon et al. [5], who adapted the algorithm so as to use simpler linear hash functions. We remark that streaming algorithms for computing a (1 + ε)approximation of the number of distinct items are presented, for example, in the work by Bar-Yossef et al. [11]. 8.3.2.2 Randomized Linear Projections and AMS Sketches We now consider the more general problem of estimating the frequency moments Fk of a data set, for k ≥ 2, focusing on the seminal work by Alon et al. [5]. In order to estimate F2 , Alon et al. introduced a fundamental technique based on the design of small randomized linear projections that summarize some essential properties of the data set. The basic idea of the sketch designed in the work by Alon et al. [5] for estimating F2 is to deﬁne a random variable whose expected value is F2 , and whose variance is relatively small. We follow the description from the work Alon et al. [4].

255

ALGORITHM DESIGN TECHNIQUES

The algorithm computes μ random variables Y1 , ..., Yμ and outputs their median Y as the estimator for F2 . Each Yi is in turn the average of α independent, identically distributed random variables Xij , with 1 ≤ j ≤ α. The parameters μ and α need to be carefully chosen in order to obtain the desired bounds on space, approximation, and probability of error: such parameters will depend on the approximation guarantee λ and on the error probability δ. Each Xij is computed as follows. Select at random a hash function ξ mapping the items of the universe U to {−1, +1}: ξ is selected from a family of 4-wise independent hash functions. Informally, 4-wise independence means that for every four distinct values u1 , ..., u4 ∈ U and for every 4-tuple ε1 , ..., ε4 ∈ {−1, +1}, exactly (1/16)fraction of the hash functions in the family map ui to εi , for i = 1, ..., 4. Given ξ, we deﬁne Zij = u∈U fu ξ(u) and Xij = Zij2 . Notice that Zij can be considered as a random linear projection (i.e., an inner product) of the frequency vector of the values in U with the random vector associated with such values by the hash function ξ. It can be proved that E[Y ] = F2 and that, thanks to averaging of the Xij , each Yi has small variance. Computing Y as the median of Yi allows it to boost the conﬁdence using standard Chernoff bounds. We refer the interested reader to the work by Alon et al. [5] for a detailed proof. We limit here to formalize the statement of the result proved in the work by Alon et al. [5]. Theorem 4 [5] For every k ≥ 1, λ > 0, and δ > 0, there exists a randomized algorithm that computes a number Y that deviates from F2 by more than λF2 with probability at most δ. The algorithm uses only O

log(1/δ) (log u + log n) λ2

memory bits and performs one pass over the data. Let us now consider the case of Fk , for k ≥ 2. The basic idea of the sketch designed in the work by Alon et al. [5] is similar to that described above, but each Xij is now computed by sampling the stream as follows: an index p = pij is chosen uniformly at random in [1, n] and the number r of occurrences of xp in the stream following position p is computed by keeping a counter. Xij is then deﬁned as n(rk − (r − 1)k ). We refer the interested reader to the works by Alon et al. [4–6] for a detailed description of this sketch and for the extension to the case where the stream length n is not known. We limit here to formalize the statement of the result proved in the work by Alon et al. [5]: Theorem 5 [5] For every k ≥ 1, λ > 0 and δ > 0, there exists a randomized algorithm that computes a number Y such that Y deviates from Fk by more than λFk with probability at most δ. The algorithm uses O

k log(1/δ) 1−1/k u (log u + log n) λ2

256

ALGORITHMS FOR DATA STREAMS

memory bits and performs only one pass over the data. √ Notice that Theorem 5 implies that F2 can be estimated using O( (log(1/δ)/λ2 ) u √ (log u + log n)) memory bits: this is worse by a u factor than the bound obtained in Theorem 4. 8.3.3

Techniques for Graph Problems

In this section we focus on techniques that can be applied to solve graph problems in the classical streaming and semi-streaming models. In Section 8.3.4 we will consider results obtained in less restrictive models that provide more powerful primitives for accessing stream data in a nonlocal fashion (e.g., stream-sort). Graph problems appear indeed to be difﬁcult in classical streaming, and only few interesting results have been obtained so far. This is in line with the linear lower bounds on the space × passes product proved in the work by Henzinger et al. [43], even using randomization and approximation. One problem for which sketches could be successfully designed is counting the number of triangles: if the graphs have certain properties, the algorithm presented in the work by Bar-Yossef et al. [10] uses sublinear space. Recently, Cormode and Muthukrishnan [24] studied three fundamental problems on multigraph degree sequences: estimating frequency moments of degrees, ﬁnding the heavy hitter degrees, and computing range sums of degree values. In all cases, their algorithms have space bounds signiﬁcantly smaller than storing complete information. Due to the lower bounds in the work by Henzinger et al. [43], most work has been done in the semistreaming model, in which problems such as distances, spanners, matchings, girth, and diameter estimation have been addressed [27,28,53]. In order to exemplify the techniques used in these works, in the rest of this section we focus on one such result, related to computing maximum weight matchings. 8.3.3.1 Approximating Maximum Weight Matchings Given an edge weighted, undirected graph G(V, E, w), the weighted matching problem is to ﬁnd a matching M ∗ such that w(M ∗ ) = e∈M ∗ w(e) is maximized. We recall that edges in a matching are such that no two edges have a common end point. We now present a one-pass semi-streaming algorithm that solves the weighted matching problem with approximation ratio 1/6; that is, the matching M returned by the algorithm is such that w(M ∗ ) ≤ 6 w(M). The algorithm has been proposed in the work by Feigenbaum et al. [27] and is very simple to describe. Algorithms with better approximation guarantees are described in the work by McGregor [53]. As edges are streamed, a matching M is maintained in main memory. Upon arrival of an edge e, the algorithm considers the set C ⊆ M of matching edges

257

ALGORITHM DESIGN TECHNIQUES

that share an end point with e. If w(e) > 2w(C), then e is added to M while the edges in C are removed; otherwise (w(e) ≤ 2w(C)) e is ignored. Note that, by deﬁnition of matching, the set C of conﬂicting edges has cardinality at most 2. Furthermore, since any matching consists of at most n/2 edges, the space requirement in bits is clearly O(n log n). In order to analyze the approximation ratio, we will use the following notion of replacement tree associated with a matching edge (see also Fig. 8.1). Let e be an edge that belongs to M at the end of the algorithm’s execution: the nodes of its replacement tree Te are edges of graph G, and e is the root of Te . When e has been added to M, it may have replaced one or two other edges e1 and e2 that were previously in M: e1 and e2 are children of e in Te , which can be fully constructed by applying the reasoning recursively. It is easy to upper bound the total weight of nodes of each replacement tree. Lemma 3 Let R(e) be the set of nodes of the replacement tree Te , except for the root e. Then, w(R(e)) ≤ w(e). Proof. The proof is by induction. When e is a leaf in Te (base step), R(e) is empty and w(R(e)) = 0. Let us now assume that e1 and e2 are the children of e in Te (the case of a unique child is similar). By inductive hypothesis, w(e1 ) ≥ w(R(e1 )) and w(e2 ) ≥ w(R(e2 )). Since e replaced e1 and e2 , it must have been w(e) ≥ 2 (w(e1 ) + w(e2 )). Hence, w(e) ≥ w(e1 ) + w(e2 ) + w(R(e1 )) + w(R(e2 )) = w(R(e)). 䊏 a

b

120 d

e

30

f

40

130

(c,f,2) (b,e,10) (h,i,4) (e,f,30) (h,f,50) (e,g,40) (d,e,62) (a,d,120) (d,g,130)

2

10 62

Σ=

c

50 4

g

h

i

(a)

a

b

120

b

2

10 62

d

e

30

f

40

130

50 4

g

(b) a

c

h

i

(c) c

a

b

c

(h,i)

(d,g) (d,e)

d

e

d

f

e

f

(e,f) (b,e)

(c,f)

(d)

g

(e)

h

i

g

h

i

(f)

FIGURE 8.1 (a) A weighted graph and an optimal matching Opt (bold edges); (b) order in which edges are streamed; (c) matching M computed by the algorithm (bold solid edges) and edges in the history H \ M (dashed edges); (d) replacement trees of edges in M; (e) initial charging of the weights of edges in Opt; (f ) charging after the redistribution.

258

ALGORITHMS FOR DATA STREAMS

Theorem 6 [27] In one pass and space O(n log n), the above algorithm constructs a (1/6)-approximate weighted matching M. Proof. Let Opt = {o1 , o2 , ...} be the set of edges in a maximum weight matching and let H = e∈M (R(e) ∪ {e}) be the set of edges that have been part of the matching at some point during the algorithm’s execution (these are the nodes of the replacement trees). We will show an accounting scheme that charges the weight of edges in Opt to edges in H. The charging strategy, for each edge o ∈Opt, is the following: If o ∈ H, we charge w(o) to o itself. If o ∈ H, let us consider the time when o was examined for insertion in M, and let C be the set of edges that share an end point with o and were in M at that time. Since o was not inserted, it must have been |C| ≥ 1 and w(o) ≤ 2 w(C). If C contains only one edge, we charge w(o) to that edge. If C contains two edges e1 and e2 , we charge w(o)w(e1 )/(w(e1 ) + w(e2 )) ≤ 2 w(e1 ) to e1 and w(o)w(e2 )/(w(e1 ) + w(e2 )) ≤ 2 w(e2 ) to e2 . The following two properties hold: (a) the charge of o to any edge e is at most 2 w(e); (b) any edge of H is charged by at most two edges of Opt, one per end point (see also Fig. 8.1). We now redistribute some charges as follows: if an edge o ∈ Opt charges an edge e ∈ H and e gets replaced at some point by an edge e ∈ H that also shares an end point with o, we transfer the charge of o from e to e . With this procedure, property (a) remains valid since w(e ) ≥ w(e). Moreover, o will always charge an incident edge, and thus property (b) also remains true. In particular, each edge e ∈ H \ M will be now charged by at most one edge in Opt: if at some point there are two edges charging e, the charge of one of them will be transferred to the edge of H that replaced e. Thus, only edges in M can be charged by two edges in Opt. By the above discussion we get 2w(e) + 4w(e) = 2w(R(e)) + 4w(e) w(Opt) ≤ e∈M

e∈H\M

≤

e∈M

e∈M

6w(e) = 6w(M),

e∈M

where the ﬁrst equality is by deﬁnition of H and the last inequality is by Lemma 3. 䊏 8.3.4

Simulation of PRAM Algorithms

In this section we show that a variety of problems for which efﬁcient solutions in classical streaming are not known or impossible to obtain can be solved very efﬁciently in the stream-sort model discussed in Section 8.2.3. In particular, we show that parallel algorithms designed in the PRAM model [48] can yield very efﬁcient algorithms in the stream-sort model. This technique is very similar to previous methods developed in the context of external memory management for deriving I/O efﬁcient

ALGORITHM DESIGN TECHNIQUES

259

algorithms (see, e.g., the work by Chiang et al. [19]). We recall that the PRAM is a popular model of parallel computation: it consists of a number of processors (each processor is a standard Random Access Machine) that communicate through a common, shared memory. The computation proceeds in synchronized steps: no processor will proceed with instruction i + 1 before all other processors complete the ith step. Theorem 7 Let A be a PRAM algorithm that uses N processors and runs in time T . Then, A can be simulated in stream-sort in p = O(T ) passes and space s = O(log N). Proof. Let = (1, val1 )(2, val2 ) · · · (M, valM ) be the input stream that represents the memory image given as input to algorithm A, where valj is the value contained at address j, and M = O(N). At each step of algorithm A, processor pi reads one memory cell at address ini , updates its internal state sti , and possibly writes one output cell at address outi . In a preprocessing pass, we append to the N tuples: (p1 , in1 , st1 , out1 ) · · · (pN , inN , stN , outN ), where ini and outi are the cells read and written by pi at the ﬁrst step of algorithm A, respectively, and sti is the initial state of pi . Each step of A can be simulated by performing the following sorting and scanning passes: 1. We sort the stream so that each (j, valj ) is immediately followed by tuples (pi , ini , sti , outi ) such that ini = j; that is, the stream has the form (1, val1 )(pi11 , 1, sti11 , outi11 )(pi12 , 1, sti12 , outi12 ) · · · (2, val2 )(pi21 , 2, sti21 , outi21 )(pi22 , 2, sti22 , outi22 ) · · · ... (M, valM )(piM1 , M, stiM1 , outiM1 )(piM2 , M, stiM2 , outiM2 ) · · · This can be done, for example, by using 2j as sorting key for tuples (j, valj ) and 2ini + 1 as sorting key for tuples (pi , ini , sti , outi ). 2. We scan the stream, performing the following operations: • If we read (j, valj ), we let currval = valj and we write (j, valj ,“old”) to the output stream. • If we read (pi , ini , sti , outi ), we simulate the task performed by processor pi , observing that the value valini that pi would read from cell ini is readily available in currval. Then we write to the output stream (outi , resi ,“new”), where resi is the value that pi would write at address outi , and we write tuple (pi , in i , st i , out i ), where in i and out i are the cells to be read and written at the next step of A, respectively, and st i is the new state of processor pi . 3. Notice that at this point, for each j we have in the stream a triple of the form (j, valj ,“old”), which contains the value of cell j before the parallel step, and possibly one or more triples (j, resi ,“new”), which store the values written by processors to cell j during that step. If there is no “new” value for cell j, we simply drop the “old” tag from (j, valj ,“old”). Otherwise, we keep for cell j

260

ALGORITHMS FOR DATA STREAMS

one of the new triples pruned of the “new” tag, and get rid of the other triples. This can be easily done with one sorting pass, which lets triples by the same j be consecutive, followed by one scanning pass, which removes tags and duplicates. To conclude the proof, we observe that if A performs T steps, then our stream-sort simulation requires p = O(T ) passes. Furthermore, the number of bits of working memory required to perform each processor task simulation and to store currval is s = O(log N). 䊏 Theorem 7 provides a systematic way of constructing streaming algorithms (in the stream-sort model) for several fundamental problems. Prominent examples are list ranking, Euler tour, graph connectivity, minimum spanning tree, biconnected components, and maximal independent set, among others: for these problems there exist parallel algorithms that use a polynomial number of processors and polylogarithmic time (see, e.g., the work by J´aj´a [48]). Hence, according to Theorem 7, these problems can be solved in the stream-sort model within polylogarithmic space and passes. Such bounds essentially match the results obtainable in more powerful computational models for massive data sets, such as the parallel disk model [64]. As observed by Aggarwal et al. [3], this suggests that using more powerful, harder to implement models may not always be justiﬁed. 8.4 LOWER BOUNDS An important technique for proving streaming lower bounds is based on communication complexity lower bounds [43]. A crucial restriction in accessing a data stream is that items are revealed to the algorithm sequentially. Suppose that the solution of a computational problem needs to compare two items directly; one may argue that if the two items are far apart in the stream, one of them must be kept in main memory for long time by the algorithm until the other item is read from the stream. Intuitively, if we have limited space and many distant pairs of items to be compared, then we cannot hope to solve the problem unless we perform many passes over the data. We formalize this argument by showing reductions of communication problems to streaming problems. This allows us to prove lower bounds in streaming based on lower bounds in communication complexity. To illustrate this technique, we prove a lower bound for the element distinctness problem, which clearly implies a lower bound for the computation of the number of distinct items F0 addressed in Section 8.3.2. Theorem 8 Any deterministic or randomized algorithm that decides whether a stream of n items contains any duplicates requires p = (n/s) passes using s bits of working memory. Proof. The proof follows from a two-party communication complexity lower bound for the bit-vector-disjointness problem. In this problem, Alice has an n-bit-vector A and Bob has an n-bit-vector B. They want to know whether A · B > 0, that is, whether there is at least one index i ∈ {1, . . . , n} such that A[i] = B[i] = 1. By a well-known

LOWER BOUNDS

261

communication complexity lower bound [50], Alice and Bob must communicate (n) bits to solve the problem. This results holds also for randomized protocols: any algorithm that outputs the correct answer with high probability must communicate (n) bits. We now show that bit-vector-disjointness can be reduced to the element distinctness streaming problem. The reduction works as follows. Alice creates a stream of items SA containing indices i such that A[i] = 1. Bob does the same for B, that is, he creates a stream of items SB containing indices i such that B[i] = 1. Alice runs a streaming algorithm for element distinctness on SA , then she sends the content of her working memory to Bob. Bob continues to run the same streaming algorithm starting from the memory image received from Alice, and reading items from the stream SB . When the stream is over, Bob sends his memory image back to Alice, who starts a second pass on SA , and so on. At each pass, they exchange 2s bits. At the end of the last pass, the streaming algorithm can answer whether the stream obtained by concatenating SA and SB contains any duplicates; since this stream contains duplicates if and only if A · B > 0, this gives Alice and Bob a solution to the problem. Assume by contradiction that the number of passes performed by Alice and Bob over the stream is o(n/s). Since at each pass they communicate 2s bits, then the total number of bits sent between them over all passes is o(n/s) · 2s = o(n), which is a contradiction as they must communicate (n) bits as noticed above. Thus, any algorithm for the element distinctness problem that uses s bits of working memory requires p = (n/s) passes. 䊏 Lower bounds established in this way are information-theoretic, imposing no restrictions on the computational power of the algorithms. The general idea of reducing a communication complexity problem to a streaming problem is very powerful, and allows it to prove several streaming lower bounds. Those range from computing statistical summary information such as frequency moments [5] to graph problems such as vertex connectivity [43], and imply that for many fundamental problems there are no one-pass exact algorithms with a working memory signiﬁcantly smaller than the input stream. A natural question is whether approximation can make a signiﬁcant difference for those problems, and whether randomization can play any relevant role. An interesting observation is that there are problems, such as the computation of frequency moments, for which neither randomization nor approximation is powerful enough for getting a solution in one pass and sublinear space, unless they are used together. 8.4.1

Randomization

As we have seen in the proof of Theorem 8, lower bounds based on the communication complexity of the bit-vector-disjointness problem hold also for randomized algorithms, which yields clear evidence that randomization without approximation may not help. The result of Theorem 8 can be generalized for all one-pass frequency moments. In particular, it is possible to prove that any randomized algorithm for computing the frequency moments that outputs the correct result with probability higher

262

ALGORITHMS FOR DATA STREAMS

than 1/2 in one pass must use (n) bits of working memory. The theorem can be proven using communication complexity tools. Theorem 9 [6] For any nonnegative integer k = 1, any randomized algorithm that makes one pass over a sequence of at least 2n items drawn from the universe U = {1, 2, . . . , n} and computes Fk exactly with probability > 1/2 must use (n) bits of working memory.

8.4.2

Approximation

Conversely, we can show that any deterministic algorithm for computing the frequency moments that approximates the correct result within a constant factor in one pass must use (n) bits of working memory. Differently from the lower bounds addressed earlier in this section, we give a direct proof of this result without resorting to communication complexity arguments. Theorem 10 [6] For any nonnegative integer k = 1, any deterministic algorithm that makes one pass over a sequence of at least n/2 items drawn from the universe U = {1, 2, . . . , n} and computes a number Y such that |Y − Fk | ≤ Fk /10 must use (n) bits of working memory. Proof. The idea of the proof is to show that if the working memory is not large enough, for any deterministic algorithm (which does not use random bits) there exist two subsets S1 and S2 in a suitable collection of subsets of U such that the memory image of the algorithm is the same after reading either S1 or S2 ; that is, S1 and S2 are indistinguishable. As a consequence, the algorithm has the same memory image after reading either S1 : S1 or S2 : S1 , where A : B denotes the stream of items that starts with the items of A and ends with the items of B. If S1 and S2 have a small intersection, then the two streams S1 : S1 and S2 : S1 must have rather different values of Fk , and the algorithm must necessarily make a large error on estimating Fk on at least one of them. We now give more details on the proof assuming that k ≥ 2. The case k = 0 can be treated symmetrically. Using a standard construction in coding theory, it is possible to build a family F of 2(n) subsets of U of size n/4 each such that any two of them have at most n/8 common items. Notice that, for every set in F, the frequency of any value of U in that set is either 0 or 1. Fix a deterministic algorithm and let s < log2 F be the size of its working memory. Since the memory can assume at most 2s different conﬁgurations and we have |F| > 2s possible distinct input sets in F, then by the pigeonhole principle there must be two input sets S1 , S2 ∈ F such that the memory image of the algorithm after reading either one of them is the same. Now, if we consider the two streams S1 : S1 and S2 : S1 , the memory image of the algorithm after processing either one of them is the same. Since by construction of F, S1 and S2 contain n/4 items each, and have at most n/8 items in common, then

263

LOWER BOUNDS

Each of the n/4 distinct items in S1 : S1 has frequency 2, thus FkS1 :S1 =

n

fik = 2k ·

i=1

n . 4

If S1 and S2 have exactly n/8 items in common, then S2 : S1 contains exactly n/8 + n/8 = n/4 items with frequency 1 and n/8 items with frequency 2. Hence, FkS2 :S1 =

n

fik =

i=1

n n + 2k · . 4 8

Notice that, for k ≥ 2, FkS2 :S1 can only decrease as |S1 ∩ S2 | decreases, and therefore we can conclude that FkS2 :S1 ≤

n n + 2k · . 4 8

To simplify the notation, let A = FkS2 :S1 and B = FkS1 :S1 . The maximum relative error performed by the algorithm on either input S2 : S1 or input S1 : S1 is

|Y − A| |Y − B| , . max A B In order to prove that the maximum relative error is always ≥ 1/10, it is sufﬁcient to show that |Y − B| 1 < B 10

⇒

|Y − A| 1 ≥ . A 10

(8.4)

Let C = n/4 + 2k · n/8. For k ≥ 2, it is easy to check that A ≤ C ≤ B = 2k · n/4. Moreover, the maximum relative error obtained for any Y < A is larger than the maximum relative error obtained for Y = A (similarly for Y > B): thus, the value of Y that minimizes the relative error is such that A ≤ Y ≤ B. Under this hypothesis, |Y − B| = B − Y and |Y − A| = Y − A. With simple calculations, we can show that proving (8.4) is equivalent to proving that Y>

9 B 10

⇒

Y≥

11 A. 10

Notice that C = n/4 + B/2. Using this fact, it is not difﬁcult to see that 9B ≥ 11C for any k ≥ 2, and therefore the above implication is always satisﬁed since C ≥ A. Since the maximum relative error performed by the algorithm on either input S1 : S1 or input S2 : S1 is at least 1/10, we can conclude that if we use fewer than log2 F = (n) memory bits, there is an input on which the algorithm outputs a value Y such that |Y − Fk | > Fk /10, which proves the claim. 䊏

264

8.4.3

ALGORITHMS FOR DATA STREAMS

Randomization and Approximation

A natural approach that combines randomization and approximation would be to use random sampling to get an estimator of the solution. Unfortunately, this may not always work: as an example, Charikar et al. [15] have shown that estimators based on random sampling do not yield good results for F0 . Theorem 11 [15] Let E be a (possibly adaptive and randomized) estimator of F0 that examines at most r items in a set of n items and let err = max{E/F0 , F0 /E} be the error of the estimator. Then, for any p > 1/er , there is a choice of the set of items √ such that err ≥ ((n − r)/2r) ln(1/p) with probability at least p. The result of Theorem 11 states that no good estimator can be obtained if we only examine a fraction of the input. On the contrary, as we have seen in Section 8.3.2, hashing techniques that examine all items in the input allow it to estimate F0 within an arbitrary ﬁxed error bound with high probability using polylogarithmic working memory space for any given data set. We notice that, while the ideal goal of a streaming algorithm is to solve a problem using a working memory of size polylogarithmic in the size of the input stream, for some problems this is impossible even using approximation and randomization, as shown in the following theorem from the work by Alon et al. [6]. Theorem 12 [6] For any ﬁxed integer k > 5, any randomized algorithm that makes one pass over a sequence of at least n items drawn from the universe U = {1, 2, . . . , n} and computes an approximate value Y such that |Y − Fk | > Fk /10 with probability < 1/2 requires at least (n1−5/k ) memory bits. Theorem 12 holds in a streaming scenario where items are revealed to the algorithm in an online manner and no assumptions are made on the input. We ﬁnally notice that in the same scenario there are problems for which approximation and randomization do not help at all. A prominent example is given by the computation of F∞ , the maximum frequency of any item in the stream. Theorem 13 [6] Any randomized algorithm that makes one pass over a sequence of at least 2n items drawn from the universe U = {1, 2, . . . , n} and computes an approximate value Y such that |Y − F∞ | ≥ F∞ /3 with probability < 1/2 requires at least (n) memory bits.

8.5 SUMMARY In this chapter we have addressed the emerging ﬁeld of data stream algorithmics, providing an overview of the main results in the literature and discussing computational models, applications, lower bound techniques, and tools for designing efﬁcient algorithms. Several important problems have been proven to be efﬁciently solvable

REFERENCES

265

despite the strong restrictions on the data access patterns and memory requirements of the algorithms that arise in streaming scenarios. One prominent example is the computation of statistical summaries such as frequency moments, histograms, and wavelet coefﬁcient, which are of great importance in a variety of applications including network trafﬁc analysis and database optimization. Other widely studied problems include norm estimation, geometric problems such as clustering and facility location, and graph problems such as connectivity, matching, and distances. From a technical point of view, we have discussed a number of important tools for designing efﬁcient streaming algorithms, including random sampling, probabilistic counting, hashing, and linear projections. We have also addressed techniques for graph problems and we have shown that extending the streaming paradigm with a sorting primitive yields enough power for solving a variety of problems in external memory, essentially matching the results obtainable in more powerful computational models for massive data sets. Finally, we have discussed lower bound techniques, showing that tools from the ﬁeld of communication complexity can be effectively deployed for proving strong streaming lower bounds. We have discussed the role of randomization and approximation, showing that for some problems neither one of them yields enough power, unless they are used together. We have also shown that other problems are intrinsically hard in a streaming setting even using approximation and randomization, and thus cannot be solved efﬁciently unless we consider less restrictive computational models.

ACKNOWLEDGMENTS We are indebted to Alberto Marchetti-Spaccamela for his support and encouragement, and to Andrew McGregor for his very thorough reading of this survey. This work has been partially supported by the Sixth Framework Programme of the EU under Contract IST-FET 001907 (“DELIS: Dynamically Evolving Large Scale Information Systems”) and by MIUR, the Italian Ministry of Education, University and Research, under Project ALGO-NEXT (“Algorithms for the Next Generation Internet and Web: Methodologies, Design and Experiments”).

REFERENCES 1. Agrawal D, Metwally A, El Abbadi, A. Efﬁcient computation of frequent and top-k elements in data stream. Proceedings of the 10th International Conference on Database Theory; 2005. p 398–412. 2. Abello J, Buchsbaum A, Westbrook JR. A functional approach to external graph algorithms. Algorithmica 2002;32(3):437–458. 3. Aggarwal G, Datar M, Rajagopalan S, Ruhl M. On the streaming model augmented with a sorting primitive. Proceedings of the 45th Annual IEEE Symposium on Foundations of Computer Science (FOCS’04); 2004.

266

ALGORITHMS FOR DATA STREAMS

4. Alon N, Gibbons P, Matias Y, Szegedy M. Tracking join and self-join sizes in limited storage. Proceedings of the 18th ACM Symposium on Principles of Database Systems (PODS’99); 1999. p 10–20. 5. Alon N, Matias Y, Szegedy M. The space complexity of approximating the frequency moments. Proceedings of the 28th Annual ACM Symposium on Theory of Computing (STOC’96). ACM Press: 1996. p 20–29. 6. Alon N, Matias Y, Szegedy M. The space complexity of approximating the frequency moments. J Comput Syst Sci 1999; 58(1):137–147. 7. Babcock B, Babu S, Datar M, Motwani R, Widom J. Models and issues in data stream systems. Proceedings of the 21st ACM Symposium on Principles of Database Systems (PODS’02); 2002. p 1–16. 8. Babcock B, Datar M, Motwani R. Sampling from a moving window over streaming data. Proceedings of the 13th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA’02); 2002. p 633–634. 9. Bar-Yossef Z, Jayram T, Kumar R, Sivakumar D. Information statistics approach to data stream and communication complexity. Proceedings of the 43rd Annual IEEE Symposium on Foundations of Computer Science (FOCS’02); 2002. 10. Bar-Yossef Z, Kumar R, Sivakumar D. Reductions in streaming algorithms, with an application to counting triangles in graphs. Proceedings of the 13th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA’02); 2002. p 623–632. 11. Bar-Yossef Z, Jayram T, Kumar R, Sivakumar D, Trevisan L. Counting distinct elements in a data stream. Proceedings of the 6th International Workshop on Randomization and Approximation Techniques in Computer Science; 2002. p 1–10. 12. Bhuvanagiri L, Ganguly S, Kesh D, Saha C. Simpler algorithm for estimating frequency moments of data streams. Proceedings of the 17th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA’06); 2006. p 708–713. 13. Buriol L, Frahling G, Leonardi S, Marchetti-Spaccamela A, Sohler C. Counting triangles in data streams. Proceedings of the 25th ACM Symposium on Principles of Database Systems (PODS’06); 2006. p 253–262. 14. Chakrabarti A, Khot S, Sun X. Near-optimal lower bounds on the multi-party communication complexity of set disjointness. Proceedings of the IEEE Conference on Computational Complexity; 2003. p 107–117. 15. Charikar M, Chaudhuri S, Motwani R, Narasayya V. Towards estimation error guarantees for distinct values. Proceedings of the 19th ACM Symposium on Principles of Database Systems (PODS’00); 2000. p 268–279. 16. Charikar M, Chen K, Farach-Colton M. Finding frequent items in data streams. Proceedings of the 29th International Colloquium on Automata, Languages and Programming (ICALP’02); 2002. p 693–703. 17. Charikar M, O’Callaghan L, Panigrahy R. Better streaming algorithms for clustering problems. Proceedings of the 35th Annual ACM Symposium on Theory of Computing (STOC’03); 2003. 18. Chaudhuri S, Motwani R, Narasayya V. Random sampling for histogram construction: How much is enough? Proceedings of the ACM SIGMOD International Conference on Management of Data; 1998. p 436–447.

REFERENCES

267

19. Chiang Y, Goodrich MT, Grove EF, Tamassia R, Vengroff DE, Vitter JS. External-memory graph algorithms. Proceedings of the 6th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA’95); 1995. p 139–149. 20. Coppersmith D, Kumar R. An improved data stream algorithm for frequency moments. Proceedings of the 15th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA’04); 2004. p 151–156. 21. Cormode G, Muthukrishnan S. Estimating dominance norms on multiple data streams. Proceedings of the 11th Annual European Symposium on Algorithms (ESA’03); 2003. p 148–160. 22. Cormode G, Muthukrishnan S. What is hot and what is not: Tracking most frequent items dynamically. Proceedings of the 22nd ACM Symposium on Principles of Database Systems (PODS’03); 2003. 23. Cormode G, Muthukrishnan S. An improved data stream summary: the count-min sketch and its applications. J Algorithms 2005;55(1):58–75. 24. Cormode G, Muthukrishnan S. Space efﬁcient mining of multigraph streams. Proceedings of the 24th ACM Symposium on Principles of Database Systems (PODS’05); 2005. 25. Demetrescu C, Finocchi I, Ribichini A. Trading off space for passes in graph streaming problems. Proceedings of the 17th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA’06); 2006. p 714–723. 26. Elkin M, Zhang J. Efﬁcient algorithms for constructing (1 + , β)-spanners in the distributed and streaming models. Proceedings of the 23rd Annual ACM Symposium on Principles of Distributed Computing (PODC’04); 2004. p 160–168. 27. Feigenbaum J, Kannan S, McGregor A, Suri S, Zhang J. On graph problems in a semistreaming model. Proceedings of the 31st International Colloquium on Automata, Languages and Programming (ICALP’04); 2004. 28. Feigenbaum J, Kannan S, McGregor A, Suri S, Zhang J. Graph distances in the streaming model: the value of space. Proceedings of the 16th ACM/SIAM Symposium on Discrete Algorithms (SODA’05); 2005. p 745–754. 29. Flajolet P, Martin GN. Probabilistic counting. Proceedings of the 24th Annual Symposium on Foundations of Computer Science; 1983. p 76–82. 30. Flajolet P, Martin GN. Probabilistic counting algorithms for database applications. J Comput Syst Sci 1985;31(2):182–209. 31. Frahling G, Indyk P, Sohler C. Sampling in dynamic data streams and applications. Proceedings of the 21st ACM Symposium on Computational Geometry; 2005. p 79–88. 32. Frahling G, Sohler C. Coresets in dynamic geometric data streams. Proceedings of the 37th Annual ACM Symposium on Theory of Computing (STOC’05); 2005. 33. Gibbons PB, Matias Y. New sampling-based summary statistics for improving approximate query answers. Proceedings of the ACM SIGMOD International Conference on Management of Data; 1998. 34. Gibbons PB, Matias Y. Synopsis data structures for massive data sets. In: External Memory Algorithms. DIMACS Series in Discrete Mathematics and Theoretical Computer Science. Volume 50. American Mathematical Society; 1999. p 39–70. 35. Gibbons PB, Matias Y, Poosala V. Fast incremental maintenance of approximate histograms. Proceedings of 23rd International Conference on Very Large Data Bases (VLDB’97); 1997.

268

ALGORITHMS FOR DATA STREAMS

36. Gilbert A, Kotidis Y, Muthukrishnan S, Strauss M. How to summarize the universe: dynamic maintenance of quantiles. Proceedings of 28th International Conference on Very Large Data Bases (VLDB’02); 2002. p 454–465. 37. Gilbert AC, Guha S, Indyk P, Kotidis Y, Muthukrishnan S, Strauss M. Fast, small-space algorithms for approximate histogram maintenance. Proceedings of the 34th ACM Symposium on Theory of Computing (STOC’04); 2002. p 389–398. 38. Gilbert AC, Kotidis Y, Muthukrishnan S, Strauss M. Surﬁng wavelets on streams: one-pass summaries for approximate aggregate queries. Proceedings of 27th International Conference on Very Large Data Bases (VLDB’01); 2001. p 79–88. 39. Golab L, Ozsu MT. Data stream management issues—a survey. Technical Report No. TR CS-2003-08. School of Computer Science, University of Waterloo; 2003. 40. Guha S, Indyk P, Muthukrishnan S, Strauss M. Histogramming data streams with fast peritem processing. Proceedings of the 29th International Colloquium on Automata, Languages and Programming (ICALP’02); 2002. p 681–692. 41. Guha S, Koudas N, Shim K. Data streams and histograms. Proceedings of the 33rd Annual ACM Symposium on Theory of Computing (STOC’01); 2001. p 471–475. 42. Guha S, Mishra N, Motwani R, O’Callaghan L. Clustering data streams. Proceedings of the 41st Annual IEEE Symposium on Foundations of Computer Science (FOCS’00); 2000. p 359–366. 43. Henzinger M, Raghavan P, Rajagopalan S. Computing on data streams. In: External Memory Algorithms. DIMACS Series in Discrete Mathematics and Theoretical Computer Science. Volume 50. American Mathematical Society; 1999. 107–118. 44. Indyk P. Stable distributions, pseudorandom generators, embeddings and data stream computation. Proceedings of the 41st Annual IEEE Symposium on Foundations of Computer Science (FOCS’00); 2000. p 189–197. 45. Indyk P. Algorithms for dynamic geometric problems over data streams. Proceedings of the 36th Annual ACM Symposium on Theory of Computing (STOC’04); 2004. p 373–380. 46. Indyk P, Woodruff D. Tight lower bounds for the distinct elements problem. Proceedings of the 44th Annual IEEE Symposium on Foundations of Computer Science (FOCS’03); 2003. 47. Indyk P, Woodruff D. Optimal approximations of the frequency moments. Proceedings of the 37th Annual ACM Symposium on Theory of Computing (STOC’05); 2005. 48. J´aj´a J. An Introduction to Parallel Algorithms. Addison-Wesley; 1992. 49. Jowhari H, Ghodsi M. New streaming algorithms for counting triangles in graphs. Proceedings of the 11th Annual International Conference on Computing and Combinatorics (COCOON’05); 2005. p 710–716. 50. Kushilevitz E, Nisan N. Communication Complexity. Cambridge University Press; 1997. 51. Manku GS, Motwani R. Approximate frequency counts over data streams. Proceedings 28th International Conference on Very Large Data Bases (VLDB’02); 2002. p 346–357. 52. Matias Y, Vitter JS, Wang M. Dynamic maintenance of wavelet-based histograms. Proceedings of 26th International Conference on Very Large Data Bases (VLDB’00); 2000. 53. McGregor A. Finding matchings in the streaming model. Proceedings of the 8th International Workshop on Approximation Algorithms for Combinatorial Optimization Problems (APPROX’05), LNCS 3624; 2005. p 170–181.

REFERENCES

269

54. Misra J, Gries D. Finding repeated elements. Sci Comput Program 1982;2:143–152. 55. Morris R. Counting large numbers of events in small registers. Commun ACM 1978;21(10):840–842. 56. Munro I, Paterson M. Selection and sorting with limited storage. Theor Comput Sci 1980; 12:315–323. A preliminary version appeared in IEEE FOCS’78. 57. Muthukrishnan S. Data streams: algorithms and applications. Technical report; 2003. Available at http://athos.rutgers.edu/∼muthu/stream-1-1.ps. 58. Muthukrishnan S, Strauss M. Maintenance of multidimensional histograms. Proceedings of the FSTTCS; 2003. p 352–362. 59. Muthukrishnan S, Strauss M. Rangesum histograms. Proceedings of the 14th Annual ACMSIAM Symposium on Discrete Algorithms (SODA’03); 2003. 60. Muthukrishnan S, Strauss M. Approximate histogram and wavelet summaries of streaming data. Technical report, DIMACS TR 2004-52; 2004. 61. Ruhl M. Efﬁcient algorithms for new computational models. Ph.D. thesis. Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology; 2003. 62. Saks M, Sun X. Space lower bounds for distance approximation in the data stream model. Proceedings of the 34th Annual ACM Symposium on Theory of Computing (STOC’02); 2002. p 360–369. 63. Vitter JS. Random sampling with a reservoir. ACM Trans Math Software 1995;11(1):37–57. 64. Vitter JS. External memory algorithms and data structures: dealing with massive data. ACM Comput Surv 2001;33(2):209–271.

CHAPTER 9

Applying Evolutionary Algorithms to Solve the Automatic Frequency Planning Problem FRANCISCO LUNA, ENRIQUE ALBA, ANTONIO J. NEBRO, PATRICK MAUROY, and SALVADOR PEDRAZA

9.1 INTRODUCTION The global system for mobile communications (GSM) [14] is an open, digital cellular technology used for transmitting mobile voice and for data services. GSM is also referred to as 2G, because it represents the second generation of this technology, and it is certainly the most successful mobile communication system. Indeed, by mid-2006 GSM services are in use by more than 1.8 billion subscribers across 210 countries, representing approximately 77 percent of the world’s cellular market. GSM differs from the ﬁrst-generation wireless systems in that it uses digital technology and frequency division multiple access/time division multiple access (FDMA/TDMA) transmission methods. It is also widely accepted that the Universal Mobile Telecommunication system (UMTS) [15], the third-generation mobile telecommunication system, will coexist with the enhanced releases of the GSM standard (GPRS [9] and EDGE [7]) at least in the ﬁrst phases. Therefore, GSM is expected to play an important role as a dominating technology for many years. The success of this multiservice cellular radio system lies in efﬁciently using the scarcely available radio spectrum. GSM uses frequency division multiplexing and time division multiplexing schemes to maintain several communication links “in parallel.” The available frequency band is slotted into channels (or frequencies) that have to be allocated to the elementary transceivers (TRXs) installed in the base stations of the network. This problem is known as the automatic frequency planning (AFP), frequency assignment problem (FAP), or channel assignment problem (CAP). Several different problem types are subsumed under these general terms and many mathematical models have been proposed since the late 1960s [1,6,12]. This chapter, 1 http://www.wirelessintelligence.com/.

Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

271

272

APPLYING EAs TO SOLVE THE AFP PROBLEM

however, is focused on concepts and models that are relevant for current GSM frequency planning and not on simpliﬁed models of the abstract problem. In GSM, a network operator has usually a small number of frequencies (few dozens) available to satisfy the demand of several thousands of TRXs. A reuse of these frequencies is therefore unavoidable. However, reusing frequencies is limited by interferences that could lead the quality of service (QoS) for subscribers to be reduced down to unsatisfactory levels. The automatic generation of frequency plans in real GSM networks [5] is a very important task for present GSM operators not only in the initial deployment of the system, but also in the subsequent expansions or modiﬁcations of the network, solving unpredicted interference reports, and/or handling anticipated scenarios (e.g., an expected increase in the trafﬁc demand in some areas). This optimization problem is a generalization of the graph coloring problem, and thus it is an NP-hard problem [10]. As a consequence, using exact algorithms to solve real-sized instances of AFP problems is not practical, and therefore other approaches are required. Many different methods have been proposed in the literature [1], and among them, metaheuristic algorithms have proved to be particularly effective. Metaheuristics [3,8] are stochastic algorithms that sacriﬁce the guarantee of ﬁnding optimal solutions for the sake of (hopefully) getting accurate (also optimal) ones in a reasonable time. This fact is even more important in commercial tools, in which the GSM operator cannot wait very long times for a frequency plan (e.g., several weeks). Among the existing metaheuristic techniques, evolutionary algorithms (EAs) [2] have been widely used [6]. EAs work iteratively on a population of individuals. Every individual is the encoded version of a tentative solution to which a ﬁtness value is assigned indicating its suitability to the problem. The canonical algorithm applies stochastic operators such as selection, crossover (merging two or more parents to yield one or more offsprings), and mutation (random alterations of the problem variables) on an initial population in order to compute a whole generation of new individuals. However, it has been reported in the literature that crossover operators do not work properly for this problem [4,17]. In this scenario, our algorithmic proposal is a fast and accurate (1 + 10) EA (see the work by Schwefel [16] for details on this notation) in which recombination of individuals is not performed. The main contributions of this chapter are the following: • We have developed and analyzed a new (1 + 10) EA. Several seeding methods as well as several mutation operators have been proposed. • The evaluation of the algorithm has been performed by using a real-world instance provided by Optimi Corp.TM This is a currently operating GSM network in which we are using real trafﬁc data, accurate models for all the system components (signal propagation, TRX, locations, etc.), and actual technologies such as frequency hopping. This evaluation of the tentative frequency plans is carried out with a powerful commercial simulator that enables users to simulate and analyze those plans prior to implementation in a real environment. • Results show that this simple algorithm is able to compute accurate frequency plans, which can be directly deployed in a real GSM network.

273

AUTOMATIC FREQUENCY PLANNING IN GSM

The chapter is structured as follows. In the next section, we provide the reader with some details on the frequency planning in GSM networks. Section 9.3 describes the algorithm proposed along with the different genetic operators used. The results of the experimentation are analyzed in Section 9.4. Finally, conclusions and future lines of research are discussed in the last section.

9.2 AUTOMATIC FREQUENCY PLANNING IN GSM This section is devoted to presenting some details on the frequency planning task for a GSM network. We ﬁrst provide the reader with a brief description of the GSM architecture. Next, we give the relevant concepts to the frequency planning problem that will be used along this chapter. 9.2.1

The GSM System

An outline of the GSM network architecture is shown in Figure 9.1. The solid lines connecting components carry both trafﬁc information (voice or data) and the “inband” signaling information. The dashed lines are signaling lines. The information exchanged over these lines is necessary for supporting user mobility, network features,

VLR BTS D

B

BSC

HLR

MSC

BTS

C AUC

BSC

EIR

E

BTS

F

MSC

VLR

BTS

PSTN Um interface

A-Bis interface

B,C,D,E,F –– MAP interfaces

A interface

BTS - Base station BSC - Base station contoller MSC - Mobile switching center VLR - Visitor location register HLR - Home location register AUC - Authentification center EIR - Equipment identity register

FIGURE 9.1 Outline of the GSM network architecture.

274

APPLYING EAs TO SOLVE THE AFP PROBLEM

operation and maintenance, authentication, encryption, and many other functions necessary for the network’s proper operation. Figure 9.1 shows the different network components and interfaces within a GSM network. As it can be seen, GSM networks are built out of many different components. The most relevant ones to frequency planning are brieﬂy described next. 9.2.1.1 Mobile Terminals Mobile terminals are the (only) part of the system’s equipment that the user is aware of. Usually, the mobile terminal is designed in the form of a phone. The GSM mobile phone is designed as a unity of two parts that are both functionally and physically separated: 1. Hardware and software speciﬁc to the GSM radio interface. 2. Subscriber identity module (SIM). The SIM is a removable part of the mobile terminal that stores a subscriber’s unique identiﬁcation information. The SIM allows the subscriber to access the network regardless of the particular mobile station being used. 9.2.1.2 Base Transceiver Station (BTS) In essence, the BTS is a set of TRXs. In GSM, one TRX is shared by up to eight users in TDMA mode. The main role of a TRX is to provide conversion between the digital trafﬁc data on the network side and radio communication between the mobile terminal and the GSM network. The site at which a BTS is installed is usually organized in sectors: one to three sectors are typical. Each sector deﬁnes a cell. A single GSM BTS can host up to 16 TRXs. 9.2.1.3 Base Station Controller (BSC) The BSC plays a role of a small digital exchange station with some mobility-speciﬁc tasks and it has a substantial switching capability. It is responsible for intra-BTS functions (e.g., allocation and release of radio channels), as well as for most processing involving inter-BTS handovers. 9.2.1.4 Other Components Every BSC is connected to one mobile service switching center (MSC), and the core network interconnects the MSC core network MSCs. Specially equipped gateway MSCs (GMSCs) interface with other telephony and data networks. The home location registers (HLRs) and the visitors location registers (VLRs) are database systems, which contain VLR subscriber data and facilitate mobility management. Each gateway MSC consults its home location register if an incoming call has to be routed to a mobile terminal. The HLR is also used in the authentication of the subscribers together with the authentication center (AuC). 9.2.2

Automatic Frequency Planning

The frequency planning is the last step in the layout of a GSM network. Prior to tackling this problem, the network designer has to address some other issues: where to install the BTSs, how to dimension signaling propagation parameters of the antennas (tilt, azimuth, etc.), how to connect BTSs to BSCs, or how to connect MSCs among

AUTOMATIC FREQUENCY PLANNING IN GSM

275

each other and to the BSCs [13]. Once the sites for the BTSs are selected and the sector layout is decided, the number of TRXs to be installed per sector has to be ﬁxed. This number depends on the trafﬁc demand that the corresponding sector has to support. The result from this process is a quantity of TRXs per cell. A channel has to be allocated to every TRX and this is the main goal of the automatic frequency planning [5]. Essentially, three kinds of allocation exist: ﬁxed channel allocation (FCA), dynamic channel allocation (DCA), and hybrid channel allocation. In FCA, the channels are permanently allocated to each TRX, while in DCA the channels are allocated dynamically upon request. Hybrid channel allocation (HCA) schemes combine FCA and DCA. Neither DCA nor HCA are supported in GSM, so we only consider here FCA. We now explain the most important parameters to be taken into account in GSM frequency planning. Let us consider the example network shown in Figure 9.2, in which each site has three installed sectors (e.g., site A operates A1, A2, and A3). The ﬁrst issue that we want to remark is the implicit topology that results from the previous steps in the network design. In this topology, each sector has an associated list of neighbors containing the possible handover candidates for the mobile residing

FIGURE 9.2 An example of GSM network.

276

APPLYING EAs TO SOLVE THE AFP PROBLEM

in a speciﬁc cell. These neighbors are further distinguished into ﬁrst-order (those that can potentially provoke strong interference to the serving sector) and secondorder neighbors. In Figure 9.2, A2 is the serving sector and the ﬁrst-order neighbors deﬁned are A1, A3, C2, D1, D2, E2, F 3, G1, G2, and B1 , whereas the second-order neighbors coming from C2 are F 1, F 2, C1, C3, D2 , D3 , A3 , B1 , B3 , G1 , G3 , and E1 . As stated before, each sector in a site deﬁnes a cell; the number of TRXs installed in each cell depends on the trafﬁc demand. A valid channel from the available spectrum has to be allocated to each TRX. Owing to technical and regulatory restrictions, some channels in the spectrum may not be available in every cell. Such channels are called locally blocked and they can be speciﬁed for each cell. Each cell operates one broadcast control channel (BCCH), which broadcasts cell organization information. The TRX allocating the BCCH can also carry user data. When this channel does not meet the trafﬁc demand, some additional TRXs have to be installed to which new dedicated channels are assigned for trafﬁc data. These are called trafﬁc channels (TCHs). In GSM, signiﬁcant interference may occur if the same or adjacent channels are used in neighboring cells. Correspondingly, they are named co-channel and adjchannel interference. Many different constraints are deﬁned to avoid strong interference in the GSM network. These constraints are based on how close the channels assigned to a pair of TRXs may be. These are called separation constraints, and they seek to ensure that there is proper transmission and reception at each TRX and/or that the call handover between cells is supported. Several sources of constraint separation exist: co-site separation, when two or more TRXs are installed in the same site, or co-cell separation, when two TRXs serve the same cell (i.e., they are installed in the same sector). This is intentionally an informal description of the automatic frequency problem in GSM networks. It is out of the scope of this chapter to propose a precise model of the problem, since we use a proprietary software that is aware of all these concepts, as well as the consideration of all the existing advanced techniques, such as frequency hopping, power control, discontinuous transmission, and so on [5], developed for efﬁciently using the scarce frequency spectrum available in GSM.

9.3 EAs FOR SOLVING THE AFP PROBLEM EAs have been widely used for solving the many existing ﬂavors of the frequency assignment problem [1,5,6,11]. However, it has been shown that well-known crossover operators such as single-point crossover do not perform well on this problem [4]. Indeed, it does not make sense for a frequency planning to randomly exchange two different, possibly nonrelated assignments. Our approach here is to use an (1 + 10) EA, in which the recombination operator is not required. In the following, we ﬁrst describe the generic (μ + λ) EA. The solution encoding used, the ﬁtness function, and several proposals for generating the initial solutions and the perturbing individuals are discussed afterward.

EAs FOR SOLVING THE AFP PROBLEM

277

FIGURE 9.3 Pseudocode of the (μ + λ) EA.

9.3.1

(μ + λ) Evolutionary Algorithm

This optimization technique ﬁrst generates μ initial solutions. Next, the algorithm perturbs and evaluates these μ individuals at each iteration, from which λ new ones are obtained. Then, the best μ solutions taken from the μ + λ individuals are moved to the next iteration. An outline of the algorithm is shown in Figure 9.3. Other works using this algorithmic approach for the AFP problem can be found in works by Dorne and Hao [4] and Vidyarthi et al. [18]. As stated before, the conﬁguration used in this chapter for μ and λ is 1 and 10, respectively. This means that 10 new solutions are generated from single initial random one, and the best from the 11 is selected as the current solution for the next iteration. With this conﬁguration, the seeding procedure for generating the initial solution and the perturbation (mutation) operator are the core components deﬁning the exploration capabilities of the (1 + 10) EA. Several approaches for these two procedures are detailed in Sections 9.3.4 and 9.3.5. 9.3.2

Solution Encoding

A major issue in this kind of algorithms is how solutions are encoded, because it will determine the set of search operators that can be applied during the exploration of the search space. Let T be the number of TRXs needed to meet the trafﬁc demand of a given GSM network. Each TRX has to be assigned with a channel. Let Fi ⊂ N be the set of valid channels for transceiver i, i = 1, 2, 3, . . . , T . A solution p (a frequency plan) is encoded

278

APPLYING EAs TO SOLVE THE AFP PROBLEM

FIGURE 9.4 Solution encoding example.

4 3 as a T -length integer array p = f1 , f2 , f3 , . . . , fT , p ∈ F1 × F2 × · · · × FT , where fi ∈ Fi is the channel assigned to TRX i. The ﬁtness function (see the next section) is aware of adding problem-speciﬁc information to each transceiver, that is, whether it allocates a BCCH channel or a TCH channel, whether it is a frequency hopping TRX or not, and so on. As an example, Figure 9.4 displays the representation of a frequency plan p for the GSM network shown in Figure 9.2. We have assumed that the trafﬁc demand in the example network is fulﬁlled by one single TRX per sector (TRX A1, TRX A2, etc.). 9.3.3

Fitness Function

As it was stated before, we have used a proprietary application provided by Optimi Corp.TM , which allows us to estimate the performance of the tentative frequency plans generated by the optimizer. Factors like frame erasure rate, block error rate, RxQual, and BER are evaluated. This commercial tool combines all aspects of network conﬁguration (BCCHs, TCHs, frequency hopping, etc.) in a unique cost function, F , which measures the impact of proposed frequency plans on capacity, coverage, QoS objectives, and network expenditures. This function can be roughly deﬁned as F=

(CostIM (v) × E (v) + CostNeighbor (v)) ,

(9.1)

v

that is, for each sector v that is a potential victim of interference, the associated cost is composed of two terms: a signaling cost computed with the interference matrix (CostIM (v)) that is scaled by the trafﬁc allocated to v, E (v), and a cost coming from the current frequency assignment in the neighbors of v. Of course, the lower the total cost, the better the frequency plan; that is, this is a minimization problem. 9.3.4

Initial Solution Generation

Two different initializations of individuals have been developed: Random Init and Advanced Init.

EAs FOR SOLVING THE AFP PROBLEM

279

1. Random Init. This is the most usual seeding method used in the evolutionary ﬁeld. Individuals are randomly generated: each TRX in the individual is assigned with a channel that is randomly chosen from the set of its valid channels. 2. Advanced Init. In this initialization method, individuals are not fully generated at random; instead, we have used a constructive method [3], which uses topological information of the GSM network. It ﬁrst assigns a random channel to the ﬁrst TRX of the individual; then, for the remainder of the TRXs, several attempts (as many as the number of valid channels of the considered TRXs) are tried with assignments that minimize interference as follows. Let t and Ft be the TRX to be allocated a new channel and its set of valid channels, respectively. A random valid channel f ∈ Ft is generated. However, f is assigned to t if no co-channel or adj-channel interference occurs with any channel already assigned to a TRX installed in the same or any ﬁrst-order neighboring sector of t. This procedure is repeated |Ft | times. If no channel is allocated to t in this process, the Random Init strategy is used. If we continue the GSM network of Figure 9.2 (assuming a TRX per sector), generating an initial solution with the Advanced Init strategy might take ﬁrst TRX A1. Let us suppose that the randomly chosen channel is 146 (Fig. 9.4). Next, a channel has to be allocated to TRX A2. In this case, channels 145, 146, and 147 are forbidden since A2 is a ﬁrst-order neighbor of A1 (see Fig. 9.2) and this will provoke co-channel (channel 146) and adj-channel (channels 145 and 147) interference. Then, TRX A2 is assigned with channel number 137 after several possible attempts at randomly selecting a channel from its set of valid channels. Of course, the Random Init scheme will surely be used for many assignments in the last sectors of each ﬁrst-order neighborhood. 9.3.5

Perturbation Operators

In (μ + λ) EAs, the perturbation (or mutation) operator largely determines the search capabilities of the algorithm. The mutation mechanisms proposed are based on modifying the channels allocated to a number of transceivers. Therefore, two steps must be performed: 1. Selection of the transceivers. The perturbation has ﬁrst to determine the set of transceivers to be modiﬁed. 2. Selection of channels. Once a list of TRXs have been chosen, a new channel allocation must be performed. 9.3.5.1 Strategies for Selecting Transceivers This is the ﬁrst decision to be made in the perturbation process. It is a major decision because it determines how explorative the perturbation is; that is, how different the resulting plan is from its original solution. Several strategies have been developed, which consist of reallocating channels on neighborhoods of TRXs. These neighborhoods are deﬁned based on the topological information of the network:

280

APPLYING EAs TO SOLVE THE AFP PROBLEM

TABLE 9.1

Co-channel Adj-channel

Weights Used in the Interference-Based Strategy Sector

First-order neighbor

16 4

8 1

1. OneHopNeighborhood. Set of TRXs belonging to the ﬁrst-order neighbors of a given transceiver. 2. TwoHopNeighborhood. The same, but using not only the ﬁrst-order neighbors, but also the second-order ones. That is, a larger number of TRXs are reassigned. We now need to specify the TRX from which the corresponding neighborhood is generated. In the experiments, the following selection schemes have been used: 1. Random. The TRX is randomly chosen from the set of all transceiver of the given problem instance. 2. Interference-based. This selection scheme uses a binary tournament. This method randomly chooses two TRXs of the network and returns the one with the higher interfering cost value. This cost value is based on counting the number of cochannel and adj-channel constraint violations provoked by these two TRXs in the current frequency planning. Since the closer the TRXs the stronger the interference, we further distinguish between co-channel and adj-channel within the same sector or within a ﬁrst-order neighboring sector. Consequently, the cost value is computed as a weighted sum with four addends. The weights used are included in Table 9.1. Since we are looking for frequency plans with minimal interference, we have used this information for perturbing those TRXs with high values of this measurement in order to hopefully reach better assignments. Note that this interference-based value is only computed for two TRXs each time the perturbation method is invoked. Let us illustrate this with an example. Consider the GSM network shown in Figure 9.5, where the trafﬁc demand is met with one single TRX per cell. This way, the number next to the name of each sector is the current channel allocated to the TRX. No intrasector interference can therefore occur. Let us now suppose that the two TRXs selected by the binary tournament are B1 and D2. Their corresponding ﬁrst-order neighbors are the sets {B2, B3, E1, E3} and {D1, D3, F 3}, respectively (see the gray-colored sectors in Fig. 9.5). With the current assignment, the interference-based value of B1 is 8 × 1 + 1 × 1 = 9, that is, a co-channel with E1 plus an adj-channel with B2. Concerning D2, this value is 8 × 2 + 1 × 1 = 17, which corresponds to two co-channels with D1 and F 3 plus an adj-channel with D3. So D2 would be the chosen sector to be perturbed in this case.

281

EAs FOR SOLVING THE AFP PROBLEM

FIGURE 9.5 A tentative frequency planning for a GSM network composed of 21 sectors.

9.3.5.2 Frequency Selection At this point, the perturbation method has deﬁned a set of TRXs whose channels can be modiﬁed. The modiﬁcation is to determine which channel is allocated to each TRX. Again, two different schemes have been used: 1. Random. The channel allocated is randomly chosen from the set of valid channels of each TRX. 2. Interference-based. In this scheme, all the valid channels of a TRX are assigned sequentially and the interference-based cost value described previously is computed. The channel showing the lowest value for this interference-based cost is then allocated to the TRX. For instance, let us continue with the example shown in Figure 9.5. Now, the TRX installed in sector D2, FD2 = {134, 143, 144, 145}, has to be assigned with a new channel. This strategy computes the cost value for all the valid channels of D2 (see Table 9.2), and the one with the lowest value is chosen (channel 134).

TABLE 9.2 Interference-Based Cost Values for the Single TRX Installed in Sector D2 from the GSM Network in Figure 9.5 Interference-based cost Channel 134 143 144 145

Co-channel

Adj-channel

Value

0 2 1 0

0 1 2 1

0 17 10 1

282

APPLYING EAs TO SOLVE THE AFP PROBLEM

TABLE 9.3

Conﬁgurations of the (1 + 10) EA That Have Been Tested

Conﬁg name

Init

Rand&Rand-1 Rand&Rand-2 Rand&Rand-3 Rand&Rand-4 Interf&Rand-1 Interf&Rand-2 Interf&Rand-3 Interf&Rand-4 Rand&Interf-1 Rand&Interf-2 Rand&Interf-3 Rand&Interf-4 Interf&Interf-1 Interf&Interf-2 Interf&Interf-3 Interf&Interf-4

Random Advanced Random Advanced Random Advanced Random Advanced Random Advanced Random Advanced Random Advanced Random Advanced

TRXs

Selection scheme for TRXs

Selection scheme for channels

OneHopNeighborhood OneHopNeighborhood TwoHopNeighborhood TwoHopNeighborhood OneHopNeighborhood OneHopNeighborhood TwoHopNeighborhood TwoHopNeighborhood OneHopNeighborhood OneHopNeighborhood TwoHopNeighborhood TwoHopNeighborhood OneHopNeighborhood OneHopNeighborhood TwoHopNeighborhood TwoHopNeighborhood

Random Random Random Random Interference-based Interference-based Interference-based Interference-based Random Random Random Random Interference-based Interference-based Interference-based Interference-based

Random Random Random Random Random Random Random Random Interference-based Interference-based Interference-based Interference-based Interference-based Interference-based Interference-based Interference-based

9.4 EXPERIMENTS In this section we now turn to present the experiments conducted to evaluate the (1 + 10) EAs proposed when solving a real-world instance of the AFP problem. We ﬁrst detail the parameterization of the algorithms and the different conﬁgurations used in the EA. A discussion of the results is carried out afterward.

9.4.1

Parameterization

Several seeding and mutation operators for the (1 + 10) EA have been deﬁned in the previous section. Table 9.3 summarizes all the combinations that have been studied. The number of iterations that are allowed to run is 2 000 in all the cases. We also want to provide the reader with some details about the AFP instance that is being solved. The GSM network used has 711 sectors with 2 612 TRXs installed. That is, the length of the individuals in the EA is 2 132. Each TRX has 18 available channels (from 134 to 151). Additional topological information indicates that, on average, each TRX has 25.08 ﬁrst-order neighbors and 96.60 second-order neighbors, thus showing the high complexity of this AFP instance, in which the available spectrum is much smaller that the average number of neighbors. Indeed, only 18 channels can be allocated to TRXs with 25.08 potential ﬁrst-order neighbors. We also want to remark that this real network operates with advanced technologies, such as frequency hopping, and it employs accurate interference information that has been actually measured at a cell-to-cell level (neither predictions nor distance-driven estimations are used).

283

EXPERIMENTS

TABLE 9.4

Initial Cost Reached with the Two Initialization Methods AFP cost

Initialization method Random Init Advanced Init

9.4.2

x¯

σn

180,631,987 113,789,997

15,438,987 11,837,857

Discussion of the Results

All the values included in Table 9.4 are the average, x¯ , and the standard deviation, σn , of ﬁve independent runs. Although it is commonly accepted that 30 independent runs should be performed at least, we were only able to run ﬁve because of the very high complexity of such a large problem instance (2 612 TRXs) and the many different conﬁgurations used. Let us start showing the performance of the two initialization methods. We present in Table 9.4 the AFP costs of the frequency plannings that result from both Random Init and Advanced Init. As expected, the latter reaches more accurate frequency assignments since it prevents the network from initially incurring in many interferences. For each conﬁguration of the EAs, the AFP costs of these ﬁnal solutions are included in Table 9.5. If we analyze these results as a whole, it can be noticed that the conﬁguration Rand&Rand-1 gets the lowest AFP cost on average, thus indicating that the computed frequency plannings achieve the smaller interference and therefore the better QoS for subscribers. Similar high quality frequency assignments are computed by the Rand&Interf-1, Rand&Interf-1, and Interf&Interf-3, where the cost values are around 20,000 units. We also want to remark two additional facts here. The ﬁrst one was already mentioned before and it lies in the huge reduction of the AFP costs that TABLE 9.5

Resulting AFP Costs (Average Over Five Executions)

Conﬁg Rand&Rand-1 Rand&Rand-2 Rand&Rand-3 Rand&Rand-4 Interf&Rand-1 Interf&Rand-2 Interf&Rand-3 Interf&Rand-4 Rand&Interf-1 Rand&Interf-2 Rand&Interf-3 Rand&Interf-4 Interf&Interf-1 Interf&Interf-2 Interf&Interf-3 Interf&Interf-4

x¯

AFP cost σn

Best run

18,808 31,506 34,819 76,115 56,191 63,028 108,146 72,043 21,279 19,754 34,292 28,422 147,062 26,346 20,087 32,982

12,589 10,088 24,756 81,103 87,562 96,670 99,839 83,198 11,990 7,753 16,178 20,473 273,132 10,086 10,468 19,814

9,966 13,638 13,075 13,683 14,224 11,606 18,908 15,525 9,936 11,608 12,291 11,493 14,011 15,304 13,235 16,818

284

APPLYING EAs TO SOLVE THE AFP PROBLEM

EAs can achieve starting from randomly generated solution (from more than 110 million to several thousand cost units). This means that the strongest interference in the network has been avoided. The second fact concerns the best solutions found so far by the solvers, which are included in the column “best” of Table 9.5. They point out that all the conﬁgurations of the (1 + 10) EA are able to compute very accurate frequency assignments. As a consequence, we can conclude that these algorithms are very suitable for solving this optimization problem. We now turn to further analyze how the different strategies proposed for initializing and perturbing work within the (1 + 10) EA framework. With this goal in mind, Figure 9.6 displays the average costs of the conﬁgurations using 1. The Random Init strategy versus those using the Advanced Init method 2. OneHopNeighborhood versus TwoHopNeighborhood strategies for determining the number of TRXs to be reallocated a channel 3. The random scheme versus interference-based one for selecting the TRXs 4. The random versus interference-based channel selection strategies. Concerning the initialization method, Figure 9.6 shows that the (1 + 10) EAs using the Advanced Init scheme reach, on average, better frequency assignments than the conﬁgurations with Random Init. It is clear from these results that our proposed EAs can proﬁt from good initial plannings that guide the search toward promising regions of the search space. If we compare the different strategies used in the perturbation method, several conclusions can be drawn. First of all, conﬁgurations of the (1 + 10) EA that reallocate the channel to a smaller number of TRXs, that is, OneHopNeighborhood strategy, against using the TwoHopNeighborhood scheme report a small improvement in the AFP cost. However, it is clear that randomly choosing the TRX (and its corresponding 70,000 60,000

AFP cost

50,000 40,000 30,000 20,000 10,000 0 Random vs Advanced

Init

OneHop vs TwoHop

TRXs

Random vs Interf-based Random vs Interf-based

TRX selection

Channel selection

FIGURE 9.6 Performance of the initialization and perturbation methods in the (1 + 10) EA.

CONCLUSIONS AND FUTURE WORK

285

neighborhood) comes up with a large reduction in the AFP costs of the conﬁgurations using this selection strategy (see Fig. 9.6). Indeed, the interference-based scheme leads the (1 + 10) EA to converge prematurely to a local minimum because of an excessive intensiﬁcation of the search. This also means that the many existing works advising sophisticated local searches work only on easy conceptualizations of low dimensionality of this problem, which is an important fact [1,5]. Even though this interference-based selection strategy does not work properly for selecting the TRXs to be perturbed, the EA conﬁgurations using this strategy for choosing channels show better performance (lower AFP costs) than those applying the random one (see the last columns in Fig. 9.6). That is, perturbations using this scheme allow the (1 + 10) EA to reach accurate frequency plans, which means that interference information is very useful at the channel selection stage of the perturbation, whereas random selection is preferred when the TRXs have to be chosen.

9.5 CONCLUSIONS AND FUTURE WORK This chapter describes the utilization of (1 + 10) EAs to solve the automatic frequency planning in a real-world GSM network composed of 2132 transceivers. Instead of using a mathematical formulation of this optimization problem, we have used a commercial application that allows the target frequency plannings to be evaluated in a real scenario where current technologies are in use (e.g., frequency hopping, discontinuous transmission, etc.). Two different methods for generating initial solutions along with several perturbation methods have been proposed. We have analyzed all the possible conﬁgurations of an (1 + 10) EA using these operators. The results show that the conﬁguration called Rand&Rand-1 gets the lowest cost values for the ﬁnal frequency planning computed, thus reaching an assignment that avoids major interference in the network. We have then compared the different seeding and perturbation methods among them to provide insight into their search capabilities within the (1 + 10) EA framework. Concerning the seeding methods, the conﬁgurations using the Advanced Init scheme outperforms those endowed with Random Init. In the perturbation operator, OneHopNeighborhood and TwoHopNeighborhood strategies for selecting how many TRXs have to be reallocated a channel are very similar. However, signiﬁcant reductions in the cost values are reached when using the random scheme to choose which TRX (and its corresponding neighboring sectors) will be perturbed, instead of the interference-based approach. We want to remark that this is contraintuitive and brings into discredit simpliﬁed works of k-coloring and small instances of 200/300 TRXs like those included in COST, CELAR, or OR Library, for example. Conversely, the interference-based strategy performs the best when a channel has to be chosen to be allocated a TRX. As future work, we plan to develop new search operators and new metaheuristic algorithms to solve this problem. Their evaluation with the current instance and other real-world GSM networks is also an ongoing research line. The formulation of the AFP problem as a multiobjective optimization problem will be investigated as well.

286

APPLYING EAs TO SOLVE THE AFP PROBLEM

ACKNOWLEDGMENTS This work has been partially funded by the Ministry of Science and Technology and FEDER under contract TIN2005-08818-C04-01 (the OPLINK project).

REFERENCES 1. Aardal KI, van Hoesen SPM, Koster AMCA, Mannino C, Sassano A. Models and solution techniques for frequency assignment problems. 4OR 2003;1(4):261–317. 2. B¨ack T. Evolutionary Algorithms: Theory and Practice. New York: Oxford University Press; 1996. 3. Blum C, Roli A. Metaheuristics in combinatorial optimization: overview and conceptual comparison. ACM Comput Surv 2003;35(3):268–308. 4. Dorne R, Hao J-K. An evolutionary approach for frequency assignment in cellular radio networks. Proceedings of the IEEE International Conference on Evolutionary Computation; 1995. p 539–544. 5. Eisenbl¨atter A. Frequency assignment in GSM networks: models, heuristics, and lower bounds. Ph.D. thesis. Institut f¨ur Mathematik, Technische Universit¨at Berlin; 2001. 6. FAP Web. http://fap.zib.de/ 7. Furuskar A, Naslund J, Olofsson H. EDGE—enhanced data rates for GSM and TDMA/136 evolution. Ericsson Rev 1999;72(1):28–37. 8. Glover FW, Kochenberger GA. Handbook of Metaheuristics. International Series in Operations Research and Management Science. Norwell, MA: Kluwer 2003. 9. Granbohm H, Wiklund J. GPRS—general packet radio service. Ericsson Rev 1999;76(2):82–88. 10. Hale WK. Frequency assignment: theory and applications. Proc the IEEE 1980;68(12):1497–1514. 11. Kampstra P, van der Mei RD, Eiben AE. Evolutionary Computing in Telecommunication Network Design: A Survey. Forthcoming. 12. Kotrotsos S, Kotsakis G, Demestichas P, Tzifa E, Demesticha V, Anagnostou M. Formulation and computationally efﬁcient algorithms for an interference-oriented version of the frequency assignment problem. Wireless Personal Commun 2001;18:289–317. 13. Mishra AR. Radio network planning and optimisation. Fundamentals of cellular network planning and optimisation: 2G/2.5G/3G... Evolution to 4G. Wiley; 2004. p 21–54. 14. Mouly M, Paulet MB. The GSM System for Mobile Communications. Palaiseau: Mouly et Paulet; 1992. 15. Rapeli J. UMTS: targets, system concept, and standardization in a global framework. IEEE Personal Commun 1995;2(1):30–37. 16. Schwefel H-P. Numerical Optimization of Computer Models. Wiley; 1981. 17. Smith DH, Allen SM, Hurley S. Characteristics of good meta-heuristics algorithms for the frequency assignment problem. Ann Oper Res 2001;107:285–301. 18. Vidyarthi G, Ngom A, Stojmenovi´c I. A hybrid channel assignment approach using an efﬁcient evolutionary strategy in wireless mobile networks. IEEE Trans Vehicular Technol 2005;54(5):1887–1895.

CHAPTER 10

Algorithmic Game Theory and Applications MARIOS MAVRONICOLAS, VICKY PAPADOPOULOU, and PAUL SPIRAKIS

10.1 INTRODUCTION Most of the existing and foreseen complex networks, such as the Internet, are operated and built by thousands of large and small entities (autonomous agents), which collaborate to process and deliver end-to-end ﬂows originating from and terminating at any of them. The distributed nature of the Internet implies a lack of coordination among its users. Instead, each user attempts to obtain maximum performance according to his own parameters and objectives. Methods from game theory and mathematical economics have been proven to be a powerful modeling tool, which can be applied to understand, control, and efﬁciently design such dynamic, complex networks. Game theory provides a good starting point for computer scientists in their endeavor to understand selﬁsh rational behavior in complex networks with many agents (players). Such scenarios are readily modeled using techniques from game theory, where players with potentially conﬂicting goals participate in a common setting with well-prescribed interactions. Nash equilibrium [73,74] distinguishes itself as the predominant concept of rationality in noncooperative settings. So, game theory and its various concepts of equilibria provide a rich framework for modeling the behavior of selﬁsh agents in these kinds of distributed or networked environments; they offer mechanisms to achieve efﬁcient and desirable global outcomes in spite of the selﬁsh behavior. Mechanism design, a subﬁeld of game theory, asks how one can design systems so that agents’ selﬁsh behavior results to desired systemwide goals. Algorithmic mechanism design additionally considers computational tractability to the set of concerns of mechanism design. Work on algorithmic mechanism design has focused on the complexity of centralized implementations of game-theoretic mechanisms for distributed optimization problems. Moreover, in such huge and heterogeneous networks, each agent does not have access to (and may not process) complete information. Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

287

288

ALGORITHMIC GAME THEORY AND APPLICATIONS

The notion of bounded rationality for agents and the design of corresponding incomplete-information distributed algorithms have been successfully utilized to capture the aspect of lack of global knowledge in information networks. In this chapter, we review some of the most thrilling algorithmic problems and solutions, and corresponding advances, achieved on the account of game theory. The areas addressed are the following. Congestion Games A central problem arising in the management of large-scale communication networks is that of routing trafﬁc through the network. However, due to the large size of these networks, it is often impossible to employ a centralized trafﬁc management. A natural assumption to make in the absence of central regulation is that network users behave selﬁshly and aim at optimizing their own individual welfare. One way to address this problem is to model this scenario as a noncooperative multiplayer game and formalize it using congestion game. Congestion games (either unweighted or weighted) offer a very natural framework for resource allocation in large networks like the Internet. In a nutshell, the main feature of congestion games is that they model congestion on a resource as a function of the number (or total weight) of all agents sharing the resource. Price of Anarchy We survey precise and approximate estimations for the price of anarchy; this is the cost of selﬁsh behavior in dynamic, large-scale networks compared to hypothetical centralized solutions. We consider the price of anarchy for some of the most important network problems that are modeled by noncooperative games; for example, we consider routing and security problems. A natural variant of the price of anarchy is the price of stability [5], which is the best-case cost of selﬁsh behavior in complex networks, compared to a hypothetical centralized solution. The best-case assumption in the formulation of the price of stability implies that this cost can be enforced to the agents since they are interested in paying as low cost as possible. Selﬁsh Routing with Incomplete Information The impact of bounded rationality in networks with incomplete information can be addressed in two successful ways: either by Bayesian games or by congestion games with player-speciﬁc payoff functions. We will survey methods and tools for approximating network equilibria and network ﬂows for a selﬁsh system comprised of agents with bounded rationality. Mechanism Design Mechanism design is a subﬁeld of game theory and microeconomics, which deals with the design of protocols for rational agents. Generally, a mechanism design problem can be described as the task of selecting, out of a collection of feasible games, one that will yield desirable results for the designer. So, mechanism design can be thought of as the “inverse problem” in game theory, where the input is a game’s outcome and the output is a game guaranteeing the desired outcome. The study of mechanism design from the algorithmic point of view starts with the seminal paper of Nisan and Ronen [76]. The routing problem in large-scale networks, where users are instinctively selﬁsh, can be modeled by a noncooperative game. Such a game could impose strategies

INTRODUCTION

289

that might induce an equilibrium close to the overall optimum. These strategies can be enforced through pricing mechanisms [28], algorithmic mechanisms [76], and network design [57,87]. Stackelberg Games We will examine network routing games from the network designer’s point of view. In particular, the network administrator or designer can deﬁne prices and rules, or even construct the network, in a way that induces near-optimal performance when the users act selﬁshly inside the system. Particularly interesting is the approach where the network manager takes part in the noncooperative game. The manager has the ability to control centrally a part of the system resources, while the rest resources are managed by the selﬁsh users. This approach has been implemented through Stackelberg or leader–follower games [16,58]. The apparent advantage of this approach is that it might be easier to be deployed in large-scale networks. This is so since there is no need to add extra components to the network, or to exchange information between the users of the network. In a typical Stackelberg game, one player acts as a leader (here, the centralized authority interested in optimizing system performance) and the rest act as followers (here, the selﬁsh users). The problem is then to compute a strategy for the leader (a Stackelberg strategy) that induces the followers to react in a way that (at least approximately) minimizes the total latency in the system. Selﬁsh routing games can be modeled as a Stackelberg game. We will survey issues related to how the manager should assign the ﬂow under his control into the system so as to induce optimal cost incurred by the selﬁsh users. In particular, we will be interested in the complexity of designing optimal Stackelberg strategies. Pricing Mechanisms Pricing mechanisms for resource allocation problems aim at allocating resources in such a way that those users who derive greater utility from the network are not denied access due to other users placing a lower value on it. In other words, pricing mechanisms are designed to guarantee economic efﬁciency. We will survey cost-sharing mechanisms for pricing the competitive usage of a collection of resources by a collection of selﬁsh agents, each coming with an individual demand. Network Security Games We will also consider security problems in dynamic, large-scale, distributed networks. Such problems can be modeled as concise, noncooperative multiplayer games played on a graph. We will investigate the associated Nash equilibria for such network security games. In the literature, there have been studied at least two such interesting network security games. Complexity of Computing Equilibria The investigation of the computational complexity of ﬁnding a Nash equilibrium in a general strategic game is deﬁnitely a fundamental task for the development of algorithmic game theory. Answers to such questions are expected to have great practical impact on both the analysis of the performance of antagonistic networks and the development and implementation of policies for the network designers themselves.

290

ALGORITHMIC GAME THEORY AND APPLICATIONS

Finding a Nash equilibrium in a game with two players could potentially be easier (than for many players) for several reasons. First, the zero-sum version of the game can be solved in polynomial time by linear programming. This grooms hopes for the polynomial solvability of the general (nonconstant sum) version of the problem. Second, the two-player version of the game admits a polynomial size rational number solution, while there are games with three or more players that may only have solutions in irrational numbers. This reasoning justiﬁed the identiﬁcation of the problem of ﬁnding Nash equilibria for a two-player game as one of the most important open questions in the ﬁeld of algorithmic game theory. The complexity of this problem was very recently settled in a perhaps surprising way in a series of breakthrough papers. In this chapter, we will later survey some of the worldwide literature related to this problem and the recent progress to it. In this chapter, we only assume a basic familiarity of the reader with some central concepts of game theory such as strategic games and Nash equilibria; for more details, we refer the interested reader to the leading textbooks by Osborne [77] and Osborne and Rubinstein [78]. We also assume some acquaintance of the reader with the basic facts of the theory of computational complexity, as laid out, for example, in the leading textbook of Papadimitriou [80]. For readers interested in recalling the fundamental of algorithms design and analysis, we refer the reader to the prominent textbook of Kleinberg and Tardos [53]. For overwhelming motivation to delving into the secrets of algorithmic game theory, we cheerfully refer the reader to the inspirational and prophetic survey of Papadimitriou in STOC 2001 [81].

10.2 CONGESTION GAMES 10.2.1

The General Framework

10.2.1.1 Congestion Games Rosenthal [84] introduced a special class of strategic games, now widely known as congestion games and currently under intense investigation by researchers in algorithmic game theory. Here, the strategy set of each player is a subset of the power set of a set of resources; so, it is a set of sets of resources. Each player has an objective function, deﬁned as the sum (over their chosen resources) of functions in the number of players sharing this resource. In his seminal work, Rosenthal showed with the help of a potential function that congestion games (in sharp contrast to general strategic games) always admit at least one pure Nash equilibrium. An extension to congestion games are weighted congestion games, in which the players have weights, and thus exert different inﬂuences on the congestion of the resources. In (weighted) network congestion games, the strategy sets of the players correspond to paths in a network.

CONGESTION GAMES

291

10.2.1.2 Price of Anarchy In order to measure the degradation of social welfare due to the selﬁsh behavior of the players, Koutsoupias and Papadimitriou [60] introduced in their seminal work a global objective function, usually coined as social cost. It is quite remarkable that no notion similar in either spirit or structure to social cost had been studied in the game theory literature before. They deﬁned the price of anarchy, also called coordination ratio and denoted as PoA, as the worst-case ratio between the value of social cost at a Nash equilibrium and that of some social optimum. The social optimum is the best-case social cost; so it is the least value of social cost achievable through cooperation. Thus, the coordination ratio measures the extent to which noncooperation approximates cooperation. As a starting point for analyzing the price of anarchy, Koutsoupias and Papadimitriou considered a very simple weighted network congestion game, now known as the KP model. Here, the network consists of a single source and a single destination (in other words, it is a single-commodity network) that are connected together by parallel links. The load on a link is the total weight of players assigned to this link. Associated with each link is a capacity (or speed) representing the rate at which the link processes load. Each of the players selﬁshly routes from the source to the destination by using a probability distribution over the links. The private objective function of a player is its expected latency. The social cost is the expected maximum latency on a link, where the expectation is taken over all random choices of the players. Fotakis et al. [34] have proved that computing social cost (in the form of expected maximum) is a #P-complete problem. The stem of this negative result is the nature of exponential enumeration explicit in the deﬁnition of social cost (as an exponentialsize expectation sum). An essentially identical #P-hardness result has been proven recently by Daskalakis et al. [19]. This is one of the very few hard enumeration problems known in algorithmic game theory as of today. Determining more remains a great challenge. Mavronicolas and Spirakis [69] introduced fully mixed Nash equilibria for the particular case of the KP model, in which each player chooses every link with positive probability. Gairing et al. [38,39] explicitly conjectured that, in case the fully mixed Nash equilibrium exists, it is the worst-case Nash equilibrium with respect to social cost. This so-called fully mixed Nash equilibrium conjecture is simultaneously intuitive and signiﬁcant. It is intuitive because the fully mixed Nash equilibrium favors an increased number of collisions between different players, since each player assigns its load with positive probability to every link. This increased probability of collisions should favor an increase to social cost. The conjecture is also signiﬁcant since it identiﬁes the worst-case Nash equilibrium over all instances. The fully mixed Nash equilibrium conjecture has been studied very intensively in the last few years over a variety of settings and models relative to the KP model. The KP model was recently extended to restricted strategy sets [9,35], where the strategy set of each player is a subset of the links. Furthermore, the KP model was

292

ALGORITHMIC GAME THEORY AND APPLICATIONS

extended to general latency functions and studied with respect to different deﬁnitions of social cost [36,37,63]. Inspired by the arisen interest in the price of anarchy, the much older Wardrop model was reinvestigated in the work by Roughgarden and Tordos[88] (see also references therein). In this weighted network congestion game, weights can be split into arbitrary pieces. The social welfare of the system is deﬁned as the sum of the edge latencies (sum or total social cost). An equilibrium in the Wardrop model can be interpreted as a Nash equilibrium in a game with inﬁnitely many players, each carrying an inﬁnitesimal amount of weight. There has been a tremendous amount of work following the work by Roughgarden and Tordos[88] on the reinvestigation of the Wardrop model. For an exposition, see the book by Roughgarden [86], which gives an account of the earliest results. Koutsoupias and Papadimitriou [60] initiated a systematic investigation of the social objective of (expected) maximum latency (also called maximum social cost) for a weighted congestion game on uniformly related parallel links. The price of anarchy for this game has been shown to be (log m/log log m) if either the users or the links are identical [18,59], and (log m/log log log m) for weighted users and uniformly related links [18]. On the contrary, Czumaj et al. [17] showed that the price of anarchy is far worse and can be even unbounded for arbitrary latency functions. For uniformly related parallel links, identical users, and the objective of total latency, the price of anarchy is 1 − o(1) for the general case of mixed equilibria and 4/3 for pure equilibria [63]. For identical users and polynomial latency functions of degree d, the price of anarchy is d (d) [8,15]. Christodoulou and Koutsoupias [15] consider the price of anarchy of pure Nash equilibria in congestion games with linear latency functions. They showed that for general (asymmetric) games, the price of anarchy for maximum social cost √ is ( n), where n is the number of players. For all other cases of symmetric or asymmetric games, and for both maximum and average social cost, the price of anarchy is shown to be 5/2. Similar results were simultaneously obtained by Awerbuch et al. [15] 10.2.2

Pearls

A comprehensive survey of some of the most important recent advances in the literature on atomic congestion games is provided by Kontogiannis and Spirakis [55]. That work is an overview of the extensive expertise on (mainly, network) congestion games and the closely related potential games [71], which has been developed in various disciplines (e.g., economics, computer science and operations research) under a common formalization and modeling. In particular, the survey goes deep into the details of some of the most characteristic results in the area in order to compile a useful toolbox that game theory provides in order to study antagonistic behavior due to congestion phenomena in computer science settings. 10.2.2.1 Selﬁsh Unsplittable Flows Fotakis et al. study congestion games where selﬁsh users with varying service demands on the system resources may request

CONGESTION GAMES

293

a joint service from an arbitrary subset of resources [32]. Each user’s demand has to be served unsplittably from a speciﬁc subset of resources. In that work, it is proved that the weighted congestion games are no longer isomorphic to the well-known potential games, although this was true for the case of users with identical service demands. The authors also demonstrate the power of the network structure in the case of users with varying demands. For very simple networks, they show that there may not exist a pure Nash equilibria, which is not true for the case of parallel links network or for the case of inﬁnitely splittable service demands. Furthermore, the authors propose a family of networks (called layered networks) for which they show the existence of at least one pure Nash equilibrium when each resource charges its users with a delay equal to its load. Finally, the same work considers the price of anarchy for the family of layered networks in the same case. It is shown that the price of anarchy for this case is (log m/log log m). That is, within constant factors, the worst-case network is the simplest one (the parallel links network). This implies that, for this family of networks, the network structure does not affect the quality of the outcome of the congestion games played on the network in an essential way. Panagopoulou and Spirakis [79] consider selﬁsh routing in single-commodity networks, where selﬁsh users select paths to route their loads (represented by arbitrary integer weights). They consider identical delay functions for the links of the network. That work focuses also on an algorithm suggested in the work by Fotakis et al. [32]; this is a potential-based algorithm for ﬁnding pure Nash equilibria in such networks. The analysis of this algorithm from the work by Fotakis et al. [32] has given an upper bound on its running time, which is polynomial in n (the number of users) and the sum W of their weights. This bound can be exponential in n when some weights are superpolynomial. Therefore, the algorithm is only known to be pseudopolynomial. The work of Panagopoulou and Spirakis [79] provides strong experimental evidence that this algorithm actually converges to a pure Nash equilibria in polynomial time in n (and, therefore, independent of the weights values). In addition, Panagopoulou and Spirakis [79] propose an initial allocation of users to paths that dramatically accelerates this algorithm, as opposed to an arbitrary initial allocation. A by-product of that work is the discovery of a weighted potential function when link loads are exponential to their loads. This guarantees the existence of pure Nash equilibria for these delay functions, while it extends the results of Fotakis et al. [32]. 10.2.2.2 Worst-Case Equilibria Fischer and V¨ocking [30] reexamined the question of worst-case Nash equilibria for the selﬁsh routing game associated with the KP model [60], where n weighted jobs are allocated to m identical machines. Recall that Gairing et al. [38,39] had conjectured that the fully mixed Nash equilibrium is the worst Nash equilibrium for this game (with respect to the expected maximum load over all machines). The known algorithms for approximating the price of anarchy relied on proven cases of that conjecture. Fischer and V¨ocking [30], interestingly present a counterexample to the conjecture showing that fully mixed Nash equilibria cannot be generally used to approximate the price of anarchy within reasonable factors. In addition, they present an algorithm that constructs the so-called concentrated Nash

294

ALGORITHMIC GAME THEORY AND APPLICATIONS

equilibria, which approximate the worst-case Nash equilibrium within constant factors. Although the work of Fischer and V¨ocking [30] has disproved the fully mixed Nash equilibrium conjecture for the case of weighted users and identical links, the possibility that the conjecture holds for the case of identical users and arbitrary links is still open. 10.2.2.3 Symmetric Congestion Games Fotakis et al. [33] continued the work and studied computational and coordination issues of Nash equilibria in symmetric network congestion games. A game is symmetric if all users have the same strategy set and users costs are given by identical symmetric functions of other users’ strategies. (Symmetric games were already considered in the original work of Nash [73,74].) In unweighted congestions games, users are identical, so that a common strategy set implies symmetry. This work proposed a simple and natural greedy method (which is called the Greedy Best Response—GBR), to compute a pure Nash equilibria. In this algorithm, each user plays only once and allocates his trafﬁc to a path selected via a shortest path computation. It is shown that this algorithm works for three special cases: (1) series-parallel networks, (2) users are identical, and (3) users are of varying demands but they have the same best response strategy for any initial network trafﬁc (this is called the Common Best Response property). The authors also give constructions where the algorithm fails if either the latter condition is violated (even for a series-parallel network) or the network is not seriesparallel (even for the case of identical users). Thus, these results essentially indicate the limits of the applicability of this greedy approach. The same work [33] also studies the price of anarchy for the objective of (expected) maximum latency. It is proved that for any network of m uniformly related links and for identical users, the price of anarchy is (log m/log log m). This result is complementary (and somewhat orthogonal) to a similar result proved in the work by Fotakis et al. [32] for the case of weighted users to be routed in a layered network. 10.2.2.4 Exact Price of Anarchy Obtaining exact bounds on price of anarchy is, of course, the ultimate wish providing a happy end to the story. Unfortunately, the cases where such exact bounds are known are truly rare as of today. We describe here a particularly interesting example of a success story for one of these rare cases. Exact bounds on the price of anarchy for both unweighted and weighted congestion games with polynomial latency functions are provided in the work by Aland et al. [3]. The authors use the total latency as the social cost measure. The result in the work by Aland et al. [3] vastly improve on results by Awerbuch et al. [8] and Christodoulou and Koutsoupias [15], where nonmatching upper and lower bounds were given. (We will later discuss the precise relation of the newer result to the older results.) For the case of unweighted congestion games, it is shown in the work by Aland et al. [3] that the price of anarchy is exactly PoA =

(k + 1)2d+1 − kd+1 (k + 2)d , (k + 1)d+1 − (k + 2)d + (k + 1)d − kd+1

SELFISH ROUTING WITH INCOMPLETE INFORMATION

295

where k = d and d is a natural generalization of the golden ratio to larger dimensions such that d is the solution to the equation (d + 1)d = d+1 d . The best known upper and lower bounds had before been shown to be of the form d d(1−o(1)) [15]. However, the term o(1) was still hiding a signiﬁcant gap between the upper and the lower bound. For weighted congestion games, the authors show that the price of anarchy is exactly PoA = d+1 d . This result closes the gap between the so far best upper and lower bounds of O(2d d d+1 ) and (d d/2 ) from the work by Awarbuch et al. [8]. Aland et al. [3] show that the above values on the price of anarchy also hold for the subclasses of unweighted and weighted network congestion games. For the upper bounds, the authors use a similar analysis as in the work by Christodoulou et al. [15]. The core of their analysis is to simultaneously determine parameters c1 and c2 such that yf (x + 1) ≤ c1 xf (x) + c2 yf (y) for all polynomial latency functions of maximum degree d and for all reals x, y ≥ 0. For the case of unweighted users, it sufﬁces to show the inequality for all pairs of integers x and y. (In order to prove their upper bound, Christodoulou and Koutsoupias [15] looked at the inequality with c1 = 1/2 and gave an asymptotic estimate for c2 .) In the analysis presented in the work by Aland et al. [3], both parameters c1 and c2 are optimized. This optimization process required new mathematical ideas and is highly nontrivial. This optimization was successfully applied by Dumrauf and Gairing [24] to the so-called polynomial Wardrop games, where it yielded almost exact bounds on price of stability.

10.3 SELFISH ROUTING WITH INCOMPLETE INFORMATION In his seminal work, Harsanyi [46] introduced an elegant approach to study noncooperative games with incomplete information, where the players are uncertain about some parameters of the game. To model such games, he introduced the Harsanyi transformation, which converts a game with incomplete information to a strategic game where players may have different types. In the resulting Bayesian game, the players’ uncertainty about each other’s types is described by a probability distribution over all possible type proﬁles. It was only recently that Bayesian games were investigated from the point of view of algorithmic game theory. Naturally, researchers were interested in formulating Bayesian versions of already studied routing games, as we described below. In more detail, the problem of selﬁsh routing with incomplete information has recently been faced via the introduction of new suitable models and the development of

296

ALGORITHMIC GAME THEORY AND APPLICATIONS

new methodologies that help to analyze such network settings. In particular, there were introduced new selﬁsh routing games with incomplete information, called Bayesian routing games [40]. In a different piece of work, the same problem has been viewed as a congestion game where latency functions are player-speciﬁc [41], or a congestion game under the restriction that the link for each user must be chosen from a certain set of allowed links for the user [9,26]. 10.3.1

Bayesian Routing Games

Gairing et al. [40] introduced a particular selﬁsh routing game with incomplete information, called Bayesian routing game. Here, n selﬁsh users wish to assign their trafﬁcs to one of m parallel links. Users do not know each other’s trafﬁc. Following Harsanyi’s approach, the authors introduce for each user a set of types. Each type represents a possible trafﬁc; so, the set of types captures the set of all possibilities for each user. Unfortunately, users know the set of all possibilities for each other, but not the actual trafﬁc itself. Gairing et al. [40] proved, with the help of a potential function, that every Bayesian routing game has a pure Bayesian Nash equilibrium. This result has also been generalized to a larger class of games, called weighted Bayesian congestion games. For the case of identical links and independent type distributions, it is shown that a pure Bayesian Nash equilibrium can be computed in polynomial time. (A probability distribution over all possible type proﬁles is independent if it can be expressed as the product of independent probability distributions, one for each type.) In the same work, Gairing et al. study structural properties of Bayesian fully mixed Nash equilibria for the case of identical links; they show that those maximize individual cost. This implies, in particular, that Bayesian fully mixed Nash equilibria maximize social cost as sum of individual costs. In general, there may exist more than one fully mixed Bayesian Nash equilibrium. Gairing et al. [40] provide a characterization of the class of fully mixed Bayesian Nash equilibria for the case of independent type distribution; the characterization determines, in turn, the dimension of Bayesian fully mixed Nash equilibria. (The dimension of Bayesian fully mixed Nash equilibria is the dimension of the smallest Euclidean space into which all Bayesian fully mixed Nash equilibria can be mapped.) Finally, Gairing et al. [40] consider the price of anarchy for the case of identical links and for three different social cost measures; that is, they consider social cost as expected maximum congestion, as sum of individual costs, and as maximum individual cost. For the latter two measures, (asymptotic) tight bounds were provided using the proven structural properties of fully mixed Bayesian Nash equilibria. 10.3.2

Player-Speciﬁc Latency Functions

Gairing et al. [41] address the impact of incomplete knowledge in (weighted) network congestion games with either splittable or unsplittable ﬂow. In this perspective, the proposed models generalize the two famous models of selﬁsh routing, namely

SELFISH ROUTING WITH INCOMPLETE INFORMATION

297

weighted (network) congestion games and Wardrop games, to accommodate playerspeciﬁc latency functions. Latency functions may be arbitrary, nondecreasing functions; however, many of the shown results in the work by Gairing et al. [41] assume that the latency function for player i on resource j is a linear function fij (x) = aij x + bij , where aij ≥ 0 and bij ≥ 0. Gairing et al. use the term player-speciﬁc capacities to denote a game where bij = 0 in all (linear) latency functions. Gairing et al. [41] derive several interesting results on the existence and computational complexity of (pure) Nash equilibria and on the price of anarchy. For routing games on parallel links with player-speciﬁc capacities, they introduce two new potential functions, one for unsplittable trafﬁc and the other for splittable trafﬁc. The ﬁrst potential function is used to prove that games with unweighted players possess the ﬁnite improvement property in the case of unsplittable trafﬁcs. It is also shown in the work by Gairing et al. [41] that games with weighted players do not possess the ﬁnite improvement property in general, even if there are only three users. The second potential function is a convex function tailored to the case of splittable trafﬁcs. This convex function is minimized if and only if the corresponding assignment is a Nash equilibrium. Since such minimization of a convex latency function can be carried out in polynomial time, the established equivalence between minimizes of the potential function and Nash equilibria implies that a Nash equilibrium can be computed in polynomial time. The same work [41] proves upper and lower bounds on the price of anarchy under a certain restriction on the linear latency functions. For the case of unsplittable trafﬁcs, the upper and lower bounds are asymptotically tight. All bounds on the price of anarchy translate to corresponding bounds for general congestion games. 10.3.3

Network Uncertainty in Selﬁsh Routing

The problem of selﬁsh routing in the presence of incomplete network information has also been studied by Georgiou et al. [43]. This work proposes an interesting new model for selﬁsh routing in the presence of incomplete network information. The model proposed by Georgiou et al. captures situations where the users have incomplete information regarding the link capacities. Such uncertainty may be caused if the network links actually represent complex paths created by routers, which are constructed differently on separate occasions and sometimes according to the presence of congestion or link failures. The new, extremely interesting model presented in the work by Georgiou et al. [43] consists of a number of users who wish to route their trafﬁc on a network of m parallel links with the objective of minimizing their latency. In order to capture the lack of precise knowledge about the capacity of the network links, Georgiou et al. [43] assumed that links may present a number of different capacities. Each user’s uncertainty about the capacity of each link is modeled via a probability distribution over all possibilities. Furthermore, it is assumed that users may have different sources of information regarding the network; therefore, Georgiou et al. assume the probability distributions of the various users to be (possibly) distinct from each other. This gives rise to a very interesting model with user-speciﬁc payoff functions, where each

298

ALGORITHMIC GAME THEORY AND APPLICATIONS

user uses its distinct probability distribution to take decisions as to how to route its trafﬁc. The authors propose simple polynomial-time algorithms to compute pure Nash equilibria in some special cases of the problem and demonstrate that a counterexample presented in the work by Milchtaich et al. [70], showing that pure Nash equilibria may not exist in the general case, does not apply to their model. Thus, Georgiou et al. identify an interesting open problem in this area, that of the existence of pure Nash equilibria in the general case of their model. Also, two different expressions for the social cost and the associated price of anarchy are identiﬁed and employed in the work by Georgiou et al. [43]. For the latter, Georgiou et al. obtain upper bounds for the general case and some better upper bounds for several special cases of their model. In the same work, Georgiou et al. show how to compute the fully mixed Nash equilibrium in polynomial time; they also show that when it exists, it is unique. Also, Georgiou et al. prove that for certain instances of the game, fully mixed Nash equilibria assign all links to all users equiprobably. Finally, the work by Georgiou et al. [43] veriﬁes the fully mixed Nash equilibrium conjecture, namely that the fully mixed Nash equilibrium maximizes social cost. 10.3.4

Restricted Selﬁsh Scheduling

Els¨asser et al. [26] further consider selﬁsh routing problems in networks under the restriction that the link for each user must be chosen from a certain set of allowed links for the user. It is particularly assumed that each user has access (that is, ﬁnite cost) to only two machines; its cost on other machines is inﬁnitely large, giving it no incentive to switch there. Interaction with just a few neighbors is a basic design principle to guarantee efﬁcient use of resources in a distributed system. Restricting the number of interacting neighbors to just two is then a natural starting point for the theoretical study of the impact of selﬁsh behavior in a distributed system with local interactions. In the model of Els¨asser et al., the (expected) cost of a user is the (expected) load on the machine it chooses. The particular way of modeling local interaction in the work by Els¨asser et al. [26] has given rise to a simple, graph-theoretic model for selﬁsh scheduling among m noncooperative users over a collection of n machines with local interaction. In their graph-theoretic model, Els¨asser et al. [26] address these bounded interactions by using an interaction graph, whose vertices and edges are the machines and the users, respectively. Els¨asser et al. [26] have been interested in the impact of their modeling on the properties of the induced Nash equilibria. The main result of Els¨asser et al. [26] is that the parallel links graph is the best-case interaction graph—the one that minimizes expected makespan of the standard fully mixed Nash equilibrium—among all 3-regular interaction graphs. (In the standard fully mixed Nash equilibria each user chooses each of its two admissible machines with probability 21 .) The proof employs a graph-theoretic lemma about orientations in 3-regular graphs, which may be of independent interest. This is a particularly pleasing case where algorithmic game theory rewards graph theory with a wealth of new interesting problems about orientations in regular graphs.

ALGORITHMIC MECHANISM DESIGN

299

A lower bound on price of anarchy is also provided in the work of Els¨asser et al. [26]. In particular, it is proved that there is an interaction graph incurring price of anarchy (log n/log log n). This bound relies on a proof employing pure Nash equilibria. Finally, the authors present counterexample interaction graphs to prove that a fully mixed Nash equilibrium may sometimes not exist at all. (A characterization of interaction graphs admitting fully mixed Nash equilibria is still missing.) Moreover, they prove existence and uniqueness properties of the fully mixed Nash equilibrium for complete bipartite graphs and hypercube graphs. The problems left open in the work by Els¨asser et al. [26] invite graph theory to a pleasing excursion into algorithmic game theory.

10.3.5

Adaptive Routing with Stale Information

Fischer and V¨ocking [29] consider the problem of adaptive routing in networks by selﬁsh users that lack central control. The main focus of this work is on simple adaption policies, or dynamics, that make possible use of stale information. The analysis provided in the work by Fischer and V¨ocking [29] covers a wide class of dynamics encompassing the well-known replicator dynamics and other dynamics from evolutionary game theory; the basic milestone is the well-known fact that choosing the best option on the basis of out-of-date information can lead to undesirable oscillation effects and poor overall performance. Fischer and V¨ocking [29] show that it is possible to cope with this problem, and guarantee efﬁcient convergence toward an equilibrium state, for all of this broad class of dynamics, if the function describing the cost of an edge depending on its load is not too steep. As it turns out, guaranteeing convergence depends solely on the size of a single parameter describing the greediness of the agents! While the best response dynamics, which corresponds to always choosing the best option, performs well if information is always up-to-date, it is interestingly clear from the results in the work by Fischer and V¨ocking [29] that this policy fails when information is stale. More interestingly, Fischer and V¨ocking [29] present a dynamics that approaches the global optimal solution in networks of parallel links with linear latency functions as fast as the best response dynamics does, but which does not suffer from poor performance when information is out-of-date.

10.4 ALGORITHMIC MECHANISM DESIGN Mechanism design is a subﬁeld of game theory and microeconomics, which, generally speaking, deals with the design of protocols for rational agents. In most simple words, a mechanism design problem can be described as the task of selecting from a collection of (feasible) games, a game that will yield desirable results for the designer. Speciﬁcally, the theory of mechanism design has focused on problems where the goal is to satisfactorily aggregate privately known preferences of several agents toward a social choice. Intuitively, a mechanism design problem has two components:

300

ALGORITHMIC GAME THEORY AND APPLICATIONS

The usual algorithmic output speciﬁcation. Descriptions of what the participating agents want, formally given as utility functions over the set of possible outputs (outcomes). The origin of algorithmic mechanism design is marked with the seminal paper of Nisan and Romen [76]. A mechanism solves a given problem by assuring that the required outcome occurs, under the assumption that agents choose their strategies as to maximize their own selﬁsh utilities. A mechanism needs thus to ensure that players’ utilities (which it can inﬂuence by handing out payments) are compatible with the algorithm. Recall that the routing problem in large-scale networks where users are instinctively selﬁsh can be modeled as a noncooperative game. Such a game is expected to impose strategies that would induce an equilibrium as close to the overall optimum as possible. Two possible approach to formulate such strategies are through pricing mechanisms [28] and network design [57,87]. In the ﬁrst approach, the network administrator deﬁnes prices (or rules) in a way that induces near optimal performance when the users act selﬁshly. This approach has been considered in the works by Caragiannis et al. [10] and Cole et al. [16] (see also references therein). In the second approach, the network manager takes part in the noncooperative game. The manager has the ability to control centrally a part of the system resources, while the rest of the resources are to be shared by the selﬁsh users. This approach has been studied through Stackelberg or leader–follower games [50,85] (see also references therein). We here overview some issues related to how should the manager assign the ﬂow he controls into the system, with the objective to induce optimal cost in spite of the behavior of the selﬁsh users. 10.4.1

Stackelberg Games

Roughgarden [85], studied the problem of optimizing the performance of a system shared by selﬁsh, noncooperative users assigned to shared machines with loaddependent latency functions. Roughgarden measured system performance by the total latency of the system. (This measure is different from that used in the KP model.) Assigning jobs according to the selﬁsh interests of individual users typically results in suboptimal system performance. However, in many systems of this type, there is a mixture of “selﬁshly controlled” and “centrally controlled” jobs; as the assignment of centrally controlled jobs will inﬂuence the subsequent actions by selﬁsh users, the degradation in system performance due to selﬁsh behavior can be reduced by scheduling the centrally controlled jobs in the best possible way. Stackelberg games provide a framework that ﬁts this situation in an excellent way. A Stackelberg game is a special game where there are two kinds of entities: a number of selﬁsh entities, called players, that are interested in optimizing their own utilities, and a distinguished leader controlling a number of non-self-interested entities called followers; the leader aims at improving the social welfare and decides on the strategies of the followers so that the resulting situation will induce suitable decisions for the players that will optimize social welfare (as much as possible).

ALGORITHMIC MECHANISM DESIGN

301

Roughgarden [85] formulated this particular goal for such a selﬁsh routing system as an optimization problem via Stackelberg games. The problem is then to compute a strategy for the leader (a Stackelberg strategy) that induces the followers to react in a way that (at least approximately) minimizes the total latency in the system. Roughgarden [85] proved that, perhaps not surprisingly, it is N P-hard to compute the optimal Stackelberg strategy; he also presented simple strategies with provable performance guarantees. More precisely, Roughgarden [85] gave a simple algorithm to compute a strategy inducing a job assignment with total latency no more than a small constant times that of the optimal assignment for all jobs; in the absence of centrally controlled jobs and a Stackelberg strategy, no result of this type is possible. Roughgarden also proved stronger performance guarantees in the special case where every latency function is linear in the load. 10.4.1.1 The Price of Optimum Kaporis and Spirakis [50] continued the study of the Stackelberg games from the work by Roughgarden [85]. They considered a system of parallel machines, each with a strictly increasing and differentiable load-dependent latency function. The users of such a system are of inﬁnite number and act selﬁshly, routing their inﬁnitesimally small portion of the total ﬂow they control to machines of currently minimum delay. In that work, such a system is modeled as a Stackelberg or leader–follower game motivated by the work by Roughgarden and Tardos [88]. Roughgarden [85] had presented the LLF Stackelberg strategy for a leader in a Stackelberg game with an inﬁnite number of followers, each routing its inﬁnitesimal ﬂow through machines of currently minimum delay (this is called the ﬂow model in the work by Roughgarden [85]). An important question posed there was the computation of the least portion βM that a leader must control in order to enforce the overall optimum cost on the system. An algorithm that computes βM was presented and its optimality was also shown [50]. Most importantly, it was proved that the algorithm presented is optimal for any class of latency functions for which Nash and optimum assignments can be efﬁciently computed. This is one of a very few known cases where the computation of optimal Stackelberg strategies is reduced to the computation of (pure) Nash equilibria and optimal assignments. 10.4.2

Cost Sharing Mechanisms

In its most general form, a cost sharing mechanism speciﬁes how costs originating from resource consumption in a selﬁsh system should be shared among the users of the system. Apparently, not all sharing ways are good. Intuitively, a cost sharing mechanism is good if it can induce equilibria optimizing social welfare as much as possible. This point of view was adopted in a recent work by Mavronicolas et al. [65]. In more detail, a simple and intuitive cost mechanism that assigns costs for the competitive usage of m resources by n selﬁsh agents was proposed by Mavronicolas et al. [65]. Each agent has an individual demand; demands are drawn according to some (unknown) probability distribution coming from a (known) class of probability distributions. The cost paid by an agent for a resource he chooses is the total demand

302

ALGORITHMIC GAME THEORY AND APPLICATIONS

put on the resource divided by the number of agents who chose that same resource. So, resources charge costs in an equitable, fair way, while each resource makes no proﬁt out of the agents. This simple model was called fair pricing in the work by Mavronicolas et al. [65]. 1 Mavronicolas et al. [65] analyzed the Nash equilibria (both pure and mixed) for the induced game; in particular, they consider the fully mixed Nash equilibrium, where each agent selects each resource with nonzero probability. While offering (in addition) an advantage with respect to convenience in handling, the fully mixed Nash equilibrium is suitable for that economic framework under the very natural assumption that each resource offers usage to all agents without imposing any access restrictions. The most signiﬁcant contribution of the work by Mavronicolas [65] was the introduction of the diffuse price of anarchy for the analysis of Nash equilibria in the induced game. Roughly speaking, the diffuse price of anarchy is an extension to the price of anarchy that takes into account the probability distribution of the demands. Roughly speaking, the diffuse price of anarchy is the worst case, over all allowed probability distributions, of the expectation (according to each speciﬁc probability distribution) of the ratio of social cost over optimum in the worst-case Nash equilibrium. The diffuse price of anarchy is meant to alleviate the sometimes overly pessimistic Price of Anarchy due to Koutsoupias and Papadimitriou [60] (which is a worst-case measure) by introducing and analyzing stochastic assumptions on the system inputs. Mavronicolas et al. [65] proved that pure Nash equilibria may not exist unless all chosen demands are identical; in contrast, a fully mixed Nash equilibrium exists for all possible choices of the demands. Further on, it was proved that the fully mixed Nash equilibrium is the unique Nash equilibrium in case there are only two agents. It was also shown that, in the worst-case choice of demands, the price of anarchy is (n); for the special case of two agents, the price of anarchy is less than 2 − 1/m. A plausible assumption is that demands are drawn from a bounded, independent probability distribution, where all demands are identically distributed and each is at most a (universal for the class) constant times its expectation. Under this very general assumption, it is proved in the work by Mavronicolas et al. [65] that the diffuse price of anarchy is at most that same universal constant; the constant is just 2 when each demand is distributed symmetrically around its expectation. 10.4.3

Tax Mechanisms

How much can taxes improve the performance of a selﬁsh system? This is a very general question since it leaves three important dimensions of it completely unspeciﬁed: the precise way of modeling taxes, the selﬁsh system itself, and the measure of performance. Making speciﬁc choices for these three dimensions gives rise to speciﬁc interesting questions about taxes. There is already a sizeable amount of lit1 One could argue that this pricing scheme is unfair in the sense that players with smaller demands can be forced to support those players with larger demands that share the same resource. However, the model can also be coined as fair on account of the fact that it treats all players sharing the same resource equally, and players are not overcharged beyond the actual cost of the resource they choose.

NETWORK SECURITY GAMES

303

erature addressing such questions and variants of them (see, e.g., the works by Caragiannis et al. [10], Cole et al. [16], and Fleischer et al. [31] and references therein). In this section, we brieﬂy describe the work of Caragiannis et al. [10], and we refer the reader to the work by Cole et al. [16] and Fleischer et al. [16,31] for additional related results. Caragiannis et al. [10] consider the (by now familiar) class of congestion games due to Rosenthal [84] as their selﬁsh system; they consider several measures for social welfare, including total latency and a new interesting measure they introduce, called total disutility, which is the sum of latencies plus taxes incurred to players. Caragiannis et al. [10] focus on the well-studied case of linear latency functions, and they provide many (both positive and negative) interesting results. Their most interesting positive result is (in our opinion) the fact that there is a way to assign taxes that can improve the performance of congestion games by forcing players to follow strategies by which the total latency is within a factor of two of the least possible; Caragiannis et al. prove that, most interestingly, this is the best possible way of assigning taxes. Furthermore, Caraginannis et al. [10] consider cases where the system performance may be very poor in the absence of taxes; they prove that, fortunately, in such cases the total disutility cannot be much larger than the optimal total latency. Another interesting result emanating from the work of Caragiannis et al. [10] is that there is a polynomial-time algorithm (based on solving convex quadratic programs) to compute good taxes; this represents the ﬁrst result on the efﬁciency of taxes for linear congestion games.

10.5 NETWORK SECURITY GAMES It is an undeniable fact that the huge growth of the Internet has signiﬁcantly extended the importance of network security [90]. Unfortunately, as it is well known, many widely used Internet systems and components are prone to security risks (see, e.g., the work by Cheswick and Bellovin [14]); some of these risks have even led to successful and well-publicized attacks [89]. Typically, an attack exploits the discovery of loopholes in the security mechanisms of the Internet. Attacks and defenses are currently attracting a lot of interest in major forums of communication research. A current challenge for algorithmic game theory is to invent and analyze appropriate theoretical models of security attacks and defenses for emerging networks like the Internet. Two independent research teams, one consisting of Aspnes et al. [6] and another consisting of Mavronicolas et al. [67,68], initiated recently the introduction of strategic games on graphs (and the study of their associated Nash equilibria) as a means of studying security problems in networks with selﬁsh entities. The nontrivial results achieved by these two teams exhibit a novel interaction of ideas, arguments, and techniques from two seemingly diverse ﬁelds, namely game theory and graph theory. This research line invites a simultaneously game-theoretic and graph-theoretic analysis of network security problems, where not only threats seek to maximize their caused damage to the network, but also the network seeks to protect itself as much as possible.

304

ALGORITHMIC GAME THEORY AND APPLICATIONS

The two graph-theoretic models of Internet security can be cast as particular cases of the so-called interdependent security games studied earlier by Kearns and Ortiz [52]. There, a large number of players must make individual decisions related to security. The ultimate safety of each player may depend in a complex way on the actions of the entire population.

10.5.1

A Virus Inoculation Game

Aspnes et al. [6] consider an interesting graph-theoretic game with an interesting security ﬂavor, modeling containment of the spread of viruses on a network with installable antivirus software. In this game, the antivirus software may be installed at individual nodes; a virus damages a node if it can reach the node starting at a random initial node and proceeding to it without crossing a node with installed antivirus software. Aspnes et al. [6] prove several algorithmic properties for their graph-theoretic game and establish connections to a certain graph-theoretic problem called sum-of-squares partition. Moscibroda et al. [72] initiate the study of Byzantine game theory in the context of the speciﬁc virus inoculation game introduced by Aspnes et al. [6]. In their extension, they allow some players to be malicious or Byzantine rather than selﬁsh. They ask the very natural question of what the impact of Byzantine players on the performance of the system compared to either the purely selﬁsh setting (where all players are self-interested and there are no Byzantine players) or to the social optimum is. To address such questions, they introduce the very interesting notion of the price of malice that captures the efﬁciency degradation due to the presence of Byzantine players (on top of selﬁsh players). Moscibroda et al. [72] use the price of malice to quantify how much the presence of Byzantine players can deteriorate the social welfare of the distributed system corresponding to the virus inoculation game of Aspnes et al. [6]. Most interestingly, Moscibroda et al. [72] demonstrate that in case the selﬁsh players are highly risk-averse, the social welfare of the system can improve as a result of taking Byzantine players into account! We expect that Byzantine game theory will further develop in the upcoming years and be applied successfully to evaluate the impact of Byzantine players on the performance of selﬁsh computer systems.

10.5.2

A Network Security Game

The work of Mavronicolas et al. [67,68] considers a security problem on a distributed network modeled as a multiplayer noncooperative game with attackers (e.g., viruses) and a defender (e.g., a security software) entities. More speciﬁcally, there are two classes of confronting randomized players on a graph: ν attackers, each choosing vertices and wishing to minimize the probability of being caught, and a single defender, who chooses edges and gains the expected number of attackers it catches. The authors exploit both game-theoretic and graph-theoretic tools for analyzing the associated Nash equilibria.

COMPLEXITY OF COMPUTING EQUILIBRIA

305

In a subsequent work, Mavronicolas et al. [64] introduced the price of defense in order to evaluate the loss in the provided security guarantees due to the selﬁsh nature of attacks and defenses. The work address the question of whether there are Nash equilibria that both are computationally tractable and offer good price of defense. An extensive collection of trade-offs between price of defense and the computational complexity of Nash equilibria is provided in the work of Mavronicolas et al. [64]. Most interestingly, the work of Mavronicolas et al. [64,66–68] introduce certain natural classes of Nash equilibria for their network security game on graphs, including matching Nash equilibria [67,68] and perfect matching Nash equilibria [64]; they prove that deciding the existence of equilibria from such classes is precisely equivalent to the recognition problem for K¨onig–Egervary graphs [25,54]. So, this establishes a very interesting (and perhaps unexpected) link to some classical pearls in graph theory.

10.6 COMPLEXITY OF COMPUTING EQUILIBRIA By Nash’s celebrating result [73,74] every strategic game has at least one Nash equilibrium (and an odd number of them). What is the complexity of computing one? Note that this question is meaningful exactly when the payoff table is given in some implicit way that allows for a succinct representation. The celebrated algorithm of Lemke and Howson [61] shows that for bimatrix games this complexity is no more than exponential. 10.6.1

Pure Nash Equilibria

A core question in the study of Nash equilibria is which games have pure Nash equilibria. Also, under what circumstances can we ﬁnd one (assuming that there is one) in polynomial time? Recall that congestion games make a class of games that are guaranteed to have pure Nash equilibria. In a classical paper [84], Rosenthal proves that, in any such game, the Nash dynamics converges; equivalently, the directed graph with action combinations as nodes and payoff-improving deviations by individual players as edges is acyclic. Hence, the game has pure Nash equilibria that are the sinks of this graph. The proof is based on a simple potential function. This existence theorem, however, again left open the question of whether there is a polynomial-time algorithm for ﬁnding pure Nash equilibria in congestion games. Fabrikant et al. [27] prove that the answer to this general question is positive when all players have the same origin and destination (the so-called symmetric case); a pure Nash equilibrium is found by computing the optimum of Rosenthal’s potential function through a reduction to min-cost ﬂow. However, it is shown that computing a pure Nash equilibrium in the general network case is PLS-complete [49]. Intuitively, this means that it is as hard to compute as any object whose existence is guaranteed by a potential function. (The precise deﬁnition of the complexity class PLS is beyond the scope of this chapter.) The proof of Fabrikant et al. [27] has the interesting con-

306

ALGORITHMIC GAME THEORY AND APPLICATIONS

sequence: the existence of examples with exponentially long shortest paths, as well as the PSPACE-completeness for the problem of computing a Nash equilibrium reachable from a speciﬁed state. The completeness proof requires reworking the reduction to the problem of ﬁnding local optimal of weighted MAX2SAT instances. Ackermann et al. [1] present a signiﬁcantly simpler proof based on a PLS-reduction from MAX-CUT showing that ﬁnding Nash equilibria in network congestion games is PLS-complete even for the case of linear latency functions. Additional results about the complexity of pure Nash equilibria in congestion games appear in the works of Ackermann et al. [1,2]. Gottlob et al. [45] provide a comprehensive study of complexity issues related to pure Nash equilibria. They consider restrictions of strategic games intended to capture certain aspects of bounded rationality. For example, they show that even in the settings where each player’s payoff function depends on the strategies of at most three other players, and where each player is allowed to choose one out of at most three strategies, the problem of determining whether a game has a pure Nash equilibrium is N P-complete. On the positive side, they also identiﬁed tractable classes of games. 10.6.2

Mixed Nash Equilibria

Daskalakis et al. [20] consider the complexity of Nash equilibria in a game with four or more players. They show that this problem is complete for the complexity class PPAD. Intuitively, this means that a polynomial-time algorithm would imply a similar algorithm, for example, for computing Brouwer ﬁxpoints; note that this is a problem for which quite strong lower bounds for large classes of algorithms are known [48]. (A precise deﬁnition of the complexity class PPAD is beyond the scope of this chapter.) Nash [73,74] had shown his celebrated result on the existence of Nash equilibria by reducing the existence of Nash equilibria to the existence of Brouwer ﬁxpoints. Given any strategic game, Nash constructs a Brouwer function whose ﬁxpoints are precisely the equilibria of the game. In Nash’s reduction, as well as in subsequent simpliﬁed ones [42], the constructed Brouwer function is quite specialized; this has led to the speculation that the ﬁxpoints of such functions (thus, Nash equilibria) are easier to ﬁnd than for general Brouwer functions. This question is answered in the negative by presenting a very interesting reduction in the opposite direction [20]: Any (computationally presented) Brouwer function can be simulated by a suitable game, so that Nash equilibria correspond to ﬁxpoints. It is proved that computing a Nash equilibrium in a three-player game is also PPAD-complete [23]. The proof is based on a variant of an arithmetical gadget from [44], Independently, Chen and Deng [11] have also come up with a quite different proof of the same result. In a very recent paper [12], Chen and Deng settle the complexity of Nash equilibria for two-player strategic games with a PPAD-completeness proof. Their proof derived a direct reduction from a search problem called the three-dimensional Brouwer problem, which is known to be PPAD-complete [20] to the objective problem. The

COMPLEXITY OF COMPUTING EQUILIBRIA

307

completeness proof of the work by Chen and Deng[12] utilizes new gadgets for various arithmetic and logic operations. 10.6.3

Approximate Nash Equilibria

As it is always the case, an established intractability invites an understanding of the limits of approximation. Since it was established that computing a Nash equilibrium is PPAD-complete [20], even for two-player strategic games [12], the question of computing approximate Nash equilibria has emerged as the central remaining open problem in the area of computing Nash equilibria. Assume from this point on that all utilities have been normalized to be between 0 and 1. (Clearly, this assumption is without any loss of generality.) Say that a set of mixed strategies is an ε-approximate Nash equilibrium, where ε > 0, if for each player all strategies have expected payoff that is at most ε more that the expected payoff for its strategy in the given set. (So, ε is an additive approximation term.) Lipton et al. [62] proved that an ε-approximate Nash equilibrium can be computed 2 in time O(nε /log n ) (that is, in strictly subexponential time) by examining all supports of size log n/2 . It had been earlier pointed out [4] that no algorithm examining supports smaller than about log n can achieve an approximation better than 41 , even for zero-sum games. In addition, it is easy to see that a 43 -approximation Nash equilibrium can be found (in polynomial time) by examining all supports of size 2. Two research teams, one consisting of Daskalakis et al. [21] and the other of Kontogiannis et al. [56], investigated very recently the approximability of Nash equilibria in two-player games, and established essentially identical, strong results. Most remarkably, there is a simple, linear-time algorithm in the work by Daskalakis et al. [21], which builds heavily on a corresponding algorithm from the work by Kontogiannis et al. [56]; it examines just two strategies per player and results in a 21 -approximate Nash equilibrium for any two-player game. Daskalakis et al. [21] also looked at the more demanding notion of well-supported approximate Nash equilibria introduced in the work by Daskalakis et al. [20] and present an interesting reduction (of the same problem) to win–lose games (that is, games with all utilities equal to 0 and 1). For this more demanding notion, Daskalakis et al. showed that an approximation of 56 is possible contingent upon a graph-theoretic conjecture. Chen et al. [13] establish strong inapproximability results for approximate Nash equilibria. Their results imply that it is unlikely to obtain a fully polynomial-time approximation scheme for Nash equilibria (unless PPAD ⊆ P). 10.6.4

Correlated Equilibria

Nash equilibrium [73,74] is widely accepted as the standard notion of rationality in game theory. However, there are several other competing formulations of rationality; chief among them is the correlated equilibrium, proposed by Aumann [7]. Observe that the mixed Nash equilibrium is a distribution on the strategy space that is uncorrelated or independent; that is, it is the product of independent probability distributions, one for each player. In sharp contrast, a correlated equilibrium is a general distribution

308

ALGORITHMIC GAME THEORY AND APPLICATIONS

over strategy proﬁles. It must, however, possess an equilibrium property: If a strategy proﬁle is drawn according to this distribution, and each player is told separately his suggested strategy (that is, his own component in the proﬁle), then no player has an incentive to switch to a different strategy (assuming that all other players also obey), because the suggested strategy is the best in expectation. Correlated equilibria enjoy a very nice combinatorial structure: The set of correlated equilibria of a multiplayer, noncooperative game is a convex polytope, and all Nash equilibria are not only included in this polytope but they all lie on the boundary of the polytope. (See the work by Nau et al. [75] for an elegant elementary proof of this latter result.) As noted in the own words of Papadimitriou [82], the correlated equilibrium has several important advantages: It is a perfectly reasonable, simple, and plausible concept; it is guaranteed to always exist (simply because the Nash equilibrium is a particular case of a correlated equilibrium); and it can be found in polynomial time for any number of players and strategies by linear programming, since the inequalities specifying the satisfaction of all players are linear. In fact, it turns out that the correlated equilibrium that optimizes any linear function of the players’ utilities (e.g., their sum) can be computed in polynomial time. Succinct Games Equilibria in games, of which the correlated equilibrium is a prominent example, are objects worth of studying from the algorithmic point of view. Multiplayer games are the most compelling specimens in this regard. But, to be of algorithmic interest, they must be represented succinctly. Succinct representation is required since otherwise a typical (multiplayer) game would need an exponential size of bits in order to be described. Some well-known games that admit a succinct representation include Symmetric games, where all players are identical and indistinguishable. Graphical games [51], where the players are the vertices of a graph, and the payoff for each player only depends on its own strategy and those of its neighbors. Congestion games, where the payoff of each player only depends on its strategy and those choosing the same strategy as him. Papadimitriou and Roughgarden [83] initiated the systematic study of algorithmic issues involved in ﬁnding equilibria (both Nash and correlated) in games with a large number of players, which are succinctly represented. The authors develop a general framework for obtaining polynomial-time algorithms for optimizing over correlated equilibria in such settings. They show how such algorithms can be applied successfully to symmetric games, graphical games, and congestion games, among others. They also present complexity results, implying that such algorithms are not in sight for certain other similar games. Finally, a polynomial-time algorithm, based on quantiﬁer elimination, for ﬁnding a Nash equilibrium in symmetric games (when the number of strategies is relatively small) was presented. Daskalakis and Papadimitriou [22] studied from the complexity point of view the problem of ﬁnding equilibria in games played on highly regular graphs with

REFERENCES

309

extremely succinct representation, such as the d-dimensional grid. There, it is argued that such games are of interest in modeling large systems of interacting agents. It has been shown by Daskalakis and Papadimitriou [22] that the problem of determining whether such a game on the d-dimensional grid has a pure Nash equilibrium depends on d, and the dichotomy is remarkably sharp: It is polynomial time solvable when d = 1, but N EX P-complete for d ≥ 2. In contrast, it was also proved that mixed Nash equilibria can be found in deterministic exponential time for any ﬁxed d by quantiﬁer elimination. Recently, Papadimitriou [82] considered, and largely settled, the question of the existence of polynomial-time algorithms for computing correlated equilibria in succinctly representable multiplayer games. Papadimitriou developed a polynomial-time algorithm for ﬁnding correlated equilibria in a broad class of succinctly representable multiplayer games, encompassing essentially all kinds of such games we mentioned before. The algorithm presented by Papadimitriou [82] was based on a careful mimicking of the existence proof due to Hart and Schmeidler [47], combined with an argument based on linear programming duality and the ellipsoid algorithm, Markov chain steady state computations, as well as application-speciﬁc methods for computing multivariate expectations. 10.7 DISCUSSION In this chapter, we attempted a glimpse at the fascinating ﬁeld of algorithmic game theory. This is a ﬁeld that is currently undergoing a very intense investigation by the community of the theory of computing. Although some fundamental theoretical questions have been resolved (e.g., the complexity of computing Nash equilibria for two-player games), there are still a lot of challenges ahead of us. Among those, most important are, in our opinion, the further complexity classiﬁcation of algorithmic problems in game theory, and the further application of systematic techniques from game theory to modeling and evaluating modern computer systems with selﬁsh entities. ACKNOWLEDGMENT This work was partially supported by the IST Program of the European Union under contract number IST-2004-001907 (DELIS). REFERENCES 1. Ackermann H, R¨oglin H, V¨ocking B. On the impact of combinatorial structure on congestion games. Proceedings of the 47th Annual IEEE Symposium on Foundations of Computer Science (FOCS 2006). IEEE Press; 2006. p 613–622. 2. Ackermann H, R¨oglin H, V¨ocking B. Pure Nash equilibria in player-speciﬁc and weighted congestion games. Proceedings of the 2nd International Workshop on Internet and

310

ALGORITHMIC GAME THEORY AND APPLICATIONS

Network Economics (WINE 2006). Lecture Notes in Computer Science. Volume 4286. Springer; 2006. p 50–61. 3. Aland S, Dumrauf D, Gairing M, Monien B, Schoppmann F. Exact price of anarchy for polynomial congestion games. Proceedings of the 23rd International Symposium on Theoretical Aspects of Computer Science (STACS 2006). Lecture Notes in Computer Science. Volume 3884. Springer; 2006; p 218–229. 4. Althofer I. On sparse approximations to randomized strategies and convex combinations. Linear Algebra Appl 1994;199:339–355. 5. Anshelevich E, Dasgupta A, Kleinberg J, Tardos E, Wexler T, Roughgarden T. The price of stability for network design with fair cost allocation. Proceedings of the 45th Annual IEEE Symposium on Foundations of Computer Science (FOCS 2004). IEEE Press; 2004. p 295–304. 6. Aspnes J, Chang K, Yampolskiy A. Inoculation strategies for victims of viruses and the sumof-squares partition problem. Proceedings of the 16th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2005). Society for Industrial and Applied Mathematics; 2005. p 43–52. 7. Aumann RJ. Subjectivity and correlation in randomized strategies. J Math Econ 1974;1: 67–96. 8. Awerbuch B, Azar Y, Epstein A. The price of routing unsplittable ﬂow. Proceedings of the 37th Annual ACM Symposium on Theory of Computing (STOC 2005). ACM Press; 2005. p 57–66. 9. Awerbuch B, Azar Y, Richter Y, Tsur D. Tradeoffs in worst-case equilibria. Theor Comput Sci 2006;361(2–3):200–209. 10. Caragiannis I, Kaklamanis C, Kanellopoulos P. Taxes for linear atomic congestion games. Proceedings of the 13th Annual European Symposium on Algorithms (ESA 2006). Volume 4168. 2006. p 184–195. 11. Chen X, Deng X. 3-Nash is PPAD-complete. Technical Report No. TR05-134. Electronic Colloquium in Computational Complexity (ECCC); 2005. 12. Chen X, Deng X. Settling the complexity of 2-player Nash-equilibrium. Proceedings of the 47th Annual IEEE Symposium on Foundations of Computer Science. IEEE Press; 2006. p 261–272. 13. Chen X, Deng X, Teng S. Computing Nash equilibria: approximation and smoothed complexity. Proceedings of the 47th Annual IEEE Symposium on Foundations of Computer. IEEE Press; 2006. p 603–612. 14. Cheswick ER, Bellovin SM. Firewalls and Internet Security. Addison-Wesley; 1994. 15. Christodoulou G, Koutsoupias E. The price of anarchy of ﬁnite congestion games. Proceedings of the 37th Annual ACM Symposium on Theory of Computing (STOC 2005). ACM Press; 2005. p 67–73. 16. Cole R, Dodis Y, Roughgarden T. Pricing network edges for heterogeneous selﬁsh users. Proceedings of the 35th Annual ACM Symposium on Theory of Computing (STOC 2003). ACM Press; 2003. p 521–530. 17. Czumaj A, Krysta P, V¨ocking B. Selﬁsh trafﬁc allocation for server farms. Proceedings of the 34th Annual ACM Symposium on Theory of Computing (STOC 2002). ACM Press; 2002. p 287–296.

REFERENCES

311

18. Czumaj A, V¨ocking B. Tight bounds for worst-case equilibria. Proceedings of the 13th Annual ACM-SIAM Symposium on discrete Algorithms (SODA 2002). Society for Industrial and Applied Mathematics; 2002. p 413–420. 19. Daskalakis C, Fabrikant A, Papadimitriou CH. The game world is ﬂat: the complexity of Nash equilibria in succinct games. Proceedings of the 33rd International Colloquium on Automata, Languages and Programming (ICALP 2006). Lecture Notes in Computer Science. Volume 4051. Springer; 2006. p 513–524. 20. Daskalakis C, Goldberg PW, and Papadimitriou CH. The complexity of computing a Nash equilibrium. Proceedings of the 38th Annual ACM Symposium on Theory of Computing (STOC 2006). ACM Press; 2006. p 71–78. 21. Daskalakis C, Mehta A, Papadimitriou C. A note on approximate Nash equilibria. Proceedings of the 2nd International Workshop on Internet and Network Economics (WINE 2006). Lecture Notes in Computer Science. Volume 4286. Springer; 2006. p 297–306. 22. Daskalakis C, Papadimitriou CH. The complexity of equilibria in highly regular graph games. Proceedings of the 13th Annual European Symposium on Algorithms (ESA 2005). Lecture Notes in Computer Science. Volume 3669. Springer; 2005. p 71–82. 23. Daskalakis C, Papadimitriou CH. Three-player games are hard. Technical report TR05-139. Electronic Colloquium in Computational Complexity (ECCC); 2005. 24. Dumrauf D, Gairing M. Price of anarchy for polynomial wardrop games. Proceedings of the 2nd International Workshop on Internet and Network Economics (WINE 2006). Lecture Notes in Computer Science. Volume 4286. Springer; 2006. p 319–330. 25. Egerv´ary J. Matrixok kombinatorius tulajdons´agair´ol. Matematikai e´ s Fizikai Lapok 1931;38:16–28. 26. Els¨asser R, Gairing M, L¨ucking T, Mavronicolas M, Monien B. A simple graph-theoretic model for selﬁsh restricted scheduling. Proceedings of the 1st International Workshop on Internet and Network Economics (WINE 2005). Lecture Notes in Computer Science. Volume 3828. Springer; 2005. p 195–209. 27. Fabrikant A, Papadimitriou CH, Talwar K. The complexity of pure Nash equilibria. Proceedings of the 36th Annual ACM Symposium on Theory of Computing (STOC 2004). ACM Press; 2004. p 604–612. 28. Feigenbaum J, Papadimitriou CH, Shenker S. Sharing the cost of muliticast transmissions. J Comput Sys Sci 2001;63:21–41. 29. Fischer S, V¨ocking B. Adaptive routing with stale information. Proceedings of the 24th Annual ACM Symposium on Principles of Distributed Computing (PODC 2005). ACM Press; 2005. p 276–283. 30. Fischer S, V¨ocking B. On the structure and complexity of worst-case equilibria. Proceedings of the 1st Workshop on Internet and Network Economics (WINE 2005). Lecture Notes in Computer Science. Volume 3828. Springer Verlag; 2005. p 151–160. 31. Fleischer L, Jain K, Mahdian M. Tolls for heterogeneous selﬁsh users in multicommodity networks and generalized congestion games. Proceedings of the 45th Annual IEEE Symposium on Foundations of Computer Science (FOCS 2004). IEEE Press; 2004. p 277–285. 32. Fotakis D, Kontogiannis S, Spirakis P. Selﬁsh unsplittable ﬂows. Theor Comp Sci 2005;348(2–3):226–239.

312

ALGORITHMIC GAME THEORY AND APPLICATIONS

33. Fotakis D, Kontogiannis S, Spirakis P. Symmetry in network congestion games: pure equilibria and anarchy cost. Proceedings of the 3rd International Workshop on Approximation and Online Algorithms (WAOA 2005). Lecture Notes in Computer Science. Volume 3879. Springer; 2006. p 161–175. 34. Fotakis D, Kontogiannis SC, Koutsoupias E, Mavronicolas M, Spirakis PG, The structure and complexity of Nash equilibria for a selﬁsh routing game. Proceedings of the 29th International Colloquium on Automata, Languages and Programming (ICALP 2002). Lecture Notes in Computer Science. Volume 2380. Springer; 2002. p 123–134. 35. Gairing M, L¨ucking T, Mavronicolas M, Monien B. Computing Nash equilibria for scheduling on restricted parallel links. Proceedings of the 36th Annual ACM Symposium on Theory of Computing (STOC 2004). ACM Press; 2004. p 613–622. 36. Gairing M, L¨ucking T, Mavronicolas M, Monien B. The price of anarchy for polynomial social cost. Proceedings of the 29th International Symposium on Mathematical Foundations of Computer Science (MFCS 2004). Lecture Notes in Computer Science. Volume 3153. Springer; 2004. p 574–585. 37. Gairing M, L¨ucking T, Mavronicolas M, Monien B, Rode M. Nash equilibria in discrete routing games with convex latency functions. Proceedings of the 31st International Colloquium on Automata, Languages and Programming (ICALP 2004). Lecture Notes in Computer Science. Volume 3142. Springer; 2004. p 645–657. 38. Gairing M, L¨ucking T, Mavronicolas M, Monien B, Spirakis PG. Extreme Nash equilibria. Proceedings of the 8th Italian Conference of Theoretical Computer Science (ICTCS 2003). Lecture Notes in Computer Science. Volume 2841. Springer; 2003. p 1–20. 39. Gairing M, L¨ucking T, Mavronicolas M, Monien B, Spirakis PG. Structure and complexity of extreme Nash equilibria. Theor Comput Sci 2005;343(1–2):133–157. (Special issue titled Game Theory Meets Theoretical Computer Science, M. Mavronicolas and S. Abramsky, guest editors). 40. Gairing M, Monien B, Tiemann K. Selﬁsh routing with incomplete information. Proceedings of the 17th Annual ACM Symposium on Parallelism in Algorithms and Architectures (SPAA 2005), ACM Press; 2005. p 203–212. Extended version accepted to Theory of Computing Systems, Special Issue with selected papers from the 17th Annual ACM Symposium on Parallelism in Algorithms and Architectures (SPAA 2005). 41. Gairing M, Monien B, Tiemann K. Routing (un-)splittable ﬂow in games with playerspeciﬁc linear latency functions. Proceedings of the 33rd International Colloquium on Automata, Languages and Programming (ICALP 2006). Lecture Notes in Computer Science. Volume 4051. Springer; 2006. p 501–512. 42. Geanakoplos J. Nash and Walras equilibrium via Brouwer. Econ Theor 2003;2(2–3): 585–603. 43. Georgiou C, Pavlides T, Philippou A. Network uncertainty in selﬁsh routing. CD-ROM Proceedings of the 20th IEEE International Parallel and Distributed Processing Symposium (IPDPS 2006); 2006. 44. Goldberg PW, Papadimitriou CH. Reducibility among equilibrium problems. Proceedings of the 38th Annual ACM Symposium on Theory of Computing (STOC 2006). ACM Press; 2006. p 61–70. 45. Gottlob G, Greco G, Scarcello F. Pure Nash equilibria: hard and easy games. J Artif Intell Res 2005;24:357–406.

REFERENCES

313

46. Harsanyi JC. Games with incomplete information played by Bayesian players, I, II, III. Manage Sci 1967;14:159–182, 320–332, 468–502. 47. Hart S, Schmeidler D. Existence of correlated equilibria. Math Oper Res 1989;14(1): 18–25. 48. Hirsch M, Papadimitriou CH, Vavasis S. Exponential lower bounds for ﬁnding brouwer ﬁxpoints. J Complexity 1989;5:379–41. 49. Johnson DS, Papadimitriou CH, Yannakakis M. How easy is local search? J Comp Sys Sci 1988;17(1):79–100. 50. Kaporis A, Spirakis P. The price of optimum in stackelberg games. Proceedings of the 18th Annual ACM Symposium on Parallelism in Algorithms and Architectures (SPAA 2006); 2006. p 19–28. 51. Kearns M, Littman M, Singh S. Graphical models for game theory. Proceedings of the 17th Conference on Uncertainty in Artiﬁcial Intelligence; 2001. p 253–260. 52. Kearns M, Ortiz L. Algorithms for interdependent security games. Proceedings of the 16th Annual Conference on Neural Information Processing Systems (NIPS 2004). MIT Press; 2004. p 288–297. ´ Algorithm Design. Addison-Wesley; 2005. 53. Kleinberg J, Tardos E. 54. K¨onig D. Graphok e´ s Matrixok. Matematikai e´ s Fizikai Lapok 1931;38:116–119. 55. Kontogiannis S, Spirakis P. Atomic selﬁsh routing in networks: a survey. Proceedings of the 1st International Workshop on Internet and Network Economics (WINE 2005). Lecture Notes in Computer Science. Volume 3828. Springer; 2005. p 989–1002. 56. Kontogiannis SC, Panagopoulou PN, Spirakis PG. Polynomial algorithms for approximating Nash equilibria of bimatrix games. Proceedings of the 2nd International Workshop on Internet and Network Economics (WINE 2006); Lecture Notes in Computer Science. Volume 4286. Springer; 2006. p 286–296. 57. Korilis YA, Lazar A, Orda A. The designer’s perspective to noncooperative networks. Proceedings of the 14th Annual Joint Conference of the IEEE Computer and Communications Societies (IEEE INFOCOM 1995). Volume 2; 1995. p 562–570. 58. Korilis YA, Lazar A, Orda A. Achieving network optima using Stackelberg routing strategies. IEEE/ACM T Netw 1997;5(1):161–173. 59. Koutsoupias E, Mavronicolas M, Spirakis PG. Approximate equilibria and ball fusion. Theor Comput Syst 2003;36(6):683–693. 60. Koutsoupias E, Papadimitriou CH. Worst-case equilibria. Proceedings of the 16th International Symposium on Theoretical Aspects of Computer Science (STACS 1999). Lecture Notes in Computer Science. Volume 1563. Springer; 1999. p 404–413. 61. Lemke CE, Howson JT, Jr. Equilibrium points of bimatrix games. J Soc Ind Appl Math 1964;12:413–423. 62. Lipton RJ, Markakis E, Mehta A. Playing large games using simple strategies. Proceedings 4th ACM Conference on Electronic Commerce (EC-2003). ACM Press; 2003. p 36–41. 63. L¨ucking T, Mavronicolas M, Monien B, Rode M. A new model for selﬁsh routing. Proceedings of the 21st International Symposium on Theoretical Aspects of Computer Science (STACS 2004). Lecture Notes in Computer Science. Volume 2996. Springer; 2004. p 547–558. 64. Mavronicolas M, Michael L, Papadopoulou VG, Philippou A, Spirakis PG. The price of defense. Proceedings of the 31st International Symposium on Mathematical Foundations

314

ALGORITHMIC GAME THEORY AND APPLICATIONS

of Computer Science (MFCS 2006). Lecture Notes in Computer Science. Volume 4162. Springer, 2006. p 717–728. 65. Mavronicolas M, Panagopoulou P, Spirakis P. A cost mechanism for fair pricing of resource usage. Proceedings of the 1st International Workshop on Internet and Network Economics (WINE 2005). Lecture Notes in Computer Science. Volume 3828. Springer; 2005. p 210–224. 66. Mavronicolas M, Papadopoulou VG, Persiano G, Philippou A, Spirakis P. The price of defense and fractional matchings. Proceedings of the 8th International Conference on Distributed Computing and Networking (ICDCN 2006). Lecture Notes in Computer Science. Volume 4308. Springer; 2006. p 115–126. 67. Mavronicolas M, Papadopoulou VG, Philippou A, Spirakis PG. A graph-theoretic network security game. Proceedings of the 1st International Workshop on Internet and Network Economics (WINE 2005). Lecture Notes in Computer Science. Volume 3828. Springer; 2005. p 969–978. 68. Mavronicolas M, Papadopoulou VG, Philippou A, Spirakis PG. A network game with attacker and protector entities. Proceedings of the 16th Annual International Symposium on Algorithms and Computation (ISAAC 2005). Lecture Notes in Computer Science. Volume 3827. Springer; 2005. p 288–297. 69. Mavronicolas M, Spirakis P. The price of selﬁsh routing. Proceedings of the 33th Annual ACM Symposium on Theory of Computing (STOC 2001). ACM Press; 2001. p 510–519. Full version accepted to Algorithmica. 70. Milchtaich I. Congestion games with player-speciﬁc payoff functions. Games Econ Behav 1996;13(1):111–124. 71. Monderer D, Shapley LS. Potential games. Games Econ Behav 1996;14(1):124–143. 72. Moscibroda T, Schmid S, Wattenhofer R. When selﬁsh meets evil: byzantine players in a virus inoculation game. Proceedings of the 25th Annual ACM Symposium on Principles of Distributed Computing (PODC 2006). ACM Press; 2006. 73. Nash JF. Equilibrium points in N-person games. Proc Natl Acad Sci USA 1950;36: 48–49. 74. Nash JF. Non-cooperative games. Ann Math 1951;54(2):286–295. 75. Nau R, Canovas SG, Hansen P. On the geometry of Nash equilibria and correlated equilibria. Int J Game Theor 2003;32(4):443–453. 76. Nisan N, Ronen A. Algorithmic mechanism design. Games Econ Behav 2001;35(1-2): 166–196. 77. Osborne M. An Introduction to Game Theory. Oxford University Press; 2003. 78. Osborne M, Rubinstein A. A Course in Game Theory. MIT Press; 1994. 79. Panagopoulou P, Spirakis P. Efﬁcient convergence to pure Nash equilibria in weighted network congestion games. Proceedings of the 4th International Workshop on Efﬁcient and Experimental Algorithms (WEA 2005). Lecture Notes in Computer Science. Volume 3503. Springer; 2005. p 203–215. 80. Papadimitriou CH. Computational Complexity. Addison-Wesley; 1994. 81. Papadimitriou CH. Algorithms, games, and the Internet. Proceedings of the 33th Annual ACM Symposium on Theory of Computing (STOC 2001). ACM Press; 2001. p 749–753.

REFERENCES

315

82. Papadimitriou CH. Computing correlated equilibria in multi-player games. Proceedings of the 37th Annual ACM Symposium on Theory of Computing (STOC 2005). ACM Press; 2005. p 49–56. 83. Papadimitriou CH, Roughgarden T. Computing equilibria in multi-player games. Proceedings of the 16th Annual ACM–SIAM Symposium on Discrete Algorithms (SODA 2005). Society for Industrial and Applied Mathematics; 2005. p 82–91. 84. Rosenthal RW. A class of games possessing pure-strategy Nash equilibria. Int J Game Theor 1973;2:65–67. 85. Roughgarden T. Stackelberg scheduling strategies. SIAM J Comput 2003;33(2):332–350. 86. Roughgarden T. Selﬁsh Routing and the Price of Anarchy. MIT Press; 2005. 87. Roughgarden T. On the severity of Braess’s paradox: designing networks for selﬁsh users is hard. J Comput Syst Sci 2006. p 922–953. ´ How bad is selﬁsh routing? J ACM 2002;49(2):236–259. 88. Roughgarden T, Tardos E. 89. Spafford EH. The Internet worm: crisis and aftermath. Commun ACM 1989;6(2–3): 678–687. 90. Stallings W. Cryptography and Network Security: Principles and Practice. 3rd ed. PrenticeHall; 2003.

CHAPTER 11

Algorithms for Real-Time Object Detection in Images MILOS STOJMENOVIC

11.1 INTRODUCTION 11.1.1

Overview of Computer Vision Applications

The ﬁeld of Computer Vision (CV) is still in its infancy. It has many real-world applications, and many breakthroughs are yet to be made. Most of the companies in existence today that have products based on CV can be divided into three main categories: auto manufacturing, computer circuit manufacturing, and face recognition. There are other smaller categories of this ﬁeld that are beginning to be developed in industry such as pharmaceutical manufacturing applications and trafﬁc control. Auto manufacturing employs CV through the use of robots that put the cars together. Computer circuit manufacturers use CV to visually check circuits in a production line against a working template of that circuit. CV is used as quality control in this case. The third most common application of CV is in face recognition. This ﬁeld has become popular in the last few years with the advent of more sophisticated and accurate methods of facial recognition. Applications of this technology are used in security situations like checking for hooligans at sporting events and identifying known thieves and cheats in casinos. There is also the related ﬁeld of biometrics where retinal scans, ﬁngerprint analysis, and other identiﬁcation methods are conducted using CV methods. Trafﬁc control is also of interest because CV software systems can be applied to already existing hardware in this ﬁeld. By trafﬁc control, we mean the regulation or overview of motor trafﬁc by means of the already existing and functioning array of police monitoring equipment. Cameras are already present at busy intersections, highways, and other junctions for the purposes of regulating trafﬁc, spotting problems, and enforcing laws such as running red lights. CV could be used to make all of these tasks automatic.

Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

317

318

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

11.2 MACHINE LEARNING IN IMAGE PROCESSING AdaBoost and support vector machines (SVMs) are, among others, two very popular and conceptually similar machine learning tools for image processing. They are both based on ﬁnding a set of hyperplanes to separate the sets of positive and negative examples. Current image processing culture involving machine learning for real-time performance almost exclusively uses AdaBoost instead of SVMs. AdaBoost is easier to program and has proven itself to work well. There are very few papers that deal with real-time detection using SVM principles. This makes the AdaBoost approach a better choice for real-time applications. A number of recent papers, using both AdaBoost and SVMs, conﬁrm the same, and even apply a two-phase process. Most windows are processed in the ﬁrst phase by AdaBoost, and in the second phase, an SVM is used on difﬁcult cases that could not be easily eliminated by AdaBoost. This way, the real-time constraint remains intact. Le and Satoh [16] maintain that “The pure SVM has constant running time of 554 windows per second (WPS) regardless of complexity of the input image, the pure AdaBoost (cascaded with 37 layers—5924 features) has running time of 640, 515 WPS.” If a pure SVM approach was applied to our test set, it would take 17, 500, 000/554 ≈ 9 h of pure run time to test the 106 images. It would take roughly 2 min to process an image of size 320 × 240. Thus, Lee and Satoh [16] claim that cascaded AdaBoost is 1000 times faster than SVMs. A regular AdaBoost with 30 features was presented in the works by Stojmenovic [24,25]. A cascaded design cannot speed up the described version by more than 30 times. Thus, the program in the works by Stojmenovic [24,25] is faster than SVM by over 1000/30 > 30 times. Bartlett et al. [3] used both AdaBoost and SVMs for their face detection and facial expression recognition system. Although they state that “AdaBoost is signiﬁcantly slower to train than SVMs,” they only use AdaBoost for face detection, and it is based on Viola and Jones’ approach [27]. For the second phase, facial expression recognition on detected faces, they use three approaches: AdaBoost, SVMs, and a combined one (all applied on Gabor representation), and reported differences within 3 percent of each other. They gave a simple explanation for choosing AdaBoost in the face detection phase, “The average number of features that need to be evaluated for each window is very small, making the overall system very fast” [3]. Moreover, each of these features is evaluated in constant time, because of integral image preprocessing. That performance is hard to beat, and no other approach in image processing literature for real-time detection is seriously considered now. AdaBoost was proposed by Freund and Schapire [8]. The connection between AdaBoost and SVMs was also discussed by them [9]. They even described two very similar expressions for both of them, where the difference was that the Euclidean norm was used by SVMs while the boosting process used Manhattan (city block) and maximum difference norms. However, they also list several important differences. Different norms may result in very different margins. A different approach is used to efﬁciently search in high dimensional spaces. The computation requirements are different. The computation involved in maximizing the margin is mathematical pro-

MACHINE LEARNING IN IMAGE PROCESSING

319

gramming, that is, maximizing a mathematical expression given a set of inequalities. The difference between the two methods in this regard is that SVM corresponds to quadratic programming, while AdaBoost corresponds only to linear programming [9]. Quadratic programming is more computationally demanding than linear programming [9]. AdaBoost is one of the approaches where a “weak” learning algorithm, which performs just slightly better than random guessing, is “boosted” into an arbitrarily accurate “strong” learning algorithm. If each weak hypothesis is slightly better than random, then the training error drops exponentially fast [9]. Compared to other similar learning algorithms, AdaBoost is adaptive to the error rates of the individual weak hypotheses, while other approaches required that all weak hypotheses need to have accuracies over a parameter threshold. It is proven [9] that AdaBoost is indeed a boosting algorithm in the sense that it can efﬁciently convert a weak learning algorithm into a strong learning algorithm (which can generate a hypothesis with an arbitrarily low error rate, given sufﬁcient data). Freund and Schapire [8] state “Practically, AdaBoost has many advantages. It is fast, simple, and easy to program. It has no parameters to tune (except for the number of rounds). It requires no prior knowledge about the weak learner and so can be ﬂexibly combined with any method for ﬁnding weak hypotheses. Finally, it comes with a set of theoretical guarantees given sufﬁcient data and a weak learner that can reliably provide only moderately accurate weak hypotheses. This is a shift in mind set for the learning-system designer: instead of trying to design a learning algorithm that is accurate over the entire space, we can instead focus on ﬁnding weak learning algorithms that only need to be better than random. On the other hand, some caveats are certainly in order. The actual performance of boosting on a particular problem is clearly dependent on the data and the weak learner. Consistent with theory, boosting can fail to perform well given insufﬁcient data, overly complex weak hypotheses, or weak hypotheses that are too weak. Boosting seems to be especially susceptible to noise.” Schapire and Singer [23] described several improvements to Freund and Schapire’s [8] original AdaBoost algorithm, particularly in a setting in which hypotheses may assign conﬁdences to each of their predictions. More precisely, weak hypotheses can have a range over all real numbers rather than the restricted range [−1, +1] assumed by Freund and Schapire [8]. While essentially proposing a general fuzzy AdaBoost training and testing procedure, Howe and coworkers [11] do not describe any speciﬁc variant, with concrete fuzzy classiﬁcation decisions. We propose in this chapter a speciﬁc variant of fuzzy AdaBoost. Whereas Freund and Schapire [8] prescribe a speciﬁc choice of weights for each classiﬁer, Schapire and Singer [23] leave this choice unspeciﬁed, with various tunings. Extensions to multiclass classiﬁcations problems are also discussed. In practice, the domain of successful applications of AdaBoost in image processing is any set of objects that are typically seen from the same angle and have a constant orientation. AdaBoost can successfully be trained to identify any object if this object is viewed from an angle similar to that in the training set. Practical real-world examples that have been considered so far include faces, buildings, pedestrians, some animals,

320

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

and cars. The backbone of this research comes from the face detector work done by Viola et al. [27]. All subsequent papers that use and improve upon AdaBoost are inspired by it.

11.3 VIOLA AND JONES’ FACE DETECTOR The face detector proposed by Viola and Jones [27] was the inspiration for all other AdaBoost applications thereafter. It involves different stages of operation. The training of the AdaBoost machine is the ﬁrst part and the actual use of this machine is the second part. Viola and Jones’ contributions come in the training and assembly of the AdaBoost machine. They had three major contributions: integral images, combining features to ﬁnd faces in the detection process, and use of a cascaded decision process when searching for faces in images. This machine for ﬁnding faces is called cascaded AdaBoost by Viola and Jones [27]. Cascaded AdaBoost is a series of smaller AdaBoost machines that together provide the same function as one large AdaBoost machine, yet evaluate each subwindow more quickly, which results in real-time performance. To understand cascaded AdaBoost, regular AdaBoost will have to be explained ﬁrst. The following sections will describe Viola and Jones’ face detector in detail. Viola and Jones’ machine takes in a square region of size equal to or greater than 24 × 24 pixels as input and determines whether the region is a face or is not a face. This is the smallest size of window that can be declared a face according to Viola and Jones. We use such a machine to analyze the entire image, as illustrated in Figure 11.1. We pass every subwindow of every scale through this machine to ﬁnd all subwindows that contain faces. A sliding window technique is therefore used. The window is shifted 1 pixel after every analysis of a subwindow. The subwindow grows in size 10 percent every time all of the subwindows of the previous size were exhaustively searched. This means that the window size grows exponentially at a rate of (1.1)p ,

FIGURE 11.1 Subwindows of an image.

VIOLA AND JONES’ FACE DETECTOR

321

where p is the number of scales. In this fashion, more than 90 percent of faces of all sizes can be found in each image. As with any other machine learning approach, the machine must be trained using positive and negative examples. Viola and Jones used 5000 positive examples of randomly found upright, forward-facing faces and 10,000 negative examples of any other nonface objects as their training data. The machine was developed by trying to ﬁnd combinations of common attributes, or features of the positive training set that are not present in the negative training set. The library of positive object (head) representatives contains face pictures that are concrete examples. That is, faces are cropped from larger images, and positive examples are basically closeup portraits only. Moreover, positive images should be of the same size (that is, when cut out of larger images, they need to be scaled so that all positive images are of the same size). Furthermore, all images are frontal upright faces. The method is not likely to work properly if the faces change orientation. 11.3.1

Features

An image feature is a function that maps an image into a number or a vector (array). Viola and Jones [27] used only features that map images into numbers. Moreover, they used some speciﬁc types of features, obtained by selecting several rectangles within the training set, ﬁnding the sum of pixel intensities in each rectangle, assigning a positive or negative sign and/or weight to each sum, and then summing them. The pixel measurements used by Viola and Jones were the actual grayscale intensities of pixels. If the areas of the dark (positive sign) and light (negative sign) regions are not equal, the weight of the lesser region is raised. For example, feature 2.1 in Figure 11.2 has a twice greater light area than a dark one. The area of the dark rectangle in this case would be multiplied by 2 to normalize the feature. The main problem is to ﬁnd which of these features, among the thousands available, would best distinguish positive and negative examples, and how to combine them into a learning machine. Figure 11.2 shows the set of basic shapes used by Viola and Jones [27]. Adding features to the feature set can increase the accuracy of the AdaBoost machine at the cost of additional training time. Each of the shapes seen in Figure 11.2 is scaled and translated anywhere in the test images, consequently forming features. Therefore, each feature includes a basic shape (as seen in Fig. 11.2), its translated position in the image, and its scaling factors (height and width scaling). These features deﬁne the separating ability between positive and negative sets. This phenomenon is illustrated in Figure 11.3. Both of the features seen in Figure 11.3 (each deﬁned by its position and scaling factors) are derived from the basic shapes in Figure 11.2.

FIGURE 11.2 Basic shapes that generate features by translation and scaling.

322

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

FIGURE 11.3 First and second features in Viola and Jones face detection.

Figure 11.3 shows the ﬁrst and second features selected by the program [27]. Why are they selected? The ﬁrst feature shows the difference in pixel measurements for the eye area and area immediately below it. The “black” rectangle covering the eyes is ﬁlled with predominantly darker pixels, whereas the area immediately beneath the eyes is covered with lighter pixels. The second feature also concentrates on the eyes, showing the contrast between two rectangles containing eyes and the area between them. This feature corresponds to feature 2.1 in Figure 11.2 where the light and dark areas are inverted. This is not a separate feature; it was drawn this way in Figure 11.3 to better depict the relatively constant number obtained by this feature when it is evaluated in this region on each face. 11.3.2

Weak Classiﬁers (WCs)

A WC is a function of the form h(x, f, s, θ), where x is the tested subimage, f is the feature used, s is the sign (+ or −), and θ is the threshold. The sign s deﬁnes on what side of the threshold the positive examples are located. Threshold θ is used to establish whether a given image passes a classiﬁer test in the following fashion: when feature f is evaluated on image x, the resulting number is compared to threshold θ to determine how this image is categorized by the given feature. The equation is given as sf (x)

323

VIOLA AND JONES’ FACE DETECTOR

In general, the threshold is found to be the value θ that best separates the positive and negative sets. When a feature f is selected as a “good” distinguisher of images between positive and negative sets, its value would be similar for images in the positive set and different for all other images. When this feature is applied to an individual image, a number f (x) is generated. It is expected that values f (x) for positive and negative images can be separated by a threshold value of θ. It is worthy to note that a single WC needs only to produce results that are slightly better than chance to be useful. A combination of WCs is assembled to produce a strong classiﬁer as seen in the following text. 11.3.3

Strong Classiﬁers

A strong classiﬁer is obtained by running the AdaBoost machine. It is a linear combination of WCs. We assume that there are T WCs in a strong classiﬁer, labelled h1 , h2 , . . . , hT , and each of these comes with its own weight labeled α1 , α2 , . . . , αT . Tested image x is passed through the succession of WCs h1 (x), h2 (x), . . . , hT (x), and each WC assesses if the image passed its test. The assessments are discrete values: hi (x) = 1 for a pass and hi (x) = 0 for a fail. αi (x) are in the range [0, +∞]. Note that hi (x) = hi (x, fi , si , θi ) is abbreviated here for convenience. The decision that classiﬁes an image as being positive or negative is made by the following inequality: α1 h1 (x) + α2 h2 (x) + . . . + αT hT (x) > α/2

where α =

T

αi .

i=1

From this equation, we see that images that pass a weighted average of half of the WC tests are cataloged as positive. It is therefore a weighted voting of selected WCs. 11.3.4

AdaBoost: Meta Algorithm

In this section we explain the general principles of the AdaBoost (an abbreviation of Adaptive Boosting) learning strategy [8]. First, a huge (possibly hundreds of thousands) “panel” of experts is identiﬁed. Each expert, or WC, is a simple thresholdbased decision maker, which has a certain accuracy. The AdaBoost algorithm will select a small panel of these experts, consisting of possibly hundreds of WCs, each with a weight that corresponds to its contribution in the ﬁnal decision. The expertise of each WC is combined in a classiﬁer so that more accurate experts carry more weight. The selection of WCs for a classiﬁer is performed iteratively. First, the best WC is selected, and its weight corresponds to its overall accuracy. Iteratively, the algorithm identiﬁes those records in the training data that the classiﬁer built so far was unable to capture. The weights of the misclassiﬁed records increase since it becomes more important to correctly classify them. Each WC might be adjusted by changing its threshold to better reﬂect the new weights in the training set. Then a single WC is selected, whose addition to the already selected WCs will make the greatest contribution to improving the classiﬁer’s accuracy. This process continues iteratively

324

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

until a satisfactory accuracy is achieved, or the limit for the number of selected WCs is reached. The details of this process may differ in particular applications, or in particular variants of the AdaBoost algorithm. There exist several AdaBoost implementations that are freely available in Weka (Java-based package http://www.cs.waikato.ac.nz/ml) and in R (http://www.rproject.org). Commercial data mining toolkits that implement AdaBoost include TreeNet, Statistica, and Virtual Predict. We did not use any of these packages for two main reasons. First, our goal was to achieve real-time performance, which restricted the choice of programming languages. Next, we have modiﬁed the general algorithm to better suit our needs, which required us to code it from scratch. AdaBoost is a general scheme adaptable to many classifying tasks. Little is assumed about the learners (WCs) used. They should merely perform only a little better than random guesses in terms of error rates. If each WC is always better than a chance, then AdaBoost can be proven to converge to a perfectly accurate classiﬁer (no training error). Boosting can fail to perform if there is insufﬁcient data or if WCs are overly complex. It is also susceptible to noise. Even when the same problem is being solved by different people applying AdaBoost, the performance greatly depends on the training set being selected and the choice of WCs (that is, features). In the next subsection, the details of the AdaBoost training algorithm, as used by Viola and Jones [27], will be given. In this approach, positive and negative training sets are separated by a cascade of classiﬁers, each constructed by AdaBoost. Real time performance is achieved by selecting features that can be computed in constant time. The training time of the face detector appears to be slow, even taking months according to some reports. Viola and Jones’ face ﬁnding system has been modiﬁed in literature in a number of articles. The AdaBoost machine itself was modiﬁed in literature in several ways. 11.3.5

AdaBoost Training Algorithm

We now show how to create a classiﬁer with the AdaBoost machine. It follows the algorithm given in the work by Viola and Jones [27]. The machine is given images (x1 , y1 ), . . . , (xq , yq ) as input, where yi = 1 or 0 for positive and negative examples, respectively. In iteration t, the ith image is assigned the weight w(t, i), which corresponds to the importance of that image for a good classiﬁcation. The initial weights are w(1, i) = 1/(2p), 1/(2n), for yi = 0 or 1, respectively, where n and p are the numbers of negatives and positives, respectively, q = p + n. That is, all positive images have equal weight, totaling 21 , and similarly for all negative images. The algorithm will select, in step t, the tth feature f, its threshold value θ, and its direction of inequality s(s = 1 or − 1). The classiﬁcation function is h(x, f, s, θ) = 1 (declared positive) if sf (x)

VIOLA AND JONES’ FACE DETECTOR

325

We revisit the classiﬁcation of numbers and letters example to illustrate the assignment of weights in the training procedure. We assume that feature 1 classiﬁes the example set in the order seen below. The threshold is chosen to be just after the “7” since this position minimizes the classiﬁcation error. We will call the combination of feature 1 with its threshold WC 1. We notice that “I”, “9,” and “2” were incorrectly classiﬁed. The number of incorrect classiﬁcations determines the weight α1 of this classiﬁer. The fewer errors that it makes, the heavier the weight it is awarded.

The weights of the incorrectly classiﬁed examples (I, 9, and 2) are increased before ﬁnding the next feature in an attempt to ﬁnd a feature that can better classify cases that are not easily sorted by previous features. We assume that feature two orders the example set as seen below.

Setting the threshold just after the “2” minimizes the error in classiﬁcation. We notice that this classiﬁer makes more mistakes in classiﬁcation than its predecessor. This means that its weight, α2 , will be less that α1 . The weights for elements “E”, “I,” “8,” and “4” are increased. These are the elements that were incorrectly classiﬁed by WC 2. The actual training algorithm will be described in pseudocode below. For t=1 to T do: Normalize the weights w(t, i), by dividing each of them with their sum (so that the new sum of all weights becomes 1); swp ← sum of weights of all positive images swn ← sum of weights of all negative images (* note that swp + swn = 1 *) FOR each candidate feature f, ﬁnd f (xi ) and w(t, i)∗ f (xi ), i = 1, . . . , q. - Consider records (f (xi ), yi , w(t, i)). Sort these records by the f (xi ) ﬁeld with mergesort, in increasing order. Let the obtained array of the f (xi ) ﬁeld be g1 , g2 , . . . , gq . The corresponding records are (gj , status(j), w (j)) = (f (xi ), yi , w(t, i)), where gj = f (xi ). That is, if the jth element gj is equal to ith element from the original array f (xi ) then status(j) = yi and w (j) = w(t, i). (*Scan through the sorted list, looking for threshold θ and direction s that minimizes the error e(f, s, θ)∗ ) sp ← 0; sn ← 0; (*weight sums for positives/negatives below a considered threshold *) emin ← minimal total weighted classiﬁcation error If swn

326

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

else { emin ← swp; smin ← 1; θmin ← g1 − 1 } (*all declared negative *) For j ← 1 to q-1 do { If status(j) = 1 then sp ← sp + w (j) else sn ← sn + w (j) θ ← (gj + gj+1 )/2 If sp + swn − sn

classiﬁer, if needed: 0 if xi is correctly classiﬁed bycurrent ht 1−e w(t + 1, i) ← w(t, i)βt , where e= 1otherwise EndFor; AdaBoost therefore assigns large weights with each good classiﬁcation and small weights with each poor function. The selection of the next feature depends on selections made for previous features. 11.3.6

Cascaded AdaBoost

Viola and Jones [27] also described the option of designing a cascaded AdaBoost. For example, instead of one AdaBoost machine with 100 classiﬁers, one could design 10 such machines with 10 classiﬁers in each. In terms of precision, there will not be much difference, but testing for most images will be faster [27]. One particular image is ﬁrst tested on the ﬁrst classiﬁer. If declared as nonsimilar, it is not tested further. If it cannot be rejected, then it is tested with the second machine. This process continues until either one machine rejects an image, or all machines “approve” it, and similarity is conﬁrmed. Figure 11.4 illustrates this process. Each classiﬁer seen in Figure 11.4 comprises one or more features. The features that deﬁne a classiﬁer are chosen so that their combination eliminates as much as possible all negative images that are

FIGURE 11.4 Cascaded decision process.

VIOLA AND JONES’ FACE DETECTOR

327

FIGURE 11.5 Concept of a classiﬁer.

passed through this classiﬁer, while at the same time accepting nearly 100 percent of the positives. It is desirable that each classiﬁer eliminates at least 50 percent of the remaining negatives in the test set. A geometric progression of elimination is created until a desired threshold of classiﬁcation is attained. The number of features in each classiﬁer varies. It typically increases with the number of classiﬁers added. In Viola and Jones’ face ﬁnder cascade, the ﬁrst classiﬁers had 2, 10, 25, 25, and 50 features, respectively. The number of features grew very rapidly afterward. Typical numbers of features per classiﬁer ranged in the hundreds. The total number of features used was roughly 6000 in Viola and Jones’ application. Figure 11.5 will help explain the design procedure of the cascaded design process. We revisit the letters and numbers example in our efforts to show the development of a strong classiﬁer in the cascaded design. At the stage seen in Figure 11.5, we assume to have two WCs with weights α1 and α2 . Together these two WCs make a conceptual hyperplane depicted by the solid dark blue line. In actuality, this line is not a hyperplane (in this case a line in two-dimensional space), but a series of orthonormal dividers. It is, however, conceptually easier to explain the design of a strong classiﬁer in a cascade if we assume that WCs form hyperplanes. So far in Figure 11.5, we have two WCs where the decision inequality would be of the form α1 h1 (x) + α2 h2 (x) > α/2, where α = α1 + α2 . At this stage, the combination of the two WCs would be checked against the training set to see if they have a 99 percent detection rate (this 99 percent is a design parameter). If the detection rate is below the desired level, the threshold α/2 is replaced with another threshold γ such that the detection rate increases to the desired level. This has the conceptual effect of translating the dark blue hyperplane in Figure 11.5 to the dotted line. This also has a residual effect of increasing the false positive rate. At the same time, once we are happy with the detection rate, we check the false positive rate of the shifted threshold detector. If this rate is satisfactory, for example, below 50 percent (also a design parameter), then the construction of the classiﬁer is completed. The negative examples that were correctly identiﬁed by this classiﬁer are ignored from further consideration by future classiﬁers. There is no need to consider them if they are already success-

328

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

fully eliminated by a previous classiﬁer. In Figure 11.5, “D”, “C,” and “F” would be eliminated from future consideration if the classiﬁer construction were completed at this point. 11.3.7

Integral Images

One of the key contributions in the work by Viola and Jones [27] (which is used and/or modiﬁed by Levi and Weiss [17], Luo et al. [19], etc.) is the introduction of a new image representation called the “integral image,” which allows the features used by their detector to be computed very quickly. In the preprocessing step, Viola and Jones [27] ﬁnd the sums ii(a, b) of pixel intensities i(a , b ) for all pixels (a , b ) such that a ≤ a, b ≤ b. This can be done in one pass over the original image using the following recurrences: s(a, b) = s(a, b − 1) + i(a, b), ii(a, b) = ii(a − 1, b) + s(a, b), where s(a, b) is the cumulative row sum, s(a, −1) = 0, and ii(−1, b) = 0. In preﬁx sum notation, the expression for calculating the integral image values is ii(a, b) =

i(a , b ).

a ≤a,b ≤b

Figure 11.6 shows an example of how the “area” for rectangle “D” can be calculated using only four operations. Let the area mean the sum of pixel intensities of a rectangular region. The preprocessing step would have found the values of corners 1, 2, 3, and 4, which are in effect the areas of rectangles A, A + B, A + C, and A + B + C + D, respectively. Then the area of rectangle D is = (A + B + C + D) +

FIGURE 11.6 Integral image.

329

CAR DETECTION

(A) − (A + B) − (A + C) = “4” + “1” − “2” − “3”. Jones and Viola [12] built one face detector for each view of the face. A decision tree is then trained to determine the viewpoint class (such as right proﬁle or rotated 60 degrees) for a given window of the image being examined. The appropriate detector for that viewpoint can then be run instead of running all of the detectors on all windows.

11.4 CAR DETECTION The most popular example of object detection is the detection of faces. The fundamental application that gave credibility to AdaBoost was Viola and Jones’ real-time face ﬁnding system [27]. AdaBoost is the concrete machine learning method that was used by Viola and Jones to implement the system. The car detection application was inspired by the work of Viola and Jones. It is based on the same AdaBoost principles, but a variety of things, both in testing and in training, were adapted and enhanced to suit the needs of the CV system described in the works by Stojmenovic [24,25]. The goal of this chapter is to analyze the capability of current machine learning techniques of solving similar image retrieval problems. The “capability” of the system includes real-time performance, a high detection rate, low false positive rate, and learning with a small training set. Of particular interest are cases where the training set is not easily available, and most of it needs to be manually created. As a particular case study, we will see the application of machine learning to the detection of rears of cars in images [24,25]. Speciﬁcally, the system is able to recognize cars of a certain type such as a Honda Accord 2004. While Hondas have been used as an instance, the same program, by just replacing the training sets, could be used to recognize other types of cars. Therefore, the input should be an arbitrary image, and the output should be that same image with a rectangle around any occurrence of the car we are searching for (see Fig. 11.7). The system will work by directly searching for an occurrence of the positive in the image, while treating all subwindows of the image the same way. It will not ﬁrst search for a general vehicle class and then specify the model of the vehicle. This is a different and much more complicated task that is not easily solvable by machine learning. Any occurrence of a rectangle around a part of the image that is not a rear of a Honda Accord 2004 is considered a negative detection. The image size in the testing set is arbitrary, while the image sizes in both the negative and positive training sets are the same. Positive training examples are the rears of Hondas. The data set was collected by taking pictures of Hondas (about

FIGURE 11.7 Input and output of the testing procedure.

330

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

300 of them) and other cars. The training set was actually manually produced by cropping and scaling positives from images to a standard size. Negative examples in the training set include any picture, of the same ﬁxed size, that cannot be considered as a rear of a Honda. This includes other types of cars, as close negatives, for improving the classiﬁer’s accuracy. Thus, a single picture of a larger size contains thousands of negatives. When a given rectangle around a rear of a Honda is slightly translated and scaled, one may still obtain a positive example, visually and even by the classiﬁer. That is, a classiﬁer typically draws several rectangles at the back of each Honda. This is handled by a separate procedure that is outside the machine learning framework. In addition to precision of detection, the second major main goal of the system was real-time performance. The program should quickly ﬁnd all the cars of the given type and position in an image, in the same way that Viola and Jones ﬁnds all the heads. The deﬁnition of “real time” depends on the application, but generally speaking the system delivers an answer for testing an image within a second. The response time depends on the size of the tested image, thus what appears to be real-time for smaller images may not be so for larger ones. Finally, this object detection system is interesting since it is based on a small number of training examples. Such criteria are important in cases where training examples are not easily available. For instance, in the works by Stojmenovic [24,25], photos of back views of a few hundred Honda Accords and other cars were taken manually to create training sets, since virtually no positive images were found on the Internet. In such cases, it is difﬁcult to expect that one can have tens of thousands of images readily available, which was the case for the face detection problem. The additional beneﬁt of a small training set is that the training time is reduced. This enabled us to perform a number of training attempts, adjust the set of examples, adjust the set of features, test various sets of WCs, and otherwise analyze the process by observing the behavior of the generated classiﬁers. 11.4.1

Limitations and Generalizations of Car Detection

Machine learning methods were applied in the work by Stojmenovic [24] in an attempt to solve the problem of detecting rears of a particular car type since they appear to be appropriate given the setting of the problem. Machine learning in similar image retrieval has proven to be reliable in situations where the target object does not change orientation. As in the work of Viola and Jones [27], cars are typically found in the same orientation with respect to the road. The situation Stojmenovic [24] is interested in is the rear view of cars. This situation is typically used in monitoring trafﬁc since license plates are universally found at the rears of vehicles. The positive images were taken such that all of the Hondas have the same general orthogonal orientation with respect to the camera. Some deviation occurred in the pitch, yaw, and roll of these images, which might be why the resulting detector has such a wide range of effectiveness. The machine that was built is effective for the following deviations in angles: pitch −15◦ ; yaw −30◦ to 30◦ ; and roll −15◦ to 15◦ . This means that pictures of Hondas taken from angles that are off by the stated amounts

CAR DETECTION

331

are still detected by the program. Yaw, pitch, and roll are common jargon in aviation describing the three degrees of freedom the pilot has to maneuver an aircraft. Machine learning concepts in the CV ﬁeld that deal with retrieving similar objects within images are generally faced with the same limitations and constraints. All successful real-time applications in this ﬁeld have been limited to successfully ﬁnding objects from only one view and one orientation that generally does not vary much. There have been attempts to combine several strong classiﬁers into one machine, but discussing only individual strong classiﬁers, we conclude that they are all sensitive to variations in viewing angle. This limits their effective range of real-world applications to things that are generally seen in the same orientation. Typical applications include faces, cars, paintings, posters, chairs, some animals, and so on. The generalization of such techniques to problems that deal with widely varying orientations is possible only if the real-time performance constraint is lifted. Another problem that current approaches are faced with is the size of the training sets. It is difﬁcult to construct a sufﬁciently large training database for rare objects. 11.4.2

Fast AdaBoost Based on a Small Training Set for Car Detection

This section describes the contributions and system [24] for detecting cars in real time. Stojmenovic [24] has revised the AdaBoost-based learning environment, for use in their object recognition problem. It is based on some of the ideas from literature, and some new ideas, all combined into a new machine. The feature set used in the work Stojmenovic [24,25] initially included most of the feature types used by Viola and Jones [27] and Lienhart [14]. The set did not include rotated features [14], since the report on their usefulness was not convincing. Edge orientation histogram (EOH)-based features [17] were considered a valuable addition and were included in the set. New features that resemble the object being searched for, that is, custom-made features, were also added. Viola and Jones [27] and most followers used weight-based AdaBoost, where the training examples receive weights based on their importance for selecting the next WC, and all WCs are consequently retrained in order to choose the next best one. Stojmenovic [24,25] states that it is better to rely on the Fast AdaBoost variant [30], where all of the WCs are trained exactly once, at the beginning. Instead of the weighted error calculation, Stojmenovic [24] believes that it is better to select the next WC to be added as the one that, when added, will make the best contribution (measured as the number of corrections made) to the already selected WCs. Each selected WC will still have an associated weight that depends on its accuracy. The reason for selecting the Fast AdaBoost variant is to achieve an O(log q) time speed-up in the training process, believing that the lack of weights for training examples can be compensated for by other “tricks” that were applied to the system. Stojmenovic [24,25] has also considered a change in the AdaBoost logic itself. In existing logic, each WC returns a binary decision (0 or 1) and can therefore be referred to as the binary WC. In the machine proposed by Schapire and Singer [23], each WC will return a number in the range [−1, 1] instead of returning a binary decision (0 or 1), after evaluating the corresponding example. Such a WC will be referred to as a fuzzy

332

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

FIGURE 11.8 Positive training examples.

WC. Evaluation of critical cases is often done by a small margin of difference from the threshold. Although the binary WC may not be quite certain about evaluating a particular feature against the adopted threshold (which itself is also determined heuristically, therefore is not fully accurate), the current AdaBoost machine assigns the full weight to the decision on the corresponding WC. Stojmenovic [24,25] therefore described an AdaBoost machine based on a fuzzy WC. More precisely, the described system proposes a speciﬁc function for making decisions, while Schapire [23] left this choice unspeciﬁed. The system produces a “doubly weighted” decision. Each WC receives a corresponding weight α, then each decision is made in the interval [−1, 1]. The WC then returns the product of the two numbers, that is, a number in the interval [−α, α] as its “recommendation.” The sum of all recommendations is then considered. If positive, the majority opinion is that the example is a positive one. Otherwise, the example is a negative one. 11.4.3

Generating the Training Set

All positives in the training set were ﬁxed to be 100 × 50 pixels in size. The entire rear view of the car is captured in this window. Examples of positives are seen in Figure 11.8. The width of a Honda Accord 2004 is 1814 mm. Therefore, each pixel in each training image represents roughly 1814/100 = 18.14 mm of the car. A window of this size was chosen due to the fact that a typical Honda is unrecognizable to the human eye at lower resolutions; therefore, a computer would ﬁnd it impossible to identify accurately. Viola and Jones used similar logic in determining their training example dimensions. All positives in the training set were photographed at a distance of a few meters from the camera. Detected false positives were added in the negative training set (bootstrapping), in addition to a set of manually selected examples, which included backs of other car models. The negative set of examples perhaps has an even bigger impact on the training procedure than the positive set. All of the positive examples look similar to the human eye. It is therefore not important to overﬁll the positive set since all of the examples there should look rather similar. The negative set should ideally combine a large variety of different images. The negative images should vary with respect to their colors, shapes, and edge quantities and orientations. 11.4.4

Reducing Training Time by Selecting a Subset of Features

Viola and Jones’ faces were 24 × 24 pixels each. Car training examples are 100 × 50 pixels each. The implications of having such large training examples are immense from a memory consumption point of view. Each basic feature can be scaled in both height and width, and can be translated around each image. There are seven basic

CAR DETECTION

333

features used by Viola and Jones. They generated a total of 180,000 WCs [27]. Stojmenovic [24,25] also used seven basic features (as described below), and they generate a total of approximately 6.5 million WCs! Each feature is shifted to each position in the image and for every vertical and horizontal scale. By shifting our features by 2 pixels in each direction (instead of 1) and making scale increments of 2 during the training procedure, we were able to cut this number down to approximately 530,000, since every second position and scale of feature was used. In the initial training of the WCs, each WC is evaluated based on its cumulative error of classiﬁcation (CE). The cumulative error of a classiﬁer is CE = (false positives + number of missed examples)/total number of examples. WCs that had a CE that was greater than a predetermined threshold were automatically eliminated from further consideration. Details are given in the works by Stojmenovic [24,25]. 11.4.5

Features Used in Training for Car Detection

Levi and Weiss [17] stress the importance of using the right features to decrease the sizes of the training sets, and increase the efﬁciency of training. A good feature is the one that separates the positive and negative training sets well. The same ideology is applied here in hopes of saving time in the training process. Initially, all of Viola and Jones’ features were used in combination with the dominant edge orientation features proposed by Levi and Weiss [17] and the redness features proposed by Luo et al. [19]. It was determined that the training procedure never selected any of Viola and Jones’ grayscale features to be in the strong classiﬁer at the end of training. This is a direct consequence of the selected positive set. Hondas come in a variety of colors and these colors are habitually in the same relative locations in each positive case. The most obvious example is the characteristic red tail lights of the Honda accord. The redness features were included speciﬁcally to be able to use the redness of the tail lights as a WC. The training algorithm immediately exploited this distinguishing feature and chose the red rectangle around one of the tail lights as one of the ﬁrst WCs in the strong classiﬁer. The fact that the body of the Honda accord comes in its own subset of colors presented problems to the grayscale set of Viola and Jones’ features. When these body colors are converted to a grayscale space, they basically cover the entire space. No adequate threshold can be chosen to beneﬁcially separate positives from negatives. Subsequently, all of Viola and Jones’ features were removed due to their inefﬁciency. The redness features we refer to are taken from the work of Luo et al. [19]. More details are given in the works by Stojmenovic [24,25]. Several dominant edge orientation features were used in the training algorithm. To get a clearer idea of what edge orientation features are, we will ﬁrst describe how they are made. Just as their name suggests, they arise from the orientation of the edges of an image. A Sobel gradient mask is a matrix used in determining the location of edges in an image. A typical mask of this sort is of size 3 × 3 pixels. It has two conﬁgurations, one for ﬁnding edges in the x-direction and the other for ﬁnding edges in the y-direction of source images ([7], p. 165). These two matrices, hx and hy (shown in Figs. 11.9 and 11.10), are known as the Sobel kernels.

334

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

FIGURE 11.9 Kernel hy .

FIGURE 11.10 Kernel hx .

Figure 11.9 shows the typical Sobel kernel for determining vertical edges (ydirection), and Figure 11.10 shows the kernel used for determining horizontal edges (x-direction). Each of these kernels is placed over every pixel in the image. Let P be the grayscale version of the input image. Grayscale images are determined from RGB color images by taking a weighted sampling of the red, green, and blue color spaces. The value of each pixel in a grayscale image was found by considering its corresponding color input intensities, and applying the following formula: 0.212671 × R + 0.715160 × G + 0.072169 × B, which is a built in function in OpenCV, which was used in the implementation. Let P(x, y) represent the value of the pixel at point (x, y) and I(x, y) is a 3 × 3 matrix of pixels centered at (x, y). Let X and Y represent output edge orientation images in the x and y directions, respectively. X and Y are computed as follows: X(i, j) = hx · I(i, j) =

−P(i − 1, j − 1) + P(i + 1, j − 1) − 2P(i − 1, j) +2P(i + 1, j) − P(i − 1, j + 1) + P(i + 1, j + 1),

Y (i, j) = hy · I(i, j) =

−P(i − 1, j − 1) − 2P(i, j − 1) − P(i + 1, j − 1) +P(i − 1, j + 1) + 2P(i, j + 1) + P(i + 1, j + 1)

A Sobel gradient mask was applied to each image to ﬁnd the edges of that image. Actually, a Sobel gradient mask was applied both in the x-dimension, called X(i, j), and in the y-dimension, called Y (i, j). A third image, called R(i, j), of the same dimensions as X, Y, and the original image, was generated such that R(i, j) = X(i, j)2 + Y (i, j)2 . The result of this operation is another grayscale image with a black background and varying shades of white around the edges of the objects in the image. The image R(i, j) is called a Laplacian image in image processing literature, and values R(i, j) are called Laplacian intensities. One more detail of our implementation is the threshold that was placed on the intensities of the Laplacian values. We used a threshold of 80 to eliminate the faint edges that are not useful. A similar threshold was employed in the work by Levi and Weiss [17]. The orientations of each pixel are calculated from the X(i, j) and Y (i, j) images. The orientation of each pixel R(i, j) in the Laplacian image is found as orientation(i,j) = arctan(Y(i,j), X(i,j)) × 180/π. This formula gives the orientation of each pixel in degrees. The orientations are divided into six bins so that similar orientations can be grouped together. The whole circle is divided into six bins. Bin shifting (rotation of all bins by 15◦ ) is applied

NEW FEATURES AND APPLICATIONS

335

to better capture horizontal and vertical edges. Details are given in the work by Stojmenovic [24]. 11.5 NEW FEATURES AND APPLICATIONS 11.5.1

Rotated Features and Postoptimization

Lienhart and Maydt [14] add a set of classiﬁers (Haar wavelets) to those already proposed by Viola and Jones. Their new classiﬁers are the same as those proposed by Viola and Jones, but they are all rotated 45◦ . They claim to gain a 10 percent improvement in the false detection rate at any given hit rate when detecting faces. The features used by Lienhart were basically Viola and Jones’ entire set rotated 45◦ counterclockwise. He added two new features that resembled the ones used by Viola and Jones, but they too failed to produce notable gains. However, there is a postoptimization stage involved with the training process. This postoptimization stage is credited with over 90 percent of the improvements claimed by this paper. Therefore, the manipulation of features did not impact the results all that much; rather the manipulation of the weights assigned to the neural network at the end of each stage of training is the source of gains. OpenCV supports the integral image function on 45◦ rotated images since Lienhart was on the development team for OpenCV. 11.5.2

Detecting Pedestrians

Viola et al. [29] propose a system that ﬁnds pedestrians in motion and still images. Their system is based on the AdaBoost framework. It considers both motion information and appearance information. In the motion video pedestrian ﬁnding system, they train AdaBoost on pairs of successive frames of people walking. The intensity differences between pairs of successive images are taken as positive examples. They ﬁnd the direction of motion between two successive frames, and also try to establish if the moving object can be a person. If single images are analyzed for pedestrians, no motion information is available, and just the regular implementation of AdaBoost seen for faces is applied to pedestrians. Individual pedestrians are taken as positive training examples. It does not work as well as the system that considers motion information since the pedestrians are relatively small in the still pictures, and also relatively low resolution (not easily distinguishable, even by humans). AdaBoost is easily confused in such situations. Their results suggest that the motion analysis system works better than the still image recognizer. Still, both systems are relatively inaccurate and have high false positive rates. 11.5.3

Detecting Penguins

Burghardt et al. [5] apply the AdaBoost machine to the detection of African penguins. These penguins have a unique chest pattern that AdaBoost can be trained on. They

336

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

were able to identify not only penguins in images, but distinguish between individual penguins as well. Their database of penguins was small and taken from the local zoo. Lienhart’s [14] adaptation of AdaBoost was used with the addition of an extra feature: the empty kernel. The empty kernel is not a combination of light and dark areas, but rather only a light area so that AdaBoost may be trained on “pure luminance information.” AdaBoost was used to ﬁnd the chests of penguins, and other methods were used to distinguish between different penguins. Their technique did not work very well for all penguins. They gave no statistics concerning how well their approach works. This is another example of how the applications of AdaBoost are limited to very specialized problems.

11.5.4

Redeye Detection: Color-Based Feature Calculation

Luo et al. [19] introduce an automatic redeye detection and correction algorithm that uses machine learning in the detection of red eyes. They use an adaptation of AdaBoost in the detection phase of redeye instances. Several novelties are introduced in the machine learning process. The authors used, in combination with existing features, color information along with aspect ratios (width to height) of regions of interest as trainable features in their AdaBoost implementation. Viola and Jones [27] used only grayscale intensities, although their solution to face detection could have used color information. Finding red eyes in photos means literally ﬁnding red oval regions, which absolutely requires the recognition of color. Another unique addition in their work is a set of new features similar to those proposed by Viola and Jones [27], yet designed speciﬁcally to easily recognize circular areas. We see these feature templates in Figure 11.11. It is noticeable that the feature templates presented in this ﬁgure have three distinct colors: white, black, and gray. The gray and black regions are taken into consideration when feature values are calculated. Each of the shapes seen in Figure 11.11 is rotated around itself or reﬂected creating eight different positions. The feature value of each of the eight positions is calculated, and the minimum and maximum of these results are taken as output from the feature calculation. The actual calculations are performed based on the RGB color space. The pixel values are transformed into a one-dimensional space before the feature values are calculated in the following way: Redness = 4R − 3G + B. This color space is biased toward the red spectrum (which is where red eyes occur). This redness feature was used in the car detection system [24].

FIGURE 11.11 Features for redeye detection.

NEW FEATURES AND APPLICATIONS

11.5.5

337

EOH-Based Features

Levi and Weiss [17] add a new perspective on the training features proposed by Viola and Jones [27]. They also detect upright, forward-facing faces. Among other contributions in their work [17], their most striking revelation was adding an edge orientation feature that the machine can be trained on. They also experimented with mean intensity features, which means taking the average pixel intensity in a rectangular area. These features did not produce good results in their experiments and were not used in their system. In addition to the features used by Viola and Jones [27], which considered sums of pixel intensities, Levi and Weiss [17] create features based on the most prevalent orientation of edges in rectangular areas. There are obviously many orientations available for each pixel but they are reduced to eight possible rotations for ease of comparison and generalization. For any rectangle, many possible features are extracted. One set of features is the ratio of any two pairs of the eight EOHs [17]. There are therefore 8 choose 2 = 28 possibilities for such features. Another feature that is calculated is the ratio of the most dominant EOH in a rectangle to the sum of all other EOHs. Levi and Weiss [17] claim that using EOHs, they are able to achieve higher detection rates at all training database sizes. Their goal was to achieve similar or better performance of the system to Viola and Jones’ work while substantially reducing training time. They primarily achieve this because EOH gives good results with a much smaller training set. Using these orientation features, symmetry features are created and used. Every time a WC was added to their machine, its vertically symmetric version was added to a parallel yet independent cascade. Using this parallel machine architecture, the authors were able to increase the accuracy of their system by 2 percent when both machines were run simultaneously on the test data. The authors also mention detecting proﬁle faces. Their results are comparable to those of other proposed systems but their system works in real-time and uses a much smaller training set.

11.5.6

Fast AdaBoost

Wu et al. [30] propose a training time performance increase over Viola and Jones’ training method. They change the training algorithm in such a way that all of the features are tested on the training set only once (per each classiﬁer). The ith classiﬁer (1 ≤ i ≤ N) is given as input the desired minimum detection rate di and the maximum false positive rate fpi . These rates are difﬁcult to predetermine because the performance of the system varies greatly. The authors start with optimistic rates and gradually decrease expectations after including over 200 features until the criterion is met. Each feature is trained so that it has minimal false positive rate fpi . The obtained WCs hj are sorted according to their detection rates. The strong classiﬁer is created by incrementally adding the feature that either increases the detection rate (if it is

338

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

ensemble classiﬁer is formed by a majority vote of the WCs (that is, each WC has equal weight in the work by wu et al. [30]). The authors state that using their model of training, the desired detection rate was more difﬁcult to achieve than the desired false positive rate. To improve this defect, they introduce asymmetric feature selection. They incorporated a weighting scheme into the selection of the next feature. They chose weights of 1 for false positive costs and λ for false negative costs. λ is the cost ratio between false negatives and false positives. This setup allows the system to add features that increase the detection rate early on in the creation of the strong classiﬁer. Wu et al. [30] state that their method works almost as well as that of Viola and Jones when applied to the detection of upright, forward-facing faces. They however achieve a training time that is two orders of magnitude faster than that of Viola and Jones. This is achieved in part by using a training set that was much smaller than Viola and Jones’ [27], yet generated similar results. We will now explain the time complexity of both Viola and Jones’ [27] and Wu’s [30] training methods. There are three factors to consider when ﬁnding the time complexity of each training procedure: the number of features F, the number of WCs in a classiﬁer T, and the number of examples in the training set q. One feature in one example takes O(1) time because of integral images. One feature on q examples takes O(q) time to evaluate, and O(q log(q)) to sort and ﬁnd the best WC. Finding the best feature takes O(Fq log(q)) time. Therefore, the construction of the classiﬁer takes O(TFq log q). Wu’s [30] method takes O(Fq log q) time to train all of the classiﬁers in the initial stage. Testing each new WC while assuming that the summary votes of all classiﬁers are previously stored would take O(q) time. It would then take O(Fq) time to select the best WC. Therefore, it takes O(TqF ) time to chose T WC. We deduce that it would take O(Fq log q + TqF ) time to complete the training using the methods described by Wu et al. [30]. The dominant term in the time complexity of Wu’s [30] algorithm is O(TqF ). This is order O(log q) times faster than the training time for Viola and Jones’ method [27]. For a training set of size q = 10, 000, log2 q ≈ 13. For the same size training sets, Wu’s [30] algorithm would be 13 times faster to train, not a 100 times as claimed by the authors. The authors compared training times to achieve a predetermined accuracy rate, which requires fewer training items than Viola and Jones’ method [27]. Froba et al. [13] elaborate on a face veriﬁcation system. The goal of this system is to be able to recognize a particular person based on his/her face. The ﬁrst step in face veriﬁcation is face detection. The second is to analyze the detected sample and see if it matches one of the training examples in the database. The mouths of input faces into the system are cropped because the authors claim that this part of the face varies the most and produces unstable results. They however include the forehead since it helps with system accuracy. The authors use the same training algorithm for face detection as Viola and Jones [27], but include a few new features. They use AdaBoost to do the training, but the training set is cropped, which means that the machine is trained on slightly different input than Viola and Jones [27]. The authors mention that a face is detectable and veriﬁable with roughly 200 features that are determined by AdaBoost during the training phase. The actual veriﬁcation or recognition step of individual people based on these images is done

NEW FEATURES AND APPLICATIONS

339

using information obtained in the detection step. Each face that is detected is made up of a vector of 200 numbers that are the evaluations of the different features that made up that face. These numbers more or less uniquely represent each face and are used as a basis of comparison of two faces. The sum of the weighted differences in the feature values between the detected face and the faces of the individual people in the database is found and compared against a threshold as the veriﬁcation step. This is a sort of nearest-neighbor comparison that is used in many other applications. 11.5.7

Downhill Feature Search

McCane and Novins [20] described two improvements over the Viola and Jones’ [27] training scheme for face detection. The ﬁrst one is a 300-fold speed improvement over the training method, with an approximately three times slower execution time for the search. Instead of testing all features at each stag (exhaustive search), McCane and Novins [20] propose an optimization search, by applying a “downhill search” approach. Starting from a feature, a certain number of neighboring features are tested next. The best one is selected as the next feature, and the procedure is repeated until no improvement is possible. The authors propose to use same size adjacent features (e.g., rectangles “below” and “above” a given one, in each of the dimensions that share one common edge) as neighbors. They observe that the work by Viola and Jones [27] applies AdaBoost in each stage to optimize the overall error rate, and then, in a postprocessing step, adjust the threshold to achieve the desired detection rate on a set of training data. This does not exactly achieve the desired optimization for each cascade step, which needs to optimize the false positive rate subject to the constraint that the required detection rate is achieved. As such, sometimes adding a level in an AdaBoost classiﬁer actually increases the false positive rate. Further, adding new stages to an AdaBoost classiﬁer will eventually have no effect when the classiﬁer improves to its limit based on the training data. The proposed optimization search allows it to add more features (because of the increased speed), and to add more parameters to the existing features, such as allowing some of the subsquares in a feature to be translated. The second improvement in the work by McCane and Novins [20] is a principled method for determining a cascaded classiﬁer of optimal speed. However, no useful information is reported, except the guideline that the false positive rate for the ﬁrst cascade stage should be between 0.5 and 0.6. It is suggested that exhaustive search [27] could be performed at earlier stages in the cascade, and replaced by optimized search [20] in later stages. 11.5.8

Bootstrapping

Sung and Poggio [22] applied the following “bootstrap” strategy to constrain the number of nonface examples in their face detection system. They incrementally select only those nonface patterns with high utility value. Starting with a small set of non-face examples, they train their classiﬁer with current database examples and run the face detector on a sequence of random images (we call this set of images a “semitesting”

340

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

set). All nonface examples that are wrongly classiﬁed by the current system as faces are collected and added to the training database as new negative examples. They notice that the same bootstrap technique can be applied to enlarge the set of positive examples. In the work by Bartlett et al. [3], a similar bootstrapping technique was applied. False alarms are collected and used as nonfaces for training the subsequent strong classiﬁer in the sequence, when building a cascade of classiﬁers. Li et al. [18] observe that the classiﬁcation performance of AdaBoost is often poor when the size of the training sample set is small. In certain situations, there may be unlabeled samples available and labeling them is costly and time consuming. They propose an active learning approach, to select the next unlabeled sample that is at the minimum distance from the optimal AdaBoost hyperplane derived from the current set of labeled samples. The sample is then labeled and entered into the training set. Abramson and Freund [1] employ a selective sampling technique, based on boosting, which dramatically reduces the amount of human labor required for labeling images. They apply it to the problem of detecting pedestrians from a video camera mounted on a moving car. During the boosting process, the system shows subwindows with close classiﬁcation scores, which are then labeled and entered into positive and negative examples. In addition to features from the work by Viola and Jones [27], authors also use features with “control points” from the work by Burghardt and Calic [2]. Zhang et al. [31] empirically observe that in the later stages of the boosting process, the nonface examples collected by bootstrapping become very similar to the face examples, and the classiﬁcation error of Haar-like feature based WC is thus very close to 50 percent. As a result, the performance of a face detection method cannot be further improved. Zhang et al. [31] propose to use global features, derived from Principal component analysis (PCA), in later stages of boosting, when local features do not provide any further beneﬁt. They show that WCs learned from PCA coefﬁcients are better boosted, although computationally more demanding. In each round of boosting, one PCA coefﬁcient is selected by AdaBoost. The selection is based on the ability to discriminate faces and nonfaces, not based on the size of coefﬁcient. 11.5.9

Other AdaBoost Based Object Detection Systems

Treptow et al. [26] described a real-time soccer ball tracking system, using the described AdaBoost based algorithm [27]. The same features were used as in the work by Viola and Jones [27]. They add a procedure for predicting ball movement. Cristinacce and Cootes [6] extend the global AdaBoost-based face detector by adding four more AdaBoost based algorithms that detect the left eye, right eye, left mouth corner, and right mouth corner within the face. Their placement within the face is probabilistically estimated. Training face images are centered at the nose and some ﬂexibility in position of other facial parts with a certain degree of rotation is allowed in the main AdaBoost face detector, because of the help provided by the four additional machines. FloatBoost [31,32] differs from AdaBoost in a step where the removal of previously selected WCs is possible. After a new WC is selected, if any of the previously added

NEW FEATURES AND APPLICATIONS

341

classiﬁers contributes to error reduction less than the latest addition, this classiﬁer is removed. This results in a smaller feature set with similar classiﬁcation accuracy. FloatBoost requires about a ﬁve times longer training time than AdaBoost. Because of the reduced set of selected WCs, Zhang et al. [31,32] built several face recognition learning machines (about 20), one for each of face orientation (from upfront to proﬁles). They also modiﬁed the set of features. The authors conclude that the method does not have the highest accuracy. Howe [11] looks at boosting for image retrieval and classiﬁcation, with comparative evaluation of several algorithms. Boosting is shown to perform signiﬁcantly better than the nearest-neighbor approach. Two boosting techniques that are compared are based on feature- and vector-based boosting. Feature-based boosting is the one used in the work by Viola and Jones [27]. Vector-based boosting works differently. First, two vectors, toward positive and negative examples, are determined, both as weighted sums (thus corresponding to a kind of average value). A hyperplane bisecting the angle between them is used for classiﬁcation. The dot product of the tested example that is orthogonal to that hyperplane is used to make a decision. Comparisons are made on ﬁve training sets containing suns, churches, cars, tigers, and wolves. The features used are color histograms, correlograms (probabilities that a pixel B at distance x from pixel A has the same color as A), stairs (patches of color and texture found in different image locations), and Viola and Jones’ features. Vector boosting is shown to be much faster than feature boosting for large dimensions. Feature-based boosting gave better results than vector based when the number of dimensions in the image representation is small. Le and Satoh [15] observe AdaBoost advantages and drawbacks, and propose to use it in the ﬁrst two stages of the classiﬁcation process. The ﬁrst stage is a cascaded classiﬁer with subwindows of size 36 × 36, the second stage is a cascaded classiﬁer with subwindows of size 24 × 24. The third stage is an SVM classiﬁer for greater precision. Silapachote et al. [21] use histograms of Gabor and Gaussian derivative responses as features for training and apply them for face expression recognition with AdaBoost and SVM. Both approaches show similar results and AdaBoost offers important feature selections that can be visualized. Barreto et al. [4] described a framework that enables a robot (equipped with a camera) to keep interacting with the same person. There are three main parts of the framework: face detection, face recognition, and hand detection. For detection, they use Viola and Jones’s features [27] improved by Lienhart and Maydt [14]. The eigenvalues and PCA are used in the face recognition stage of the system. For hand detection, they apply the same techniques used for face detection. They claim that the system recognizes hands in a variety of positions. This is contrary to the claims made by Kolsch et al. [13] who built one cascaded AdaBoost machine for every typical hand position and even rotation. Kolsch and Turk [16,17] describe and analyze a hand detection system. They create a training set for each of the six posture/view combinations from different people’s right hands. Then both training and validation sets were rotated and a classiﬁer was trained for each angle. In contrast to the case of the face detector, they found poor accuracy with rotated test images for as little as a 4◦ rotation. They then added rotated

342

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

example images to the same training set, showing that up to 15◦ of rotation can be efﬁciently detected with one detector. 11.5.10

Binary and Fuzzy Weak Classiﬁers

Most AdaBoost implementations that we found in literature use binary WCs, where the decision of a WC is either accept or reject, which will be valued at +1 and −1, respectively (and described in Chapter 2). We also consider fuzzy WCs [23] as follows. Instead of making binary decisions, fuzzy WCs make a ‘weighted’ decision, as a real number in the interval [−1, 1]. Fuzzy WCs can then simply replace binary WCs as basic ingredients in the training and testing programs, without affecting the code or structure of the other procedures. A fuzzy WC is a function of the form h(x, f, s, θ, θmn , θmx ) where x is the tested sub image, f is the feature used, s is the sign (+ or −), θ is the threshold, and θmn and θmx are the adopted extreme values for positive and negative images. The sign s deﬁnes on what side the threshold the positive examples are located. Threshold θ is used to establish whether a given image passes a classiﬁer test in the following fashion: when feature f is applied to image x, the resulting number is compared to threshold θ to determine how this image is categorized by the given feature. The equation is given below sf (x) < sθ. If the equation evaluates true, the image is classiﬁed as positive. The function h(x, f, s, θ, θmn , θmx ) is then deﬁned as follows. If the image is classiﬁed as positive (sf (x) < sθ) then h(x, f, s, θ, θmn , θmx ) = min(1, |(f (x) − θ)/(θmn − θ)|). Otherwise h(x, f, s, θ, θmn , θmx ) = max(−1, −|(f (x) − θ)/(θmx − θ)|). This deﬁnition is illustrated in the following example.

Let s = 1, thus the test is f (x) < θ. One way to determine θmn and θmx (used in our implementation) is to ﬁnd the minimal feature value of the positive examples (example “1” seen here), and maximal negative value (example “H” seen here) and assign them to θmn and θmx , respectively. If s = −1, then the deﬁnitions are modiﬁed accordingly. Suppose that an image is evaluated to be around the letter “I” in the example (it could be exactly the letter “I” in the training process or a tested image at runtime). Since f (x) < θ, the image is estimated as positive. The degree of conﬁdence in the estimation is |(f (x) − θ)/(θmn − θ)|, which is about 0.5 in the example. If the ratio is > 1, then it is replaced by 1. The result of the evaluation is then h(x, f, s, θ, θmn , θmx ) = 0.5, which is returned as the recommendation. 11.5.11

Strong Classiﬁers

A strong classiﬁer is obtained by running the AdaBoost machine. It is a linear combination of WCs. We assume that there are T WCs in a strong classiﬁer, labeled

CONCLUSIONS AND FUTURE WORK

343

h1 , h2 , . . . , hT , and each of these comes with its own weight labeled α1 , α2 , . . . , αT . The tested image x is passed through the succession of WCs h1 (x), h2 (x), . . . , hT (x), and each WC assesses if the image passed its test. In case of binary WCs, the recommendations are either −1 or 1. In case of using fuzzy WCs, the assessments are values ρ in the interval [−1, 1]. Values ρ from interval (0, 1] correspond to a pass (with conﬁdence ρ) and in the interval [0, −1] a fail. Note that hi (x) = hi (x, fi , si , θi , θmn , θmx ) is abbreviated here for convenience (parameters θmn and θmx are needed only for fuzzy WCs). The decision that classiﬁes an image as being positive or negative is made by the following inequality: α = α1 h1 (x) + α2 h2 (x) + · · · + αT hT (x) > δ. From this equation, we see that images that pass (binary or weighted) weighted recommendations of the WC tests are cataloged as positive. It is therefore a (simple or weighted) voting of selected WCs. The value α also represents the conﬁdence of overall voting. The error is expected to be minimal when δ = 0, and this value is used in our algorithm. The α values are determined once at the beginning of the training procedure for each WC, and are not subsequently changed. Each αi = − log(ei /(1 − ei )). Each ei is equal to the cumulative error of the WC. 11.6 CONCLUSIONS AND FUTURE WORK It is not so trivial to apply any AdaBoost approach to the recognition of a new vision problem. Pictures of the new object may not be readily available (such as those for faces). A positive training set numbering in the thousands is easily acquired with a few days spent on the internet hunting for faces. It took roughly a month to collect the data set required for the training and testing of the detection of the Honda Accord [24]. Even if a training set of considerable size could be assembled, how long would it take to train? Certainly, it would take in the order of months. It is therefore not possible to easily adapt Viola and Jones’ standard framework to any vision problem. This is the driving force behind the large quantity of research that is being done in this ﬁeld. Many authors still try to build upon the AdaBoost framework developed by Viola and Jones, which only credits this work further. The ideal object detection system in CV would be the one that can easily adapt to ﬁnding different objects in different settings while being autonomous from human input. Such a system is yet to be developed. It is easy to see that there is room for improvement in the detection procedures seen here. The answer does not lie in arbitrarily increasing the number of training examples and WCs. The approach of increasing the number of training examples is brute force, and is costly when it comes to training time. Increasing the number of WCs would result in slower testing times. We propose to do further research in designing a cascaded classiﬁer that will still work with a limited number of training examples, but can detect a wide range of objects. This new cascaded training procedure must also work in very limited time; in the order of hours, not days or months as proposed by predecessors.

344

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

The design of fuzzy WCs and the corresponding fuzzy training procedure may be worth further investigation. We have perhaps only seen applications that were solvable efﬁciently with standard binary WCs. There are perhaps some more difﬁcult problems, with ﬁner boundaries between positive and negative examples, where fuzzy WCs would produce better results. Since the change that is involved is quite small, affecting only a few lines of code, it is worth trying this method in future object detection cases. All of the systems that were discussed here were mainly custom made to suit the purpose of detecting one object (or one class of objects). Research should be driven to ﬁnd a ﬂexible solution with a universal set of features that is capable of solving many detection problems quickly and efﬁciently. An interesting open problem is to also investigate constructive learning of good features for object detection. This is different from applying an automatic feature triviality test on existing large set of features, proposed in the works by Stojmenovic [24,25]. The problem is to design a machine that will have the ability to build new features that will have good performance on a new object detection task. This appears to be an interesting ultimate challenge for the machine learning community. REFERENCES 1. Abramson Y, Freund Y. Active Learning for Visual Object Recognition. Forthcoming. 2. Burghardt T, Calic J. Analysing animal behaviour in wildlife videos using face detection and tracking. IEE Proc Vision, Image Signal Proces. Special issue on the Integration of Knowledge, Semantics and Digital Media Technology; March 2005. 3. Bartlett MS, Littlewort G, Fasel I, Movellan JR. Real-time face detection and expression recognition: development and application to human-computer interaction. CVPR Workshop on Computer Vision and Pattern Recognition for Human–Computer Interaction, IEEE CVPR; Madison, Wi; 2003 June 17. 4. Barreto J, Menezes P, Dias J. Human–robot interaction based on Haar-like features and eigenfaces. Proceedings of the New Orleans International Conference on Robotics and Automation; 2004. p 1888–1893. 5. Burghardt T, Thomas B, Barham P, Calic J. Automated visual recognition of individual african penguins. Proceedings of the Fifth International Penguin Conference; Ushuaia, Tierra del Fuego, Argentina; September 2004. 6. Cristinacce D, Cootes T. Facial feature detection using AdaBoost with shape constraints. Proceedings of 14th BMVA British Machine Vision Conference; Volume 1; Norwich, UK; September 2003. p 231–240, 7. Efford N. Digital Image Processing: A Practical Introduction Using Java. Addison Wesley; 2000. 8. Freund Y, Schapire RE. A decision-theoretic generalization on on-line learning and an application to boosting. Proceedings of the 2nd European Conference on Computational Learning Theory (Eurocolt95); Barcelona, Spain; 1995. p 23–37. J Comput Syst Sci 1997;55(1):119–139. 9. Freund Y, Schapire RE. A short introduction to boosting. J J Soc Artif Intell 1999;14(5): 771–780.

REFERENCES

345

10. Fr¨oba B, Stecher S, K¨ublbeck C. Boosting a Haar-like feature set for face veriﬁcation. Lecture Notes in Computer Science; 2003. p 617–624. 11. Howe NR. A closer look at boosted image retrieval. Proceedings of the International Conference on Image and Video Retrieval; July 2003. p 61–70. 12. Jones M, Viola P. Fast multi-view face detection. Mitsubishi Electric Research Laboratories, TR2003-96 July 2003, http://www.merl.com; shown as demo at IEEE Conference on Computer Vision and Pattern Recognition (CVPR); June 2003. 13. Kolsch M, Turk M. Robust hand detection. Proceedings of the IEEE Interanational Conference on Automatic Face and Gesture Recognition; May 2004. p 614–619. 14. Lienhart R, Maydt J. An extended set of haar-like features for rapid object detection. Proceedings of the IEEE International Conference Image Processing; Volume 1; 2002. p 900–903. 15. Le DD, Satoh S. Feature selection by AdaBoost for SVM-based face detection. Information Technology Letters, The Third Forum on Information Technology (FIT2004); 2004. 16. Le D, Satoh S. Fusion of local and global features for efﬁcient object detection. IS & T/SPIE Symposium on Electronic Imaging; 2005. 17. Levi K, Weiss Y. Learning object detection from a small number of examples: the importance of good features. Proceedings of the International Conference on Computer Vision and Pattern Recognition (CVPR); Volume 2; 2004. p 53–60. 18. Li X, Wang L, Sung E. Improving AdaBoost for classiﬁcation on small training sample sets with active learning. Proceedings of the Sixth Asian Conference on Computer Vision (ACCV); Korea; 2004. 19. Luo H, Yen J, Tretter D. An efﬁcient automatic redeye detection and correction algorithm. Proceedings of the 17th IEEE International Conference on Pattern Recognition (ICPR’04); Volume 2; Aug 23–26, 2004; Cambridge, UK. p 883–886. 20. McCane B, Novins K. On training cascade face detectors. Image and Vision Computing. Palmerston North, New Zealand; 2003. p 239–244. 21. Silapachote P, Karuppiah DR, Hanson AR. Feature selection using AdaBoost for face expression recognition. Proceedings of the 4th IASTED International Conference on Visualization, Imaging, and Image Processing, VIIP 2004; Marbella, Spain; September 2004. p 452–273. 22. Sung K, Poggio T. Example based learning for view-based human face detection. IEEE Trans Pattern Anal Mach Intell 1998;20:39–51. 23. Schapire R, Singer Y. Improved boosting algorithms using conﬁdence-rated predictions. Mach Learn 1999;37(3):297–336. 24. Stojmenovic M. Real time machine learning based car detection in images with fast training. Mach Vis Appl 2006;17(3):163–172. 25. Stojmenovic M. Real time object detection in images based on an AdaBoost machine learning approach and a small training set. Master thesis, Carleton University; June 2005. 26. Treptow A, Masselli A, Zell A. Real-time object tracking for soccer-robots without color information. Proceedings of the European Conference on Mobile Robotics ECMR; 2003. 27. Viola P, Jones M. Robust real-time face detection. Int J Comput Vis 2004; 57(2):137–154. 28. Viola P, Jones M. Fast and robust classiﬁcation using asymmetric AdaBoost. Neural Inform Processing Syst 2002;14.

346

ALGORITHMS FOR REAL-TIME OBJECT DETECTION IN IMAGES

29. Viola P, Jones M, Snow D. Detecting pedestrians using patterns of motion and appearance. Proceedings of 9th International Conference on Computer Vision ICCV. Volume 2; 2003. p 734–741. 30. Wu J, Regh J, Mullin M. Learning a rare event detection cascade by direct feature selection. Proceedings of the Advances in Neural Information Processing Systems 16 (NIPS*2003). MIT Press; 2004. 31. Zhang D, Li S, Gatica-Perez D. Real-time face detection using boosting learning in hierarchical feature spaces. Proceedings of the International Conference on Pattern Recognition (ICPR); Cambridge, August. 2004. p 411–414. 32. Li SZ, Zhang Z. FloatBoost learning and statistical face detection. IEEE Trans Pattern Anal Machine Intell 2004;26(9):1112–1123.

CHAPTER 12

2D Shape Measures for Computer Vision ˇ ZUNI ´ ˇ PAUL L. ROSIN and JOVISA C

12.1 INTRODUCTION Shape is a critical element of computer vision systems. Its potential value is made more evident by considering how its effectiveness has been demonstrated in biological visual perception. For instance, in psychophysical experiments it was shown that for the task of object recognition, the outline of the shape was generally sufﬁcient, rendering unnecessary the additional internal detail, texture, shading, and so on available in the control photographs [1,22]. A second example is the so-called shape bias. When children are asked to name new objects, generalizing from a set of previously viewed artiﬁcial objects, it was found that they tend to generalize on the basis of shape, rather than material, color, or texture [28,56]. There are many components in computer vision systems that can use shape information, for example, classiﬁcation [43], shape partitioning [50], contour grouping [24], removing spurious regions [54], image registration [62], shape from contour [6], snakes [11], image segmentation [31], data mining [64], and content-based image retrieval [13], to name just a few. Over the years, many ways have been reported in the literature for describing shape. Sometimes they provide a uniﬁed approach that can be applied to determine a variety of shape measures [35], but more often they are speciﬁc to a single aspect of shape. This material is covered in several reviews [26,32,53,67], and a comparison of some different shape representations has been carried out as part of the Core Experiment CE-Shape-1 for MPEG-7 [2,29,61]. Many shape representations (e.g., moments, Fourier, tangent angle) are capable of reconstructing the original data, possibly up to a transformation (e.g., modulo translation, rotation, scaling, etc.). However, for this chapter the completeness of the shape representations is not an issue. A simpler and more compact class of representation in common use is the one-dimensional signature (e.g., the histogram of tangent angles). This chapter does not cover such schemes either, but is focused on shape measures that compute single scalar values from a shape. Their advantage is that not only are

Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

347

348

2D SHAPE MEASURES FOR COMPUTER VISION

these measures extremely concise (beneﬁting storage and matching) but they tend to be designed to be invariant to rotations, translations, and uniform scalings, and often have an intuitive meaning (e.g., circularity) since they describe a single aspect of the shape. The latter point can be helpful for users of computer vision systems to understand their reasoning. The shapes themselves we assume to be extracted from images and are presented either in the form of a set of boundary or interior pixels, or as polygons. The majority of the measures described have been normalized so that their values lie in the range [0, 1] or (0, 1]. Nevertheless, even when measuring the same attribute (e.g., there are many measures of convexity) the values of the measures are not directly comparable since they have not been developed in a common framework (e.g., a probabilistic interpretation). The chapter is organized as follows: Section 12.2 describes several shape descriptors that are derived by the use of minimum bounding rectangles. The considered shape descriptors are rectangularity, convexity, rectilinearity, and orientability. Section 12.3 extends the discussion to the shape descriptors that can be derived from other bounding shapes (different from rectangles). Fitting a shape model to the data is a general approach to the measurement of shape; an overview of this is given in Section 12.4. Geometric moments are widely used in computer vision, and their application to shape analysis is described in Section 12.5. The powerful framework of Fourier analysis has also been applied, and Fourier descriptors are a standard means of representing shape, as discussed in Section 12.6.

12.2 MINIMUM BOUNDING RECTANGLES As we will see in the next section, using a bounding shape is a common method for generating shape measures, but here we will concentrate on a single shape, optimal bounding rectangles, and outline a variety of its applications to shape analysis. Let R(S, α) be the minimal area rectangle with edges parallel to the coordinate axes, which includes polygon S rotated by an angle α around the origin. Brieﬂy, R(S) means R(S, α = 0). Let Rmin (S) be the rectangle that minimizes area(R(S, α)). This can be calculated in linear time with respect to the number of vertices of S by ﬁrst computing the convex hull followed by Toussaint’s [59] “rotating orthogonal calipers” method.

12.2.1

Measuring Rectangularity

There are a few shape descriptors that can be estimated from Rmin (S). For example, a standard approach to measure the rectangularity of a polygonal shape S is to compare S and Rmin (S). Of course, the shape S is said to be a perfectly rectangular shape (i.e., S is a rectangle) if and only if S = Rmin (S). Such a trivial observation suggests that

349

MINIMUM BOUNDING RECTANGLES

rectangularity can be estimated by area(S) . area(Rmin (S)) Also, the orientation of S can be deﬁned by the orientation of Rmin (S), or more precisely, the orientation of S can be deﬁned by the orientation of the longer edge of Rmin (S). Finally, the elongation of S can be derived from Rmin (S), where the elongation of S is estimated by the ratio of the lengths of the orthogonal edges of Rmin (S). Analogous measures can be constructed using the minimum perimeter bounding rectangle instead of the minimum area bounding rectangle. Of course, in both cases where the bounding rectangles are used, a high sensitivity to boundary defects is expected. 12.2.2

Measuring Convexity

Curiously, the minimum area bounding rectangle can also be used to measure convexity [70]. Indeed, a trivial observation is that the total sum of projections of all the edges of a given shape S onto the coordinate axes is equal to the Euclidean perimeter of R(S), which will be denoted by P 2 (R(S)). The sum of projections of all the edges of S onto coordinate axes can be written as P1 (S), where P1 (S) means the perimeter of S in the sense of l1 distance (sometimes called the “city block distance”), and so we have P1 (S, α) = P2 (R(S, α))

(12.1)

for every convex polygon S and all α ∈ [0, 2π) (P1 (S, α) denotes the l1 perimeter of S after rotation of an angle α). The equality (12.1) could be satisﬁed for some nonconvex polygons as well (see ˇ c and Rosin [70]) shows that Fig. 12.1), but a deeper observation (see the work by Zuni´ for any nonconvex polygonal shape S there is an angle α such that the strict inequality P1 (S, α) > P2 (R(S, α))

(12.2)

holds. Combining (12.1) and (12.2) the following theorem that gives a useful characterization of convex polygons can be derived. Theorem 1

([70]) A polygon S is convex if and only if P1 (S, α) = P2 (R(S, α))

holds for all α ∈ [0, 2π).

350

2D SHAPE MEASURES FOR COMPUTER VISION

y

y

Ruv(P)

R(P)

u

B.

P

v

P

Rxy(P)

A.

x

x

(a)

(b)

FIGURE 12.1 (a) Since S is convex, then P1 (S) = P2 (R(S)). (b) If x and y are chosen to be the coordinate axes, then P2 (R(S)) = P1 (S). Since S is not convex, there is another choice of the coordinate axes, say u and v, such that the strict inequality P2 (R(S)) < P1 (S) holds.

Taking into account the previous discussion, inequality (12.2), and Theorem 1, the following convexity measure C(S) for a given polygonal shape S is very reasonable: C(S) = min

α∈[0,2π]

P2 (R(S, α)) . P1 (S, α)

(12.3)

The convexity measure deﬁned as above has several desirable properties:

The estimated convexity is always a number from (0, 1]. The estimated convexity is 1 if and only if the measured shape is convex. There are shapes whose estimated convexity is arbitrary close to 0. The new convexity measure is invariant under similarity transformations.

The minimum of the function P2 (R(S, α))/P1 (S, α) that is used to estimate the convexity of a given polygonal shape S cannot be given in a “closed” form. Also, it is obvious that the computation of P2 (R(S, α))/P1 (S, α) for a big enough number of uniformly distributed different values of α ∈ [0, 2π] would lead to an estimate of ˇ c and C(S) within an arbitrary required precision. But a result from the work by Zuni´ Rosin [70] shows that there is a deterministic, very efﬁcient algorithm that enables the exact computation of C(S). That is an advantage of the method. It turned out that it is enough to compute P2 (R(S, α))/P1 (S, α) for a number of O(n) different, precisely deﬁned, values of α and take the minimum from the computed values (n denotes the number of vertices of S). C(S) is a boundary-based convexity measure that implies a high sensitivity to the boundary defects. In the majority of computer vision tasks robustness (rather than sensitivity) is a preferred property, but in high precision tasks the priority has to be given to the sensitivity.

351

MINIMUM BOUNDING RECTANGLES

1.0000

0.9757

0.8648

0.8475

0.7894

0.6729

0.5617

0.5503

0.5422

0.4997

0.4672

0.4053

FIGURE 12.2 Shapes ranked by the C convexity measure.

Several shapes with their measured convexity values (the convexity measure C is used) are presented in Figure 12.2. Each shape S is rotated such that the function P2 (R(S, α))/P1 (S, α) reaches the minimum. The ﬁrst shape (the ﬁrst shape in the ﬁrst row) is convex leading to the measured convexity equal to 1. Since the used measure C is boundary based, boundary defects are strongly penalized. For example, the ﬁrst shape in the second row, the last shape in the second row, and the last shape in the third row all have measured convexity values that strongly depend on the intrusions. Also note that there are a variety of different shape convexity measures (e.g., [5,42,58]) including both boundary- and area-based ones. 12.2.3

Measuring Rectilinearity

In addition to the above, we give a sketch of two recently introduced shape descriptors with their measures that also use optimal (in a different sense) bounding rectangles. We start with rectilinearity. This shape measure has many possible applications such as shape partitioning, shape from contour, shape retrieval, object classiﬁcation, image segmentation, skew correction, deprojection of aerial photographs, and scale selection ˇ c [55,69]. Another application is the detection of (see the works by Rosin and Zuni´ buildings from satellite images. The assumption that extracted polygonal areas whose interior angles belong to {π/2, 3π/2} very likely correspond to building footprints on satellite images seems to be reasonable. Consequently, a shape descriptor that would detect how much an extracted region differs from a polygonal area with interior angles belonging to {π/2, 3π/2} could be helpful in detecting buildings on satellite images (see Fig. 12.3). Thus, a shape with interior angles belonging to {π/2, 3π/2} is named a “rectilinear shape,” while a shape descriptor that measures the degree to which shape can be described as a rectilinear one is named “shape rectilinearity.” It has turned out that

352

2D SHAPE MEASURES FOR COMPUTER VISION

(a)

(b)

FIGURE 12.3 (a) The presented rectilinear polygons correspond to building footprints. (b) The presented (nonpolygonal) shapes correspond to building footprints but they are not rectilinear polygons.

the following two quantities R1 (S) =

R2 (S) =

4 · 4−π

π

√ · π−2 2

P2 (S) π − α∈[0,2π) P1 (S, α) 4

max

√ P1 (S, α) 2 2 max √ − α∈[0,2π) 2P2 (S, α) π

(12.4)

(12.5)

are appropriate to be used as rectilinearity measures. For a detailed explanation see ˇ c and Rosin [69]. It is obvious that both R1 and R2 are boundarythe work by Zuni´ based shape descriptors. An area-based rectilinear descriptor is not deﬁned yet. A reasonably good area-based rectilinearity measure would be very useful as a building detection tool when working with low quality images. The following desirable properties of rectilinearity measures R1 and R2 hold (for ˇ c [55,69]): details see the works by Rosin and Zuni´ Measured rectilinearity values are numbers from (0, 1]. A polygon S has a measured rectilinearity equal to 1 if and only if S is rectilinear. For each ε > 0, there is a polygon whose measured rectilinearity belongs to (0, ε). Measured rectilinearities are invariant under similarity transformations. Although R1 and R2 are derived from the same source and give similar results, they are indeed different and they could lead to different shape ranking (with respect to the measured rectilinearity). For an illustration see Figure 12.4; shapes presented in Figure 12.4a are ranked with respect to R1 while the shapes presented in Figure 12.4b are ranked with respect to R2 . 12.2.4

Measuring Orientability

To close this section on related shape measures based on bounding rectangles, we discuss “shape orientability” as a shape descriptor that should indicate the degree to

353

MINIMUM BOUNDING RECTANGLES

(a)

(b)

FIGURE 12.4 Shapes ranked by rectilinearity measures (a) R1 and (b) R2 .

which a shape has a distinct (but not necessarily unique) orientation. This topic was recently investigated by the authors [71]. The deﬁnition of the orientability measure uses two optimal bounding rectangles. One of them is the minimum area rectangle Rmin (S) that inscribes the measured shape S while another is the rectangle Rmax (S) that maximizes area(R(S, α)). A modiﬁcation of Toussaint’s [59] rotating orthogonal calipers method can be used for an efﬁcient computation of Rmax (S). The orientability D(S) of a given shape S is deﬁned as D(S) = 1 −

Rmin (S) . Rmax (S)

(12.6)

Deﬁned as above, the shape orientability has the following desirable properties:

D(S) ∈ [0, 1) for any shape S. A circle has measured orientability equal to 0. No polygonal shape has measured orientability equal to 0. The measured orientability is invariant with respect to similarity transformations.

Since both Rmin (S) and Rmax (S) are easily computable, it follows that the shape orientability of a given polygonal shape S is also easy to compute. For more details ˇ c et al. [71]. we refer to the work by Zuni´

354

2D SHAPE MEASURES FOR COMPUTER VISION

FIGURE 12.5 Trademarks ranked by orientability using D(S). The bounding rectangles Rmin (S) and Rmax (S) are displayed for each measured shape S.

Note that a trivial approach could be to measure shape orientability by the degree of elongation of the considered shape. Indeed, it seems reasonable to expect that the more elongated a shape, the more distinct its orientation. But if such an approach is used then problems arise with many-fold symmetric shapes, as described later in Sections 12.5.1 and 12.5.2. However, measuring shape orientability by the new measure D(S) is possible in the case of such many-fold symmetric shapes, as demonstrated in Figure 12.5. This ﬁgure gives several trademark examples whose orientability is computed by D(S). As expected, elongated shapes are considered to be the most orientable. Note, however, that the measure D(S) is also capable of distinguishing different degrees of orientability for several symmetric shapes that have similar compactness, such as the ﬁrst and last examples in the top row.

12.3 FURTHER BOUNDING SHAPES The approach taken to measure rectangularity (Section 12.2.1) can readily also be applied to other shape measures, as long as the bounding geometric primitive can be computed reasonably efﬁciently. However, in some cases it is not appropriate; for instance, sigmoidality (see Section 12.4) is determined more by the shape of its medial axis than its outline, while other measures such as complexity [40] or elongation (see Section 12.5.2) are not deﬁned with respect to any geometric primitive. A simple and common use of such a method is to measure convexity. If we denote the convex hull of polygon S by CH(S), then the standard convexity measure is deﬁned

355

FITTING SHAPES

as C1 (S) =

area(S) . area(CH(S))

The computation time of the convex hull of a simple polygon is linear in the number of its vertices [36] and so the overall computational complexity of the measure is linear. A perimeter-based version can be used in place of the area-based measure:

C2 =

P2 (CH(S)) . P2 (S)

It was straightforward to apply the same approach to compute triangularity [51]. Moreover, since linear time (w.r.t. number of polygon vertices) algorithms are available to determine the minimum area bounding triangle [37,39], this measure could be computed efﬁciently. Many other similar measures are possible, and we note that there are also linear time algorithms available to ﬁnd bounding circles [18] and bounding ellipses [19] that can be used for estimating circularity and ellipticity. A more rigorous test of shape is, given a realization of an ideal shape, to consider ﬂuctuations in both directions, that is, intrusions and protrusions. Thus, in the ﬁeld of metrology there is an ANSII standard for measuring roundness, which requires ﬁnding the minimum width annulus to the data. This involves determining the inscribing and circumscribing circles that have a common center and minimize the difference in their radii. Although the exact solution is computationally expensive, Chan [8] presented an O(n + −2 ) algorithm to ﬁnd an approximate solution that is within a (1 + )-factor of optimality, where the polygon contains n vertices and > 0 is an input parameter. We note that, in general, inscribed shapes are more computationally expensive to compute than their equivalent circumscribing versions (even when the two are ﬁtted independently). For instance, the best current algorithm for determining the maximum area empty (i.e., inscribed) rectangle takes O(n3 ) time [10] compared to the linear time algorithm for the minimum area bounding rectangle. Even more extreme is the convex skull algorithm; the optimal algorithm runs in O(n7 ) time [9] compared again to a linear time algorithm for the convex hull.

12.4 FITTING SHAPES An obvious scheme for a general class of shape measures is to ﬁt a shape model to the data and use the goodness of ﬁt as the desired shape measure. There is of course great scope in terms of which ﬁtting procedure is performed, which error measure is used, and the choice of the normalization of the error of ﬁt.

356

12.4.1

2D SHAPE MEASURES FOR COMPUTER VISION

Ellipse Fitting

For instance, to ﬁt ellipses, Rosin [48] used the least median of squares (LMedS) approach that is robust to outliers and enables the ellipse to be ﬁtted reliably even in the presence of outliers. The LMedS enables outliers to be rejected, and then a more accurate (and ellipse-speciﬁc) least squares ﬁt to the inliers was found [15]. Calculating the shortest distance from each data point to the ellipse requires solving a quartic equation, and so the distances were approximated using the orthogonal conic distance approximation method [47]. The average approximated error over the data E was combined with the region’s area A to make the ellipticity measure scale invariant [51]:

E 1+ √ A

12.4.2

−1 .

Triangle Fitting

For ﬁtting triangles, a different approach was taken. The optimal three-line polygonal approximation that minimized the total absolute error to the polygon was found using dynamic programming. The average error was then normalized as above to give a triangularity measure [51]. 12.4.3

Rectangle Fitting

An alternative approach to measure rectangularity [51] from the one introduced in Section 12.2 is to iteratively ﬁt a rectangle R to S by maximizing the functional 1−

area(R \ S) + area(S \ R) area(S ∩ R)

(12.7)

based on the two set differences between R and S normalized by the union of R and S. This provides a trade-off between forcing the rectangle to contain most of the data while keeping the rectangle as small as possible, as demonstrated in Figure 12.6. Each iteration can be performed in O(n log n) time [12], where n is the number of vertices.

(a)

(b)

FIGURE 12.6 The rectangle shown in (a) was ﬁtted according to (12.7) as compared to the minimum bounding rectangle shown in (b).

357

FITTING SHAPES

12.4.4

Sigmoid Fitting

To measure sigmoidality (i.e., how much a region is S-shaped), several methods were developed that analyze a single centerline curve that was extracted from the region by smoothing the region until the skeleton (obtained by any thinning algorithm) is nonbranching. The centerline is then rotated so that its principal axis lies along the x-axis. Fischer and Bunke [14] ﬁtted a cubic polynomial y = ax3 + bx2 + cx + d and classiﬁed the shape into linear, C-shaped, and sigmoid classes based on the coefﬁcient values. A modiﬁed version speciﬁcally designed to produce only a sigmoidality measure [52] ﬁtted the symmetric curve given by y = ax3 + bx + c. The correlation coefﬁcient ρ was used to measure the quality of ﬁt between the data and the sampled model. Inverse correlation was not expected, and so the value was truncated at zero. Rather than ﬁt models directly to the coordinates, other derived data can be used instead. The following approach to compute sigmoidality used the tangent angle that was modeled by a generalized Gaussian distribution [52] (see Fig. 12.7). The probability density function is given by p(x) =

vη(v, σ) −[η(v,σ)|x|]v , e 2Γ (1/v)

where "(x) is the gamma function, σ is the standard deviation, v is a shape parameter controlling the peakiness of the distribution (values v = 1 and v = 2 correspond to Laplacian and Gaussian densities), and the following is a scaling function: 5 1 η(v, σ) = σ

Γ (3/v) . Γ (1/v)

Mallat’s method [34] for estimating the parameters was employed. First, the mean absolute value and variance of the data xi are matched to the generalized Gaussian.

100

50

0

-5

0

5

FIGURE 12.7 The tangent angle of the handwritten digit “5” is overlaid with the best ﬁt generalized Gaussian (dashed) — the good ﬁt yields a high sigmoidality measure.

358

2D SHAPE MEASURES FOR COMPUTER VISION

If m1 = (1/n)

n

i=1 |xi |

and m2 = (1/n) v=F

−1

n

2 i=1 xi ,

m1 √ m2

then

,

where Γ (2/α) F (α) = √ . Γ (1/α)Γ (3/α) In practice, the values of F (α) are precomputed, and the inverse function is determined by a lookup table with linear interpolation. Finally, the tangent angle is scaled so that the area under the curve sums to 1. It was found that rather than calculating the measure as the correlation coefﬁcient, better results were obtained by taking the area of intersection A of the curves as an indication of the error of ﬁt. An approximate normalization was found by experimentation as max(2A − 1, 0). 12.4.5

Using Circle and Ellipse Fits

Koprnicky et al. [27] ﬁtted two model shapes M (a circle and ellipse) to the data S and for each considered four different error measures: the outer difference area(S ∩ M) , area(S) the inner difference area(S ∩ M) , area(S) as well as the sum and difference of the above. This provided four different measures, from which the ﬁrst three can be considered as circularity and ellipticity measures, focusing on the different aspects of the errors.

12.5 MOMENTS Moments are widely used in shape analysis tasks. Shape normalization, shape encoding (characterization), shape matching, and shape identiﬁcation are just some examples where moments techniques are successfully applied. To be precise, by “shape moments” we mean geometric moments. The geometric moment mp,q (S) of a given planar shape S is deﬁned by 66 xp yq dx dy.

mp,q (S) = S

359

MOMENTS

In real image processing applications, we are working with discrete data resulting from a particular digitization process applied to real data. In the most typical situation, real objects are replaced with a set of pixels whose centers belong to the considered shape. In such a case, the exact computation of geometric moments is not possible and each used moment mp,q (S) is usually replaced with its discrete analog μp,q (S), which is deﬁned as μp,q (S) = ip j q , (i,j)∈S∩Z2

where Z means the set of integers. The order of mp,q (S) is said to be p + q. Note that the zeroth-order moment m0,0 (S) of a shape S coincides with the area of S. 12.5.1

Shape Normalization: Gravity Center and Orientation

Shape normalization is usually an initial step in image analysis tasks or a part of data preprocessing. It is important to provide an efﬁcient normalization because a signiﬁcant error in this early stage of image analysis would lead to a large cumulative error at the end of processing. Shape normalization starts with the computation of image position. A common approach is that the shape position is determined by its gravity center (i.e., center of mass or, simply, centroid) of a given shape. Formally, for a given planar shape S its gravity center (xc (S), yc (S)) is deﬁned as a function of the shape area (i.e., the zeroth-order moment of the shape) and the ﬁrst-order moments m1,0 (S) m0,1 (S) , . (12.8) (xc (S), yc (S)) = m0,0 (S) m0,0 (S) Computation of shape orientation is another step in the shape normalization procedure, which is computed using moments. The orientation seems to be a very natural feature for many shapes, although obviously there are some shapes that do not have a distinct orientation. Many rotationally symmetric shapes are shapes that do not have a unique orientation while the circular disk is a shape that does not have any speciﬁc orientation at all. The standard approach deﬁnes the shape orientation by a line that minimizes the integral of the squared distances of points (belonging to the shape) to this line. Such a line is also known as the “axis of the least second moment of inertia.” If r(x, y, δ, ρ) denotes the perpendicular distance from the point (x, y) to the line given in the form x cos δ − y sin δ = ρ, then the integral that should be minimized is 66 I(δ, ρ, S) = r2 (x, z, δ, ρ) dx dy. S

360

2D SHAPE MEASURES FOR COMPUTER VISION

Elementary mathematics shows that the line that minimizes I(δ, ρ, S) passes through the centroid (xc (S), yc (S)) of S and consequently we can set ρ = 0. Thus, the problem of orientation of a given shape S is transformed to the problem of computing the angle δ for which the integral 66 I(δ, S) =

(−x sin δ + y cos δ)2 dx dy

(12.9)

S

reaches the minimum. Finally, if we introduce central geometric moments mp,q (S) deﬁned as usual 66 (x − xc (S))2 (y − yc (S))2 dx dy, mp,q (S) S

then the function I(δ, S) can be written as I(δ, S) = m2,0 (S)(sin δ)2 − 2m1,1 (S) sin δ cos δ + m0,2 (S)(cos δ)2 ,

(12.10)

that is, as a polynomial in cos δ and sin δ whose coefﬁcients are the second-order moments of S. The angle δ for which I(δ, S) reaches its maximum deﬁnes the orientation of S. Such an angle δ is easy to compute and it can be derived that the required δ satisﬁes the equation sin(2δ) 2m1,1 (S) . = cos(2δ) m2,0 (S) − m0,2 (S)

(12.11)

It is worth mentioning that if working in discrete space, that is, if continuous shapes are replaced with their digitizations, then real moments have to be replaced with their discrete analogs. For example, the orientation of discrete shape that is the result of digitization of S is deﬁned as a solution of the following optimization problem: ⎧ ⎨ min

δ∈[0,2π) ⎩ (i,j)∈S∩Z2

(i sin δ − j cos δ)2

⎫ ⎬ ⎭

.

The angle δ that is a solution of the above problem satisﬁes the equation 2μ1,1 (S) sin(2δ) = , cos(2δ) μ2,0 (S) − μ0,2 (S) which is an analog to (12.11). So, the shape orientation deﬁned by the axis of the least second moment of inertia is well motivated and easy to compute in both continuous and discrete versions. As expected, there are some situations when the method does not give any answer as

361

MOMENTS

to what the shape orientation should be. Such situations, where the standard method cannot be applied, are characterized by I(δ, S) = constant.

(12.12)

There are many regular and irregular shapes that satisfy (12.12). The result from the work by Tsai and Chou [60] says that (12.12) holds for all N-fold rotationally symmetric shapes with N > 2, where N-fold rotationally symmetric shapes are such shapes that are identical to themselves after being rotated through any multiple of 2π/N. In order to expand the class of shapes with a computable orientation, Tsai and Chou [60] suggested a use of the so-called Nth order central moments IN (δ, S). For a discrete shape S those moments are deﬁned by IN (δ, S) =

(−x sin δ + y cos δ)N

(12.13)

(x,y)∈S

assuming that the centroid of S is coincident with the origin. Now, the shape orientation is deﬁned by the angle δ for which IN (δ, S) reaches the minimum. For N = 2, we have the standard method. Note that IN (δ, S) is a polynomial in cos δ and sin δ while polynomial coefﬁcients are central moments of S having the order less than or equal to N. A beneﬁt from this redeﬁned shape orientation is that the method can be applied to a wider class of shapes. For example, since a square is a fourfold rotationally symmetric shape, the standard method does not work. If I4 (δ, S) is used, then the square can be oriented. A disadvantage is that there is not a closed formula (as (12.11)) that gives δ for which IN (δ, S) reaches the minimum for an arbitrary shape S. Thus, a numerical computation has to be applied in order to compute shape orientation in the modiﬁed sense. Figure 12.8 displays some shapes whose orientation is computed by applying the standard method (N = 2) and by applying the modiﬁed method with N = 4 and N = 8. Shapes (1), (2), and (3) are not symmetric, but they have a very distinct orientation. Because of that all three measured orientations are almost identical. Shapes (4), (5), and (6) have exactly one axis of symmetry and consequently their orientation is well determined. That is the reason why all three computed orientations coincide. The small variation in the case of the bull sketch (shape (5)) is caused by the fact that the sketch contains a relatively small number of (black) pixels, and consequently the digitization error has a large inﬂuence. Shapes (7), (8), (9), and (10) do not have a distinct orientation. That explains the variation in the computed orientations. For shapes (11) and (12), the standard method does not work. The presented regular triangle is a threefold rotationally symmetric shape and its orientation cannot be computed for N = 4, as well. For N = 8, the computed orientation is 150◦ , which is very reasonable. This is the direction of one of the symmetry axes. Of course, the modiﬁed method (in the case of N = 8) gives the angles δ = 270◦ and δ = 30◦ as the minimum of the function I8 (δ, S) and those angles can also be taken as the orientation of the

362

2D SHAPE MEASURES FOR COMPUTER VISION

FIGURE 12.8 Computed orientation of the presented shapes for N = 2, N = 4, and N = 8 are given (in degrees).

presented triangle. The last shape is a fourfold rotationally symmetric shape whose orientation cannot be computed by the standard method. 12.5.2

Shape Elongation

Shape elongation is another shape descriptor with a clear intuitive meaning. A commonly used measure of elongatedness uses the central moments and is computed as the ratio of the maximum of I(δ, S) and the minimum of I(δ, S); that is, shape elongation is measured as [38] μ20 (S) + μ02 (S) + μ20 (S) + μ02 (S) −

(μ20 (S) − μ02 (S))2 + 4μ11 (S)2 (μ20 (S) − μ02 (S))2 + 4μ11 (S)2

which can be simpliﬁed and reformulated as (μ20 (S) − μ02 (S))2 + 4μ11 (S)2 μ20 (S) + μ02 (S) to provide a measure in the range [0, 1].

,

(12.14)

363

MOMENTS

Similarly as in the previous subsection some problems arise when working with shapes satisfying I(δ, S) = constant. All such shapes have the same measured elongation equal to 1. Rather, it is more reasonable that all the regular 2n-gons have the same measured elongation. It seems natural that the elongation of regular 2n-gons decreases if n increases. Partially, the problem can be avoided if higher order moments ˇ c et al. [68]) is to deﬁne the of inertia are used. A possibility (see the work by Zuni´ elongation of a given shape S as max{IN (δ, S) | δ ∈ [0, 2π)} . min{IN (δ, S) | δ ∈ [0, 2π)}

(12.15)

Again, an advantage of the modiﬁed deﬁnition of the shape orientation is that a smaller class of shapes would have the measured elongation equal to 1. Such a minimum possible measured elongation should be reserved for the circular disk only. On the contrary, for N > 2 there is no closed formula (like (12.14)) that can be used for immediate computation of the shape elongation. More expensive numerical algorithms have to be applied. For more details about elongation of many-fold rotationally symmetric ˇ c et al. [68]. shapes see the work by Zuni´ 12.5.3

Other Shape Measures

A simple scheme for measuring rectangularity [49] considers the moments of a rectangle (dimensions a × b) centered at the origin and aligned with the axes. The moments are m00 = ab and m22 = a3 b3 /144, and so the quantity R = 144 ×

m22 m300

is invariant for rectangles of variable aspect ratio and scaling, and can be normalized as ⎧ ⎪ ⎨ R if R ≤ 1, RM = 1 ⎪ ⎩ otherwise. R To add invariance to rotation and translation, the data are ﬁrst normalized in the standard way by moving its centroid to the origin and orienting its principal axis to lie along the X-axis. A straightforward scheme to measure similarity to shapes such as triangles and ellipses that do not change their category of shape under afﬁne transformations is to use afﬁne moment invariants [51]. The simplest version is to characterize shape using just the ﬁrst, lowest order afﬁne moment invariant [16] I1 =

m20 m02 − m211 . m400

364

2D SHAPE MEASURES FOR COMPUTER VISION

This has the advantage that it is less sensitive to noise than the higher order moments. The moments for the unit radius circle are 6 6 √ μpq =

r2 −x2

1

−1

√

−

r2 −x2

xp yq dy dx

leading to the value of its invariant as I1 = 1/16π2 . When normalized appropriately, this then provides a measure of ellipticity ⎧ 1 ⎪ 2 ⎪ , ⎨ 16π I1 if I1 ≤ 16π2 EI = 1 ⎪ ⎪ ⎩ otherwise, 16π2 I1 which ranges over [0, 1], peaking at 1 for a perfect ellipse. The same approach was applied to triangles, all of which have the value I1 = 1/108, and the triangularity measure is ⎧ 1 ⎪ ⎪ , ⎨ 108I1 if I1 ≤ 108 TI = . 1 ⎪ ⎪ ⎩ otherwise. 108I1 Of course, using a single moment invariant is not very speciﬁc, and so the above two measures will sometimes incorrectly assign high ellipticity or triangularity values to some other nonelliptical or triangular shapes. This can be remedied using more moment values, either in the above framework, or as described next. Voss and S¨uße describe a method for ﬁtting geometric primitives by the method of moments [63]. The data are normalized into a (if possible unique) canonical frame, which is generally deﬁned as the simplest instance of each primitive type, by applying an afﬁne transformation. Applying the inverse transformation to the primitive produces the ﬁtted primitive. For example, for an ellipse they take the unit circle as the canonical form, and the circle in the canonical frame is transformed back to an ellipse, thereby providing an ellipse ﬁt to the data. For the purposes of generating shape measures, the inverse transformation is not necessary as the measures can be calculated in the canonical frame. This is done by computing the differences between the normalized moments of the data (m ij ) and the moments of the canonical primitive (mij ) where only the moments not used to determine the normalization are included: ⎛ ⎝1 +

⎞−1 (m ij − mij )2 ⎠

.

i+j≤4

The above approach method was applied in this manner by Rosin [51] to generate measures of ellipticity and triangularity. Measuring rectangularity can be done in

365

FOURIER DESCRIPTORS

the same way, except that for ﬁtting rectangles the procedure is modiﬁed to apply a similarity transformation rather than an afﬁne transformation. After this transformation the rectangle’s aspect ratio remains to be determined, and this is done by a one-dimensional optimization using the higher order moments (up to fourth order). We note that the above methods can all compute the moments either from the polygon boundary directly (line moments) [57] or else can operate on the rasterized set of pixels inside the polygon (region) [33].

12.6 FOURIER DESCRIPTORS Like moments, Fourier descriptors are a standard means of representing shape. This involves taking a Fourier expansion of the boundary function, which itself may be described in a variety of ways. If the boundary of the region is given by the points (xj , yj ), j = 1, . . . , N, then one approach is to represent the coordinates by complex numbers zj = xj + iyj [21]. Other possibilities are to represent the boundary by real 1D functions versus arc length such as tangent angle [66] or radius from the centroid. Taking the representation zj = xj + iyj and applying the discrete Fourier transform leads to the complex coefﬁcients that make up the descriptors Fk = ak + ibk =

N−1 1 zm exp (−i2πmk/N). N m=0

7 Often just the magnitude is used rk = ak2 + bk2 , and since r1 indicates the size of the region it can be used to make the descriptors scale invariant: wk = rk /r1 . For a study of sand particles, Bowman et al. [4] used individual Fourier descriptors to describe speciﬁc aspects of shape, for example, w−3 , w−2 , w−1 , and w+1 to measure, respectively, squareness, triangularity, elongation, and asymmetry. However, this approach is rather crude. A modiﬁcation [53] to make the measure more speciﬁc includes the relevant harmonics and also takes into account the remaining harmonics that do not contribute to squareness: (w−3 + w−7 + w−11 + · · ·)/

wi .

∀i∈{−1,0,1} /

Kakarala [25] uses the same boundary representation and derives the following expression for the Fourier expansion of the boundary curvature: Kn =

N 9 8 1 m (m + n)2 F¯ m Fm+n + (m − n)2 Fm F¯ m−n , 2 m=−N

where F is the complex conjugate of F .

366

2D SHAPE MEASURES FOR COMPUTER VISION

He shows that for a convex contour K0 ≥ 2

2N

|Kn |

n=1

from which the following convexity shape measure is derived: K0 − 2 2N

2N

n=1 |Kn |

n=−2N

|Kn |

.

Another measure based on curvature is “bending energy,” which considers the analog of the amount of energy required to deform a physical rod [65]. If a circle (which has minimum bending energy) is considered to be the simplest possible shape, then bending energy can be interpreted as a measure of shape complexity or deviation from circularity. The normalized energy is the summed squared curvature values along the boundary, which can be expressed in the Fourier domain as N 2πm 4 |am |2 + |bm |2 N

m=−N

although in practice the authors performed the computation in the spatial domain. When the boundary is represented instead by the radius function, a “roughness coefﬁcient” can be deﬁned as : ; [(N+1)/2]−1 ;1 < an2 + bn2 . 2 n=1

This shape measure is effectively the mean squared deviation of the radius function from a circle of equal area [26].

12.7 CONCLUSIONS This chapter has described several approaches for computing shape measures and has showed how each of these can then be applied to generate a variety of speciﬁc shape measures such as convexity, rectangularity, and so on. Figure 12.9 illustrates some of the geometric primitives that have been inscribed, circumscribed, or otherwise ﬁtted to example data, and which are then used to generate shape measures. Our survey is not complete, as there exist some methodologies in the literature that we have not covered. Here, for instance, Information Theory has been used to measure convexity [41] and complexity [17,40,44]. Projections are a common tool in image processing, and in the context of the Radon transform have also been used

367

CONCLUSIONS

min-R

max-R robust-R circ-C

insc-C

voss-C

voss-E

voss-R

voss-T

FIGURE 12.9 Geometric primitives ﬁtted to shapes. min-R: minimum area rectangle; max-R: maximum area rectangle; robust-R: best ﬁt rectangle — equation (12.7); circ-C: circumscribing circle; insc-C: inscribed circle; voss-C, voss-E, voss-R, voss-T: circle, ellipse, rectangle, and triangle ﬁtted by Voss and S¨uße’s moment-based method [63]. These primitives are used to generate some of the shape measures described in this chapter.

to compute convexity, elongation, and angularity shape measures [30]; a measure of triangularity was also based on projections [51]. Only a brief mention has been made to the issues of digitization, but it is important to note that this can have a signiﬁcant effect. For instance, the popular compactness measure P2 (S)2 /area(S) in the continuous domain is minimized by a circle but this is not true when working with digital data [45]. Therefore, some measures explicitly consider the digitization process, for example, for convexity [46], digital compactness [3,7], and other shape measures [20]. Given these methodologies, it should be reasonably straightforward for the reader to construct new shape measures as necessary. For instance, consider an application requiring a “pentagonality” measure, that is, the similarity of a polygon to a regular pentagon. Considering the various methods discussed in this chapter, several seem to be readily applicable: A measure could be generated from the polygon’s bounding pentagon; see Section 12.3. Once a pentagon is ﬁtted to the polygon’s coordinates, various shape measures can be produced; see Section 12.4.

368

2D SHAPE MEASURES FOR COMPUTER VISION

Rather than directly processing the polygon’s coordinates the histogram of boundary tangents could be used instead, and it would be straightforward to ﬁt ﬁve regular peaks and then compute a shape measure from the error of ﬁt; see again Section 12.4. The two methods for generating shape measures from moments by Voss and S¨uße [63] and Rosin [51] could readily be applied; see Section 12.5.3. The Fourier descriptor method for calculating triangularity in Section 12.6 could also be readily adapted to computing pentagonality.

The natural question is, which is the best shape measure? While measures can be rated in terms of their computational efﬁciency, sensitivity to noise, invariance to transformations, and robustness to occlusion, ultimately their effectiveness depends on their application. For example, whereas for one application reliability in the presence of noise may be vital, for another sensitivity to subtle variations in shape may be more important. It should also be noted that, while there are many possible shape measures already available in the literature, and many more that can be designed, they are not all independent. Some analysis on this topic was carried out by Hentschel and Page [23] who computed the correlations between many similar measures as well as determined the most effective one for the speciﬁc task of powder particle analysis.

REFERENCES 1. Biederman I, Ju G. Surface versus edge-based determinants of visual recognition. Cogn Psychol 1988;20:38–64. 2. Bober M. MPEG-7 visual shape descriptors. IEEE Trans Circuits Syst Video Technol 2001;11(6):716–719. 3. Bogaert J, Rousseau R, Van Hecke P, Impens I. Alternative area–perimeter ratios for measurement of 2D-shape compactness of habitats. Appl Math Comput 2000;111:71–85. 4. Bowman ET, Soga K, Drummond T. Particle shape characterization using Fourier analysis. Geotechnique 2001;51(6):545–554. 5. Boxer L. Computing deviations from convexity in polygons. Pattern Recog Lett 1993;14:163–167. 6. Brady M, Yuille AL. An extremum principle for shape from contour. IEEE Trans Pattern Anal Mach Intell 1984;6(3):288–301. 7. Bribiesca E. Measuring 2D shape compactness usng the contacct perimeter. Pattern Recog 1997;33(11):1–9. 8. Chan TM. Approximating the diameter, width, smallest enclosing cylinder, and minimumwidth annulus. Int J Comput Geom Appl 2002;12(1–2):67–85. 9. Chang JS, Yap CK. A polynomial solution for the potato-peeling problem. Discrete Comput Geom 1986;1:155–182. 10. Chaudhuri J, Nandy SC, Das S. Largest empty rectangle among a point set. J Algorithms 2003;46(1):54–78.

REFERENCES

369

11. Cremers D, Tischh¨auser F, Weickert J, Schn¨orr C. Diffusion snakes: introducing statistical shape knowledge into the Mumford–Shah functional. Int J Comput Vision 2002;50(3):295– 313. 12. de Berg M, van Kreveld M, Overmars M, Schwarzkopf O. Computational Geometry: Algorithms and Applications. 2nd ed. Springer-Verlag; 2000. 13. Flickner M, Sawhney H, Niblack W, Ashley J, Huang Q, Dom B, Gorkani M, Hafner J, Lee D, Petkovic D, Steele D, Yanker P. Image and video content: the QBIC system. IEEE Comput 1995;28(9):23–32. 14. Fischer S, Bunke H. Identiﬁcation using classical and new features in combination with decision tree ensembles. In: du Buf JMH, Bayer MM. editors. Automatic Diatom Identiﬁcation. World Scientiﬁc; 2002. p 109–140. 15. Fitzgibbon AW, Pilu M, Fisher RB. Direct least square ﬁtting of ellipses. IEEE Trans Pattern Anal Mach Intell 1999;21(5):476–480. 16. Flusser J, Suk T. Pattern recognition by afﬁne moment invariants. Pattern Recog 1993;26:167–174. 17. Franco P, Ogier J.-M, Loonis P, Mullot R. A topological measure for image object recognition. Graphics recognition. Lecture Notes in Computer Science. Volume 3088. 2004. p 279–290. 18. G¨artner B. Fast and robust smallest enclosing balls. Algorithms—ESA. LNCS. Volume 1643. 1999. p 325–338. 19. G¨artner B, Sch¨onherr S. Exact primitives for smallest enclosing ellipses. Inform Process Lett 1998;68(1):33–38. 20. Ghali A, Daemi MF, Mansour M. Image structural information assessment. Pattern Recog Lett 1998;19(5–6):447–453. 21. Granlund GH. Fourier preprocessing for hand print character recognition. IEEE Trans Comput 1972;21:195–201. 22. Hayward WG. Effects of outline shape in object recognition. J Exp Psychol: Hum Percept Perform 1998;24:427–440. 23. Hentschel ML, Page NW. Selection of descriptors for particle shape characterization. Part Part Syst Charact 2003;20:25–38. 24. Jacobs DW. Robust and efﬁcient detection of salient convex groups. IEEE Trans Pattern Anal Mach Intell 1996;18(1):23–37. 25. Kakarala R. Testing for convexity with Fourier descriptors. Electron Lett 1998;34(14):1392–1393. 26. Kindratenko VV. On using functions to describe the shape. J Math Imaging Vis 2003;18(3):225–245. 27. Koprnicky M, Ahmed M, Kamel M. Contour description through set operations on dynamic reference shapes. International Conference on Image Analysis and Recognition. Volume 1. 2004. p 400–407. 28. Landau B, Smith LB, Jones S. Object shape, object function, and object name. J Memory Language 1998;38:1–27. 29. Latecki LJ, Lak¨amper R, Eckhardt U. Shape descriptors for non-rigid shapes with a single closed contour. Proceedings of the Conference on Computer Vision Pattern Recognition; 2000. p 1424–1429.

370

2D SHAPE MEASURES FOR COMPUTER VISION

30. Leavers VF. Use of the two-dimensional radon transform to generate a taxonomy of shape for the characterization of abrasive powder particles. IEEE Trans Pattern Anal Mach Intell 2000;22(12):1411–1423. 31. Liu L, Sclaroff S. Deformable model-guided region split and merge of image regions. Image Vision Comput 2004;22(4):343–354. 32. Loncaric S. A survey of shape analysis techniques. Pattern Recog 1998;31(8):983–1001. 33. Maitra S. Moment invariants. Proc IEEE 1979;67:697–699. 34. Mallat SG. A theory for multiresolution signal decomposition: the wavelet representation. IEEE Trans Pattern Anal Mach Intell 1989;11(7):674–693. 35. Martin RR, Rosin PL. Turning shape decision problems into measures. Int J Shape Model 2004;10(1):83–113. 36. McCallum D, Avis D. A linear algorithm for ﬁnding the convex hull of a simple polygon. Inform Process Lett 1979;9:201–206. 37. Medvedeva A, Mukhopadhyay A. An implementation of a linear time algorithm for computing the minimum perimeter triangle enclosing a convex polygon. Canadian Conference on Computational Geometry; 2003. p 25–28. 38. Mukundan R, Ramakrishnan KR. Moment Functions in Image Analysis—Theory and Applications. World Scientiﬁc; 1998. 39. O’Rourke J, Aggarwal A, Maddila S, Baldwin M. An optimal algorithm for ﬁnding minimal enclosing triangles. J Algorithms 1986;7:258–269. 40. Page DL, Koschan A, Sukumar SR, Roui-Abidi B, Abidi MA. Shape analysis algorithm based on information theory. International Conference on Image Processing; Volume 1; 2003. p 229–232. 41. Pao HK, Geiger D. A continuous shape descriptor by orientation diffusion. Proceedings of the Workshop on Energy Minimization Methods in Computer Vision and Pattern Recognition. LNCS. Volume 2134. 2001. p 544–559. 42. Rahtu E, Salo M, Heikkila J. Convexity recognition using multi-scale autoconvolution. International Conference on Pattern Recognition; 2004. p 692–695. 43. Rangayyan RM, Elfaramawy NM, Desautels JEL, Alim OA. Measures of acutance and shape for classiﬁcation of breast-tumors. IEEE Trans Med Imaging 1997;16(6):799–810. 44. Rigau J, Feixas M, Sbert M. Shape complexity based on mutual information. International Conference on Shape Modeling and Applications; 2005. p 357–362. 45. Rosenfeld A. Compact ﬁgures in digital pictures. IEEE Trans Syst Man Cybernet 1974;4:221–223. 46. Rosenfeld A. Measuring the sizes of concavities. Pattern Recog Lett 1985;3:71–75. 47. Rosin PL. Ellipse ﬁtting using orthogonal hyperbolae and Stirling’s oval. CVGIP: Graph Models Image Process 1998;60(3):209–213. 48. Rosin PL. Further ﬁve-point ﬁt ellipse ﬁtting. CVGIP: Graph Models Image Process 1999;61(5):245–259. 49. Rosin PL. Measuring rectangularity. Mach Vis Appl 1999;11:191–196. 50. Rosin PL. Shape partitioning by convexity. IEEE Trans Syst Man Cybernet A, 2000;30(2):202–210. 51. Rosin PL. Measuring shape: ellipticity, rectangularity, and triangularity. Mach Vis Appl 2003;14(3):172–184. 52. Rosin PL. Measuring sigmoidality. Pattern Recog 2004;37(8):1735–1744.

REFERENCES

371

53. Rosin PL. Computing global shape measures. In: Chen CH, Wang PS-P, editors. Handbook of Pattern Recognition and Computer Vision. 3rd ed. World Scientiﬁc; 2005. p 177–196. 54. Rosin PL, Herv´as J. Remote sensing image thresholding for determining landslide activity. Int J Remote Sensing 2005;26(6):1075–1092. ˇ c J. Measuring rectilinearity. Comput Vis Image Understand 55. Rosin PL, Zuni´ 2005;99(2):175–188. 56. Samuelson LK, Smith LB. They call it like they see it: spontaneous naming and attention to shape. Dev Sci 2005;8(2):182–198. 57. Singer MH. A general approach to moment calculation for polygons and line segments. Pattern Recog 1993;26(7):1019–1028. 58. Stern HI. Polygonal entropy: a convexity measure. Pattern Recog Lett 1989;10:229–235. 59. Toussaint GT. Solving geometric problems with the rotating calipers. Proceedings of IEEE MELECON’83;1983. p A10.02/1–A10.02/4. 60. Tsai WH, Chou SL. Detection of generalized principal axes in rotationally symetric shapes. Pattern Recog 1991;24(1):95–104. 61. Veltkamp RC, Latecki LJ. Properties and performances of shape similarity measures. Conference on Data Science and Classiﬁcation; 2006. 62. Ventura AD, Rampini A, Schettini R. Image registration by recognition of corresponding structures. IEEE Trans Geosci Remote Sensing 1990;28(3):305–314. 63. Voss K, S¨uße H. Invariant ﬁtting of planar objects by primitives. IEEE Trans Pattern Anal Mach Intell 1997;19(1):80–84. 64. Wei L, Keogh E, Xi X. SAXually explicit images: ﬁnding unusual shapes. International Conference on Data Mining; 2006. 65. Young IT, Walker JE, Bowie JE. An analysis technique for biological shape. I. Inform Control 1974;25(4):357–370. 66. Zahn CT, Roskies RZ, Fourier descriptors for plane closed curves. IEEE Trans Comput 1972;C-21:269–281. 67. Zhang D, Lu G. Review of shape representation and description techniques. Pattern Recog 2004;37(1):1–19. ˇ c J, Kopanja L, Fieldsend JE. Notes on shape orientation where the standard method 68. Zuni´ does not work. Pattern Recog 2006;39(2):856–865. ˇ c J, Rosin PL. Rectilinearity measurements for polygons. IEEE Trans Pattern Anal 69. Zuni´ Mach Intell 2003;25(9):1193–1200. ˇ c J, Rosin PL. A new convexity measurement for polygons. IEEE Trans Pattern Anal 70. Zuni´ Mach Intell 2004;26(7):923–934. ˇ c J, Rosin PL, Kopanja L. On the orientability of shapes. IEEE Trans Image Process 71. Zuni´ 2006;15(11):3478–3487.

CHAPTER 13

Cryptographic Algorithms BIMAL ROY and AMIYA NAYAK

13.1 INTRODUCTION TO CRYPTOGRAPHY Cryptography is as old as writing itself and has been used for thousands of years to safeguard military and diplomatic communications. It has a long fascinating history. Kahn’s The Codebreakers [23] is the most complete nontechnical account of the subject. This book traces cryptography from its initial and limited use by Egyptians some 4000 years ago, to the twentieth century where it played a critical role in the outcome of both the world wars. The name cryptography comes from the Greek words “kruptos” (means hidden) and “graphia” (means writing). For electronic communications, cryptography plays an important role and that is why cryptography is quickly becoming a crucial part of the world economy. Organizations in both the public and private sectors have become increasingly dependent on electronic data processing. Vast amount of digital data are now gathered and stored in large computer databases and transmitted between computers and terminal devices linked together in complex communication networks. Without appropriate safeguards, these data are susceptible to interception (i.e., via wiretaps) during transmission, or they may be physically removed or copied while in storage. This could result in unwanted exposures of data and potential invasions of privacy. Before the 1980s, cryptography was used primarily for military and diplomatic communications, and in fairly limited contexts. But now cryptography is the only known practical method for protecting information transmitted through communications networks that use land lines, communications satellites, and microwave facilities. In some instances, it can be the most economical way to protect stored data. A cryptosystem or cipher system is a method of disguising messages so that only certain people can see through the disguise. Cryptography, the art of creating and using cryptosystems, is one of the two divisions of the ﬁeld called cryptology. The other division of cryptology is cryptanalysis, which is the art of breaking cryptosystems, seeing through the disguise even when you are not supposed to be able to. Thus, cryptology is the study of both cryptography and cryptanalysis. In cryptology, the

Handbook of Applied Algorithms: Solving Scientiﬁc, Engineering and Practical Problems Edited by Amiya Nayak and Ivan Stojmenovi´c Copyright © 2008 John Wiley & Sons, Inc.

373

374

CRYPTOGRAPHIC ALGORITHMS

original message is called a plaintext. The disguised message is called a ciphertext, and the encryption means any procedure to convert plaintext into ciphertext, whereas decryption means any procedure to convert cipher text into plaintext. The fundamental objective of cryptography is to enable two people, say A and B, to communicate over an insecure channel in such a way that an opponent O, cannot understand what is being said. Suppose A encrypts the plaintext using the predetermined key and sends the resulting ciphertext over the channel. O (opponent) on seeing the ciphertext in the channel by intercepting (i.e., wire tapping), cannot determine what the plaintext was; but B, who knows the key for encryption, can decrypt the ciphertext and reconstruct the plaintext. The plaintext message M that the sender wants to transmit will be considered to be a sequence of characters from a set of ﬁxed characters called alphabet. M is encrypted to produce another sequence of characters from the set alphabet called the cipher C. In practice, we use the binary digits (bits) as alphabet. The encryption function E ke operates on M to produce C, and the decryption function Dkd operates on C to recover original plaintext M. Both the encryption function Eke and the decryption function Dkd are parameterized by the keys ke and kd , respectively, which are chosen from a very large set of possible keys called keyspace. The sender encrypts the plaintext by computing C = Eke (M) and sends C to the receiver. Those functions have properties that receiver recovers the original text by computing Dkd (C) = Dkd (Eke (M)) = M (see Fig. 13.1). Two types of cryptographic schemes are typically used in cryptography. They are private key (symmetric key) cryptography and public key (asymmetric key) cryptography. Public key cryptography is a relatively new ﬁeld. It was invented by Difﬁe and Hellman [11] in 1976. The idea behind a public key cryptosystem is that it might be possible to ﬁnd a cryptosystem where it is computationally infeasible to determine the decryption rule given the encryption rule. Moreover, in public key cryptography, the encryption and the decryption are performed with different keys, whereas in private key cryptography both parties possesses the same key. Private key cryptography is again subdivided into block cipher and stream cipher. The stream ciphers operate with a time-varying transformation on smaller units of plane text, usually bits, whereas the block ciphers operate with a ﬁxed transformation on larger blocks of data. Symmetric and asymmetric systems have their own strengths and weaknesses. In particular, asymmetric systems are vulnerable in different ways, such as through impersonation, and are much slower in execution than symmetric systems. However, they have particular beneﬁts and, importantly, can work together with symmetric keyspace

keyspace

ke

sender

M

Ek e (M )

kd C

D k d (C )

public channel

FIGURE 13.1 Basic cryptosystem.

M

receiver

375

STREAM CIPHERS

systems to create cryptographic mechanisms that are elegant and efﬁcient and can give an extremely high level of security. In this chapter, we will deal with both stream and block ciphers. Let us ﬁrst talk about stream ciphers. In the following section, we will deﬁne and explain some of the important terms regarding stream ciphers.

13.2 STREAM CIPHERS In stream ciphers, plaintext P is a binary string; keystream, K, is a pseudo-random binary string; ciphertext, C, is a bit-wise XOR (addition modulo 2) of plaintext and keystream. Decryption is bit-wise XOR of ciphertext and keystream. Let us consider the following example. P : 100011010101111011011 K : 010010101101001101101 C : 110001111000110110110 In this example, one can observe that C = P ⊕ K. Also, P = C ⊕ K. In 1949, Claude Shannon published a paper “Communication Theory of Secrecy Systems” [34] that had a great impact on the scientiﬁc study of cryptography. In the following subsection, we will discuss about Shannon’s notion of perfect secrecy. 13.2.1

Shannon’s Notion of Perfect Secrecy

Let P, K, and C denote the ﬁnite set of possible plaintexts, keys, and ciphertexts, respectively, for a given cryptosystem. We assume that a particular key k ∈ K is used for only one encryption. Let us suppose that there are probability distributions on both P and K. Thus, two probability distributions on P and K induce a probability distribution on C. Then, the cryptosystem has a perfect security, if Pr(x | y) = Pr(x)

for all x ∈ P and for all y ∈ C.

This basically means that the ciphertext has no information about the plaintext. The basic strength of stream- cipher lies in how “random” the keystream is. Random keystream will satisfy Shannon’s notion [34]. Let us consider the following illustration. Illustration Let us consider one bit encryption; C = P ⊕ K. Here, K random means Pr(K = 0) = Pr(K = 1) = 21 . Let Pr(P = 0) = 0.6, Pr(P = 1) = 0.4. Then Pr(P = 0 | C = 1) = =

Pr(P = 0, C = 1) Pr(C = 1)

Pr(P = 0, C = 1) Pr(P = 0, C = 1) + Pr(P = 1, C = 1)

376

CRYPTOGRAPHIC ALGORITHMS

=

Pr(C = 1 | P = 0) · Pr(P = 0) Pr(C = 1 | P = 0) · Pr(P = 0) + Pr(C = 1 | P = 1) · Pr(P = 1)

=

Pr(K = 1) · Pr(P = 0) Pr(K = 1) · Pr(P = 0) + Pr(K = 0) · Pr(P = 1)

=

1 2 1 2 .

× 0.6 +

1 2

× 0.6

× 0.4 = 0.6 = Pr(P = 0)

= 0 6 = Pr(P = 0). Likewise, Pr(P = 0 | C = 0) = Pr(P = 0), Pr(P = 1 | C = 1) = Pr(P = 1), and Pr(P = 1 | C = 0) = Pr(P = 1). The main objective of a stream cipher construction is to get K as much random as possible. So the measurement of randomness plays an important role in cryptography. In the following subsection, we will discuss about the randomness measurements. 13.2.2

Randomness Measurements

Randomness of a sequence is the unpredictability property of sequence. The aim is to measure randomness of the sequence generated by a deterministic method called a generator. The test is performed by taking a sample output sequence and subjecting it to various statistical tests to determine whether the sequence possesses certain kinds of attributes, a truly random sequence would be likely to exhibit. This is the reason the sequence is called pseudo-random sequence instead of random sequence and the generator is called pseudo-random sequence generator (PSG) in literature. The sequence s = s0 , s1 , s2 , . . . is said to be periodic if there is some positive integer N such that si+N = si and smallest N is called the period of sequence. Golomb’s Randomness Postulates is one of the initial attempts to establish some necessary conditions for a periodic pseudo-random sequence to look random. 13.2.2.1 Golomb’s Randomness Postulates R-1: In every period, of 1’s differ from the number of 0’s by at most the number si | ≤ 1. (−1) 1. Thus, | N−1 i=0 R-2: In every period, half the runs have length 1, one fourth have length 2, oneeighth have length 3, and so on, as long as the number of runs so indicated exceeds 1. Moreover, for each of these lengths, there are (almost) equally many runs of 0’s and of 1’s. si +si+τ is two valued. ExR-3: The autocorrelation function C(τ) = N−1 i=0 (−1) plicitly C(τ) = where T is a constant.

N if τ ≡ 0(mod N) T if τ ≡ 0(mod N),

377

STREAM CIPHERS

As an example, let us consider the periodic sequence s of period 15 with cycle s15 = 011001000111101. One can observe that R-1: There are seven 0’s and eight 1’s. R-2: Total runs are 8. Four runs of length 1 (2 for each 0’s and 1’s), two runs of length 2 (one for each 0’s and 1’s), one run of 0’s of length 3, and one run of 1’s of length 4. R-3: The function C(τ) takes only two values: C(0) = 15 and C(τ) = −1 for 1 ≤ τ ≤ 14.

13.2.3

Five Basic Tests

1. Frequency test (monobit test): To test whether the number of 0’s and 1’s in sequence s is approximately the same, as would be expected for a random sequence. 2. Serial test (two-bit test): To determine whether the number of 00, 01, 10, and 11 as subsequences of s are approximately the same, as would be expected for a random sequence. 3. Poker test: Let m be a positive integer. Divide the sequence into n/m nonoverlapping parts of length m. To test whether the number of each sequence of length m is approximately the same, as would be expected for a random sequence. 4. Runs test: To determine whether the number of runs of various lengths in the sequence satisfy the R-2, as expected for a random sequence. 5. Autocorrelation test: To check whether correlation between the sequence and its sifted version is approximately 0 when the number of shifts is not divisible by the period as expected for a random sequence. Here, autocorrelation is taken as C(τ)/N, C(τ) is as deﬁned in R-3. For details on randomness measurement one can see the work by Gong [20]. In the next subsection, we will discuss about an efﬁcient method of producing keystream in hardware using linear feedback shift register (LFSR). 13.2.4

LFSR

One of the basic constituents in many stream ciphers is a LFSR. An LFSR of length L consists of L stages numbered 0, 1, . . . , L − 1, each storing one bit and having one input and one output; together with a clock that controls the movement of data. During each unit of time, the following operations are performed: (i) The content of stage 0 is the output and forms part of the output sequence. (ii) The content of stage i is moved to stage i − 1.

378

CRYPTOGRAPHIC ALGORITHMS

(iii) The new content of stage L − 1 is the feedback bit that is calculated by adding together modulo 2 the previous contents of a ﬁxed subset of stages 0, 1, . . . , L − 1. The position of these previous contents may be thought of having a correspondence with a polynomial. A polynomial ki=0 ai Xi induces the recurrence on the output

{Dn : n ≥ 1} as Dn =

k

ak−i Dn−i .

i=1

Let us consider the following example. Example Consider an LFSR 4, 1 + X3 + X4 . It induces the recurrence Dn = Dn−1 + Dn−4 . t 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

D3 0 0 1 0 0 0 1 1 1 1 0 1 0 1 1 0

D2 1 0 0 1 0 0 0 1 1 1 1 0 1 0 1 1

D1 1 1 0 0 1 0 0 0 1 1 1 1 0 1 0 1

D0 0 1 1 0 0 1 0 0 0 1 1 1 1 0 1 0

Output: s = 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, . . . . For cryptographic use, the LFSR should have period as long as possible. The following result takes care of it. If C(X) is a primitive polynomial, then each of the 2L − 1 nonzero initial states of the LFSR L, C(X) produces an output sequence with maximum possible period 2L − 1. If C(X) ∈ Z2 [X] is a primitive polynomial of degree L, then L, C(X) is called a maximum-length LFSR.

379

STREAM CIPHERS

13.2.5

Linear Complexity

Linear complexity is a very important concept for the study of randomness of sequences. The linear complexity of an inﬁnite binary sequence s, denoted L(s), is deﬁned as follows: (i) If s is the zero sequence s = 0, 0, 0, ..., then L(s) = 0. (ii) If no LFSR generates s, then L(s) = ∞. (iii) Otherwise, L(s) is the length of the shortest LFSR that generates s. The linear complexity of a ﬁnite binary sequence s(n) , denoted L(s(n) ), is the length of the shortest LFSR that generates a sequence having s(n) as its ﬁrst n terms. 13.2.6

Properties of Linear Complexity

Let s and t be binary sequences. (i) For any n ≥ 1, the linear complexity of the subsequence s(n) satisﬁes 0 ≤ L(s(n) ) ≤ n. (ii) L(s(n) ) = 0 if and only if s(n) is the zero sequence of length n. (iii) L(s(n) ) = n if and only if sn = 0, 0, 0, . . . , 0, 1. (iv) If s is periodic with period N , then L(s) ≤ N. (v) L(s ⊕ t) ≤ L(s) + L(t), where s ⊕ t denotes the bitwise XOR of s and t. (vi) For a ﬁnite sequence of length n, linear complexity ≤ n/2. If the linear complexity is strictly less than n2 , the sequence is not random. For a random sequence, linear complexity should be n2 . This is one of the strongest measure of randomness. Berlekamp [1] and Massey [26] devised an algorithm for computing the linear complexity of a binary sequence. Let us deﬁne, s(N+1) = s0 , s1 , . . . , sN−1 , sN . The basic idea is as follows. Let L, C(X) be an LFSR that generates the sequence s(N) = s0 , s1 , . . . , sN−1 . Let us deﬁne the next discrepancy as dN =

sN +

L

ci sN−i

mod 2.

i=1

If dN is 0, the same LFSR also produces S N+1 , else the LFSR is to be modiﬁed. The detailed algorithm is stated below. 13.2.6.1 Berlekamp–Massey Algorithm Input: a binary sequence s(n) = s0 , s1 , s2 , . . . , sn−1 . Output: the linear complexity L(s(n) ) of s(n) .

380

CRYPTOGRAPHIC ALGORITHMS

1 Initialize C(X) ← 1, L ← 0, m ← −1, B(X) ← 1, N ← 0. 2 While (N < n) do 2.1Compute d ← (sN + L i=1 ci sN−i ) 2.2If d = 1 then T (X) ← C(X), C(X) ← C(X) + B(X)XN−m . If L ≤ N/2 then L ← N + 1 − L, m ← N, B(X) ← T (X). 2.3N ← N + 1. 3 Return(L).

Let us illustrate the algorithm for two sequences: s(n) = 0, 0, 1, 1, 0, 1, 1, 1, 0 and t (n) = 0, 0, 1, 1, 0, 0, 0, 1, 1, 0. The ﬁrst sequence has linear complexity 5 and an LFSR that generates it is 5, 1 + X3 + X5 . The second sequence has the linear complexity 3 and and an LFSR that generates it is 3, 1 + x + x2 . Since linear complexity is less than n/2 = 5, the sequence is not random, which is also evident from the sequence. The steps of the Berlekamp–Massey algorithms are explained in the two following tables. sN – 0 0 1 1 0 1 1 1 0

d – 0 0 1 1 1 1 0 1 1

T (X) – – – 1 1 + X3 1 + X + X3 1 + X + X2 + X3 1 + X + X2 + X3 1 + X + X2 1 + X + X2 + X5

C(X) 1 1 1 1 + X3 1 + X + X3 1 + X + X 2 + X3 1 + X + X2 1 + X + X2 1 + X + X 2 + X5 1 + X3 + X5

L 0 0 0 3 3 3 3 3 5 5

m −1 −1 −1 2 2 2 2 2 7 7

B(X) 1 1 1 1 1 1 1 1 1 + X + X2 1 + X + X2

tN – 0 0 1 1 0 0 0 1 1 0

d – 0 0 1 1 1 0 0 0 0 0

T (X) – – – 1 1 + X3 1 + X + X3 1 + X + X3 1 + X + X3 1 + X + X3 1 + X + X3 1 + X + X3

C(X) 1 1 1 1 + X3 1 + X + X3 1 + X + X 2 + X3 1 + X + X 2 + X3 1 + X + X 2 + X3 1 + X + X 2 + X3 1 + X + X 2 + X3 1 + X + X 2 + X3

L 0 0 0 3 3 3 3 3 3 3 3

m −1 −1 −1 2 2 2 2 2 2 2 2

B(X) 1 1 1 1 1 1 1 1 1 1 1

381

STREAM CIPHERS

Running key

f

FIGURE 13.2 Nonlinear ﬁlter generator.

The running time of the algorithm for determining the linear complexity of a binary sequence of bit length n is O(n2 ) bit operations. For a ﬁnite binary sequence of length n, let the linear complexity be L. Then there is a unique LFSR of length L which generates the sequence iff L ≤ n/2. For an inﬁnite binary sequence (s) of linear complexity L, let t be a (ﬁnite) subsequence of length at least 2L. Then the Berlekamp– Massey algorithm on input t determines an LFSR of length L which generates s. 13.2.7

Nonlinear Filter Generator

A ﬁlter generator is a running key generator for stream cipher applications. It consists of a single LFSR that is ﬁltered by a nonlinear Boolean function f . This model has been in practical use for generating the keystream of a stream cipher. However, the strength of this model depends on the choice of the nonlinear Boolean function (Fig.13.2). 13.2.8

Synchronous and Asynchronous Stream Ciphers

There are two types of stream ciphers. 1. Synchronous: keys are generated before encryption process independently of the plaintext and ciphertext. Example: DES in OFB mode. 2. Asynchronous: encryption keys are generated using keys and a set of former ciphertext bits. Example: A5 used in GSM, DES in CFB mode (Fig.13.3). 13.2.8.1 Synchronous vs Asynchronous Stream Ciphers synchronous stream ciphers: Easy to generate. No error propagation. Insertion, deletion can be detected.

Attributes of

382

CRYPTOGRAPHIC ALGORITHMS

Key Plaintext

Ciphertext

ENCRYPTION

Key

Plaintext Ciphertext DECRYPTION

FIGURE 13.3 Asynchronous stream cipher.

Data authentication and integrity check required. Synchronization required. Both the sender and receiver must be synchronized. If synchronization is lost, then decryption fails and can only be restored by resynchronization. Technique for resynchronization includes reinitialization, placing special markers at regular intervals in the ciphertext, or, if the plaintext contains enough redundancy, trying all possible keystream offsets. Attributes of asynchronous stream ciphers.

Self-synchronized and limited error propagation. More difﬁcult to detect insertion and deletion. Plaintext statistics are dispersed through ciphertext. More resistant to eavesdropping. Harder to generate.

13.2.9

RC4 Stream Ciphers

RC4 was created by Rivest for RSA Securities. Inc. in 1994. Its key size varies from 40 to 256 bits. It has two parts, namely, a key scheduling algorithm (KSA) and a pseudo-random generator algorithm (PRGA). KSA turns a random key into a initial permutation S of {0, · · · , N − 1}. PRGA uses this permutation to generate a pseudorandom output sequence.

383

STREAM CIPHERS

13.2.9.1 Key scheduling algorithm KSA(K) Initialization : For i = 0, . . . , N − 1 DO S[i] = i j=0 endDo Scrambling For i = 0, . . . , N − 1 Do j = j + S[i] + K[i mod l], where l is the byte length of key Swap (S[i], S[j]) endDo Example

Let N = 8, l = 8, and the key K= 1

3

0

0

1

2

0

0

S= 0

1

2

3

4

5

6

7

i = 0, j = 0 + 0 + 1 = 1, S = 1

0

2

3

4

5

6

7

i = 1, j = 1 + 0 + 3 = 4, S = 1

4

2

3

0

5

6

7

13.2.9.2 Pseudo-random Sequence Generator Initialization i=0 j=0 Generating loop i=i+1 j = j + S[i] Swap (S[i], S[j]) Output z = S(S[i] + S[j])

PRGA(K)

Example Let S= 7

2

6

0

i = 1, j = 2, S = 7

4 6

5 2

1 0

3 4

5

1

3

z = S(6 + 2) = S(0) = 7 13.2.9.3 Weaknesses in RC4 1. The most serious weakness in RC4 was observed by Mantin and Shamir [25] who noted that the probability of a zero output byte at the second round is twice as large as expected. In broadcast applications, a practical ciphertext only attack

384

CRYPTOGRAPHIC ALGORITHMS

S1

X1

m

f Sn

k

c

Xn

FIGURE 13.4 Nonlinear combiner model.

can exploit this weakness. 2. Fluhrer et al. [18] have shown that if some portion of the secret key is known then RC4 can be broken completely. This is of practical importance. 3. Pudovkina [31] has attempted to detect a bias, only analytically, in the distribution of the ﬁrst and second output values of RC4 and digraphs under certain uniformity assumptions. 4. Paul and Preneel [30] have shown a statistical bias in the distribution of the ﬁrst two output bytes of the RC4 keystream generator. They have shown that the probability of the ﬁrst two output bytes being equal is (1/N)(1 − 1/N). (Note that RC4 produced output bytes uniformly then the probability of that event would have been 1/N.) The number of outputs required to reliably distinguish RC4 outputs from random strings using this bias is only 225 bytes. Most importantly, the bias exists even the ﬁrst N bytes and after dropping the probability of that event is (1/N) 1 − 1/N 2 . 13.2.10

Combiner Model

In this model, several LFSRs are considered. The output of these are combined by a Boolean function to produce the “keystream.” This is one of the most commonly used stream cipher models. The strength of this model lies in the choice of the combining function. In the next subsec