Aggregation and Constraint Processing in Lifted Probabilistic Inference by Jacek Jerzy Kisyński M.Sc., Maria Curie-Skłodowska University in Lublin, 2001 A THESIS SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF Doctor of Philosophy in THE FACULTY OF GRADUATE STUDIES (Computer Science) The University of British Columbia (Vancouver) March 2010 c© Jacek Jerzy Kisyński, 2010 Abstract Representations that mix graphical models and first-order logic—called either first- order or relational probabilistic models—were proposed nearly twenty years ago and many more have since emerged. In these models, random variables are param- eterized by logical variables. One way to perform inference in first-order models is to propositionalize the model, that is, to explicitly consider every element from the domains of logical variables. This approach might be intractable even for simple first-order models. The idea behind lifted inference is to carry out as much inference as possible with- out propositionalizing. An exact lifted inference procedure for first-order probabilistic models was developed by Poole [2003] and later extended to a broader range of problems by de Salvo Braz et al. [2007]. The C-FOVE algorithm by Milch et al. [2008] expanded the scope of lifted inference and is currently the state of the art in exact lifted inference. In this thesis we address two problems related to lifted inference: aggregation in directed first-order probabilistic models and constraint processing during lifted inference. Recent work on exact lifted inference focused on undirected models. Directed first-order probabilistic models require an aggregation operator when a parent ran- dom variable is parameterized by logical variables that are not present in a child random variable. We introduce a new data structure, aggregation parfactors, to describe aggregation in directed first-order models. We show how to extend the C-FOVE algorithm to perform lifted inference in the presence of aggregation par- factors. There are cases where the polynomial time complexity (in the domain size ii of logical variables) of the C-FOVE algorithm can be reduced to logarithmic time complexity using aggregation parfactors. First-order models typically contain constraints on logical variables. Con- straints are important for capturing knowledge regarding particular individuals. However, the impact of constraint processing on computational efficiency of lifted inference has been largely overlooked. In this thesis we develop an efficient algo- rithm for counting the number of solutions to the constraint satisfaction problems encountered during lifted inference. We also compare, both theoretically and em- pirically, different ways of handling constraints during lifted inference. iii Table of Contents Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii Table of Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Probabilistic reasoning in complex domains . . . . . . . . . . . . 1 1.2 Thesis overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.3 Summary of thesis contributions . . . . . . . . . . . . . . . . . . 5 1.4 Thesis organization . . . . . . . . . . . . . . . . . . . . . . . . . 5 2 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.2 Belief networks . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.3 Inference in belief networks . . . . . . . . . . . . . . . . . . . . 7 2.3.1 Factors . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.3.2 Variable elimination for belief networks . . . . . . . . . . 9 2.3.2.1 Complexity of variable elimination . . . . . . . 11 2.4 First-order probabilistic models . . . . . . . . . . . . . . . . . . . 12 2.4.1 Parameterized random variables . . . . . . . . . . . . . . 13 2.4.1.1 Counting formulas . . . . . . . . . . . . . . . . 15 2.4.2 Independent Choice Logic . . . . . . . . . . . . . . . . . 16 iv 2.5 Lifted probabilistic inference . . . . . . . . . . . . . . . . . . . . 21 2.5.1 Parametric factors . . . . . . . . . . . . . . . . . . . . . 22 2.5.1.1 Normal-form constraints . . . . . . . . . . . . 24 2.5.2 C-FOVE . . . . . . . . . . . . . . . . . . . . . . . . . . 25 2.5.2.1 Lifted elimination . . . . . . . . . . . . . . . . 26 2.5.2.2 Parfactor multiplication . . . . . . . . . . . . . 31 2.5.2.3 Splitting, expanding and propositionalizing . . . 33 2.5.2.4 Counting . . . . . . . . . . . . . . . . . . . . . 36 2.5.2.5 Unification . . . . . . . . . . . . . . . . . . . . 38 2.5.2.6 The C-FOVE algorithm . . . . . . . . . . . . . 46 2.5.2.7 Example computation . . . . . . . . . . . . . . 48 2.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 3 Aggregation in Lifted Inference . . . . . . . . . . . . . . . . . . . . 56 3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 3.2 Need for aggregation . . . . . . . . . . . . . . . . . . . . . . . . 57 3.3 Modeling aggregation . . . . . . . . . . . . . . . . . . . . . . . 58 3.3.1 Causal independence . . . . . . . . . . . . . . . . . . . . 58 3.3.2 Causal independence-based aggregation . . . . . . . . . . 60 3.4 Aggregation parfactors . . . . . . . . . . . . . . . . . . . . . . . 63 3.4.1 Conversion to parfactors . . . . . . . . . . . . . . . . . . 65 3.4.1.1 Conversion using counting formulas . . . . . . 66 3.4.1.2 Conversion for MAX and MIN operators . . . . 69 3.4.2 Operations on aggregation parfactors . . . . . . . . . . . 76 3.4.2.1 Splitting . . . . . . . . . . . . . . . . . . . . . 76 3.4.2.2 Multiplication . . . . . . . . . . . . . . . . . . 85 3.4.2.3 Summing out . . . . . . . . . . . . . . . . . . 87 3.4.3 Generalized aggregation parfactors . . . . . . . . . . . . 92 3.5 Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 3.5.1 Memory usage . . . . . . . . . . . . . . . . . . . . . . . 98 3.5.2 Social network experiment . . . . . . . . . . . . . . . . . 101 3.6 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 v 4 Solver for #CSP with Inequality Constraints . . . . . . . . . . . . . 105 4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 4.2 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 4.2.1 Constraint satisfaction problems . . . . . . . . . . . . . . 108 4.2.2 Variable elimination for #CSP . . . . . . . . . . . . . . . 109 4.2.3 Set partitions . . . . . . . . . . . . . . . . . . . . . . . . 111 4.3 Counting solutions to CSP instances with inequality constraints . . 113 4.3.1 Analysis of the problem . . . . . . . . . . . . . . . . . . 113 4.3.2 The #VE 6= algorithm . . . . . . . . . . . . . . . . . . . . 117 4.3.2.1 S-constants . . . . . . . . . . . . . . . . . . . . 118 4.3.2.2 #VE 6= factors . . . . . . . . . . . . . . . . . . 118 4.3.2.3 Multiplication . . . . . . . . . . . . . . . . . . 121 4.3.2.4 Summing out . . . . . . . . . . . . . . . . . . 126 4.3.2.5 The algorithm . . . . . . . . . . . . . . . . . . 129 4.3.3 Example computation . . . . . . . . . . . . . . . . . . . 131 4.3.4 Complexity of the algorithm . . . . . . . . . . . . . . . . 134 4.3.4.1 Preprocessing . . . . . . . . . . . . . . . . . . 134 4.3.4.2 Inference . . . . . . . . . . . . . . . . . . . . . 137 4.3.5 Empirical evaluation . . . . . . . . . . . . . . . . . . . . 138 4.4 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 5 Constraint Processing in Lifted Inference . . . . . . . . . . . . . . . 144 5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 5.2 Overview of constraint processing in lifted inference . . . . . . . 145 5.2.1 Splitting and expanding . . . . . . . . . . . . . . . . . . 147 5.2.2 Multiplication . . . . . . . . . . . . . . . . . . . . . . . . 149 5.2.3 Summing out . . . . . . . . . . . . . . . . . . . . . . . . 150 5.3 Splitting as needed vs. shattering . . . . . . . . . . . . . . . . . . 153 5.4 Normal form parfactors vs. #CSP solver . . . . . . . . . . . . . . 159 5.4.1 Multiplication . . . . . . . . . . . . . . . . . . . . . . . . 165 5.4.2 Summing out . . . . . . . . . . . . . . . . . . . . . . . . 166 5.4.3 Experiment . . . . . . . . . . . . . . . . . . . . . . . . . 167 5.5 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 vi 6 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 6.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 6.2 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 A 1-dimensional Representation of VE Factors . . . . . . . . . . . . . 179 B Hierarchical Representation of #VE 6= Factors . . . . . . . . . . . . 182 C From Parfactors to #VE 6= Factors . . . . . . . . . . . . . . . . . . . 185 D From #VE 6= Factors to Parfactors . . . . . . . . . . . . . . . . . . . 188 E Splitting as Needed . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 vii List of Figures 1.1 Lifted inference vs propositional inference . . . . . . . . . . . . . 3 2.1 A simple belief network . . . . . . . . . . . . . . . . . . . . . . . 7 2.2 VE algorithm for inference in belief networks . . . . . . . . . . . 10 2.3 A graph and its induced graph . . . . . . . . . . . . . . . . . . . 11 2.4 ICL theory from Example 2.6 . . . . . . . . . . . . . . . . . . . . 18 2.5 ICL theory for multiple lots from Example 2.6 . . . . . . . . . . . 19 2.6 More elegant ICL theory for multiple lots from Example 2.6 . . . 19 2.7 Graphical representation of the ICL theory for multiple lots . . . . 20 2.8 AC-3 algorithm for replacing logical variables with constants . . 39 2.9 MGU algorithm for parameterized random variables . . . . . . . 41 2.10 Algorithm for checking if an MGU is consistent with constraints . 42 2.11 Algorithm for splitting a parfactor on an MGU . . . . . . . . . . 43 2.12 Algorithm for splitting a parfactor on a set of constraints . . . . . 44 3.1 A first-order model from Example 3.1 . . . . . . . . . . . . . . . 57 3.2 A first-order model from Example 3.2 . . . . . . . . . . . . . . . 58 3.3 A first-order model with OR-based aggregation . . . . . . . . . . 60 3.4 A first-order model with MAX-based aggregation . . . . . . . . . 61 3.5 A first-order model from Example 3.5 . . . . . . . . . . . . . . . 62 3.6 Decomposed aggregation . . . . . . . . . . . . . . . . . . . . . . 87 3.7 A first-order model from Example 3.14 . . . . . . . . . . . . . . 92 3.8 Results of the experiment . . . . . . . . . . . . . . . . . . . . . . 99 3.9 Performance on model (a) (with OR-based aggregation) . . . . . . 99 3.10 Performance on model (b) (with MAX-based aggregation) . . . . 100 3.11 Performance on model (c) (with SUM|3-based aggregation) . . . . 100 viii 3.12 Performance on model (d) (generalized aggregation parfactors) . . 101 3.13 ICL theory for the smoking-friendship model . . . . . . . . . . . 102 3.14 Illustration of how ind(X) works . . . . . . . . . . . . . . . . . . . 103 3.15 Performance on the smoking-friendship model . . . . . . . . . . . 104 4.1 #VE algorithm for #CSP from Dechter [2003] . . . . . . . . . . . 110 4.2 Comparison of ϖn and exponential functions . . . . . . . . . . . . 112 4.3 Constraint graph with tree structure . . . . . . . . . . . . . . . . 113 4.4 Constraint graph with a cycle . . . . . . . . . . . . . . . . . . . . 114 4.5 Constraint graph discussed in Example 4.5 . . . . . . . . . . . . . 115 4.6 Constraint graph discussed in Example 4.5 . . . . . . . . . . . . . 115 4.7 Relationship between #VE 6= and #VE . . . . . . . . . . . . . . . 117 4.8 A CSP used in Examples 4.11–4.15 . . . . . . . . . . . . . . . . 121 4.9 #VE 6= algorithm for #CSP with inequality constraints . . . . . . . 130 4.10 Initialization procedure for the #VE 6= algorithm . . . . . . . . . . 131 4.11 A CSP used in Section 4.3.3 . . . . . . . . . . . . . . . . . . . . 131 4.12 Domains of three variables represented with disjoint subsets . . . 135 4.13 Summary of experiments . . . . . . . . . . . . . . . . . . . . . . 140 4.14 Summary of experiments . . . . . . . . . . . . . . . . . . . . . . 140 4.15 Results of experiments on CSP instances with P(u) = 0.1 . . . . 141 4.16 Results of experiments on CSP instances with P(u) = 0.01 . . . . 142 5.1 A first-order model from Example 5.2 . . . . . . . . . . . . . . . 147 5.2 Speedup of splitting as needed over shattering for Example 5.8 . . 157 5.3 Splitting as needed vs. shattering speedup for Example 5.9 . . . . 159 5.4 Algorithm for converting a parfactor to normal form . . . . . . . . 162 5.5 A simple constraint graph from Example 5.10 . . . . . . . . . . . 163 5.6 Summing out with and without a #CSP solver . . . . . . . . . . . 168 A.1 Structure of a VE factor . . . . . . . . . . . . . . . . . . . . . . . 180 A.2 Procedure indexToTuple( f , t) . . . . . . . . . . . . . . . . . . . . 181 B.1 Domains of three variables represented with disjoint subsets . . . 183 B.2 Structure of a #VE 6= factor . . . . . . . . . . . . . . . . . . . . . 183 ix Acknowledgments I am grateful to Dr. David Poole, my research supervisor, for his guidance. I could always rely on his expertise in artificial intelligence, computer science and science in general. I thank Dr. Nando de Freitas, Dr. William Evans, and Dr. Kevin Murphy, members of my supervisory committee, for their advice and feedback throughout the course of my work. I would like to thank Dr. Dan Roth (External Examiner), Dr. Martin Puterman (University Examiner), Dr. Kevin Leyton-Brown (University Examiner), and Dr. Vijay Bhargava (Examination Chair) for the time they spent reading and reviewing my thesis. The Laboratory for Computational Intelligence and the Department of Com- puter Science at The University of British Columbia provided me with an inspiring work environment. I thank Peter Carbonetto and Mike Chiang for their work on joint projects. In addition to my thesis research I had the opportunity to participate in the AIspace project. My collaboration with Dr. David Poole, Dr. Alan Mack- worth, Dr. Giuseppe Carenini, Dr. Cristina Conati, Byron Knoll, and Kyle Porter was a valuable experience. The UBC Department of Computer Science is also a great place to make friends. My lab-mates Asher, Andrea, Dustin, Eric, Firas, Kasia, Mark, Mike, Rita, Robert, and Scott, and, in particular, my officemates Matt, Hendrik, and Peter were very tolerant of my passion for chitchat. Vancouver is a paradise for a skiing and swimming enthusiast. Vast slopes of Whistler and Blackcomb mountains offer a seven-months-long skiing season. Together with my riding buddies Ken, Clint, Reid, Jonathan, and Lowell I took full x advantage of it. The Empire Pool at The UBC Aquatic Centre is open seven months per year for outdoor swimming. I took full advantage of it as well. My friendship with Gośka, Kris, and Sam started there. The duration of my Ph.D. studies can easily be explained by the fact that on occasion research had to compete with skiing and swimming. Ever since I arrived in Vancouver I was lucky to have great landlords and room- mates. Andy and Dave care more about well-being of their tenants than about col- lecting the rent. Tom, Mike, Wini, Manos, Adam and Maher were cool roommates and we had a good time living together. I would not be able to enter a Ph.D. program without the education I received in Poland. My high school math teacher, Waldemar “Byko” Łobodziński, not only taught me mathematics, but also respect for knowledge and contempt for igno- rance. Dr. Tadeusz Kuczumow’s courses in calculus and measure theory were of world-class quality. Dr. Jerzy Mycka, my M.Sc. thesis supervisor, introduced me to computability theory as well as to the art of logic and functional programming. I am also indebted to my family. My aunt Anne and uncle Andrzej encouraged me to pursue studies abroad and provided support once I arrived in Canada. My wife Sylwia has made a lot sacrifices to help me with my studies. People to whom I owe the most are my parents, Magdalena and Jan Kisyńscy. I would like to thank them for everything they have done for me. xi Chapter 1 Introduction I could never bear to be buried with people to whom I had not been introduced. — Norman Parkinson 1.1 Probabilistic reasoning in complex domains Artificial intelligence studies the design and synthesis of agents that act intelli- gently and are rational [Poole and Mackworth, 2010; Russell and Norvig, 2009]. Any agent acting in the real world faces uncertainty. Uncertainty arises because of limited information available to an agent: an agent’s observations might be incom- plete, an agent’s sensor might be noisy, and the effects of an agent’s own actions might be unknown to an agent. The design of representation and reasoning systems for agents is a core area of artificial intelligence. These systems are used to model and make predictions about the world and to support decision making. Unavoidably, they must handle uncertainty. Probability theory provides a foundation for representation and reasoning sys- tems that can reason under uncertainty. Given a model of the world, a usual prob- abilistic inference task is to make predictions about the value of a random variable given evidence bout the value of other random variables. While reasoning about the real world, an agent has to deal with domains that involve a large number of individuals. It might be interested only in a few of them, 1 but it cannot ignore the influence of other objects and individuals. Poole [2003] gives the following example of a domain involving a large number of individuals. We are given a description of a person who committed a crime in a town. We also happen to know that a guy named Marian roughly matches the description. What is the probability that Marian is guilty? The probability depends on how well Marian matches the description. It also depends on the rest of the population of the town. If the town is a small village, Marian is likely to be guilty. If the town is a large city, there are potentially many people living in the city who match the description and Marian is likely to be innocent. To represent this problem and compute the probability of Marian being guilty we need to reason about Marian, but we also have to represent and reason about a potentially large number of individuals about whom we do not have any specific information. Probabilistic graphical models, such as belief networks or Markov networks [Koller and Friedman, 2009], are a popular tool for representing dependencies be- tween random variables. However, such standard representations are propositional (zeroth-order), and therefore are not well suited for describing relations between in- dividuals or quantifying over sets of individuals. In order to reason about multiple individuals, we typically make each property of each individual into a separate ran- dom variable. Even the relatively simple example domain described above could not be easily represented using probabilistic graphical models. First-order logic has the capacity for representing relations and quantification of logical variables, but it does not treat uncertainty. It has only a very primitive mechanism for handling uncertainty, namely disjunction and existential quantifica- tion. Representations that mix graphical models and first-order logic—called ei- ther first-order or relational probabilistic models—were proposed nearly twenty years ago [Breese, 1992; Horsch and Poole, 1990] and many more have since emerged [De Raedt et al., 2008; Getoor and Taskar, 2007]. In these models, random variables are parameterized by logical variables that are typed with populations of individuals. This allows a model to be represented before modeled individuals are known, or even before their numbers are known. It also allows an agent to com- pactly represent the same information about multiple individuals, and to exploit this compactness facilitate efficient inference. 2 propositional inference lifted inference p rop osition alization propositional model first-order model p rop osition alization propositional posterior first-order posterior Figure 1.1: Lifted inference vs propositional inference for first-order proba- bilistic models A popular exact inference technique in first-order probabilistic models is based on dynamical propositionalization of the portion of the model that is relevant to the query, followed by probabilistic inference performed at the propositional level. Un- fortunately, even for simple relational probabilistic models, inference at the propo- sitional level—that is, inference that explicitly considers every individual—is very often intractable. The idea of lifted probabilistic inference is to carry out as much inference as possible without propositionalizing. The correctness of this approach is judged by having the same result as if we had first propositionalized the model and then carried out standard probabilistic inference (see Figure 1.1). An exact lifted proba- bilistic inference procedure for first-order probabilistic directed models was pro- posed in Poole [2003]. It was later extended to a broader range of problems by de Salvo Braz et al. [2005, 2006, 2007]. Further work by Milch et al. [2008] expanded the scope of lifted probabilistic inference and resulted in the C-FOVE algorithm, which is currently the state of the art in exact lifted probabilistic infer- ence. In this thesis we address two problems related to exact lifted probabilistic infer- ence. The first one is the efficient aggregation during lifted probabilistic inference in directed relational probabilistic models. The second one is constraint process- 3 ing during lifted probabilistic inference in both directed and undirected relational probabilistic models. 1.2 Thesis overview While early work on lifted probabilistic inference by Poole [2003] considered di- rected models, later work by de Salvo Braz et al. [2007] and Milch et al. [2008] focused on undirected models. Although their results can also be used for directed models, one aspect that arises exclusively in directed models is the need for ag- gregation that occurs when a parent random variable is parameterized by logical variables that are not present in a child random variable. Currently available lifted inference algorithms do not represent aggregation in relational probabilistic mod- els using data-structures that are independent of sizes of populations. In this thesis we introduce a new data structure, aggregation parfactor and describe how to use it to represent aggregation in first-order probabilistic models. We also show how to perform lifted probabilistic inference in presence of aggregation parfactors, by integrating it into the C-FOVE algorithm. Results of our theoretical and empirical evaluations show that inference with aggregation parfactors can lead to gains in efficiency. First-order models typically contain constraints on logical variables. Con- straints are important for capturing knowledge regarding particular individuals. Constraint processing during lifted probabilistic inference includes counting the number of solutions to constraint satisfaction problems induced during the infer- ence (this counting problem is written as #CSP). In this thesis we present an al- gorithm for solving #CSPs encountered during lifted probabilistic inference and through empirical evaluation show that it significantly improves the efficiency of the inference. Previous works on lifted probabilistic inference adopted various approaches to constraint processing. The impact of these different strategies on computational efficiency of lifted inference has been largely overlooked. In this thesis we analyze constraint processing during lifted probabilistic inference, both theoretically and empirically. Our results stress the importance of informed constraint processing in lifted inference and motivate our work on a specialized #CSP solver. 4 Although this thesis focuses on exact lifted probabilistic inference, our results in the area of constraint processing for lifted probabilistic inference apply to re- search on approximate lifted probabilistic inference, for example to work by Singla and Domingos [2008]. 1.3 Summary of thesis contributions The contributions of this thesis are as follows: • efficient aggregation algorithms for lifted probabilistic inference • specialized algorithm for #CSPs that greatly improves the efficiency of lifted probabilistic inference • analysis of constraint processing in lifted probabilistic inference. 1.4 Thesis organization The rest of this thesis is organized as follows. In Chapter 2 we provide the nec- essary background for the topics covered in this thesis; in particular, we describe existing exact lifted probabilistic inference techniques. The contributions of this thesis begin in Chapter 3, where we present algorithms for lifted aggregation in directed first-order probabilistic models. In Chapter 4 we develop an efficient al- gorithm for solving #CSPs encountered during lifted probabilistic inference. Next, in Chapter 5, we analyze various approaches to constraints processing in lifted probabilistic inference. Finally, in Chapter 6, we summarize the contributions of the thesis and discuss possible future work. Some of the parts of this work have been published as technical papers in AI conferences [Kisyński and Poole, 2009a,b]. 5 Chapter 2 Background No matter how hard a man may labor, some woman is always in the background of his mind. — Gertrude Franklin Atherton 2.1 Introduction In this chapter we introduce notation and concepts used throughout the thesis. First, we describe belief networks (Section 2.2) and the variable elimination algorithm (Section 2.3), which is used to perform inference in belief networks. Next, we give an overview of first-order probabilistic models (Section 2.4). We describe in more detail an example of first-order probabilistic modeling, Independent Choice Logic (Section 2.4.2). Finally, we discuss currently available exact lifted probabilistic inference methods (Section 2.5). 2.2 Belief networks One of the areas of artificial intelligence is the design of representation and reason- ing formalisms. Belief networks (also known as Bayesian networks) were proposed by Pearl [1988] and have since became a popular representation for independence among random variables. They are a member of class of models known as proba- bilistic graphical models. 6 wet grass sprinklerrain Figure 2.1: A simple belief network. In the definition below and in the rest of this chapter we use lower case letters for random variables and upper case letters for logical variables. It is not a standard notation, but it helps to distinguish logical variables from random variables. Definition 2.1. A belief network over a set of random variables {x1,x2, . . . ,xn} consist of a acyclic directed graph over random variables x1,x2, . . . ,xn, with one node of each random variable, and a set of conditional probability distributions {P(xi| parent(xi)) |i= 1,2, . . . ,n}, where parent(xi) denotes the nodes in the asso- ciated graph that have directed edges going into xi. A belief network represents the joint probability over random variables x1,x2, . . . ,xn: P(x1,x2, . . . ,xi) = n ∏ i=1 P(xi| parent(xi)) . Example 2.1. Figure 2.1 presents a simple belief network over three random vari- ables rain, sprinkler, and wet_grass. Assume they all have domain { f alse, true}. Associated with the belief network are three probability distributions: P(rain), P(sprinkler) and P(wet_grass|rain,sprinkler). The distributions could, for in- stance, encode that rain increases probability of grass being wet and so does run- ning sprinkler (see Example 2.2). 2.3 Inference in belief networks Given a belief network, a common inference problem is to compute the posterior distribution over a set of random variables given some evidence. We will describe how to solve this problem with the variable elimination (VE) algorithm [Zhang and Poole, 1994]. The aim of VE is to obtain the global solution in an efficient manner 7 through local computations. The variable elimination algorithm uses factors to represent the input problem instance, the results of intermediate local computations and the final solution. 2.3.1 Factors Let dom(x) denote the domain of random variable x. A factor on random variables x1,x2, . . . ,xn is a representation of a function from dom(x1) ×dom(x2)×·· ·×dom(xn) into the real numbers. Let v denote an assignment of values to some set of random variables; v is a function that takes a random variable and returns its value. Let F be a factor on a set of random variables S = {x1,x2, . . . ,xn}. Let v be an assignment of values to random variables in S. We extend v to factors and denote by v(F) the value of the factor F given v, that is v(F) = F(v(x1),v(x2), . . . ,v(xn)). If v does assign values only to some of the random variables in S, then v(F) denotes a factor on other random variables. Example 2.2. Consider a belief network from Example 2.1 and Figure 2.1. The three probability distributions could be represented by the following three factors: P(rain = f alse) P(rain = true) 0.8 0.2 , P(sprinkler = f alse) P(sprinkler = true) 0.6 0.4 , rain sprinkler P(wet_grass = f alse) P(wet_grass = true) f alse f alse 1.0 0.0 f alse true 0.2 0.8 true f alse 0.1 0.9 true true 0.01 0.99 . Operations on factors include computing a product of factors and summing out random variables from a factor. 8 Suppose F1 is a factor on random variables x1, . . . ,xi,y1, . . . ,y j, and F2 is a factor on random variables y1, . . . ,y j,z1, . . . ,zl , where sets {x1, . . . ,xi}, {y1, . . . ,y j} and {z1, . . . ,zl} are pairwise disjoint. Given an assignment of values to random variables v, the product ofF1 andF2 is a factorF1F2 on the union of the random variables, namely x1, . . . ,xi,y1, . . . ,y j,z1, . . . ,zl , defined by: (F1F2)(x1, . . . ,xi,y1, . . . ,y j,z1, . . . ,zl) = F1(x1, . . . ,xi,y1, . . . ,y j) ·F2(y1, . . . ,y j,z1, . . . ,zl). (2.1) Suppose F is a factor on random variables x1, . . . ,xi, . . . ,x j. The summing out of random variable xi from F , denoted as ∑xiF is the factor on random variables x1, . . . ,xi−1,xi+1, . . . ,x j such that( ∑ xi F ) (x1, . . . ,xi−1,xi+1, . . . ,x j) = ∑ x∈dom(xi) F(x1, . . . ,xi−1,xi = x,xi+1, . . . ,x j). Given a total ordering of the random variables and total ordering of their do- mains, factors can be implemented as 1-dimensional arrays (see Appendix A). 2.3.2 Variable elimination for belief networks Variable elimination (VE) is a general technique that can solve many problems, such as, CSP [Dechter, 1999] or belief network inference [Zhang and Poole, 1994]. The first VE algorithm was a non-serial dynamic programming [Bertelè and Brioschi, 1972]. In this section we present a variant of VE for inference in belief networks. Consider a belief network over a set of random variables V = {x1,x2, . . . ,xn}. We represent conditional probability distributions from the network as factors. For each random variable xi ∈ V , we represent the conditional probability distribution P(xi| parent(xi)) as a factor Fxi on a set of random variables {xi}∪ parent(xi). Assume that we are given: • a set of observations of values on a set of random variables O⊂V , which we can think of as an assignment vO of values to random variables O; • a query random variable q ∈V \O. 9 [00] procedure VE_BN(V,F,vO,q,H) [01] input: set of random variables V , [02] set of factors F , [03] assignment of values to random variables O⊂V , vO, [04] query random variable q ∈V \O, [05] elimination ordering heuristic H; [06] output: factor F representing the posterior distribution on q; [07] set E :=V \ (O∪{q}); [08] while there is a factor in F involving a random variable from E do [09] select random variable y ∈ E according to H; [10] set F :=eliminate(y,F); [11] set E := E \{y}; [12] end [13] set F :=⊙Fi∈F Fi; [14] compute normalizing constant c := ∑qF ; [15] return F /c; [16] end [17] procedure eliminate(y,F) [18] input: random variable to be eliminated y, [19] set of factors F; [20] output: set of factors F with y summed out; [21] partition F into set of factors on y, Fy and set F−y := F \Fy; [22] return F−y∪{∑y ⊙ Fi∈FyFi}; [23] end Figure 2.2: VE algorithm for inference in belief networks. Let V \ (O∪{q}) = {xs1 ,xs2 , . . . ,xsm}. We want to compute the posterior distribu- tion on q: ∑ xs1 ∑ xs2 . . .∑ xsm vO(Fx1)vO(Fx2)·· ·vO(Fxn). Computing the product vO(Fx1)vO(Fx2)·· ·vO(Fxn) is usually not trac- table. Instead, we take advantage of the (possible) sparseness of the associated graph. First, we order sums according to an elimination ordering ρ: ∑ xρ(m) . . .∑ xρ(2) ∑ xρ(1) vO(Fx1)vO(Fx2)·· ·vO(Fxn). Next, we use the distribution law, distribute factors that are not functions of xρ(1) outside of the sum ∑xρ(1) , multiply remaining factors and sum out xρ(1) from their 10 ab d e c a b c d e Figure 2.3: A graph (left) and its induced graph generated by ordering ρ = 〈a,b,c,d,e〉 (right). Edges added during construction of the induced graph are represented by dotted lines. We have w(ρ) = w∗(ρ) = 3. product. We repeat the process for sums ∑xρ(2) to ∑xρ(m) . The above procedure is the essence of the VE algorithm. Table 2.2 presents the pseudo-code involved. The next section discusses the impact of an elimination ordering on computa- tional cost of the VE algorithm. 2.3.2.1 Complexity of variable elimination First, we need to introduce some concepts from the graph theory. Given an ordered or unordered graph G and an ordering of its nodes ρ , an ordered graph is a pair (G,ρ). The width of a node is the number of nodes sharing an edge with the node that precede it in the ordering ρ . The width of the ordering, w(ρ), is the maximum width over all nodes, and the width of the graph is the minimum width over all orderings of the graph. For the ordered graph (G,ρ), the induced graph (G∗,ρ) is constructed in the following way: nodes are traversed in the opposite order to ρ . When a node is visited, we connect all of the nodes sharing an edge with the node that precede it in the ordering ρ . The induced width of the ordered graph (G,ρ), w∗(ρ), is the width of the induced ordered graph (G∗,ρ) (Figure 2.3). Assume that domains of all random variables have the same size |dom(x1) |= · · · = |dom(xn) | = d and that random variables were processed according to or- dering ρ . The time and space complexity of the variable elimination algorithm are determined by the size of the biggest factor created during inference, which depends on the induced width w∗(ρ) of the belief network graph O(ndw∗(ρ)). 11 The problem of finding an optimal elimination ordering, that is an ordering ρ that minimizes w∗(ρ), is NP-hard [Arnborg et al., 1987], so usually an elimination ordering heuristic is used [Kjærulff, 1990]. 2.4 First-order probabilistic models Belief networks and other probabilistic graphical models are widely used for repre- senting dependencies between random variables. However, they are propositional representations. That is, in order to represent information about multiple individu- als, each property of each individual is represented as a separate node. Probabilistic graphical models are not well suited for describing relations between individuals or quantifying over sets of individuals. First-order logic has the capacity for rep- resenting relations and quantification of logical variables, but it does not handle uncertainty well. Representations that mix graphical models and first-order logic (first-order probabilistic models) were proposed nearly twenty years ago [Breese, 1992; Horsch and Poole, 1990]. A common building block of these models is a parameterized random variable, a random variable parameterized by logical vari- ables. Logical variables are typed with populations of individuals. Among the appeals of the first-order probabilistic models is that it is possible to fully specify a model, that is, its structure and the accompanying probability distributions, before knowing the individuals in the modeled domain. This means that, even though we might not know the populations or even their sizes, we still should be able to specify the model. In order to make this possible, the length of a specification of a first-order probabilistic model must be independent of the sizes of the populations in the model. This thesis is not tied to any particular first-order probabilistic language. We reason at the level of data structures and assume that various first-order languages (or their subsets) will compile to these data structures. As we said above, first- order probabilistic languages share a concept of a parameterized random variable. We introduce it formally in Section 2.4.1. We also describe Independent Choice Logic (Section 2.4.2), an example of a first-order probabilistic language. 12 2.4.1 Parameterized random variables A population is a set of individuals. A population corresponds to a domain in logic. A logical variable will be written starting with an uppercase letter. A logical variable is typed with a population. Given a logical variable X , we denote its population by D(X). Given a set of constraints C on X , we denote the set of individuals from D(X) that satisfy the constraints in C by D(X) : C. A term is a logical variable or a constant denoting an individual from a popu- lation. Definition 2.2. A parameterized random variable is of the form f (t1, . . . , tk), where f is a symbol, called a functor, and ti are terms. Each functor has a set of values called the range of the functor. We denote the range of the functor f by range( f ). Functors with range { f alse, true} are predicate symbols, other are called function symbols. We denote the set of logical variables that appear in the parameterized random variable f (t1, . . . , tk) by param( f (t1, . . . , tk)). A substitution to a set of distinct logical variables {X1, . . . ,Xl} is of the form {X1/ti1 , . . . ,Xl/til}, where each ti j is a term. A ground substitution is a substitution, where each ti j is a constant. The application of a substitution θ = {X1/ti1 . . . . ,Xl/til} to a parameterized random variable f (t1, . . . , tk), written f (t1, . . . , tk)[θ ], is a parameterized random variable that is the original parameterized random variable f (t1, . . . , tk) with every occurrence of X j in f (t1, . . . , tk) replaced by the corresponding ti j . The parame- terized random variable f (t1, . . . , tk)[θ ] is called an instance of f (t1, . . . , tk). An instance f (t1, . . . , tk)[θ ] that does not contain logical variables is called a ground instance of f (t1, . . . , tk). Let f (t1, . . . , tk) be a parameterized random variable and θ be a ground sub- stitution to all logical variables in param( f (t1, . . . , tk)). An application of θ to f (t1, . . . , tk), f (t1, . . . , tk)[θ ] results in a ground instance of f (t1, . . . , tk). A ground instance of a parameterized random variable is a random variable. A parameterized random variable f (t1, . . . , tk) represents a set of random vari- ables, one random variable for each ground substitution to all logical variables 13 in param( f (t1, . . . , tk)). We denote this set by ground( f (t1, . . . , tk)). The domain of each random variables represented by f (t1, . . . , tk) is the range of f . Given a parameterized random variable f (t1, . . . , tk), a set of constraints C on param( f (t1, . . . , tk)), and its ground instance f (t1, . . . , tk)[θ ], we say that ground instance f (t1, . . . , tk)[θ ] satisfies the constraints in C if substitution θ satisfies the constraints in C. We denote the set of ground instances of f (t1, . . . , tk) that satisfy the constraints in C by ground( f (t1, . . . , tk)) : C. We extend our notation of an assignment of values to random variables to pa- rameterized random variables. When we say that v assigns a value to a param- eterized random variable f (t1, . . . , tk), we mean that it assigns this value to each random variable in the set ground( f (t1, . . . , tk)). Example 2.3. Let Lot be a logical variable typed with a population of all lots in a town {lot1, . . . , lotn}. We have |D(Lot) |= n. Let wet_grass(Lot) be a parameter- ized random variable, where wet_grass is a functor with range { f alse, true}. Thus, range(wet_grass) = { f alse, true} and param(wet_grass(Lot)) = {Lot}. The pa- rameterized random variable wet_grass(Lot) represents a set of n random vari- ables, each with domain { f alse, true}, one random variable for each substitution {Lot/lot1}, . . . , {Lot/lotn}. Let v be an assignment of values to random variables such that v(wet_grass(Lot)) = true. It means that each of the random variables in the set ground(wet_grass(Lot)), is assigned the value true by v. Substitution θ is a unifier of two parameterized random variables f (ti1 , . . . , tik) and f (t j1 , . . . , t jk) if f (ti1 , . . . , tik)[θ ] = f (t j1 , . . . , t jk)[θ ]. We then say that the two parameterized random variables unify. Substitution θ is a most general unifier (MGU) of two parameterized random variables if • θ is a unifier of the two parameterized random variables, and • if there exists another unifier θ ′ of the two parameterized random variables, then f (. . .)[θ ′]must be an instance of f (. . .)[θ ] for all parameterized random variables f (. . .). If two parameterized random variables have a unifier, they have at least one MGU. Sets of random variables represented by two parameterized random vari- ables that unify have a non-empty intersection. 14 Example 2.4. Parameterized random variables wet_grass(Lot) and wet_grass(lot1) have a unifier {Lot/lot1}. Let Parcel be a logical variable such that D(Parcel) = D(Lot). Parameterized random variables wet_grass(Lot) and wet_grass(Parcel) have a unifier {Lot/Parcel}. Let adjacent be a binary functor, adjacent(Lot, lot1) and adjacent(lot3,Parcel) have a unifier {Lot/lot3,Parcel/lot1}. Parameterized random variables wet_grass(lot1) and wet_grass(lot2) do not unify. Parameterized random variables adjacent(Lot,Lot) and adjacent(lot1, lot3) also do not unify. Fi- nally, parameterized random variables f (ti1 , . . . , tik) and h(t j1 , . . . , t jl ) do not unify as they have different functors. 2.4.1.1 Counting formulas So far, we can specify a value assignment for named individuals, or for all individ- uals from some population. Sometimes it is useful to be able to say that a certain number of individuals have some assignment, without specifying which individu- als. We can achieve this with counting formulas [Milch et al., 2008]. Counting formulas were inspired by work on cardinality potentials [Gupta et al., 2007] and counting elimination [de Salvo Braz et al., 2007]. Definition 2.3. A counting formula is of the form #A:CA [ f (. . . ,A, . . .)], where A is a logical variable that is bound by the # sign, C is a set of inequality constraints involving A and f (. . . ,A, . . .) is a parameterized random variable. The value of #A:CA [ f (. . . ,A, . . .)], given an assignment of values to random variables v, is the histogram function hv : range( f )→ N defined by v(#A:CA [ f (. . . ,A, . . .)]) = h v(x) = |{a ∈ (D(A) :C) : v( f (. . . ,a, . . .)) = x}|, where x is in the range of f . Thus, the set of values of the above counting formula is the set of histograms having a bucket for each element x in the range of f with entries adding up to |D(A) : C |. The number of such histograms is (|D(A):C |+|range( f ) |−1 |range( f ) |−1 ) , which for small values of |range( f ) | is O(|D(A) : C ||range( f ) |−1). Therefore, a tabular rep- resentation of a function on a counting formula #A:CA [ f (. . . ,A, . . .)] requires an 15 amount of space that is linear in |D(A) : C | for functor f with a binary range and increases dramatically with range size. Example 2.5. Consider a counting formula #Lot [wet_grass(Lot)]. It has a range {(# f alse = n,#true = 0),(# f alse = n−1,#true = 1), . . . ,(# f alse = 0,#true = n)}. As- sume that assignment of values to random variables v assigns value f alse to ran- dom variables wet_grass(lot4),wet_grass(lot5) and wet_grass(lot9) and value true to all other ground instances of wet_grass(Lot). We have v(#Lot [wet_grass(Lot)])= (# f alse = 3,#true = n−3). Counting formulas are a form of parameterized random variables. Consider a counting formula #A:CA [ f (. . . ,A, . . .)]. If the set param( f (. . . ,A, . . .))\{A} is not empty, the counting formula #A:CA [ f (. . . ,A, . . .)] represents a set of random variables, one random variable for each ground substitution to all logical variables in param( f (. . . ,A, . . .))\{A}, such that the substitution satisfies the constraints in CA. The domain of each of these random variables is the range of the counting formula, that is, the domains is the set of histograms having a bucket for each element x in the range of f with entries adding up to |D(A) : CA |. Very often we need to analyze a set of random variables underlying a counting formula #A:CA [ f (. . . ,A, . . .)], that is random variables ground( f (. . . ,A, . . .)). For simplicity, by ground(#A:CA [ f (. . . ,A, . . .)])we denote the set ground( f (. . . ,A, . . .)), rather than random variables described in the previous paragraph. Unless otherwise stated, by parameterized random variables we understand both forms: the standard and counting formulas. First-order probabilistic models describe probabilistic dependencies between parameterized random variables. A grounding of a first-order probabilistic model is a propositional probabilistic model obtained by replacing each parameterized random variable with the random variables it represents and replicating appropriate probability distributions. In the next section we describe an example first-order probabilistic modeling language. 2.4.2 Independent Choice Logic The Independent Choice Logic (ICL) [Poole, 1993, 1997, 2000] is a simple and powerful first-order probabilistic language. It subsumes both belief networks and 16 logic programs Lloyd [1987]. We have chosen ICL among many other formalisms for its easy syntax and semantics and because it defines directed first-order proba- bilistic models which are the focus of a big part of this thesis. We start with defining concepts related to logic programs and proceed to define the ICL formally. A term is either a constant, a logical variable, or is of the form f (t1, t2, . . . , tk) where f is a function symbol and t1, t2, . . . , tk are terms. An atom is of the form p(t1, t2, . . . , tk), where p is a predicate symbol and t1, t2, . . . , tk are terms. A clause is either an atom or is of the form h← a1∧a2∧·· ·∧ak, where h is an atom and ai is an atom or the negation (¬) of an atom, for i = 1,2, . . . ,k. We call h the head of the clause and a1∧a2∧·· ·∧ak the body of the clause. A logic program is a set of clauses. Informally, acyclic logic programs [Apt and Bezem, 1991] are a restricted class of logic programs for which all recursions for variable-free queries eventually halt. The ICL can be understood as an acyclic logic program with stochastic inputs. The stochastic part is defined by a choice space. An atomic choice is an atom that does not unify with the head of any clause. An alternative is a set of atomic choices that do not unify with each other. A choice space is a set of alternatives such that the atomic choices in different alternatives do not unify. Definition 2.4. An ICL theory consist of: F: facts, an acyclic logic program; C: a choice space; P0: a probability distribution over the alternatives in C such that ∀A ∈ C ∑ α∈A P0(α) = 1. The meaning of an ICL theory is defined in terms of possible worlds. A total choice for choice space C is a selection of exactly one atomic choice from each grounding of each alternative in C. Each total choice corresponds to a possible world. The logic program F together with the atoms chosen by the total choice define what is true in a possible world. 17 [00] C = {{rain, ¬rain}, [01] {sprinkler, ¬sprinkler}, [02] {wet_r_s, ¬wet_r_s}, [03] {wet_r_ns, ¬wet_r_ns}, [04] {wet_nr_s, ¬wet_nr_s}, [05] {wet_nr_ns, ¬wet_nr_ns}} [06] F = {wet_grass← rain ∧ sprinkler ∧ wet_r_s, [07] wet_grass← rain ∧ ¬sprinkler ∧ wet_r_ns, [08] wet_grass← ¬rain ∧ sprinkler ∧ wet_nr_s, [09] wet_grass← ¬rain ∧¬sprinkler ∧ wet_nr_ns} [10] P0(rain) = 0.2 P0(¬rain) = 0.8 [11] P0(sprinkler) = 0.4 P0(¬sprinkler) = 0.6 [12] P0(wet_r_s) = 0.99 P0(¬wet_r_s) = 0.01 [13] P0(wet_r_ns) = 0.9 P0(¬wet_r_ns) = 0.1 [14] P0(wet_nr_s) = 0.8 P0(¬wet_nr_s) = 0.2 [15] P0(wet_nr_ns) = 0.0 P0(¬wet_nr_ns) = 1.0 Figure 2.4: ICL theory from Example 2.6. When domains of logical variables are finite, the probability of a possible world is the product of the probabilities of the atomic choices in the corresponding total choice1. The probability of a proposition is the sum of probabilities of possible worlds in which the proposition is true. More details on ICL semantics are provided in [Poole, 2000], see also an overview in [Poole, 2008]. In the example below we show how a belief network from Examples 2.1 and 2.2 can be represented as an ICL theory. Example 2.6. Consider an ICL theory in Figure 2.4. It represents the same prob- ability distribution as a belief network described in Examples 2.1 and 2.2. The probability distribution has 6 parameters. The ICL theory has a choice space con- sisting of 6 alternatives with 2 atomic choices each (lines [00] – [05]). In each possible world it rains or not (line [00], a sprinkler is on or not (line [01]), grass is wet or dry when it is raining and the sprinkler is on (line [02]) and so on. The probability distribution over the alternatives is specified in lines [07] – [18]. For ex- 1In the general case, which is beyond the scope of this thesis, we need measure over sets of possible worlds. 18 [00] C = {{rain, ¬rain}, [01] {sprinkler(Lot), ¬sprinkler(Lot)}, [02] {wet_r_s(Lot), ¬wet_r_s(Lot)}, [03] {wet_r_ns(Lot), ¬wet_r_ns(Lot)}, [04] {wet_nr_s(Lot), ¬wet_nr_s(Lot)}, [05] {wet_nr_ns(Lot), ¬wet_nr_ns(Lot)}} [06] F = {wet_grass(Lot)← rain ∧ sprinkler(Lot) ∧ wet_r_s(Lot), [07] wet_grass(Lot)← rain ∧ ¬sprinkler(Lot) ∧ wet_r_ns(Lot), [08] wet_grass(Lot)← ¬rain ∧ sprinkler(Lot) ∧ wet_nr_s(Lot), [09] wet_grass(Lot)← ¬rain ∧¬sprinkler(Lot) ∧ wet_nr_ns(Lot)} [10] P0(rain) = 0.2 P0(¬rain) = 0.8 [11] P0(sprinkler(Lot)) = 0.4 P0(¬sprinkler(Lot)) = 0.6 [12] P0(wet_r_s(Lot)) = 0.99 P0(¬wet_r_s(Lot)) = 0.01 [13] P0(wet_r_ns(Lot)) = 0.9 P0(¬wet_r_ns(Lot)) = 0.1 [14] P0(wet_nr_s(Lot)) = 0.8 P0(¬wet_nr_s(Lot)) = 0.2 [15] P0(wet_nr_ns(Lot)) = 0.0 P0(¬wet_nr_ns(Lot)) = 1.0 Figure 2.5: ICL theory for multiple lots from Example 2.6. [00] C = {{rain(false), rain(true)}, [01] {sprinkler(Lot,false), sprinkler(Lot,true)}, [02] {wet_rain_sprinkler(Lot,false,false,false), wet_rain_sprinkler(Lot,true,false,false)}, [03] {wet_rain_sprinkler(Lot,false,false,true), wet_rain_sprinkler(Lot,true,false,true)}, [04] {wet_rain_sprinkler(Lot,false,true,false), wet_rain_sprinkler(Lot,true,true,false)}, [05] {wet_rain_sprinkler(Lot,false,true,true), wet_rain_sprinkler(Lot,true,true,true)}} [06] F = {wet_grass(Lot,X)← rain(Y) ∧ sprinkler(Lot,Z) ∧ wet_rain_sprinkler(Lot,X,Y,Z)} [07] P0(rain(false)) = 0.8 [08] P0(rain(true)) = 0.2 [09] P0(sprinkler(Lot,false)) = 0.6 [10] P0(sprinkler(Lot,true)) = 0.4 [11] P0(wet_rain_sprinkler(Lot,false,false,false)) = 1.0 [12] P0(wet_rain_sprinkler(Lot,true,false,false)) = 0.0 [13] P0(wet_rain_sprinkler(Lot,false,false,true)) = 0.2 [14] P0(wet_rain_sprinkler(Lot,true,false,true)) = 0.8 [15] P0(wet_rain_sprinkler(Lot,false,true,false)) = 0.1 [16] P0(wet_rain_sprinkler(Lot,true,true,false)) = 0.9 [17] P0(wet_rain_sprinkler(Lot,false,true,true)) = 0.01 [18] P0(wet_rain_sprinkler(Lot,true,true,true)) = 0.99 Figure 2.6: More elegant ICL theory for multiple lots from Example 2.6. 19 FIRST-ORDER PROPOSITIONAL {lot1, . . . , lotn} rain sprinkler(lot1) sprinkler(Lot) wet grass(Lot) rain wet grass(lot1) sprinkler(lotn) wet grass(lotn) Figure 2.7: Graphical representation of the ICL theory for multiple lots from Example 2.6. ample, P0(wet_r_s) = 0.99=P(wet_grass = true|rain = true,sprinkler = true). Finally, clauses in lines [06]–[09] specify the conditional probability for wet_grass given rain and sprinkler. Atoms rain, wet_grass, and sprinkler from the ICL theory correspond to nodes of the belief network. The above theory can be easily generalized to multiple lots as we show in Fig- ure 2.5. Figure 2.7 illustrates the resulting directed first-order probabilistic model using plates. The notion of plates [Buntine, 1994] is similar to the idea of param- eterized random variables; we use plates notation in our figures throughout this thesis. Consider the left part of Figure 2.7. A subgraph involving two parame- terized random variables sprinkler(Lot) and wet_grass(Lot) is enclosed within a box. The box is referred to as a plate. It implies that the subgraph is duplicated as many times as there are individuals in the population associated with the plate. The individuals are enumerated in the bottom-right corner of the plate. Arcs com- ing into the plate and leaving the plate are duplicated as well. Atoms from the ICL theory presented in Figure 2.5 are parameterized random variables. Atoms rain, wet_grass(Lot), and sprinkler(Lot) from the ICL theory correspond to nodes of the first-order probabilistic model shown in Figure 2.7. Facts can be specified in a more elegant way if we parameterize atoms over truth values of the corresponding parameterized random variables from the first- order model. Figure 2.6 shows a version of the ICL theory from Figure 2.5 that does this. Variable X parameterizes truth values of a parameterized random vari- able wet_grass(Lot), variable Y parameterizes truth values of a parameterized ran- 20 dom variable rain(), and variable Z parameterizes truth values of a parameter- ized random variable sprinkler(Lot). For example, an atom sprinkler(Lot, true) is true when the parameterized random variable sprinkler(Lot) is true and an atom sprinkler(Lot, f alse) is true when when the parameterized random variable sprinkler(Lot) is false. 2.5 Lifted probabilistic inference Although many first-order probabilistic languages have emerged, for many years the most common exact inference technique has been based on dynamical propo- sitionalization of the portion of the first order model that is relevant to the query, followed by probabilistic inference performed at the propositional level [Breese, 1992]. This approach is known as knowledge-based model construction (KBMC). Unfortunately, even a very simple first-order model can result in a very large propo- sitional model and the inference at propositional level can be formidably expensive. The big computational cost of the KBMC approach motivated work on exploit- ing redundant computation [Koller and Pfeffer, 1997; Pfeffer and Koller, 2000] during inference in first-order probabilistic models and work on compiling first- order models to secondary structures (for example arithmetic circuits [Chavira et al., 2006]) to facilitate efficient inference. The idea of lifted probabilistic inference is to carry out as much inference as possible without propositionalizing a first-order probabilistic model or its part. An exact lifted probabilistic inference procedure (in some literature called inversion elimination) for first-order probabilistic models was presented in Poole [2003]. Under certain conditions, the inversion elimination procedure can sum out multi- ple random variables from a model without considering each variable separately. de Salvo Braz et al. [2005, 2006, 2007] worked on increasing the scope of lifted probabilistic inference and introduced a counting elimination procedure. Further work by Milch et al. [2008] added counting formulas (see Section 2.4.1.1) and further expanded the scope of lifted probabilistic inference. Their work resulted in the C-FOVE algorithm, which is currently the state of the art in exact lifted probabilistic inference. 21 While Poole considered directed models, the later work by de Salvo Braz et al. and Milch et al. focused on undirected models, although their results can be used for directed models. Directed models have the advantage of allowing pruning of the part of a model that is irrelevant to the query. Also, conditional probability distributions in directed models can be interpreted and learned locally, which is important for models that are specified by people or need to be understood by people. In Section 2.5.1 we describe data structures used during lifted inference and in Section 2.5.2 we provide an overview of the C-FOVE algorithm. 2.5.1 Parametric factors To perform inference in first-order probabilistic models we need a data structure that would fulfill a role analogical to the role of factors (Section 2.3.1) during in- ference in belief networks. The above is a motivation behind parfactors [Poole, 2003]. They are used to represent conditional probability distributions in directed first-order models and potentials in undirected first-order models as well as inter- mediate computation results during lifted inference in first-order models. Definition 2.5. A parametric factor or parfactor is a triple 〈C,V,F〉 where: • C is a set of inequality constraints on logical variables (between a logical variable and a constant or between two logical variables); • V is a set of parameterized random variables, such that for any two parame- terized random variables f (. . .), f ′(. . .) from V we have ground( f (. . .)) : C∩ground( f ′(C)) : C = /0; (2.2) • F is a factor from the Cartesian product of ranges of parameterized random variables in V to the reals. A parfactor 〈C,V,F〉 represents a set of factors, one for each ground substitution G to all free logical variables in V that satisfies the constraints in C. Each such factor FG is a factor on the set of random variables obtained by applying a substitution G. Given an assignment v to random variables represented by V , v(FG) = v(F). | 〈C,V,F〉| denotes the number of factors represented by a parfactor 〈C,V,F〉. 22 Condition (2.2) ensures that each ground substitution G to all free logical vari- ables in V that satisfies the constraints in C results in a set of random variables of the same size. In this thesis we additionally assume that two logical variables that partici- pate in the same inequality constraint from C are typed with the same population. Extending lifted inference to handle hierarchies of types is an interesting idea for future work, but it is orthogonal to the focus of this thesis. Example 2.7. The ICL theory for multiple lots from Example 2.6 (shown in Fig- ure 2.7) can be represented by the following parfactors:〈 /0,{rain()}, P(rain() = f alse) P(rain() = true) 0.8 0.2 〉 , [01] 〈 /0,{sprinkler(Lot)}, P(sprinkler(Lot) = f alse) P(sprinkler(Lot) = true) 0.6 0.4 〉 , [02] 〈 /0,{rain(),sprinkler(Lot),wet_grass(Lot)}, [03] rain() sprinkler(Lot) P(wet_grass(Lot) = f alse) P(wet_grass(Lot) = true) f alse f alse 1.0 0.0 f alse true 0.2 0.8 true f alse 0.1 0.9 true true 0.01 0.99 〉 . Parfactor [01] represents a set containing one factor. Parfactors [02] and [03] repre- sent sets of factors of size n. Constraints within parfactors allow us to store knowledge about particular in- dividuals. It might be prior knowledge as well as coming from observations. Example 2.8. Assume that we know that sprinkler on lot loti is very likely to be on. Then the second parfactor from Example 2.7 ([02]) could be replaced by the following two parfactors:〈 /0,{sprinkler(loti)}, P(sprinkler(loti) = f alse) P(sprinkler(loti) = true)0.1 0.9 〉 , 〈{Lot 6= loti},{sprinkler(Lot)}, P(sprinkler(Lot) = f alse) P(sprinkler(Lot) = true)0.6 0.4 〉. Next example illustrates the trade-offs between the sizes of parfactors on stan- dard parameterized random variables, parfactors on counting formulas and parfac- tors on not parameterized random variables and their expressive power. 23 Example 2.9. Let wet_grass(Lot) be a parameterized random variable from Ex- ample 2.3 and #Lot [wet_grass(Lot)] be a counting formula from Example 2.5. Re- call that Lot is a logical variable typed with a population {lot1, lot2, . . . , lotn} and wet_grass is a functor with range { f alse, true} . Consider the following three parfactors: 〈 /0,{wet_grass(Lot)},F1〉; [1] 〈 /0,{#Lot [wet_grass(Lot)]},F2〉; [2] 〈 /0,{wet_grass(lot1),wet_grass(lot2), . . . ,wet_grass(lotn)},F3〉 . [3] Factor F1 represents a function from { f alse, true} to the reals and has size 2, thus its size is independent of |D(Lot) | = n. Parfactor [1] can represent a set of n identical real-valued discrete functions on each random variable from ground(wet_grass(Lot)). The next factor, F2, represents a function from the set {(# f alse = n,#true = 0), . . . ,(# f alse = 0,#true = n)} to the set of real numbers and has size n+1. Parfactor [2] can represent these real-valued discrete functions on random variables from the set ground(wet_grass(Lot)) that only depend the number of random variables from ground(wet_grass(Lot)) that take a particular value not on which of them take it. Finally, factor F3 represents a function from×ni=1 { f alse, true} to the reals and has size 2n. Parfactor [3] can represent arbitrary real-valued discrete functions on random variables ground(wet_grass(Lot)). 2.5.1.1 Normal-form constraints Let X be a logical variable in V from a parfactor 〈C,V,F〉. In general, the size of the set D(X) : C depends on other logical variables in V . Example 2.10. Consider a parfactor 〈{X 6= x1,X 6= Y},{g(X),h(X ,Y )},F〉, where D(X) =D(Y ) = {x1, . . . ,xn}. The size of the set D(X) : {X 6= x1,X 6= Y} depends on the logical variable Y . It is equal n−1 when Y = x1 and n−2 when Y 6= x1. The above property is undesirable for parfactors involving counting formulas because the set of possible values of a counting formula #A:CA [ f (. . . ,A, . . .)] can 24 take depends on the size of the set D(A) : C. Milch et al. [2008] introduced a special class of sets of inequality constraints. Let C be a set of inequality constraints on logical variables and X be a logical variable. We denote by ECX the excluded set for X , that is, the set of terms t such that (X 6= t) ∈ C. Set C is in normal form if for each inequality (X 6=Y ) ∈ C, where X and Y are logical variables, ECX \{Y} = ECY \{X}. A parfactor 〈C,V,FF〉 is in normal form if set C is in normal form. Consider a parfactor 〈C,V,FF〉, where C is in normal form. For all logical variables X in V , |D(X) : C |= |D(X) |− |ECX |. Example 2.11. Consider the parfactor from Example 2.10. Let C denote a set of constraints from this parfactor. The set C contains only one inequality be- tween logical variables, namely X 6= Y . We have ECX = {x1,Y} and ECY = {X}. As ECX \{Y} 6= ECY \{X}, the parfactor is not in normal form. Consider a parfactor 〈{X 6= Y, X 6= x1, Y 6= x1},{g(X), h(X ,Y )},F〉, where D(X) =D(Y ) = {x1, . . . ,xn}. Let C′ denote a set of constraints from this parfactor. As EC′X \{Y} = EC ′ Y \{X}, the parfactor is in normal form and |D(X) : C′ | = n− 2 and |D(Y ) : C′ |= n−2. Following Milch et al. [2008] we require that for a parfactor 〈C,V,FF〉 in- volving counting formulas, the union of C and the constraints in all the counting formulas in V is in normal form. Other parfactors do not need to be in normal form. The trade-off between requiring normal-form and allowing unrestricted sets of inequality constraints is discussed in Section 5.4. 2.5.2 C-FOVE In this section we provide an overview of the C-FOVE algorithm [Milch et al., 2008]. The algorithm builds on previous work by Poole [2003] and de Salvo Braz et al. [2007]. C-FOVE is not tied to any first-order probabilistic language. It can be used to perform inference in any model for which joint probability distribution can be represented as a product of factors. Let Φ be a set of parfactors. Let J (Φ) denote a factor equal to the product of all factors represented by elements of Φ. Let U be the set of all random variables represented by parameterized random variables present in parfactors in Φ. Let Q 25 be a subset of U. The marginal of J (Φ) on Q, denoted JQ(Φ), is defined as JQ(Φ) = ∑U\QJ (Φ). Given Φ and Q, the C-FOVE algorithm computes the marginal JQ(Φ) by summing out random variables from U \Q, where possible in a lifted manner. Evidence can be handled by adding to Φ additional parfactors on observed random variables. The C-FOVE algorithm assumes that all parfactors are in normal form. As lifted summing out is only possible under certain conditions, the C-FOVE algorithm uses elimination enabling operations, such as applying substitutions to parfactors and multiplication. We start our description of C-FOVE with lifted elimination, then describe elimination enabling operations and finally show how they can be combined to perform lifted probabilistic inference. Milch et al. [2008] define parfactors as quadruples 〈C,L,V,F〉. C, V , F have the same meaning as in Section 2.5.1 and L is a set of logical variables. Thus, the only difference with our notation is that they explicitly list logical variables present in a parfactor. This lets L be a superset of the set of logical variables that parameterize elements of V . 2.5.2.1 Lifted elimination The aim of lifted elimination is to sum out a parameterized random variable from a parfactor with much less computation then it would be required if we first con- verted the parfactor to a set of factors and summed out the ground instances of the parameterized random variable from these factors. We first describe a lifted sum- mation of a parameterized random variable that is not a counting formula and next present a lifted elimination of a counting formula. Let F be a factor and r be a real number. By F r we denote a factor such that given an assignment v of values to random variables, v(F r) = v(F)r. In F r, the values of factor F are brought to power r. Let 〈C,V,F〉 be a parfactor and r be a real number. By 〈C,V,F〉r we denote a parfactor 〈C,V,F r〉. The following two propositions follow directly from Propositions 1, 2 and 4 from Milch et al. [2008]. The first proposition considers summing out a set of 26 random variables represented by a parameterized random variable (not a counting formula) from a product of factors represented by a set of parfactors. Proposition 2.1. LetΦ= {g1,g2, . . . ,gm} be a set of parfactors. Let gi = 〈Ci,Vi,Fi〉 be a normal-form parfactor from Φ and f (. . .) be a parameterized random variable (not a counting formula) from Vi. Suppose that: (S1) For all parfactors g j = 〈C j,V j,F j〉 ∈ Φ, i 6= j and all h(. . .) ∈ V j we have ground( f (. . .)) : Ci∩ground(h(. . .)) : C j = /0. That is, no other parfactor in Φ includes parameterized random variables that represent random variables represented by f (. . .). (S2) param( f (. . .))⊇ ⋃ f ′(...)∈(V\{ f (...)}) param( f ′(. . .)). That is, the set of logi- cal variables in f (. . .) is a superset of the union of logical variables in other parameterized random variables from V . Let g′i = 〈 Ci,Vi \{ f (. . .)},∑ f (...)F 〉 and r = |gi|/|g′i|, where . Then ∑ ground( f (...)):Ci J (Φ) = J (Φ\{gi}∪{(g′i)r}) . (2.3) Condition (S1) makes sure that we are completely eliminating random vari- ables ground( f (. . .)) : Ci from the set of parfactors Φ. Condition (S2) guarantees that a result of lifted summation is equivalent to performing a series of summations at a propositional level. If after summing out f (. . .) some logical variables disap- pear from the parfactor gi, then g′i represents less factors than gi. To compensate for this, the values of the factor in g′i are brought to the power r = |gi|/|g′i|. 27 Example 2.12. Consider the following set of parfactors: Φ= {〈{A 6= B},{ f (A,B),h(B)}, f (A,B) h(B) value f alse f alse α1 f alse true α2 true f alse α3 true true α4 〉 , [1] 〈 /0,{e(C),h(x1)}, e(C) h(x1) value green f alse β1 green true β2 orange f alse β3 orange true β4 red f alse β5 red true β6 〉}, [2] where range( f ) = range(h) = { f alse, true}, range(e) = {green, orange, red}, D(A) =D(B) = {x1,x2, . . . ,xn},D(C) = {y1,y2, . . . ,ym}, and α1, . . . ,α4,β1, . . . ,β6 are real numbers. Assume we want to compute ∑ground( f (A,B)):{A 6=B}J (Φ). Condi- tions (S1) and (S2) of Proposition 2.1 are satisfied. Let us define a new parfactor [1′]: 〈 /0,{h(B)},∑ f (A,B) f (A,B) h(B) value f alse f alse α1 f alse true α2 true f alse α3 true true α4 〉 = 〈 /0,{h(B)}, h(B) value f alse α1+α3 true α2+α4 〉 . [1′] The logical variable A is present in parfactor [1] and it is absent from parfactor [1′]. Parfactor [1] represents n(n−1) factors. Parfactor [1′] represents n factors, that is, it represents n−1 times fewer factors than [1]. We have [1′](n−1) = 〈{A 6= B},{ f (A,B),h(B)}, h(B) valuef alse (α1+α3)(n−1) true (α2+α4)(n−1) 〉 . From Proposition 2.1: ∑ ground( f (A,B)):{A 6=B} J (Φ) = J ({[1′](n−1), [2]}) . An analogous proposition to Proposition 2.1 holds for counting formulas. It considers summing out a set of random variables represented by a counting formula from a product of factors represented by a set of parfactors. 28 Proposition 2.2. LetΦ= {g1,g2, . . . ,gm} be a set of parfactors. Let gi = 〈Ci,Vi,Fi〉 be a normal-form parfactor from Φ and #A:CA [ f (. . . ,A, . . .)] be a counting formula from Vi. Suppose that: (SC1) For all g j = 〈C j,V j,F j〉 ∈Φ, i 6= j and all h(. . .) ∈ V j we have ground(#A:CA [ f (. . . ,A, . . .)]) : Ci∩ground(h(. . .)) : C j = /0; (SC2) param(#A:CA [ f (. . . ,A, . . .)]) ⊇ ⋃ f ′(...)∈(V \{#A:CA [ f (...,A,...)]}) param( f ′(. . .)). That is, the set of logical variables of #A:CA [ f (. . . ,A, . . .)] is a superset of the union of logical variables of other parameterized random variables from set V . Let g′i = 〈Ci,V ′i ,Fi′〉, where V ′i = Vi \{#A:CA [ f (. . . ,A, . . .)]} and Fi′ is a factor from the Cartesian product of ranges of parameterized random variables in V ′i to the re- als. Let v be a value assignment to all random variables but ground( f (. . . ,A, . . .)) : Ci∪CA. Factor Fi′ is defined as follows: v(Fi′) = ∑ h()∈range(#A:CA [ f ()]) |D(A) : CA|! ∏x∈range( f (...,A,...)) h(x)! v(Fi)(h()), (2.4) Let r = |gi|/|g′i|. Then ∑ ground( f (...)):Ci J (Φ) = J (Φ\{gi}∪{(g′i)r}) . (2.5) The only difference between Proposition 2.2 and Proposition 2.1 is the expres- sion |D(A) : CA|! ∏x∈range( f (...,A,...)) h(x)! . The expression is equal to the number of assignments v′ of values to random vari- ables in a set ground(#A:CA [ f (. . . ,A, . . .)]) such that v′(#A:CA [ f (. . . ,A, . . .)]) = h(). 29 Example 2.13. Consider the following set of parfactors: Φ= {〈 /0,{#A:{A6=B}[ f (A)],h(B)}, #A:{A6=B}[ f (A)] h(B) value (# f alse = n−1,#true = 0) f alse α1 (# f alse = n−1,#true = 0) true α2 (# f alse = n−2,#true = 1) f alse α3 (# f alse = n−2,#true = 1) true α4 ... ... ... (# f alse = 0,#true = n−1) f alse α2n−1 (# f alse = o,#true = n−1) true α2n 〉 , [1] 〈 /0,{e(C),h(x1)}, e(C) h(x1) value green f alse β1 green true β2 orange f alse β3 orange true β4 red f alse β5 red true β6 〉}, [2] where range( f ) = range(h) = { f alse, true}, range(e) = {green, orange, red}, D(A)=D(B)= {x1,x2, . . . ,xn},D(C)= {y1,y2, . . . ,ym}, and α1, . . . ,α2n,β1, . . . ,β6 are real numbers. Assume we want to compute ∑ground(#A:{A6=B}[ f (A)])J (Φ). Condi- tions (SC1) and (SC2) of Proposition 2.2 are satisfied. Let us define a new parfactor [1′]: 〈 /0,{h(B)},∑#A:{A6=B}[ f (A)] #A:{A6=B}[ f (A)] h(B) value (# f alse = n−1,#true = 0) f alse α1 (# f alse = n−1,#true = 0) true α2 (# f alse = n−2,#true = 1) f alse α3 (# f alse = n−2,#true = 1) true α4 ... ... ... (# f alse = 0,#true = n−1) f alse α2n−1 (# f alse = 0,#true = n−1) true α2n 〉 , = 〈 /0,{h(B)}, h(B) value f alse ∑ni=1 (n−1 n−i ) α2i−1 true ∑ni=1 (n−1 n−i ) α2i 〉 . [1′] In the above calculation the expression |D(A):CA|!∏x∈range( f (...,A,...)) h(x)! from Proposition 2.2 for histogram (# f alse = n− i,#true = i−1) is equal to (n−1)!(n−i)!(i−1)! , which is equal to(n−1 n−i ) . 30 Parfactor [1] represents n factors and so does parfactor [1′]. Therefore we do not need to bring elements of [1′] to any power. From Proposition 2.2: ∑ ground(#A:{A6=B}[ f (A)]) J (Φ) = J ({[1′],[2]}) . 2.5.2.2 Parfactor multiplication Parfactor multiplication allows us to combine parfactors which involve parameter- ized random variables that represent the same set of random variables. This allows us to satisfy condition (S1) of Proposition 2.1 and condition (SC1) of Proposi- tion 2.2. Parfactor multiplication can be performed in a lifted manner. This means that, although parfactors participating in a multiplication as well as their product represent multiple factors, only one factor multiplication is performed. The follow- ing proposition is a consequence of Propositions 5 and 4 from Milch et al. [2008] and earlier work by de Salvo Braz et al. [2007]. Proposition 2.3. LetΦ= {g1,g2, . . . ,gm} be a set of parfactors. Let gi = 〈Ci,Vi,Fi〉 and g j = 〈C j,V j,F j〉 be parfactors from Φ. Suppose that: (M1) ∀ f (. . .) ∈ Vi∀ f ′(. . .) ∈ V j (ground( f (. . .)) : Ci = ground( f ′(. . .)) : C j) ∨ (ground( f (. . .)) : Ci∩ground( f ′(. . .)) : C j = /0). That is, sets of random variables represented by parameterized random variables from each parfac- tor are identical or disjoint. (M2) All parameterized random variables f (. . .) ∈ Vi and f ′(. . .) ∈ V j such that ground( f (. . .)) : Ci = ground( f ′(. . .)) : C j, f (. . .) and f ′(. . .) are identi- cally parameterized by logical variables and the set of other logical variables present in parfactor gi is disjoint with the set of logical variables present in parfactor g j. Let g = 〈 Ci∪C j,Vi∪V j,FiF j 〉 , ri = |gi|/|g| and r j = |g j|/|g|. Then J (Φ) = J (Φ\{gi,g j}∪{〈Ci∪C j,Vi∪V j,FiriF jr j〉}) . (2.6) Condition (M1) makes sure that the product of parfactors represents a set of factors of the same dimensionality. Condition (M2) guarantees correctness of set 31 unions in the definition of parfactor g. Similarly to lifted elimination, Equation 2.6 accounts for logical variables present in the product. The product parfactor g may represent more factors than a parfactor participating in the product, for example gi. To compensate for this, the values of the factor in gi are brought to the power ri = |gi|/|g| before computing the final product. Example 2.14. Consider the following set of parfactors: Φ= {〈{A 6= B},{ f (A,B),h(B)}, f (A,B) h(B) value f alse f alse α1 f alse true α2 true f alse α3 true true α4 〉 , [1] 〈 /0,{e(C),h(B)}, e(C) h(B) value green f alse β1 green true β2 orange f alse β3 orange true β4 red f alse β5 red true β6 〉}, [2] where range( f ) = range(h) = { f alse, true}, range(e) = {green, orange, red}, D(A) =D(B) = {x1,x2, . . . ,xn},D(C) = {y1,y2, . . . ,ym}, and α1, . . . ,α4,β1, . . . ,β6 are real numbers. Assume we want to multiply parfactors [1] and [2]. Conditions (M1) and (M2) of Proposition 2.3 are satisfied. Parfactor [1] represents n(n− 1) factors, parfactor [2] represents nm factors and their product will represent n(n− 1)m factors. We need to take it into account while computing a factor component of the product. Let us define a new parfactor [3]: 32 〈{A 6= B},{ f (A,B),e(C),h(B)}, f (A,B) h(B) value f alse f alse α n(n−1) n(n−1)m 1 f alse true α n(n−1) n(n−1)m 2 true f alse α n(n−1) n(n−1)m 3 true true α n(n−1) n(n−1)m 4 e(C) h(B) value green f alse β nm n(n−1)m 1 green true β nm n(n−1)m 2 orange f alse β nm n(n−1)m 3 orange true β nm n(n−1)m 4 red f alse β nm n(n−1)m 5 red true β nm n(n−1)m 6 〉 = 〈{A 6= B},{ f (A,B),e(C),h(B)}, f (A,B) e(C) h(B) value f alse green f alse α 1 m 1 β 1 n−1 1 f alse green true α 1 m 2 β 1 n−1 2 f alse orange f alse α 1 m 1 β 1 n−1 3 f alse orange true α 1 m 2 β 1 n−1 4 f alse red f alse α 1 m 1 β 1 n−1 5 f alse red true α 1 m 2 β 1 n−1 6 true green f alse α 1 m 3 β 1 n−1 1 true green true α 1 m 4 β 1 n−1 2 true orange f alse α 1 m 3 β 1 n−1 3 true orange true α 1 m 4 β 1 n−1 4 true red f alse α 1 m 3 β 1 n−1 5 true red true α 1 m 4 β 1 n−1 6 〉 . [3] From Proposition 2.3 J (Φ) = J ({[3]}). 2.5.2.3 Splitting, expanding and propositionalizing Condition (M1) from Proposition 2.3 for parfactor multiplication requires sets of random variables represented by parameterized random variables from parfactor participating in a product to be identical or disjoint. It can be satisfied through splitting parfactors on substitutions and expanding counting formulas. These two operations modify parameterized random variables which affects sets of random variables the parameterized random variables represent. The first proposition characterizes the splitting operation. It is Proposition 6 from Milch et al. [2008]. 33 Proposition 2.4. LetΦ= {g1,g2, . . . ,gm} be a set of parfactors. Let gi = 〈Ci,Vi,Fi〉 be a parfactor from Φ. Let X be a logical variable present in gi. Let {X/t} be a substitution such that t /∈ ECiX and either term t is a constant t ∈D(X), or term t is a logical variable present in gi such that D(t) = D(X). Let gi[X/t] be a parfactor gi with all occurrences of X replaced by term t and g′i = 〈Ci∪{X 6= t},Vi,Fi〉. Then J (Φ) = J (Φ\{gi}∪{gi[X/t],g′i}) . (2.7) We call the operation described above a split of parfactor gi on substitution {X/t} and we call g′i a residual parfactor. Example 2.15. Consider the following parfactor: 〈{A 6= B},{ f (A,B),h(B)}, f (A,B) h(B) value f alse f alse α1 f alse true α2 true f alse α3 true true α4 〉 , [1] where range( f ) = range(h) = { f alse, true}, D(A) =D(B) = {x1,x2, . . . ,xn}, and α1, . . . ,α4 are real numbers. Parfactor [1] represents n(n− 1) factors, its factor component has size 4. Let us split parfactor [1] on substitution {B/x1}. We obtain two new parfactors: 〈{A 6= x1},{ f (A,x1),h(x1)}, f (A,x1) h(x1) value f alse f alse α1 f alse true α2 true f alse α3 true true α4 〉 [1′] and 〈{A 6= B,B 6= x1},{ f (A,B),h(B)}, f (A,B) h(B) value f alse f alse α1 f alse true α2 true f alse α3 true true α4 〉 . [1′′] Parfactor [1′] represents n−1 factors, parfactor [1′′] represents (n−1)+(n−1)(n− 2) = (n− 1)2 factors, their factor component has size 4. From Proposition 2.4, J ({[1]}) = J ({[1′],[1′′]}). 34 Given a parfactor g = 〈C,V,F〉 and a logical variable X present in one or more parameterized random variables from V , we may need to propositionalize g on X , that is replace it by a set of parfactors of the form g[X/c], one for each constant c fromD(X) : C. Propositionalization can be thought of as splitting g on substitution {X/c} for every c ∈ D(X) : C. The next proposition characterizes the expanding operation. It is Proposition 7 from Milch et al. [2008]. Proposition 2.5. Let Φ{g1,g2, . . . ,gm} be a set of parfactors. Let gi = 〈Ci,Vi,Fi〉 be a normal-form parfactor from Φ and #A:CA [ f (. . . ,A, . . .)] be a counting for- mula from Vi. Let t be a term such that t /∈ ECAA and t ∈ ECY for each logical variable Y ∈ ECAA . Let g′ = 〈Ci,V ′i ,Fi′〉, where V ′i = Vi \ {#A:CA [ f (. . . ,A, . . .)]} ∪ { f (. . . , t, . . .),#A:CA∪{A6=t}[ f (. . . ,A, . . .)]} and factor Fi′ is a factor from the Carte- sian product of ranges of parameterized random variables in V ′i to the reals. Let v be a value assignment to to all random variables but ground( f (. . . ,A, . . .)) : Ci∪CA. Factor Fi′ is defined as follows: v(Fi′)(x,h()) = v(Fi)(h′()), (2.8) where x ∈ range( f ), histogram h() ∈ range(#A:CA∪{A 6=t}[ f (. . . ,A, . . .)]), histogram h′() ∈ range(#A:CA [ f (. . . ,A, . . .)]), and h′() is obtained by taking h() and adding 1 to the count for the value x. Then J (Φ) = J (Φ\{gi}∪{g′i}) . (2.9) Example 2.16. Consider the following parfactor: 〈 /0,{#A:{A6=B}[ f (A)],h(B)}, #A:{A6=B}[ f (A)] h(B) value (# f alse = n−1,#true = 0) f alse α1 (# f alse = n−1,#true = 0) true α2 (# f alse = n−2,#true = 1) f alse α3 (# f alse = n−2,#true = 1) true α4 ... ... ... (# f alse = 0,#true = n−1) f alse α2n−1 (# f alse = o,#true = n−1) true α2n 〉 . [1] where D(A) = D(B) = {x1,x2, . . . ,xn} and range( f ) = range(h) = { f alse, true}, and α1, . . . ,α2n are real numbers. Parfactor [1] represents n factors, its factor com- 35 ponent has size 2n. Let us expand counting formula #A:{A 6=B}[ f (A)] on constant x1. We obtain a new parfactor: 〈 /0,{#A:{A 6=B,A 6=x1}[ f (A)], f (x1),h(B)}, #A:{A 6=B,A6=x1}[ f (A)] f (x1) h(B) value (# f alse = n−2,#true = 0) f alse f alse α1 (# f alse = n−2,#true = 0) f alse true α2 (# f alse = n−2,#true = 0) true f alse α3 (# f alse = n−2,#true = 0) true true α4 (# f alse = n−3,#true = 1) f alse f alse α3 (# f alse = n−3,#true = 1) f alse true α4 ... ... ... ... (# f alse = 0,#true = n−2) true f alse α2n−1 (# f alse = o,#true = n−2) true true α2n 〉 . [1′] Parfactor [1′] represents n factors, its factor component has size 4(n− 1). From Proposition 2.5, J ({[1]}) = J ({[1′]}). We can fully expand a counting formula #A:CA [ f (. . . ,A, . . .)] by expanding it on all constants in D(A) : CA. 2.5.2.4 Counting Condition (S2) of Proposition 2.1 and condition (SC2) of Proposition 2.2 require that the set of logical variables of a parameterized random variable being elimi- nated from a parfactor is a superset of the union of logical variables of other pa- rameterized random variables from this parfactor. When this condition does not hold, we can sometimes satisfy it by performing counting. Counting eliminates a free logical variable from a parfactor. The next proposition characterizes the counting operation. It is Proposition 3 from Milch et al. [2008]. Proposition 2.6. LetΦ= {g1,g2, . . . ,gm} be a set of parfactors. Let gi = 〈Ci,Vi,Fi〉 be a normal-form parfactor from Φ and A be a logical variable such that there is exactly one parameterized random variable f (. . . ,A, . . .) ∈ Vi for which A ∈ param( f (. . . ,A, . . .)). Let CA be a set of those constraints from Ci that involve A, let V ′i = Vi \{ f (. . . ,A, . . .)}∪{#A:CA [ f (. . . ,A, . . .)]} and let Fi′ be a factor from the Cartesian product of ranges of parameterized random variables in V ′i to the reals. Let v be a value assignment to all random variables but ground( f (. . . ,X , . . .)) : Ci. 36 Factor Fi′ is defined as follows: v(Fi′)(h()) = ∏ x∈range( f (...,A,...)) v(Fi))(x)h(x), (2.10) where histogram h() ∈ range(#A:CA [ f (. . . ,A, . . .)]). Then J (Φ) = J (Φ\{gi}∪{〈Ci \CA,V ′i ,Fi′〉}) . (2.11) As suggested in Milch et al. [2008], a good way to think about Equations 2.10 and 2.11 is to consider J ({gi}). We can represent gi as a product of parfactors ob- tained from parfactor gi by propositionalizing the logical variable A. In this prod- uct, given an assignment of values to random variables, it does not matter which ground instance of f (. . . ,A, . . .) is assigned a particular value from range( f ), but only how many of them are assigned the value. The above property allows us to use a counting formula #A:CA [ f (. . . ,A, . . .)] to collapse the product to a single parfactor. While the new parfactor has bigger factor component than the original parfactor, the logical variable A no longer occurs free in the new parfactor. Example 2.17. Consider the following parfactor: 〈{A 6= B},{ f (A),h(B)}, f (A) h(B) value f alse f alse α1 f alse true α2 true f alse α3 true true α4 〉 , [1] where range( f ) = range(h) = { f alse, true}, D(A) =D(B) = {x1,x2, . . . ,xn}, and α1, . . . ,α4 are real numbers. Parfactor [1] represents n(n− 1) factors, its factor component has size 4. Note, that we cannot eliminate ground( f (A)) : {A 6= B} from J ({[1]}) in a lifted manner since condition (S1) of Proposition 2.1 is not satisfied. The same applies to lifted elimination of ground(h(A)) : {A 6= B}. We can however apply Proposition 2.6 and eliminate either of two logical variables present in the parfactor through counting. Let us eliminate the logical variable A. We create a new parfactor where f (A) is replaced with a counting formula: 37 〈 /0,{#A:{A 6=B}[ f (A)],h(B)}, #A:{A 6=B}[ f (A)] h(B) value (# f alse = n−1,#true = 0) f alse (α1)n−1(α3)0 (# f alse = n−1,#true = 0) true (α2)n−1(α4)0 (# f alse = n−2,#true = 1) f alse (α1)n−2(α3)1 (# f alse = n−2,#true = 1) true (α2)n−2(α4)1 ... ... ... (# f alse = 0,#true = n−1) f alse (α1)0(α3)n−1 (# f alse = o,#true = n−1) true (α2)0(α4)n−1 〉 . [1′] Parfactor [1′] represents n factors, its factor component has size 2n. From Proposi- tion 2.6, J ({[1]}) = J ({[1′]}). The counting elimination algorithm of de Salvo Braz et al. [2007] is equivalent to introducing counting formulas as described above and eliminating them imme- diately. The C-FOVE algorithm, by introducing counting formulas explicitly and allowing them to be part of parfactors increases flexibility of lifted inference (see Section 2.5.2.7). 2.5.2.5 Unification Several conditions present in propositions that theoretically characterize opera- tions on parfactors refer to sets of random variables represented by parameterized random variables. Conditions are concerned about sets of random variables be- ing identical or disjoint. Checking these conditions through analysis of these sets would defeat the goal of lifted inference, that is carrying inference without propo- sitionalizing a first-order probabilistic model or its part. We need syntactic criteria that can be checked quickly. Poole [2003] showed how these conditions can be en- sured efficiently using unification [Sterling and Shapiro, 1994]. Milch et al. [2008] extended his work to counting formulas. In the presence of constraints in parfac- tors, unification needs to be accompanied by constraint analysis and processing. In this section we give an overview of unification and constraint processing necessary to verify and ensure conditions discussed above. We start with two pa- rameterized random variables that are not counting formulas. We illustrate our description with multiple examples. Consider two parfactors 〈C1,V1,F1〉 and 〈C2,V2,F2〉. Assume that we want to find out the relation between sets of random variables represented by parameterized 38 [00] procedure replace(〈C,V,F〉) [01] input: parfactor 〈C,V,F〉; [02] output: parfactor 〈C,V,F〉[θ ], where substitution θ replaces every logical [03] variable constrained to a single constant with this constant, [04] error if 〈C,V,F〉 represents 0 factors; [05] add logical variables from C to the queue; [06] while queue not empty do [07] remove logical variable X from the queue; [08] case [09] |D(X) : {X 6= t ∈ C : t is a constant}|= 0 [10] return error; [11] end [12] |D(X) : {X 6= t ∈ C : t is a constant}|= 1 [13] set {x} :=D(X) : {X 6= t ∈ C : t is a constant}; [14] remove unary constraints involving X from C; [15] add logical variables from the set {Y : X 6= Y ∈ C} to the queue; [16] replace every occurrence of X in C and in V with x; [17] end [18] otherwise [19] // do nothing [20] end [21] end [22] return 〈C,V,F〉; [23] end Figure 2.8: AC-3 algorithm for replacing logical variables with constants. random variables f (t11 , . . . , t 1 k ) ∈ V1 and f (t21 , . . . , t2k ) ∈ V2 in respective parfactors, that is, the relation between sets of random variables ground( f (t11 , . . . , t 1 k )) : C1 and ground( f (t21 , . . . , t 2 k )) : C2. If the sets are not disjoint and are not identical, we want to find out splits that are required to make these sets identical. Note that standard parameterized random variables with different functors represent disjoint sets of random variables. Sometimes the constraints in a parfactor are tight enough to uniquely identify an individual from the population of a logical variable. In this case it is useful to be able to replace the logical variable with a constant denoting the only individual that is possible (we will justify the need for this step later on). Note that binary constraints we are dealing with are inequality constraints like X 6= Y . The X 6= Y constraint is a weak constraint, it only constraints the set of possible values for Y , 39 when the set of possible values of X contains a single element. Figure 2.8 shows the AC-3 algorithm [Mackworth, 1977] adapted to perform the task described above. The algorithm does not enumerate populations of involved logical variables, but it needs to know their sizes. Example 2.18. Consider a parfactor 〈C,V,F〉, where constrains set C = {A 6= x1,A 6= x2,A 6= x3,A 6= B,A 6= C,B 6= x1,B 6= x3,B 6= C} and D(A) = D(B) = D(C) = {x1,x2,x3,x4}. The algorithm presented in Figure 2.8 detects that pop- ulation of the logical variable A is constrained to x4 and replaces A with x4 inside the parfactor. We obtain the following set of constraints: {x4 6= B,x4 6= C,B 6= x1,B 6= x3,B 6=C}. Now B is constrained to x2 and can be replaced by this constant and the constraint set reduces to {x4 6=C,x2 6=C}. In total, the algorithm applied two substitutions, {A/x4} and {B/x2}, to the parfactor 〈C,V,F〉. If we change the population of A, B and C to {x1,x2,x3,x4,x5}, then none of the logical variables is constrained to a single individual and the algorithm from Figure 2.8 will not change the parfactor. The scope of logical variables is restricted to the enclosing parfactor. Two logi- cal variables with the same name present in two different parfactors might be typed with different populations and be completely unrelated. For unification to work properly we need to remove such name clashes between considered parfactors. We rename logical variables in both parfactors so that the set of logical variables present in the first parfactor is disjoint with the set of logical variables present in the second parfactor. Example 2.19. Consider set of parfactors Φ0: Φ0 = {〈{X 6= x2},{ f (X ,Y ),q(Y )},F1〉, [1] 〈{X 6= Z,Z 6= x1},{p(X), f (x1,Z)},F2〉}, [2] where the logical variable X in parfactor [1] is unrelated to the logical variable X from parfactor [2] and we need to separate them. Assume that in parfactor [1] D(X) = {x1,x2, . . . ,xn} and D(Y ) = {y1,y2, . . . ,ym}, and in parfactor [2] D(X) = D(Z) = {y1,y2, . . . ,ym}. If n and m are greater than 2, the algorithm from Fig- ure 2.8 will not modify the two parfactors and we can proceed with renaming. We 40 [00] procedure MGU( f (t11 , . . . , t 1 k ), f (t 2 1 , . . . , t 2 k )) [01] input: parameterized random variables f (t11 , . . . , t 1 k ), f (t 2 1 , . . . , t 2 k ); [02] output: MGU θ of f (t11 , . . . , t 1 k ) and f (t 2 1 , . . . , t 2 k ), [03] error if f (t11 , . . . , t 1 k ) and f (t 2 1 , . . . , t 2 k ) do not unify; [04] set θ := {}; [05] push equations t11 = t 2 1 , . . . , t 1 k = t 2 k to the stack; [06] while stack not empty do [07] pop equation ti = t j from the stack; [08] case [09] ti and t j are identical terms [10] // do nothing [11] end [12] ti is a parameter [13] replace every occurrence of ti in the stack and in θ with t j; [14] add {ti/t j} to θ ; [15] end [16] t j is a parameter [17] replace every occurrence of t j in the stack and in θ with ti; [18] add {t j/ti} to θ ; [19] end [20] otherwise [21] return error; [22] end [23] end [24] return θ ; [25] end Figure 2.9: MGU algorithm for parameterized random variables. obtain a new set of parfactors Φ1: Φ1 = {〈{X1 6= x2},{ f (X1,X2),q(X2)},F1〉, [3] 〈{X3 6= X4,X4 6= x1},{p(X3), f (x1,X4)},F2〉}, [4] where D(X1) = {x1,x2, . . . ,xn} and D(X2) = D(X3) = D(X4) = {y1,y2, . . . ,ym}. We have J (Φ0) = J (Φ1). Assume that we have already performed the above two preprocessing opera- tions on parfactors 〈C1,V1,F1〉 and 〈C2,V2,F2〉. We can now compute an MGU of parameterized random variables f (t11 , . . . , t 1 k ) ∈ V1 and f (t21 , . . . , t2k ) ∈ V2. An al- gorithm for computing MGU is presented in Figure 2.9. The algorithm is adapted 41 [00] procedure checkMGU(θ ,C) [01] input: MGU θ , [02] set of inequality constraints C; [03] output: true if θ is consistent with C, f alse otherwise; [04] set θ := {}; [05] for each constraint X 6= t from C do [06] if {{X/t}} ⊂ θ [07] return f alse; [08] if t is a parameter [09] if {{X/t1},{t/t1}} ⊂ θ or {{t/X}} ⊂ θ [10] return f alse; [11] end [12] return true; [13] end Figure 2.10: Algorithm for checking if an MGU is consistent with a set of inequality constraints. from Sterling and Shapiro [1994]. The time and space complexity of the algorithm are O(k). If parameterized random variables do not unify, they represent disjoint sets of random variables. If the MGU is empty, neither parameterized random variable is parameterized by logical variables and each represents the same set containing a single random variable. The above is true because we have renamed logical vari- ables and logical variables present in one parameterized random variable are not present in the other one. Finally, if parameterized random variables unify and the MGU is not empty, we need to check if the MGU is consistent with the constraints in both parfactors. A check if an MGU is consistent with a constraints can be per- formed using an algorithm shown in Figure 2.10. Example 2.20. Let us continue Example 2.19. Parameterized random variables f (X1,X2) and f (x1,X4) unify with MGU θ = {X1/x1,X2/X4}. θ is consistent with constraints {X1 6= x2}∪{X3 6= X4,X4 6= x1}. If non-empty MGU is not consistent with the constraints, parameterized ran- dom variables f (t11 , . . . , t 1 k ) and f (t 2 1 , . . . , t 2 k ) represent disjoint sets of random vari- ables. If non-empty MGU is consistent with the constraints in both parfactors, sets of random variables represented by the analyzed parameterized random variables 42 [00] procedure splitOnMGU(θ ,〈C,V,F〉) [01] input: MGU θ , [02] parfactor 〈C,V,F〉; [03] output: parfactor g obtained by splitting 〈C,V,F〉 on θ , [04] set of residual parfactors Ψ; [05] set g := 〈C,V,F〉 [06] set Ψ := {}; [07] for each substitution {X/t} from θ do [08] if X is a logical variable in g [09] if t is a constant or t is a logical variable in g [10] split g on {X/t}; [11] set g to the result; [12] add the residual parfactor to Ψ; [13] else [14] replace all occurrences of X in g with t; [15] end [16] return g and Ψ; [17] end Figure 2.11: Algorithm for splitting a parfactor on an MGU. are not disjoint and possibly are not identical. To make them identical, we split both parfactors on the MGU as described by Poole [2003]. The splitting algorithm is shown in Figure 2.11. Given parfactor g and MGU θ the algorithm returns a par- factor obtained from applying substitutions in θ to g as well as residual parfactors resulting from these operations. After applying the MGU to 〈C1,V1,F1〉 and 〈C2,V2,F2〉, we obtain sets of residual parfactors and parfactors 〈C′1,V ′1,F1〉 and 〈C′2,V ′2,F2〉. Thanks to the splitting on the MGU, parameterized random variables f (t11 , . . . , t 1 k ) from V1 and f (t21 , . . . , t 2 k ) from V2 are replaced in V ′1 and V ′2 by the same parameterized ran- dom variable f (t1, . . . , tk). However, we want sets ground( f (t1, . . . , tk)) : C′1 and ground( f (t1, . . . , tk)) : C′2 to be identical and we need to process constraints in C′1 and C′2. Note that, by splitting parfactors on the MGU, not only the sets of random variables represented by targeted parameterized random variables became identi- cal, but also the symbolic representation of the parameterized random variables is identical in both parfactors. The latter brings us closer to satisfying condition (M2) of Proposition 2.6 and allowing for multiplication of these two parfactors. 43 [00] procedure splitOnConstraints(CS,〈C,V,F〉) [01] input: set of constraints CS, [02] parfactor 〈C,V,F〉; [03] output: parfactor g obtained by splitting θ to 〈C,V,F〉, [04] set of by-product parfactors Ψ; [05] set g := 〈C,V,F〉 [06] set Ψ := {}; [07] for each constraint X 6= t from CS do [08] if (X 6= t) /∈ C and X is a logical variable in g [09] and (t is a constant or t is a logical variable in g) [10] split g on {X/t}; [11] add the result to Ψ; [12] set g to the residual parfactor; [13] end [14] return g and Ψ; [15] end Figure 2.12: Algorithm for splitting a parfactor on a set of constraints. Example 2.21. Let us continue Examples 2.19 and 2.20. We split parfactors from set Φ1: Φ1 = {〈{X1 6= x2},{ f (X1,X2),q(X2)},F1〉, [3] 〈{X3 6= X4,X4 6= x1},{p(X3), f (x1,X4)},F2〉}, [4] on MGU θ = {X1/x1,X2/X4}. We obtain the following set of parfactors: Φ2 = {〈{X3 6= X4,X4 6= x1},{p(X3), f (x1,X4)},F2〉, [4] 〈 /0,{ f (x1,X4),q(X4)},F1〉, [5] 〈{X1 6= x1,X1 6= x2},{ f (X1,X2),q(X2)},F1〉} [6] Parfactor [4] is not affected by splitting on θ , because it does not contain logi- cal variables X1 and X2. From parfactor [3] we obtain parfactor [5] and a resid- ual parfactor [6]. We have J (Φ1) = J (Φ2). Note that ground( f (x1,X4)) : /0 6= ground( f (x1,X4)) : {X1 6= x1,X1 6= x2} and the set of random variables represented by parameterized random variable f (x1,X4) in parfactor [4] is different from the set of random variables it represents in parfactor [5]. 44 The final step processes constraints. Let S be a set of logical variables that are shared between parfactor 〈C′1,V ′1,F1〉 and parfactor 〈C′2,V ′2,F2〉. Sets of random variables ground( f (t1, . . . , tk)) : C′1 and ground( f (t1, . . . , tk)) : C′2 might be different, because inequality constraints that have impact on the set of random variables represented by f (t1, . . . , tk) might be different in parfactors 〈C′1,V ′1,F1〉 and 〈C′2,V ′2,F2〉. These are constraints between a logical variable and a constant such that the logical variable is in S and constraints between two logical variables such that both logical variables are in S . We can ignore constraints that do not involve logical variables from S . Earlier, we replaced logical variables constrained to single individuals with appropriate constants (see Figure 2.8), and now we can ignore binary constraints that involve a logical variable from S and a logical variable not from S. An algorithm presented in Figure 2.12 inputs a set of constraints and a parfactor and modifies the parfactor so that it contains all relevant constraints from the given set of constraints. The algorithm also returns a set of by-product parfactors. Given 〈C′1,V ′1,F1〉 and 〈C′2,V ′2,F2〉, we apply the algorithm to set of constraints C′2 and parfactor 〈C′1,V ′1,F1〉 and obtain a parfactor 〈C1 ”,V1”,F1〉. Then we apply the algorithm to set of constraints C′1 and parfactor 〈C′2,V ′2,F2〉 and obtain a parfactor 〈C2 ”,V2”,F2〉. We have ground( f (t1, . . . , tk)) : C1 ” = ground( f (t1, . . . , tk)) : C2 ”, which was the goal of the process of unification. Example 2.22. Let us continue Example 2.21. We have set of parfactors Φ2: Φ2 = {〈{X3 6= X4,X4 6= x1},{p(X3), f (x1,X4)},F2〉, [4] 〈 /0,{ f (x1,X4),q(X4)},F1〉, [5] 〈{X1 6= x1,X1 6= x2},{ f (X1,X2),q(X2)},F1〉}. [6] We will use the algorithm from Figure 2.12 to modify parfactors [4] and [5] so that parameterized random variable f (x1,X4) represent the same set of random variables in the modified parfactors. Since parfactor [5] does not contain any con- straints, we only need to split parfactor [5] on constraints from parfactor [4]. The algorithm will ignore constraint X3 6= X4 as the logical variable X3 is not present in [5] and split on substitution {X4/x1} induced by constraint X4 6= x1. We obtain a 45 new set of parfactors: Φ3 = {〈{X3 6= X4,X4 6= x1},{p(X3), f (x1,X4)},F2〉, [4] 〈{X1 6= x1,X1 6= x2},{ f (X1,X2),q(X2)},F1〉 [6] 〈 /0,{ f (x1,x1),q(X4)},F1〉, [7] 〈{X4 6= x1},{ f (x1,X4),q(X4)},F1〉}. [8] Parameterized random variable f (x1,X4) represent the same set of random vari- ables in parfactors [4] and [8]. We also have J (Φ2) = J (Φ3). Above, we talked only about standard parameterized random variables. As- sume we want to find out relation between sets of random variables represented by a counting formula #A:CA [ f (. . . ,A, . . .)] from a parfactor 〈C,V,F〉 and another parameterized random variable (possibly also a counting formula, but not necessar- ily). The process is quite similar to what we described for standard parameterized random variables with two differences pointed out by Milch et al. [2008]. The first difference is that we should apply unification to f (. . . ,A, . . .) and combine con- straints CA with C instead of considering #A:CA [ f (. . . ,A, . . .)] itself. It is because the set of random variables underlying f (. . . ,A, . . .) with respect to constraints CA∪C is the same as for #A:CA [ f (. . . ,A, . . .)] with constraints C, even though they have dif- ferent functors (see Section 2.4.1.1). The second difference is that where procedure called for splitting parameterized random variables, we expand counting formulas. In this section we described how to compare and change sets of random vari- ables represented by parameterized random variables. The described procedure operates at a syntactic level and it does not enumerate populations of involved log- ical variables, it only needs to know their sizes. 2.5.2.6 The C-FOVE algorithm Milch et al. [2008] describe the C-FOVE algorithm in terms of the following macro-operations: • SHATTER(Φ) - given a set of parfactors Φ, the shattering macro-operation performs all the splits and expansions (defined in Section 2.5.2.3) neces- sary to ensure that for any two parameterized random variables present in 46 parfactors from Φ, the sets of random variables represented by these two parameterized random variables are either identical or disjoint. The neces- sary splits in expansions are determined using unification as described in Section 2.5.2.5; • GLOBAL-SUM-OUT(Φ, f (. . .), C) - given a set of parfactorsΦ, a parameter- ized random variable f (. . .) and a set of constraints C, the macro-operation multiplies all parfactors from Φ containing parameterized random variables that represent ground( f (. . .)) : C (see Section 2.5.2.2) and eliminates ran- dom variables ground( f (. . .)) : C from the product (see Section 2.5.2.1); the macro-operation is only applicable if the product satisfies condition (S2) of Proposition 2.1 (or condition (SC2) of Proposition 2.2 if we are eliminating a counting formula), multiplication operations can always be performed be- cause of initial shattering, this is the only macro-operation that eliminates random variables from J (Φ); • COUNTING-CONVERT(Φ, 〈C,V,F〉, X ) - given a set of parfactors Φ, a par- factor 〈C,V,F〉 from Φ and a free logical variable X , such that X occurs in exactly one parameterized random variable from V , the counting macro- operation eliminates X from the parfactor (see Section 2.5.2.4); • PROPOSITIONALIZE(Φ, 〈C,V,F〉, X ) - given a set of parfactors Φ, a par- factor 〈C,V,F〉 from Φ and a free logical variable X , the macro-operation propositionalizes the logical variable X (see Section 2.5.2.3), afterwards it performs shattering to ensure that the sets of random variables represented by parameterized random variables in Φ are still either identical or disjoint after the propositionalization; • FULL-EXPAND(Φ, 〈C,V,F〉, #A:CA [ f (. . . ,A, . . .)]) - given a set of parfactors Φ, a parfactor 〈C,V,F〉 from Φ and a counting formula #A:CA [ f (. . . ,A, . . .)], the macro-operation expands the given counting formula on every constant in D(A) : CA (see Section 2.5.2.3), afterwards it performs shattering to en- sure that the sets of random variables represented by parameterized random variables in Φ are still either identical or disjoint after the expansion; 47 Given a set of parfactors Φ and a set of queried random variables Q, which could be given in a form of a parameterized random variable and a set of con- straints, the C-FOVE algorithm computes the marginal JQ(Φ). It starts with a shattering macro-operation. Parfactors in Φ are also shattered against the random variables in Q. Next the C-FOVE algorithm eliminates non-queried random vari- ables fromΦ by iteratively performing one of the other four macro-operations. The macro-operations are chosen by a greedy-search with the cost of each operation de- fined as the total size of parfactors an operation creates, which in practice is equal to the size of factor components of these parfactors. While global elimination and counting operations are not always possible to perform because their preconditions might not be satisfied, propositionalization and full expansion can always be ex- ecuted and, in an extreme case, fully propositionalize the set of parfactors. This implies C-FOVE’s completeness. It is worth pointing out, that similarly to the VE algorithm for inference in belief networks, the C-FOVE algorithm in directed models allows for pruning of random variables irrelevant to the query. See [Taghipour et al., 2009] for an example how pruning can be performed in lifted manner. 2.5.2.7 Example computation In this section we present a simple lifted computation which illustrates the C- FOVE algorithm. Consider the parfactors from Example 2.7 (page 23), which represent the ICL theory from Example 2.6 (page 18) and Figure 2.5 (page 19). Assume D(Lot) = {lot1, lot2, . . . , lotn} and that it is observed that grass is wet on lot1, which can be represented by the following parfactor:〈 /0,{wet_grass(lot1)}, P(wet_grass(lot1) = f alse) P(wet_grass(lot1) = true)0.0 1.0 〉 . 48 LetΦ be a set of the three parfactors from Example 2.7 and the above parfactor (in what follows, we don’t show details of factor components of parfactors): Φ= {〈 /0,{rain()},F1〉, [01] 〈 /0,{sprinkler(Lot)},F2〉, [02] 〈 /0,{rain(),sprinkler(Lot),wet_grass(Lot)},F3〉, [03] 〈 /0,{wet_grass(lot1)},F4〉}. [04] Assume we want to compute Jground(wet_grass(Lot)):{Lot 6=lot1}(Φ) using the C-FOVE algorithm. Note that this is the joint on wet_grass(Lot) for all lots except lot1. Below we describe a run of the C-FOVE algorithm. After each step we show an updated set of parfactors Φ indexed with the step number. After initial shattering, before each step we list available macro-operations and their cost according to the C-FOVE heuristic. First, C-FOVE invokes SHATTER(Φ) macro-operation. The macro-operation splits parfactor [03] on substitution {Lot/lot1} which creates parfactor [05] and residual parfactor [06]. Next, it splits parfactor [02] on {Lot/lot1} which creates parfactor [07] and residual parfactor [08]. After shattering, set Φ1 is as follows: Φ1 = {〈 /0,{rain()},F1〉, [01] 〈 /0,{wet_grass(lot1)},F4〉, [04] 〈 /0,{rain(),sprinkler(lot1),wet_grass(lot1)},F3〉, [05] 〈{Lot 6= lot1},{rain(),sprinkler(Lot),wet_grass(Lot)},F3〉, [06] 〈 /0,{sprinkler(lot1)},F2〉, [07] 〈{Lot 6= lot1},{sprinkler(Lot)},F2〉}. [08] Note that parfactors created by the same splitting operation have identical fac- tor components. A smart implementation would represent these factors using the same, single object. We discuss this issue in more detail in Section 5.3. The following (parameterized random variable, set of constraints) pairs are present in set Φ1: (rain(), /0),(sprinkler(lot1), /0),(sprinkler(Lot),{Lot 6= lot1}), 49 (wet_grass(lot1), /0), and (wet_grass(Lot),{Lot 6= lot1}). C-FOVE will eliminate all of them, except for the last one. After the initial shattering, the C-FOVE algorithm has choice between per- forming the following macro-operations: • GLOBAL-SUM-OUT(Φ1, wet_grass(lot1), /0), which during the multiplica- tion step would create a factor of size 8 and after summing out would create a factor of size 4; it would eliminate one random variable; • GLOBAL-SUM-OUT(Φ1, sprinkler(lot1), /0), which during the multiplica- tion step would create a factor of size 8 and after summing out would create a factor of size 4; it would eliminate one random variable; • GLOBAL-SUM-OUT(Φ1, sprinkler(Lot), {Lot 6= lot1}), which during the multiplication step would create a factor of size 8 and after summing out would create a factor of size 4; it would eliminate n−1 random variables; • PROPOSITIONALIZE(Φ1, [06], Lot), which would create n−1 identical fac- tors of size 2 and, because of subsequent shattering, n− 1 identical factors of size 2; it would not eliminate any random variables; • PROPOSITIONALIZE(Φ1, [08], Lot), which would create n−1 identical fac- tors of size 8 and n−1 identical factors of size 2; it would not eliminate any random variables; • COUNTING-CONVERT(Φ1, [08], Lot), which would create a factor of size n; it would not eliminate any random variables. The first three macro-operations have identical cost. Tie-breaking is not discussed by Milch et al. [2008]. Let us assume that C-FOVE uses the number of random variables that would be eliminated for tie-breaking (the more, the better) and if the number does not resolve the tie than the algorithm chooses one of equally good operations at random. Under this assumption, C-FOVE chooses the third macro-operation. The macro-operation first applies Proposition 2.3 and multiplies parfactors that involve ground(sprinkler(Lot)) : {Lot 6= lot1}, that is, parfactors [06] and [08]. Both parfactors represent the same number of factors, namely n−1, 50 and no correction is necessary. The product is as follows: 〈{Lot 6= lot1},{rain(),sprinkler(Lot),wet_grass(Lot)},F2F3〉 . The macro-operation applies Proposition 2.1 and sums out ground(sprinkler(Lot)): {Lot 6= lot1} from the above product. No logical variable disappears from the par- factor and C-FOVE does not need to compensate for it. C-FOVE obtains the following parfactor: 〈{Lot 6= lot1},{rain(),wet_grass(Lot)},F5〉, [09] where F5 = ∑sprinkler(Lot)F2F3. The new set of parfactors is as follows: Φ2 = {〈 /0,{rain()},F1〉, [01] 〈 /0,{wet_grass(lot1)},F4〉, [04] 〈 /0,{rain(),sprinkler(lot1),wet_grass(lot1)},F3〉, [05] 〈 /0,{sprinkler(lot1)},F2〉, [07] 〈{Lot 6= lot1},{rain(),wet_grass(Lot)},F5〉}. [09] Next, C-FOVE has choice between performing the following macro-operations: • GLOBAL-SUM-OUT(Φ2, wet_grass(lot1), /0), which during the multiplica- tion step would create a factor of size 8 and after summing out would create a factor of size 4; it would eliminate one random variable; • GLOBAL-SUM-OUT(Φ2, sprinkler(lot1), /0), which during the multiplica- tion step would create a factor of size 8 and after summing out would create a factor of size 4; it would eliminate one random variable; • PROPOSITIONALIZE(Φ2, [09], Lot), which would create n−1 identical fac- tors of size 4; it would not eliminate any random variables; • COUNTING-CONVERT(Φ2, [09], Lot), which would create a factor of size 2n; it would not eliminate any random variables. 51 The first two macro-operations have identical cost. Let us assume that C-FOVE randomly chooses the second one. GLOBAL-SUM-OUT(Φ2, wet_grass(lot1), /0) first multiplies parfactors [05] and [07] and obtains the following product: 〈 /0,{rain(),sprinkler(lot1),wet_grass(lot1)},F2F3〉 . The macro-operation sums out ground(sprinkler(lot1)) from the above product and obtains the following parfactor: 〈 /0,{rain(),sprinkler(lot1)}, ∑ sprinkler(lot1) F2F3〉 . [10] Note that = ∑sprinkler(lot1)F2F3 = F5. Factor F5 has already been computed by the previous macro-operation. This overhead is due to shattering, which takes a brute-force approach to constraint processing. We discuss this issue in Section 5.3. The new set of parfactors is as follows: Φ3 = {〈 /0,{rain()},F1〉, [01] 〈 /0,{wet_grass(lot1)},F4〉, [04] 〈{Lot 6= lot1},{rain(),wet_grass(Lot)},F5〉, [09] 〈 /0,{rain(),wet_grass(lot1)},F5〉}. [10] Next, C-FOVE has choice between performing the following macro-operations: • GLOBAL-SUM-OUT(Φ3, wet_grass(lot1), /0), which during the multiplica- tion step would create a factor of size 4 and after summing out would create a factor of size 2; it would eliminate one random variable; • PROPOSITIONALIZE(Φ3, [09], Lot), which would create n−1 identical fac- tors of size 4; it would not eliminate any random variables; • COUNTING-CONVERT(Φ3, [09], Lot), which would create a factor of size 2n; it would not eliminate any random variables. 52 C-FOVE chooses the first macro-operation. The macro-operation multiplies par- factors [04] and [10]. Their product is as follows: 〈 /0,{rain(),wet_grass(lot1)},F4F5〉 . The macro-operation sums out ground(wet_grass(lot1)) from the above product and obtains the following parfactor: 〈 /0,{rain()},F6〉, [11] where F6 = ∑wet_grass(lot1)F4F5. The new set of parfactors is as follows: Φ4 = {〈 /0,{rain()},F1〉, [01] 〈{Lot 6= lot1},{rain(),wet_grass(Lot)},F5〉, [09] 〈 /0,{rain()},F6〉}. [11] Next, C-FOVE can perform only one macro-operation: • COUNTING-CONVERT(Φ4, [09], Lot), which creates a factor of size 2n; it does not eliminate any random variables. This macro-operation applies Proposition 2.6 and performs counting on logical variable Lot. It obtains: 〈 /0,{rain(),#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F7〉, [12] where F7 is defined as in Equation 2.10. The new set of parfactors is as follows: Φ5 = {〈 /0,{rain()},F1〉, [01] 〈 /0,{rain()},F6〉, [11] 〈 /0,{rain(),#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F7〉}. [12] A call to the SHATTER(Φ5) macro-operation does not change the set Φ5. 53 Next, C-FOVE has choice between performing the following macro-operations: • GLOBAL-SUM-OUT(Φ5, rain(), /0), which during multiplication step would create a factor of size 2n and after summing out would create a factor of size n; it would eliminate one random variable; • FULL-EXPAND(Φ5, [12], #Lot:{Lot 6=lot1}[wet_grass(Lot)]), which would cre- ate a factor of size 2n; it would not eliminate any random variables. C-FOVE chooses the first macro-operation. The macro-operation multiplies par- factors [01], [11] and [12]. Their product is as follows: 〈 /0,{rain(),#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F1F6F7〉 . Next, C-FOVE sums out ground(rain()) from the above product and obtains the following parfactor: 〈 /0,{#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F8〉, [13] where F8 = ∑rain()F1F6F7. The new set of parfactors is as follows: Φ6 = {〈 /0,{#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F8〉}. [13] We have Jground(wet_grass(Lot)):{Lot 6=lot1}(Φ) = J (Φ6) . During computation, constants lot2, lot3, . . . , lotn were not explicitly enumerated, we only needed to know that D(Lot) = n. The biggest factor created during infer- ence had size 8 (factor F3) for n≤ 4 and 2n (factor F7) for n > 4. 2.6 Summary In this chapter we presented a brief overview of belief networks and the variable elimination algorithm. Belief networks and probabilistic inference in belief net- works is discussed in great detail in [Darwiche, 2009] and [Koller and Friedman, 54 2009] as well as in general AI textbooks [Poole and Mackworth, 2010; Russell and Norvig, 2009]. Next, we discussed first-order probabilistic models. As focus of this thesis is on inference, rather than modeling, we gave only one example of first-order prob- abilistic formalism: ICL. Collections by Getoor and Taskar [2007] and De Raedt et al. [2008] contain chapters devoted to many other first-order probabilistic lan- guages. Milch [2006] provides a very good summary of first-order probabilistic languages. Finally, we gave an overview of current state of the art in exact lifted proba- bilistic inference. While approximate lifted inference is not the focus of this thesis, it is worth mentioning that there is an ongoing effort in designing approximate lifted inference algorithms [de Salvo Braz et al., 2009; Kersting et al., 2009; Sen et al., 2009; Singla and Domingos, 2008]. In chapters to follow, we will present our contributions to this area. Our work aims to satisfy desiderata already mentioned in his chapter: • the length of a specification of a first-order probabilistic model must be in- dependent of the sizes of the populations in the model; • the cost of inference should be logarithmic when possible and at most at most linear in the sizes of the populations in the model. 55 Chapter 3 Aggregation in Lifted Inference Here’s something to think about: How come you never see a headline like ’Psychic Wins Lottery’? — Jay Leno 3.1 Introduction One aspect that arises in directed first-order probabilistic models is the need for aggregation that occurs when a parent parameterized random variable has logical variables that are not present in a child parameterized random variable. Previously available lifted inference algorithms do not allow a description of aggregation in first-order models that is independent of the sizes of the populations. In this thesis we introduce a new data structure, the aggregation parfactor, describe how to use it to represent aggregation in first-order models, and show how to perform efficient lifted inference in its presence. We analyze the need for aggregation (Section 3.2) and describe how to model aggregation (Section 3.3) in directed first-order probabilistic models. Next, in Sec- tion 3.4, we introduce a new data structure, aggregation parfactors, and describe how to perform lifted inference in its presence. For clarity, we start with a sim- ple form of aggregation parfactors and later present a generalized version (Sec- tion 3.4.3). In Section 3.5, through experiments, we show that aggregation parfac- tors can lead to gains in efficiency. 56 FIRST-ORDER Person jackpot won() PROPOSITIONAL jackpot won() played(Person) played(jan) played(sylwia) played(magda) Figure 3.1: A first-order model from Example 3.1 and its equivalent belief network. Aggregation is denoted by curved arcs. 3.2 Need for aggregation In a directed first-order probabilistic model, when a child parameterized random variable has a parent parameterized random variable with extra logical variables, in the grounding the child parameterized random variable has an unbounded number of parents. We need some aggregation operator to describe how the child parame- terized random variable depends on the parent parameterized random variable. We illustrate this point with the following two simple examples. Example 3.1. Consider the directed first-order probabilistic model and its ground- ing presented in Figure 3.1. The model is meant to represent that a person who fills in a single 6/49 lottery ticket has a chance of guessing correctly all six num- bers and that when it happens, the jackpot is won. A person who does not play the lottery has no chances of winning. The model has two nodes: a parameter- ized random variable played(Person) with range { f alse, true}, and a random vari- able jackpot_won() with range { f alse, true} that is true if some person guesses correctly all six numbers. We have D(Person) = { jan,sylwia, . . . ,magda} and |D(Person) |= n. A parameterized random variable played(Person) represents the n random variables in the corresponding propositional model. Therefore, in the propositional model, the number of parent nodes influencing the node jackpot_won() is n. Their common effect aggregates in the child node. 57 FIRST-ORDER Person best match() PROPOSITIONAL best match() played(Person) played(jan) played(sylwia) played(magda) Figure 3.2: A first-order model from Example 3.2 and its equivalent belief network. Aggregation is denoted by curved arcs. The next example illustrates aggregation over non-binary random variables. Example 3.2. Consider the directed first-order probabilistic model and its ground- ing presented in Figure 3.2. It is a modified model from Example 3.1. A person who plays a 6/49 lottery has a chance of matching correctly zero, one, . . . , five, or all six numbers. The model has two nodes: a parameterized random variables played(Person) with range { f alse, true}, and a random variable best_match() with range {0,1,2,3,4,5,6} that is equal to the highest number of matched lot- tery numbers among lottery participants. 3.3 Modeling aggregation In this thesis we base aggregation on causal independence. We introduce causal in- dependence in Section 3.3.1 and show how to use it to describe aggregation in Sec- tion 3.3.2. 3.3.1 Causal independence We use the definition of causal independence from Zhang and Poole [1996]. Definition 3.1. Parent random variables p1, p2, . . . , pn are said to be causally in- dependent with respect to child random variable c if there exist random variables p̃1, p̃2, . . . , p̃n such that: 58 1. ∀i∈[1,n] range of p̃i is a subset of the range of c, and 2. ∀i∈[1,n] p̃i probabilistically depends on pi and p̃i is independent of p1, . . . , pi−1, pi+1, . . . , pn, p̃1, . . . , p̃i−1, p̃i+1, . . . , p̃n given pi, and 3. there exists a commutative and associative binary operator ∗ over the range of c such that c = p̃1 ∗ p̃2 ∗ · · · ∗ p̃n. We call ∗ the base combination operator of c. The above definition covers common causal independence models such as noisy-OR [Pearl, 1986], noisy-MAX [Díez, 1993] and noisy-adders as special cases. The next example illustrates how Definition 3.1 can be used to describe a noisy-OR model. Example 3.3. The noisy-OR model consists of a Boolean child node c and a set of n Boolean parents nodes p = {p1, p2, . . . , pn}. Associated with each parent node pi is its causal strength si, which gives the probability that the c is true when pi is true independently of the values of other parents. Let true(p) be a set of parent nodes which are true, then the conditional probability distribution specified by the noisy-or is given by: P(c = true|p) = 1− ∏ i∈true(p) (1− si) (3.1) and P(c = f alse|p) = ∏ i∈true(p) (1− si). (3.2) Given Definition 3.1 the noisy-OR model can be described using n Boolean random variables p̃i, n conditional probability distributions: pi P(p̃i = f alse) P(p̃i = true) f alse 1 0 true 1− si si , i ∈ [1,n], and the logical OR operator as the base combination operator. 59 FIRST-ORDER Person jackpot won() matched 6(Person) played(Person) PROPOSITIONAL jackpot won() matched 6(jan) played(jan) matched 6(sylwia) played(sylwia) matched 6(magda) played(magda) Figure 3.3: A first-order model with OR-based aggregation from Exam- ple 3.4 and its equivalent belief network. 3.3.2 Causal independence-based aggregation In this thesis, to describe aggregation we assume that the range of the parent pa- rameterized random variable is a subset of the range of the child parameterized random variable, and use a commutative and associative deterministic binary op- erator over the range of the child parameterized random variable as an aggregation operator ⊗. Given probabilistic input to the parent parameterized random vari- able, we can construct any causal independence model covered by the definition of causal independence from Section 3.3.1. In other words, this allows any causal independence model to act as underlying mechanism for aggregation in directed first-order models. While some first-order probabilistic formalisms allow for richer forms of ag- gregation, see for example work of Jaeger [2002] on combination functions, the above mechanism allows us to satisfy desiderata stated in Section 2.6 and, as we will see in Section 3.4, integrate aggregation into calculus of parfactors. Example 3.4. Let us come back to Example 3.1. We add to the model a parame- terized random variable matched_6(Person) with range { f alse, true}. It is a noisy version of the parameterized random variable played(Person). If played(Person) has value f alse, then matched_6(Person) also has value f alse. If played(Person) 60 FIRST-ORDER Person best match() matched(Person) played(Person) PROPOSITIONAL best match() matched(jan) played(jan) matched(sylwia) played(sylwia) matched(magda) played(magda) Figure 3.4: A first-order model with MAX-based aggregation from Exam- ple 3.4 and its equivalent belief network. has value true, then matched_6(Person) has value true with probability equal to a chance of guessing correctly all six numbers. The common effect of random variables represented by matched_6(Person) aggregates in jackpot_won(). We use logical OR as an aggregation operator to describe the (deterministic) condi- tional probability distribution P( jackpot_won()|matched_6(Person)). The modi- fied model is presented in Figure 3.3. Similarly, we can adapt the model from Example 3.2 by adding a parame- terized random variable matched(Person) with range {0,1,2,3,4,5,6} and using the MAX operator as an aggregation operator to describe the probability distri- bution P(best_match()|matched(Person)). The modified model is presented in Figure 3.4. Aggregation can also be used with more abstract operators. Example 3.5. Consider the directed first-order probabilistic model and its ground- ing presented in Figure 3.5. The model has three nodes: parameterized random variables played(Person) and matched_6(Person), both with range { f alse, true}, and a random variable jackpot_winners() with range {0,1,2, many} that repre- sents the number of lottery participants that correctly matched all six numbers. 61 FIRST-ORDER Person jackpot winners() matched 6(Person) played(Person) PROPOSITIONAL jackpot winners() matched 6(jan) played(jan) matched 6(sylwia) played(sylwia) matched 6(magda) played(magda) Figure 3.5: A first-order model from Example 3.5 and its equivalent belief network. Let us define SUM|3 : {0,1,2,many}×{0,1,2,many}→ {0,1,2,many} as fol- lows: SUM|3(x,y) = x+ y, if x,y ∈ {0,1,2} and x+ y≤ 2;many, otherwise. The operator SUM|3 can be interpreted as sum capped at 3. We use SUM|3 as an aggregation operator to describe P( jackpot_winners()|matched_6(Person)). In this thesis we require that the directed first-order probabilistic models satisfy the following conditions: (1) for each parameterized random variable, its parent has at most one extra logical variable (2) if a parameterized random variable c(. . .) has a parent p(. . . ,A, . . .) with an extra logical variable A, then: (a) p(. . . ,A, . . .) is the only parent of c(. . .) (b) the range of p is a subset of the range of c (c) c(. . .) is a deterministic function of the parent: c(. . .) = p(. . . ,a1, . . .)⊗ . . .⊗ p(. . . ,an, . . .) =⊗a∈D(A) p(. . . ,a, . . .), where ⊗ is a commutative and associative deterministic binary operator over the range of c. 62 At first the above conditions seem to be very restrictive, but they in fact are not. There is no need to define the aggregation over more than one logical variable due to the associativity and commutativity of the ⊗ operator. We can obtain more complicated distributions by introducing auxiliary parameterized random variables and combining multiple aggregations. Example 3.6. Consider a parent parameterized random variable p(A,B,C) and a child parameterized random variable c(C). We can describe a ⊗-based aggre- gation over A and B, c(C) = ⊗ (a,b)∈D(A)×D(B) p(A,B,C) using an auxiliary pa- rameterized random variable c′(B,C) such that c′ has the same range as c. Let c′(B,C) = ⊗ a∈D(A) p(A,B,C), then c(C) = ⊗ b∈D(B) c′(B,C). Similarly, with the use of auxiliary nodes, we can construct a distribution that combines an aggregation with influence from other parent nodes or even combines multiple aggregations generated with different operators. In the rest of the chapter, we assume that the discussed models satisfy condi- tions (1) and (2), for ease of presentation and with no loss of generality. 3.4 Aggregation parfactors In this section we introduce a new data structure, aggregation parfactors, describe how to use it to represent aggregation in first-order models, and show how to per- form efficient lifted inference in its presence. We need to introduce a new data structure, because parfactors, including parfactors on counting formulas, are not adequate representations, as their size would depend on the population size of the extra logical variable. Example 3.7. Consider the first-order model presented in Figure 3.3, which is also discussed in Examples 3.1 and 3.4. We cannot represent the conditional probability distribution P( jackpot_won()|matched_6(Person)) with a parfactor 〈 /0, {matched_6(Person), jackpot_won()}, F〉 as even simple noisy-OR cannot be represented as a product of factors represented by this parfactor. A parfactor 〈 /0,{matched_6( jan), . . . ,matched_6(magda), jackpot_won()},F〉 is not an adequate input representation of this distribution because its size would depend on |D(Person) |. The same applies to 〈 /0,{#Person: /0[matched_6(Person)], 63 jackpot_won()}, F〉 as the size of the range of #Person: /0[matched_6(Person)] de- pends on |D(Person) |. An analogous problem arises for the first-order models presented in Figures 3.4 and 3.5. Definition 3.2. An aggregation parfactor is a hextuple 〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉, where • p(. . . ,A, . . .) and c(. . .) are parameterized random variables • the range of p is a subset of the range of c • A is the only logical variable in p(. . . ,A, . . .) that is not in c(. . .) • C is a set of inequality constraints not involving A • Fp is a factor from the range of p to real numbers • ⊗ is a commutative and associative deterministic binary operator over the range of c • CA is a set of inequality constraints involving A, such that (D(A) : CA) 6= /0. An aggregation parfactor 〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉 represents a set of factors, one factor Fpc for each ground substitution G to all logical variables in param(c(. . .)) that satisfies the constraints in C. Each factor Fpc is a mapping from the Cartesian product ×a∈D(A):CA range(p)×range(c) to the reals, which, given an assignment of values to random variables v, is defined as follows: Fpc(v(p(. . . ,a1, . . .)), . . . ,v(p(. . . ,an, . . .)),v(c(. . .))) = ∏ a∈{a1,...,an} Fp rp rc (v(p(. . . ,a, . . .))), if ⊗ a∈{a1,...,an} v(p(. . . ,a, . . .)) = v(c(. . .)); 0, otherwise, whereD(A) : CA = {a1, . . . ,an}, rp = |ground(p(. . . ,a, . . .)) :C |, a ∈D(A) :CA and rc = |ground(c(. . .)) :C |. The space required to represent an aggregation parfactor does not depend on the size of the set D(A) :CA. It is O(n2 logn) where n is the size of range(c), as the operator ⊗ can be represented as a factor from range(c)×range(c) to range(c). Exponent rprc compensates for the possibility that parameterized random vari- able c(. . .) might be parameterized by logical variables not present in p(. . . ,A, . . .). 64 It is also important to notice that D(A) :CA might vary for different ground substi- tutions G if the set C∪CA is not in normal form (see Section 2.5.1.1). We comment on this issue in Section 5.2.3. When an aggregation parfactor 〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉 is used to describe aggregation in a first-order model, the factorFp will be a constant function with the value 1. We use 1 to denote such factors. An aggregation parfactor created during inference may have a non-trivial Fp component (see Section 3.4.2). Example 3.8. Consider the first-order model from Figure 3.3. The conditional probability distributionP( jackpot_won()|matched_6(Person)) can be represented with an aggregation parfactor 〈 /0,matched_6(Person), jackpot_won(),1,OR, /0〉. The size of the representation does not depend on the population size of the logi- cal variable Person. Parameterized random variable jackpot_won() represents one random variable therefore the aggregation parfactor represents one factor: matched_6( jan) . . . matched_6(magda) jackpot_won() value f alse . . . f alse f alse 1 f alse . . . f alse true 0 f alse . . . true f alse 0 f alse . . . true true 1 ... ... ... ... ... ... ... true . . . true f alse 0 true . . . true true 1 . Similarly, for the model from Figure 3.4, P(best_match()|matched(Person)) can be represented with 〈 /0,matched(Person),best_match(),1,MAX, /0〉, for the model from from Figure 3.5, P( jackpot_winners()|matched_6(Person)) can be represented with 〈 /0,matched_6(Person), jackpot_winners(),1,SUM|3, /0 〉 . In the rest of this thesis, Φ denotes a set of parfactors and aggregation par- factors. The notation introduced in Section 2.5 remains valid under the extended meaning of the symbol Φ. 3.4.1 Conversion to parfactors In this section we show how aggregation parfactors can be converted to parfactors that in turn can be used during inference with C-FOVE. 65 3.4.1.1 Conversion using counting formulas Consider an aggregation parfactor 〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉. Since ⊗ is an associative and commutative operator, given an assignment of values to ran- dom variables v, it does not matter which of the parameterized random variables p(. . . ,a, . . .), a ∈ D(A) :CA are assigned each value from range(p), but only how many of them are assigned each value. This property was a motivation for the counting elimination algorithm [de Salvo Braz et al., 2007] (see Section 2.5.2.4) and counting formulas [Milch et al., 2008] (see Section 2.4.1.1), and allows us to convert aggregation parfactors to a product of two parfactors, where one of the parfactors is a parfactor on a counting formula: Proposition 3.1. Let gA = 〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉 be an aggregation parfactor from Φ such that set C∪CA is in normal form. Let F# be a factor from the Cartesian product range(#A:CA [p(. . . ,A, . . .)])×range(c) to {0,1}. Given an assignment of values v to all random variables but ground(p(. . . ,A, . . .)) : C∪CA, the function is defined as follows: F#(h(),v(c(. . .))) = 1, if ⊗ x∈range(p) h(x)⊗ i=1 x = v(c(. . .)); 0, otherwise, where h() is a histogram from range(#A:CA [p(. . . ,A, . . .)]). Then J (Φ) = J (Φ\{gA}∪{〈C∪CA,{p(. . . ,A, . . .)},Fp〉, 〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#〉}). Proof. It suffices to show that J ({gA}) = J ({〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉}) (3.3) equals J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉,〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#〉}) . (3.4) 66 We are going to transform expression (3.4) into expression (3.3) by proposi- tionalizing logical variable A. Let D(A) : CA = {a1,a2, . . . ,an}. J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉,〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#〉}) = (by n applications of Proposition 2.4) = J ({〈C,{p(. . . ,a1, . . .)},Fp〉,〈C,{p(. . . ,a2, . . .)},Fp〉, . . . , 〈C,{p(. . . ,an, . . .)},Fp〉,〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#〉}}) = (by n−1 applications of Proposition 2.3) = J ({〈C,{p(. . . ,a1, . . .), p(. . . ,a2, . . .), . . . , p(. . . ,an, . . .)},F1〉, 〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#〉}}), (3.5) where factor F1 is a mapping from the Cartesian product ×a∈D(A):CA range(p) to the reals, which, given an assignment of values to random variables v, is defined as follows: v(F1) = ∏ a∈D(A):CA Fp(v(p(. . . ,a, . . .))). Next, we apply n times Proposition 2.5 to expression (3.5) and obtain: J ({〈C,{p(. . . ,a1, . . .), p(. . . ,a2, . . .), . . . , p(. . . ,an, . . .)},F1〉, 〈C,{p(. . . ,a1, . . .), p(. . . ,a2, . . .), . . . , p(. . . ,an, . . .),c(. . .)},F2〉}). (3.6) FactorF2 is a mapping from the Cartesian product×a∈D(A):CA range(p)×range(c) to the reals, which, given an assignment of values to random variables v, is defined as follows: v(F2) = 1, if ⊗ a∈D(A):CA v(p(. . . ,a, . . .)) = v(c(. . .)); 0, otherwise. Finally, we apply Proposition 2.3 to parfactors from expression (3.6) and obtain: J ({〈C,{p(. . . ,a1, . . .), p(. . . ,a2, . . .), . . . , p(. . . ,an, . . .),c(. . .)},F1 rp rc F2〉}), 67 where rp= |ground(p(. . . ,a, . . .)) :C |, a ∈D(A) :CA, and rc= |ground(c(. . .)) :C |. Parfactor 〈C, {p(. . . ,a1, . . .), p(. . . ,a2, . . .), . . . , p(. . . ,an, . . .),c(. . .)}, F1 rp rc F2〉 represents a set of factors, one for each ground substitution G to all logical vari- ables in param(p(. . . ,A, . . .))∪ param(c(. . .))\{A}= param(c(. . .)) that satisfies the constraints in C. Each factor FG is a mapping from the Cartesian product ×a∈D(A):CA range(p)×range(c) to the reals, which, given an assignment of values to random variables v, is defined as follows: v(FG)= ∏ a∈D(A):CA Fp rp rc (v(p(. . . ,a, . . .))), if ⊗ a∈D(A):CA v(p(. . . ,a, . . .))=v(c(. . .)); 0, otherwise. From Definition 3.2 such set of factors can be represented as an aggregation par- factor 〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉. Therefore J ({〈C,{p(. . . ,a1, . . .), p(. . . ,a2, . . .), . . . , p(. . . ,an, . . .),c(. . .)},F3〉}) = J ({〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉}), which completes the proof. If the set C∪CA is not in normal form (Section 2.5.1.1) we will need to use the splitting operation described in Section 3.4.2.1 to convert the aggregation parfactor to a set of aggregation parfactors with constraint sets in normal form (see algorithm presented in Figure 5.4 on page 162). The Proposition 3.1 shows how an aggregation parfactor can be replaced by a parfactors involving a counting formula. The following example illustrates how it is done in practice. Example 3.9. Consider the aggregation parfactor introduced in Example 3.8: 〈 /0,matched_6(Person), jackpot_won(),1,OR, /0,〉. 68 Let n = |D(Person) |. The conversion described in Proposition 3.1 creates two parfactors: 〈 /0,{matched_6(Person)},1〉 and 〈 /0,{#Person: /0[matched_6(Person)], jackpot_won()},F#〉, F# is a factor from the Cartesian product range(#Person: /0[matched_6(Person)])× range( jackpot_won) to {0,1}. The range of #Person: /0[matched_6(Person)] is a set of histograms h() with a bucket for value f alse, a bucket for value true and entries adding up to n: {(# f alse = n,#true = 0),(# f alse = n−1,#true = 1), . . . ,(# f alse = 0,#true = n)}. The range of jackpot_won is { f alse, true}. The factor F# is defined as follows: F#(h(),v( jackpot_won())) = 1, if ORx∈{ f alse,true} h(x) OR i=1 x = v( jackpot_won()); 0, otherwise. Note that the expression OR x∈{ f alse,true} h(x) OR i=1 x evaluates to f alse if h( f alse) = n and to true if h( f alse)< n. Below we show a tabular representation of factor F#: #Person: /0[matched_6(Person)] jackpot_won() value (# f alse = n ,#true = 0) f alse 1 (# f alse = n ,#true = 0) true 0 (# f alse = n−1,#true = 1) f alse 0 (# f alse = n−1,#true = 1) true 1 ... ... ... (# f alse = 0 ,#true = n) f alse 0 (# f alse = 0 ,#true = n) true 1 . The size of the factor F# is n+1. 3.4.1.2 Conversion for MAX and MIN operators If in an aggregation parfactor ⊗ is the MAX operator (which includes the OR op- erator as a special case), we can use a factorization presented by Díez and Galán 69 [2003] to convert the aggregation parfactor to parfactors without counting formu- las. The factorization is an example of the tensor rank-one decomposition of a conditional probability distribution [Savicky and Vomlel, 2007]. The factorization of Díez and Galán can be used to convert an aggregation parfactor to a pair of standard parfactors as follows: Proposition 3.2. Let gA = 〈C, p(. . . ,A, . . .),c(. . .),Fp,MAX,CA〉 be an aggrega- tion parfactor from Φ, where MAX operator is induced by a total ordering ≺ of range(c) and set C∪CA is in normal form. Let s() be a successor function induced by ≺. Let c′(. . .) be an auxiliary parameterized random variable with the same parameterization and the same range as c. Let Fc be a factor from the Cartesian product range(p)×range(c) to real numbers that, given an assignment of values to random variables v, is defined as follows: Fc(v(p(. . . ,A, . . .)),v(c′(. . .))) = Fp rc rp (v(p(. . . ,A, . . .))), if v(p(. . . ,A, . . .))4 v(c′(. . .)); 0, otherwise, (3.7) where rp= |ground(p(. . . ,a, . . .)) :C |, a ∈D(A) :CA, and rc= |ground(c(. . .)) :C |. Let F∆ be a factor from the Cartesian product range(p)×range(c) to {−1,0,1} that, given v, is defined as follows: F∆(v(c(. . .)),v(c′(. . .))) = 1, if v(c(. . .)) = v(c′(. . .)); −1, if v(c(. . .)) = s(v(c′(. . .))); 0, otherwise. Then J (Φ) = ∑ ground(c′(...)) J (Φ\{gA}∪{〈C∪CA,{p(. . . ,A, . . .),c′(. . .)},Fc〉, 〈C,{c(. . .),c′(. . .)},F∆〉}). 70 Proof. It is sufficient to prove that J ({gA}) = J ({〈C, p(. . . ,A, . . .),c(. . .),Fp,MAX,CA〉}) (3.8) is equal to ∑ ground(c′(...)) J ({〈C∪CA,{p(. . . ,A, . . .),c′(. . .)},Fc〉,〈C,{c(. . .),c′(. . .)},F∆〉}). (3.9) We start with expression (3.8) and convert the aggregation parfactor to parfac- tors. By Proposition 3.1 J ({〈C, p(. . . ,A, . . .),c(. . .),Fp,MAX,CA〉}) = J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉,〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#〉}) . F# is a factor from the Cartesian product range(#A:CA [p(. . . ,A, . . .)])×range(c) to a set {0,1} that, given an assignment of values v to all random variables but ground(p(. . . ,A, . . .)) : C∪CA, is defined as follows: F#(h(),v(c(. . .))) = 1, if max x∈range(p),h(x)>0 x = v(c(. . .)); 0, otherwise, where h() is a histogram from range(#A:CA [p(. . . ,A, . . .)]). Next, we transform expression (3.9) and represent the first parfactor as a prod- uct of two parfactors. From (3.7) and Proposition 2.3 J ({〈C∪CA,{p(. . . ,A, . . .),c′(. . .)},Fc〉) = J ({〈C∪CA,{p(. . . ,A, . . .)},Fp rc rp rp rc 〉,〈C ∪CA,{p(. . . ,A, . . .),c′(. . .)},F1〉) = J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉,〈C ∪CA,{p(. . . ,A, . . .),c′(. . .)},F1〉), where F1 is a factor from the Cartesian product range(p)×range(c) to real num- bers that, given an assignment of values to random variables v, is defined as fol- 71 lows: F1(v(p(. . . ,A, . . .)),v(c′(. . .))) = 1, if v(p(. . . ,A, . . .))4 v(c′(. . .));0, otherwise. After applying the above transformations to expressions (3.8) and (3.9) we are reduced to proving that J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉,〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#〉}) = ∑ ground(c′(...)) J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉,〈C ∪CA,{p(. . . ,A, . . .),c′(. . .)},F1〉, 〈C,{c(. . .),c′(. . .)},F∆〉}). The above is equivalent to proving that J ({〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#〉}) = (3.10) ∑ ground(c′(...)) J ({〈C∪CA,{p(. . . ,A, . . .),c′(. . .)},F1〉,〈C,{c(. . .),c′(. . .)},F∆〉}) . We are going to transform the right hand side of the Equation 3.10 into the left hand side. We start with counting over logical variable A. By Proposition 2.6 ∑ ground(c′(...)) J ({〈C∪CA,{p(. . . ,A, . . .),c′(. . .)},F1〉,〈C,{c(. . .),c′(. . .)},F∆〉}) = ∑ ground(c′(...)) J ({〈C,{#A:CA [p(. . . ,A, . . .)],c′(. . .)},F2〉,〈C,{c(. . .),c′(. . .)},F∆〉}) . F2 is a factor from the Cartesian product range(#A:CA [p(. . . ,A, . . .)])×range(c′) to a set {0,1} that, given an assignment of values v to all random variables but ground(p(. . . ,A, . . .)) : C∪CA, is defined as follows: F2(h(),v(c′(. . .))) = 1, if max x∈range(p),h(x)>0 x4 v(c′(. . .)); 0, otherwise. 72 Next, we perform multiplication. By Proposition 2.3 ∑ ground(c′(...)) J ({〈C,{#A:CA [p(. . . ,A, . . .)],c′(. . .)},F2〉,〈C,{c(. . .),c′(. . .)},F∆〉}) = ∑ ground(c′(...)) J ({〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .),c′(. . .)},F3〉}), F3 = F2F∆ is a factor from the Cartesian product range(#A:CA [p(. . . ,A, . . .)])× range(c)× range(c′) to {−1,0,1} that, given an assignment of values v to all random variables but ground(p(. . . ,A, . . .)) : C∪CA, is defined as follows: F3(h(),v(c(. . .)),v(c′(. . .))) = = 1, if max x∈range(p),h(x)>0 x4 v(c′(. . .)) ∧ v(c(. . .)) = v(c′(. . .)); −1, if max x∈range(p),h(x)>0 x4 v(c′(. . .)) ∧ v(c(. . .)) = s(v(c′(. . .))); 0, otherwise; = (in the first case v(c(. . .)) = v(c′(. . .)) and we replace v(c′(. . .)) by v(c(. . .)) in the inequality) = 1, if max x∈range(p),h(x)>0 x4 v(c(. . .)) ∧ v(c(. . .)) = v(c′(. . .)); −1, if max x∈range(p),h(x)>0 x4 v(c′(. . .)) ∧ v(c(. . .)) = s(v(c′(. . .))); 0, otherwise; = (in the second case v(c(. . .)) = s(v(c′(. . .))) and we replace v(c′(. . .)) by v(c(. . .)) and 4 by ≺ in the inequality) = 1, if max x∈range(p),h(x)>0 x4 v(c(. . .)) ∧ v(c(. . .)) = v(c′(. . .)); −1, if max x∈range(p),h(x)>0 x≺ v(c(. . .)) ∧ v(c(. . .)) = s(v(c′(. . .))); 0, otherwise; = 73 (we split the first case into two cases) = 1, if max x∈range(p),h(x)>0 x = v(c(. . .)) ∧ v(c(. . .)) = v(c′(. . .)); 1, if max x∈range(p),h(x)>0 x≺ v(c(. . .)) ∧ v(c(. . .)) = v(c′(. . .)); −1, if max x∈range(p),h(x)>0 x≺ v(c(. . .)) ∧ v(c(. . .)) = s(v(c′(. . .))); 0, otherwise, (3.11) where h() is a histogram from range(#A:CA [p(. . . ,A, . . .)]). Finally, we perform summation. By Proposition 2.1 ∑ ground(c′(...)) J ({〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .),c′(. . .)},F3〉}) = J ({ ∑ ground(c′(...)) 〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .),c′(. . .)},F3〉}) = J ({ 〈 C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},∑c′(...)F3 〉 }) . Factor∑c′(...)F3 is a factor from the Cartesian product range(#A:CA [p(. . . ,A, . . .)])× range(c) to the reals. Let us analyze factor F3 as it is defined via four cases in ex- pression (3.11). We fix value of #A:CA [p(. . . ,A, . . .)] to h() and value of c(. . .) to y. Assume that h() and y satisfy equality in the first case from (3.11). There is only one value in range(c′) equal to y and F3 has value 1, for all other values of range(c′), F3 has value 0. Next, assume that h() and y satisfy inequality in the second and third case from (3.11). Note that, since there exists value x∈ range(p)⊂ range(c′) such that x≺ y, then y is a successor of exactly one element from range(c′). When c′(. . .) is equal to this element, F3 has value −1. When c′(. . .) is equal to y, F3 has value 1. For all other values from range(c′), F3 has value 0. Finally, for all other h() and y, regardless of the value of c′(. . .), F3 returns value 0. 74 Based on the above analysis, given an assignment of values v to all random variables but ground(p(. . . ,A, . . .)) : C∪CA, we have ( ∑c′(...)F3 ) (h(),v(c(. . .))) = 1, if max x∈range(p),h(x)>0 x = v(c(. . .)); 0, otherwise, = F#(h(),v(c(. . .))), where h() is a histogram from range(#A:CA [p(. . . ,A, . . .)]). The above gives us J ({ 〈 C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},∑c′(...)F3 〉 }) = J ({〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#〉}) and finishes a proof of Equation 3.10 and a proof of the proposition. Example 3.10 illustrates the decomposition introduced in the Proposition 3.2. Example 3.10. Let us consider the aggregation parfactor introduced in Exam- ple 3.8: 〈 /0,matched_6(Person), jackpot_won(),1,OR, /0〉. The conversion described in Proposition 3.2 introduces an auxiliary parameterized random variable jackpot_won′(), where jackpot_won′ has range { f alse, true}. The aggregation parfactor is replaced with two parfactors: 〈 /0,{matched_6(Person), jackpot_won′()},F jackpot_won〉 and 〈 /0,{ jackpot_won(), jackpot_won′()},F∆〉 . F jackpot_won is a factor from the Cartesian product { f alse, true}×{ f alse, true} to real numbers: matched_6(Person) jackpot_won′() value f alse f alse 1( f alse) f alse true 1( f alse) true f alse 0 true true 1(true) . 75 F∆ is a factor from the Cartesian product { f alse, true}× { f alse, true} to a set {−1,0,1}: jackpot_won() jackpot_won′() value f alse f alse 1 f alse true 0 true f alse −1 true true 1 . Note that the size of factors F jackpot_won and F∆ is independent of |D(Person) |. An analogous proposition holds for the MIN operator. In both cases, as illus- trated by Examples 3.9 and 3.10 and experiments in Section 3.5, the above con- version is advantageous to the conversion described in Section 3.4.1.1, which uses counting formulas. 3.4.2 Operations on aggregation parfactors In the previous section we showed how aggregation parfactors can be used dur- ing a modeling phase and then, during inference with the C-FOVE algorithm, once populations are known, aggregation parfactors can be converted to parfactors. Such a solution allows us to take advantage of the modeling properties of aggre- gation parfactors and C-FOVE inference capabilities. It is also possible to exploit aggregation parfactors during inference. In this section we describe operations on aggregation parfactors that can be added to the C-FOVE algorithm. These oper- ations can delay or even avoid conversion of aggregation parfactors to parfactors involving counting formulas. This in turn, as we will see in Section 3.5, can result in more efficient inference. 3.4.2.1 Splitting The C-FOVE algorithm applies substitutions to parfactors to handle observations and queries and to enable the multiplication of parfactors. As this operation results in the creation of a residual parfactor, it is called splitting. Below we present how aggregation parfactors can be split on substitutions. We start with splitting on a substitution that does not involve the aggregation logical variable: Proposition 3.3. Let gA = 〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉 be an aggregation parfactor from Φ. Let {X/t} be a substitution such that (X 6= t) /∈ C and X ∈ 76 param(c(. . .)). Let term t be a constant from D(X), or a logical variable such that t ∈ param(c(. . .)). Let gA[X/t] be a parfactor gA with all occurrences of X replaced by term t. Then J (Φ) = J (Φ\{gA}∪{gA[X/t],〈C ∪{X 6= t}, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉}) . Proof. It suffices to show that a set of factors represented by the aggregation par- factor gA is equal to the union of sets of factors represented by the aggregation parfactors gA[X/t] and 〈C ∪{X 6= t}, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉. From Definition 3.2 we know that gA represents a set of factors, one for each ground substitution G to all logical variables in param(c(. . .)) that satisfies the constraints in C. Assume that the term t is a constant. Each ground substitution G either substi- tutes X with t or substitutes X with some other constant from D(X). The former substitutions result in a set of factors equal to the set of factors represented by gA[X/t] while the latter substitutions result in a set of factors equal to the set of factors represented by 〈C ∪{X 6= t}, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉. Assume that the term t is a logical variable. Each ground substitution G either substitutes X and t with the same constant or substitutes X and t with different con- stants. The former substitutions result in a set of factors equal to the set of factors represented by gA[X/t] while the latter substitutions result in a set of factors equal to the set of factors represented by 〈C ∪{X 6= t}, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉. Proposition 3.3 allows us to split an aggregation parfactor on a substitution that does not involve the aggregation logical variable. Below we show how to split on a substitution that involves the aggregation logical variable A and a constant. After such operation the individuals fromD(A) : C are represented in two data structures: an aggregation parfactor and a standard parfactor. We have to make sure that after splitting c(. . .) is still equal to a⊗-based aggregation over the wholeD(A) : C. The following proposition describes how it can be done using an auxiliary parameter- ized random variable: 77 Proposition 3.4. Let gA = 〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉 be an aggregation parfactor from Φ. Let {A/t} be a substitution such that (A 6= t) /∈ CA and term t is a constant from D(A), or a logical variable from param(p(. . . ,A, . . .))\{A}. Let c′(. . .) be an auxiliary parameterized random variable with the same param- eterization and range as c(. . .). Let CA[A/t] be a set of constraints CA with all occurrences of A replaced by term t. Let Fc be a factor from the Cartesian product range(p)×range(c′)×range(c) to real numbers. Given an assignment of values to random variables v, Fc is defined as follows: Fc(v(p(. . . ,A, . . .)),v(c′(. . .)),v(c(. . .)))= Fp rc rp (p(. . . , t, . . .)), if v(c(. . .)) = v(p(. . . , t, . . .))⊗v(c′(. . .)); 0, otherwise, where rp = |ground(p(. . . ,a, . . .)) :C |, a ∈ D(A) : CA, and rc = |ground(c(. . .)) : C |. Then J (Φ) = ∑ ground(c′(...)) J (Φ\{gA}∪{〈C, p(. . . ,A, . . .),c′(. . .),Fp,⊗,CA∪{A 6= t}〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc〉}). Proof. It suffices to show that J ({gA}) = J (〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉) (3.12) is equal to ∑ ground(c′(...)) J ({〈C, p(. . . ,A, . . .),c′(. . .),Fp,⊗,CA∪{A 6= t}〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc〉}). (3.13) 78 We start with expression (3.12) and convert the aggregation parfactor to par- factors. By Proposition 3.1 J ({〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉}) = J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉,〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#1〉}) . (3.14) F#1 is a factor from the Cartesian product range(#A:CA [p(. . . ,A, . . .)])×range(c) to a set {0,1} that, given an assignment of values v to all random variables but ground(p(. . . ,A, . . .)) : C∪CA, is defined as follows: F#1(h(),v(c(. . .))) = 1, if ⊗ x∈range(p) h(x)⊗ i=1 x = v(c(. . .)); 0, otherwise, (3.15) where h() is a histogram from range(#A:CA [p(. . . ,A, . . .)]). Next, we transform expression (3.13). We convert the aggregation parfactor to parfactors. By Proposition 3.1 ∑ ground(c′(...)) J ({〈C, p(. . . ,A, . . .),c′(. . .),Fp,⊗,CA∪{A 6= t}〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc〉}) = ∑ ground(c′(...)) J ({〈C∪CA∪{A 6= t},{p(. . . ,A, . . .)},Fp〉, 〈C,{#A:CA∪{A 6=t}[p(. . . ,A, . . .)],c′(. . .)},F#2〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc〉}), (3.16) whereF#2 is a factor from the Cartesian product range(#A:CA∪{A 6=t}[p(. . . ,A, . . .)])× range(c′) to a set {0,1} that, given an assignment of values v to all random vari- ables but ground(p(. . . ,A, . . .)) : C∪CA∪{A 6= t}, is defined as follows: F#2(h(),v(c′(. . .))) = 1, if ⊗ x∈range(p) h(x)⊗ i=1 x = v(c′(. . .)); 0, otherwise, 79 where h() is a histogram from range(#A:CA∪{A 6=t}[p(. . . ,A, . . .)]). Further, the third parfactor from (3.16) can be represented as a product of two parfactors. By Proposition 2.3 ∑ ground(c′(...)) J ({〈C∪CA∪{A 6= t},{p(. . . ,A, . . .)},Fp〉, 〈C,{#A:CA∪{A 6=t}[p(. . . ,A, . . .)],c′(. . .)},F#2〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc〉}) = ∑ ground(c′(...)) J ({〈C∪CA∪{A 6= t},{p(. . . ,A, . . .)},Fp〉, 〈C,{#A:CA∪{A 6=t}[p(. . . ,A, . . .)],c′(. . .)},F#2〉, 〈C ∪CA[A/t],{p(. . . , t, . . .)},Fp rc rp rp rc 〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc2〉}) = ∑ ground(c′(...)) J ({〈C∪CA∪{A 6= t},{p(. . . ,A, . . .)},Fp〉, 〈C,{#A:CA∪{A 6=t}[p(. . . ,A, . . .)],c′(. . .)},F#2〉, 〈C ∪CA[A/t],{p(. . . , t, . . .)},Fp〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc2〉}), (3.17) Fc2 is a factor from the Cartesian product range(p)×range(c′)×range(c) to real numbers that, given an assignment of values to random variables v, is defined as follows: Fc2(v(p(. . . ,A, . . .)),v(c′(. . .)),v(c(. . .)))= 1, if v(c(. . .)) = v(p(. . . , t, . . .))⊗v(c′(. . .)); 0, otherwise. 80 The first and the third parfactor from (3.17) can be combined into one parfactor (as if we were reversing a splitting operation). By Proposition 2.4 ∑ ground(c′(...)) J ({〈C∪CA∪{A 6= t},{p(. . . ,A, . . .)},Fp〉, 〈C,{#A:CA∪{A 6=t}[p(. . . ,A, . . .)],c′(. . .)},F#2〉, 〈C ∪CA[A/t],{p(. . . , t, . . .)},Fp〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc2〉}) = ∑ ground(c′(...)) J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉, 〈C,{#A:CA∪{A 6=t}[p(. . . ,A, . . .)],c′(. . .)},F#2〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc2〉}). (3.18) After replacing expression (3.12) with (3.14) and expression (3.13) with (3.18) we are reduced to proving that J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉,〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#1〉}) = ∑ ground(c′(...)) J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉, 〈C,{#A:CA∪{A 6=t}[p(. . . ,A, . . .)],c′(. . .)},F#2〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc2〉}). The above is equivalent to proving that J ({〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#1〉}) = ∑ ground(c′(...)) J ({〈C,{#A:CA∪{A 6=t}[p(. . . ,A, . . .)],c′(. . .)},F#2〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc2〉}). (3.19) 81 We are going to transform the right hand side of the Equation 3.19 into the left hand side. We start with multiplying the two parfactors. By Proposition 2.3 ∑ ground(c′(...)) J ({〈C,{#A:CA∪{A 6=t}[p(. . . ,A, . . .)],c′(. . .)},F#2〉, 〈C ∪CA[A/t],{p(. . . , t, . . .),c′(. . .),c(. . .)},Fc2〉}) = ∑ ground(c′(...)) J ({〈C∪CA[A/t],{#A:CA∪{A6=t}[p(. . . ,A, . . .)], p(. . . , t, . . .), c′(. . .),c(. . .)},F#3〉}), (3.20) whereF#3 is a factor from the Cartesian product range(#A:CA∪{A 6=t}[p(. . . ,A, . . .)])× range(p)×range(c′)×range(c) to a set {0,1} that, given an assignment of values v to all random variables but ground(p(. . . ,A, . . .)) : C∪CA∪{A 6= t}, is defined as follows: F#3(h(),v(p(. . . , t, . . .)),v(c′(. . .)),v(c(. . .))) = 1, if ⊗ x∈range(p) h(x)⊗ i=1 x = v(c′(. . .)) ∧ v(c(. . .)) = v(p(. . . , t, . . .))⊗v(c′(. . .)); 0, otherwise; = 1, if ⊗ x∈range(p) h(x)⊗ i=1 x = v(c′(. . .)) ∧ ⊗ x∈range(p) h(x)⊗ i=1 x⊗v(p(. . . , t, . . .)) = v(c(. . .)), 0, otherwise, (3.21) where h() is a histogram from range(#A:CA∪{A 6=t}[p(. . . ,A, . . .)]). We continue transformation by performing summation in (3.20). By Proposi- tion 2.1 ∑ ground(c′(...)) J ({〈C∪CA[A/t],{#A:CA∪{A 6=t}[p(. . . ,A, . . .)], p(. . . , t, . . .), c′(. . .),c(. . .)},F#3〉}) = J ({〈C∪CA[A/t],{#A:CA∪{A 6=t}[p(. . . ,A, . . .)], p(. . . , t, . . .),c(. . .)},∑c′(...)F#3〉}). (3.22) 82 ∑c′(...)F#3 is a factor from the Cartesian product range(#A:CA∪{A 6=t}[p(. . . ,A, . . .)])× range(p)×range(c) to a set {0,1}. Let us consider factor F#3 as it is defined in (3.21). If we fix value of #A:CA [p(. . . ,A, . . .)] to h(), there is only one value y in range(c′) such that h(x)⊗ i=1 x= y. Therefore, given an assignment of values v to all ran- dom variables but ground(p(. . . ,A, . . .)) : C∪CA∪{A 6= t}, ∑c′(...)F#3 is defined as follows: ∑c′(...)F#3(h(),v(p(. . . , t, . . .)),v(c(. . .))) = 1, if ⊗ x∈range(p) h(x)⊗ i=1 x⊗v(p(. . . , t, . . .)) = v(c(. . .)), 0, otherwise, (3.23) where h() is a histogram from range(#A:CA∪{A 6=t}[p(. . . ,A, . . .)]). We will denote ∑c′(...)F#3 by F#4. Let us define factorF#5 from the Cartesian product range(#A:CA [p(. . . ,A, . . .)])× range(c) to a set {0,1} as follows: F#5(h′(),y) = F#4(h(),x,y), (3.24) where x∈range(p), y∈range(c), histogram h()∈range(#A:CA∪{A 6=t}[p(. . . ,A, . . .)]), histogram h′() ∈ range(#A:CA [p(. . . ,A, . . .)]), and h′() is obtained by taking h() and adding 1 to the count for the value x. From (3.15), (3.23) and (3.24) we have F#5 = F#1. Note that Equation 3.24 reassembles Equation 2.8 from Proposi- tion 2.5. Indeed, we can further transform (3.22) by applying Proposition 2.5 as if we were reversing an expansion of a counting formula: J ({〈C∪CA[A/t],{#A:CA∪{A 6=t}[p(. . . ,A, . . .)], p(. . . , t, . . .),c(. . .)},F#4〉}) = J ({〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#5〉}) = J ({〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#1〉}) . The above and finishes a proof of Equation 3.19 and a proof of the proposition. Example 3.11 illustrates Proposition 3.4. 83 Example 3.11. Consider Example 3.2. As discussed in Example 3.8 the con- ditional probability distribution P(best_match()|matched(Person)) can be repre- sented with 〈 /0,matched(Person),best_match(),1,MAX, /0〉. Assume that we have observed that sylwia matched 5 numbers. Before we can project this observation onto our model, we need to split, among others, the above aggregation parfactor on substitution {Person/sylwia}. We follow the procedure described in Theorem 3.4 and introduce an auxiliary parameterized random vari- able best_match′(). It is equal to the maximum number of matched lottery num- bers among all individuals from the population of the logical variable Person except for sylwia. An aggregation parfactor 〈 /0,matched(Person),best_match′(),1,MAX, {Person 6= sylwia}〉 captures this dependency. Recall that parameterized random variable best_match() is equal to the maximum number of matched lottery num- bers among all individuals from the population of the logical variable Person, in- cluding sylwia. Hence, it is a maximum of matched(sylwia) and best_match′(). This relation is represented by a parfactor 〈 /0,{matched(sylwia),best_match′(), best_match()},Fbest_match〉, where Fbest_match() is a factor from the Cartesian prod- uct {0,1, . . . ,6}×{0,1, . . . ,6}×{0,1, . . . ,6} to real numbers: matched(sylwia) best_match′() best_match() value 0 0 0 1 0 0 1 0 ... ... ... ... 0 0 6 0 0 1 0 0 0 1 1 1 ... ... ... ... 0 1 6 0 ... ... ... ... ... ... ... ... 6 6 0 0 6 6 1 0 ... ... ... ... 6 6 6 1 . Splitting presented in Proposition 3.4 corresponds to the expansion of a count- ing formula in C-FOVE. The case where a substitution is of the form {X/A} can be handled in a similar fashion as described in Proposition 3.4. 84 3.4.2.2 Multiplication The C-FOVE algorithm multiplies parfactors to enable elimination of parameter- ized random variables. An aggregation parfactor can be multiplied by a parfactor on p(. . . ,A, . . .): Proposition 3.5. Let gA = 〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉 be an aggregation parfactor from Φ and g1 = 〈C ∪CA,{p(. . . ,A, . . .)},F1〉 be a parfactor from Φ. Let g2 = 〈C, p(. . . ,A, . . .),c(. . .),FpF1,⊗,CA〉. Then J (Φ) = J (Φ\{gA,g1}∪{g2}) . We call g2 the product of gA and g1. Proof. It suffices to show that J ({gA,g1}) = J ({〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉, 〈C ∪CA,{p(. . . ,A, . . .)},F1〉}) (3.25) is equal to J ({〈C, p(. . . ,A, . . .),c(. . .),FpF1,⊗,CA〉}) . (3.26) We start with expression (3.25). First we convert the aggregation parfactor gA to parfactors and then multiply one of the resulting parfactors by g1. J ({〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉,〈C1,{p(. . . ,A, . . .)},F1〉}) = (by Proposition 3.1) J ({〈C∪CA,{p(. . . ,A, . . .)},Fp〉,〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#1〉, 〈C ∪CA,{p(. . . ,A, . . .)},F1〉}) = (by Proposition 2.3) J ({〈C∪CA,{p(. . . ,A, . . .)},FpF1〉,〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#1〉}). F#1 is a factor from the Cartesian product range(#A:CA [p(. . . ,A, . . .)])×range(c) to a set {0,1} that, given an assignment of values v to all random variables but 85 ground(p(. . . ,A, . . .)) : C∪CA, is defined as follows: F#1(h(),v(c(. . .))) = 1, if ⊗ x∈range(p) h(x)⊗ i=1 x = v(c(. . .)); 0, otherwise, (3.27) where h() is a histogram from range(#A:CA [p(. . . ,A, . . .)]). By Proposition 3.1 J ({〈C∪CA,{p(. . . ,A, . . .)},FpF1〉,〈C,{#A:CA [p(. . . ,A, . . .)],c(. . .)},F#1〉}) is equal to expression (3.26) which finishes a proof of the proposition. Below we provide an example of multiplication between an aggregation par- factor and a parfactor. Example 3.12. Consider the model from Figure 3.3 and Example 3.4. Probabil- ity distributions P(played(Person)) and P(matched_6(Person)|played(Person)) can be represented with a parfactor 〈 /0,{played(Person)},Fplayed〉 and a parfac- tor 〈 /0,{played(Person),matched_6(Person)},Fmatched_6〉, respectively. Fplayed is a factor from set { f alse, true} to the reals: played(Person) value f alse 0.95 true 0.05 . Fmatched_6 is a factor from the Cartesian product { f alse, true}×{ f alse, true} to the reals: played(Person) matched_6(Person) value f alse f alse 1.00000000 f alse true 0.00000000 true f alse 0.99999993 true true 0.00000007 . As shown in Example 3.8, P( jackpot_won()|matched_6(Person)) can be repre- sented with 〈 /0,matched_6(Person), jackpot_won(),1,OR, /0〉. Let Φ be a set of the three above parfactors. Assume that we want to compute Jground( jackpot_won())(Φ). 86 p(...a1...) p(...a2...) p(...a3...) p(...a4...) ⊗⊗ ⊗ ⊗ c1,1(...) c1,2(...) p(...an...) ⊗ p(...an−1...) ⊗ c1,n/2(...) c(...) = clog2 n,1(...) ⊗ ⊗ c(log2 n)−1,2(...)c(log2 n)−1,1(...) Figure 3.6: Decomposed aggregation. We multiply the first two parfactors, sum out random variables from the set ground(played(Person)) and obtain 〈 /0,{matched_6(Player)},Fsum〉, where Fsum is a factor from set { f alse, true} to the reals: matched_6(Person) value f alse 0.9999999965 true 0.0000000035 . Now we need to multiply 〈 /0,matched_6(Person), jackpot_won(),1,OR, /0〉 by 〈 /0,{matched_6(Player)},Fsum〉. We apply results of Proposition 3.5 and obtain an aggregation parfactor 〈 /0,matched_6(Person), jackpot_won(),Fsum,OR, /0〉. This simple example involved a trivial factor multiplication 1Fsum = Fsum; in general, we might need to multiply two non-trivial factors. 3.4.2.3 Summing out The C-FOVE algorithm sums out random variables to compute the marginal. Be- low we show how in some cases we can sum out p(. . . ,A, . . .) directly from an aggregation parfactor 〈 /0, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉. Consider an aggregation parfactor 〈 /0, p(. . . ,A, . . .),c(. . .),Fp,⊗, /0〉, assume that param(c(. . .)) = param(p(. . . ,A, . . .))\{A}. Operator ⊗ is associative and we can decompose the aggregation into binary tree of applications of the opera- tor ⊗. For simplicity of the discussion, let us first assume that n = |D(A) :CA | is 87 a power of two. Figure 3.6 illustrates this case. Let ci, j be a functor with range equal to the range of the functor c and ci, j(. . .) be a parameterized random vari- able such that param(ci, j(. . .)) = param(p(. . . ,A, . . .))\{A} for i = 0, . . . , log2 n; j = 1, . . . ,n/2i. Let c0, j(. . .) = p(. . . ,a j, . . .), for j = 1, . . . ,n; ci, j(. . .) = ci−1,2 j−1(. . .)⊗ ci−1,2 j(. . .), for i = 1, . . . , log2 n; j = 1, . . . ,n/2i; c(. . .) = clog2 n,1(. . .). As desired, we obtain: c(. . .) = clog2 n,1(. . .) = clog2 n−1,1(. . .)⊗ clog2 n−1,2(. . .) = · · ·= = n⊗ j=1 p(c0, j(. . .)) = n⊗ j=1 p(. . . ,a j, . . .). When p(. . . ,A, . . .) represents a set of random variables that can be treated as in- dependent, the results at each level of the tree shown in Figure 3.6 are identical, therefore we need to compute them only once. When n = |D(A) : CA | is an arbitrary natural number, we can use a square- and-multiply method [Piṅgala, 200 B.C.], whose time complexity is logarithmic in |D(A) :CA |, to eliminate p(. . . ,A, . . .) from an aggregation parfactor. This method is formalized in Proposition 3.6. Proposition 3.6. Let gA = 〈C, p(. . . ,A, . . .),c(. . .),Fp,⊗,CA〉 be an aggregation parfactor from Φ. Assume that that set of constraints C∪CA is in normal form and that param(c(. . .)) = param(p(. . . ,A, . . .))\{A}. Assume that no other par- factor or aggregation parfactor in Φ involves parameterized random variables that represent random variables from ground(p(. . . ,A, . . .)). Let m= blog2 |D(A) : CA |c and bm . . .b0 be the binary representation of |D(A) : CA |. Let (F0, . . . ,Fm) be a sequence of factors from range of c to the reals, defined 88 recursively as follows: F0(x) = Fp(x), if x ∈ range(p);0, otherwise, Fk(x) = ∑ y,z∈range(c) y⊗z=x Fk−1(y)Fk−1(z), if bm−k = 0; ∑ w,y,z∈range(c) w⊗y⊗z=x Fp(w)Fk−1(y)Fk−1(z), if bm−k = 1. Then ∑ ground(p(...,A,...)) J (Φ) = J (Φ\{ga}∪{〈C,{c(. . .)},Fm〉}) . Note that F0, . . . ,Fm are functions stored as factors. Therefore expression Fk−1(y)Fk−1(z) requires only one recursive step that computes factor Fk−1. Once Fk−1 is computed it is applied twice, to y and to z. In the worst case (when the binary representation of |D(A) : CA | is 11 . . .1) elimination of p(. . . ,A, . . .) from an aggregation parfactor 〈C, p(. . . ,A, . . .),c(. . .), Fp,⊗,CA〉 requires 2(blog2 |D(A) : CA |c)(range(c))3 applications of the ⊗ opera- tor, the same number of multiplications, and (blog2 |D(A) : CA |c)((range(c))3−1) additions. The example below illustrates Proposition 3.6. Example 3.13. We continue Example 3.12 and apply Proposition 3.6 to eliminate matched_6(Person) from 〈 /0,matched_6(Person), jackpot_won(),Fsum,OR, /0〉, where Fsum is a factor from set { f alse, true} to the reals: matched_6(Person) value f alse 0.9999999965 true 0.0000000035 . Assume that n = |D(Person) | = 5. Thus m = 2 and b2 = 1,b1 = 0,b0 = 1. Let us compute (F0,F1,F2). We have F0 = Fsum. Since b1 = 0, F1 is defined as follows: F1(x) = ∑ y,z∈{ f alse,true} yORz=x F0(y)F0(z), 89 where x ∈ { f alse, true}. This gives F1( f alse) = F0( f alse)F0( f alse)≈ 0.999999993 F1(true) = F0( f alse)F0(true)+F0(true)F0( f alse)+F0(true)F0(true) ≈ 0.000000007. As b0 = 0, F2 is defined as follows: F2(x) = ∑ w,y,z∈{ f alse,true} wORyORz=x F1(w)F1(y)F1(z), where x ∈ { f alse, true}. This gives F2( f alse) = F0( f alse)F1( f alse)F1( f alse)≈ 0.9999999825 F2(true) = F0( f alse)F1( f alse)F1(true)+F0( f alse)F1(true)F1( f alse) +F0( f alse)F1(true)F1(true)+F0(true)F1( f alse)F1( f alse) +F0(true)F1( f alse)F1(true)+F0(true)F1(true)F1( f alse) +F0(true)F1(true)F1(true)≈ 0.0000000175. and Jground( jackpot_won())(Φ) = J (〈 /0,{ jackpot_won()},F2〉). Operations presented above required 20 applications of operator OR, 20 multi- plications and 8 additions. For n = |D(Person) |= 19771128, we would need 264 applications of operator OR, 264 multiplications and 118 additions to compute the result: matched_6(Person) value f alse ≈ 0.933141 true ≈ 0.066859 . As expected, P( jackpot_won() = true) increases as |D(Person) | grows. Proposition 3.6 does not allow parameterized random variable c(. . .) in an ag- gregation parfactor to have extra logical variables that are not present in parameter- ized random variable p(. . . ,A, . . .). The C-FOVE algorithm handles extra logical variables by introducing counting formulas on these logical variables. Then it can proceed with standard summation. We cannot apply the same approach to aggrega- 90 tion parfactors as newly created counting formulas could have ranges incompatible with the range of the aggregation operator. We need a special summation proce- dure, described below in Proposition 3.7. Proposition 3.7. Let gA = 〈C, p(. . . ,A, . . .),c(. . . ,E, . . .),Fp,⊗,CA〉 be an aggre- gation parfactor from Φ. Assume that set of constraints C∪CA is in normal form and that param(c(. . .))\{E} = param(p(. . . ,A, . . .))\{A}. Assume that no other parfactor or aggregation parfactor in Φ involves parameterized random variables that represent random variables from ground(p(. . . ,A, . . .)). Let m= blog2 |D(A) : CA |c and bm . . .b0 be the binary representation of |D(A) : CA |. Let (F0, . . . ,Fm) be a sequence of factors from range of c to real numbers, defined recursively as follows: F0(x) = Fp(x), if x ∈ range(p);0, otherwise, Fk(x) = ∑ y,z∈range(c) y⊗z=x Fk−1(y)Fk−1(z), if bm−k = 0; ∑ w,y,z∈range(c) w⊗y⊗z=x Fp(w)Fk−1(y)Fk−1(z), otherwise. Let CE be a set of constraints from C that involve E. Let F# be a factor from the range of counting formula #E:CE [c(. . . ,E, . . .)] to real numbers defined as follows: F#(h()) = Fm(x), if ∃x ∈ range(c) h(x) = |D(E) : CE |;0, otherwise, where h() is a histogram from range(#E:CE [c(. . . ,E, . . .)]). Then ∑ ground(p(...,A,...)) J (Φ) = J (Φ\{ga}∪{〈C \CE ,{#E:CE [c(. . . ,E, . . .)]},F#〉}) . If set C∪CA is not in normal form, then |D(A) : CA | might vary for different ground substitutions to all logical variables in p(. . . ,A, . . .) and we will not be 91 FIRST-ORDER Person jackpot won() matched 6(Person) PROPOSITIONAL jackpot won() matched 6(jan) played(jan) matched 6(sylwia) matched 6(magda) played(magda)played(Person) big jackpot() played(sylwia) big jackpot() Figure 3.7: A first-order model from Example 3.14 and its equivalent belief network. Aggregation is denoted by curved arcs. able to apply Propositions 3.6 and 3.7. We can bring constraints in the aggregation parfactor to a normal form by splitting it on appropriate substitutions (see algorithm presented in Figure 5.4 on page 162). Once the constraints are in normal form, |D(A) :CA | does not change for different ground substitutions. Another approach is to compute |D(A) : CA | conditioned on logical variables in p(. . . ,A, . . .) with a constraint solver and use this information when summing out p(. . . ,A, . . .) (see Section 5.2.3 and Section 5.4). 3.4.3 Generalized aggregation parfactors Propositions 3.6 and 3.7 require that random variables represented by p(. . . ,A, . . .) are independent. They are dependent if they either have a common ancestor in the grounding or a common observed descendant. If during inference we eliminate the common ancestor or condition on the observed descendant before we elimi- nate p(. . . ,A, . . .) through aggregation, we may introduce a counting formula on p(. . . ,A, . . .). While we can always delay conditioning, with current form of ag- gregation parfactors sometimes we cannot delay eliminating the common ancestor. 92 Example 3.14. Consider the directed first-order probabilistic model and its ground- ing presented in Figure 3.7. It is a modification of the model from Example 3.1, represented with causal independence-based aggregation, as in Example 3.4. The new model has additional parameterized random variable big_ jackpot()with range { f alse, true} which is a parent of parameterized random variable played(Person). Assume that people are more likely to play the lottery when big_ jackpot() is true. Ground instances of parameterized random variable played(Person) are no longer independent. DistributionsP(big_ jackpot()),P(played(Person)|big_ jackpot()), P(matched_6(Person)|played(Person)), P( jackpot_won()|matched_6(Person)) can be represented with parfactors: Φ0 = {〈 /0,{big_ jackpot()},Fbig_ jackpot〉, [1] 〈 /0,{big_ jackpot(), played(Person)},Fplayed〉, [2] 〈 /0,{played(Person),matched_6(Person)},Fmatched_6〉, [3] 〈 /0,matched_6(Person), jackpot_won(),1,OR, /0〉}, [4] respectively. Fbig_ jackpot is a factor from set { f alse, true} to the reals: big_ jackpot() value f alse 0.8 true 0.2 . Fplayed is a factor from the Cartesian product { f alse, true}×{ f alse, true} to the reals: big_ jackpot() played(Person) value f alse f alse 0.95 f alse true 0.05 true f alse 0.85 true true 0.15 . Fmatched_6 is a factor from the Cartesian product { f alse, true}×{ f alse, true} to the reals: played(Person) matched_6(Person) value f alse f alse 1.00000000 f alse true 0.00000000 true f alse 0.99999993 true true 0.00000007 . Let n = |D(Person) |= 5 (as in Example 3.13). Assume that we want to compute Jground( jackpot_won())(Φ0), which requires eliminating three parameterized random 93 variables: big_ jackpot(), played(Person) and matched_6(Person). Eliminating big_ jackpot() would introduce counting formula #Person: /0[played(Person)], which would prevent as from performing aggregation in logarithmic time. We cannot eliminate matched_6(Person), because it is present in two parfactors, [3] and [4], which cannot be multiplied as they do not satisfy conditions of Proposition 3.5. Our only choice is eliminating played(Person), which involves multiplying parfactors [2] and [3] and summing out played(Person) from the product, all in lifted manner. We obtain an updated set of parfactors: Φ1 = {〈 /0,{big_ jackpot()},Fbig_ jackpot〉, [1] 〈 /0,{big_ jackpot(),matched_6(Person)},Fmatched_6′〉, [5] 〈 /0,matched_6(Person), jackpot_won(),1,OR, /0〉}, [4] whereFmatched_6′ is a factor from the Cartesian product { f alse, true}×{ f alse, true} to the reals: big_ jackpot() matched_6(Person) value f alse f alse 0.9999999965 f alse true 0.0000000035 true f alse 0.999999989 true true 0.000000011 . We have ∑ground(played(Person))J (Φ0) = J (Φ1). At this stage, we are left with two parameterized random variables to eliminate: big_ jackpot() and matched_6(Person). As before, eliminating big_ jackpot() first would introduce a counting formula and we cannot eliminate matched_6(Person), because it is present in two parfactors, [4] and [5], which cannot be multiplied. Models like the one described in Example 3.14 do not allow us to apply the results of Propositions 3.6 and 3.7 and perform efficient lifted aggregation. We ad- dress this problem by introducing a generalized version of the aggregation parfactor data structure. The generalized version not only can represent aggregation-based dependency between parameterized random variables p(. . . ,A, . . .) and c(. . .), but also describes how this aggregation depends on a set of context parameterized ran- dom variables V . The latter dependency is captured by factor Fp∪V , a generalized version of factor Fp from the aggregation parfactor data structure. 94 Definition 3.3. A generalized aggregation parfactor is a septuple 〈C, p(. . . ,A, . . .),c(. . .),V,Fp∪V ,⊗,CA〉, where • p(. . . ,A, . . .) and c(. . .) are parameterized random variables • the range of p is a subset of the range of c • A is the only logical variable in p(. . . ,A, . . .) that is not in c(. . .) • V is a set of parameterized random variables, such that: for any two parame- terized random variables fi(. . .), f j(. . .) from V we have (ground( fi(. . .)) : C∪CA)∩ (ground( f j(C)) : C∪CA) = /0; and for any fi(. . .) from V we have (ground( fi(. . .)) : C∪CA)∩ (ground(p(. . . ,A, . . .)) : C∪CA) = /0 as well as (ground( fi(. . .)) : C∪CA)∩ground(c(. . .)) : C = /0 • C is a set of inequality constraints not involving A • Fp∪V is a factor from the Cartesian product of ranges of parameterized ran- dom variables in {p(. . . ,A, . . .)}∪V to real numbers. • ⊗ is a commutative and associative deterministic binary operator over the range of c • CA is a set of inequality constraints involving A, such that (D(A) : CA) 6= /0. A generalized aggregation parfactor 〈C, p(. . . ,A, . . .),c(. . .),V,Fp,⊗,CA〉 repre- sents a set of factors, one factor FpVc for each ground substitution G to all log- ical variables in a set ⋃ fi(...)∈V param( fi(. . .))∪ param(c(. . .)) that satisfies the constraints in C∪CA. Each factor FpVc is a mapping from the Cartesian product ×a∈D(A):CA range(p)× fi(...)∈V range( fi)×range(c) to the reals, which, given an assignment of values to all random variables v, is defined as follows: FpVc(v(p(. . . ,a1, . . .)),. . . ,v(p(. . . ,an, . . .)),v( f1(. . .)),. . . ,v( fm(. . .)),v(c(. . .))) = ∏ a∈{a1,...,an} Fp∪V rp rc (v(p(. . . ,a, . . .)),v( f1(. . .)), . . . ,v( fm(. . .))), if ⊗ a∈{a1,...,an} v(p(. . . ,a, . . .)) = v(c(. . .)); 0, otherwise, 95 whereD(A):CA={a1, . . . ,an}, V={ f1(. . .), . . . , fm(. . .)}, rc=|ground(c(. . .)):C | and rp = |ground(p(. . . ,a, . . .)) :C |, a ∈ D(A) : CA. Propositions 3.1–3.7 from Sections 3.4.1 and 3.4.2 can be adapted to gener- alized parameterized parfactors. The only major changes are that a generalized parfactor can be multiplied by any parfactor on p(. . . ,A, . . .) and context parame- terized random variables and that summing out of p(. . . ,A, . . .) from a generalized aggregation parfactor involves repeating computation described in Section 3.4.2.3 for each value assignment to context parameterized random variables. We illustrate this with the following example: Example 3.15. Let us come back to Example 3.14. Assume that we performed all the steps described there, the only difference being that parfactor [4] is a general- ized aggregation parfactor: Φ1 = {〈 /0,{big_ jackpot()},Fbig_ jackpot〉, [1] 〈 /0,{big_ jackpot(),matched_6(Person)},Fmatched_6′〉, [5] 〈 /0,matched_6(Person), jackpot_won(), /0,1,OR, /0〉}. [4] We can now multiply parfactors [4] and [5]: Φ2 = {〈 /0,{big_ jackpot()},Fbig_ jackpot〉, [1] 〈 /0,matched_6(Person), jackpot_won(),{big_ jackpot()}, Fmatched_6′ ,OR, /0〉}. [6] We have J (Φ1) = J (Φ2). The above step involved a trivial multiplication 1Fmatched_6′ =Fmatched_6′ ; in general, we might need to multiply two non-trivial factors. Recall that n = |D(Person) |= 5 and Fmatched_6′ is a factor from the Cartesian product { f alse, true}×{ f alse, true} to the reals: big_ jackpot() matched_6(Person) value f alse f alse 0.9999999965 f alse true 0.0000000035 true f alse 0.999999989 true true 0.000000011 . 96 Now we eliminate matched_6(Person) from a generalized aggregation parfactor [6]. The computation involves two steps, one for the case where context parameter- ized random variable big_ jackpot() is f alse and on for the case where it is true. The first step manipulates numbers from the first two rows of factor Fmatched_6′ and is identical to the computation presented in Example 3.13. The second step manipulates numbers from the last two rows of factor Fmatched_6′ and otherwise is identical to the first step. We obtain a parfactor [7]: Φ3 = {〈 /0,{big_ jackpot()},Fbig_ jackpot〉, [1] 〈 /0,{big_ jackpot(), jackpot_won()},F jackpot_won〉}, [7] F jackpot_won is a factor from the Cartesian product { f alse, true}×{ f alse, true} to the reals: big_ jackpot() jackpot_won() value f alse f alse 0.9999999825 f alse true 0.0000000175 true f alse 0.9999999450 true true 0.0000000550 . We have ∑ground(matched_6(Person))J (Φ2) = J (Φ3). Finally, we eliminate big_ jackpot(), which involves multiplying parfactors [1] and [7] and summing out big_ jackpot() from the product. We obtain an updated set of parfactors: Φ4 = {〈 /0,{ jackpot_won()},F jackpot_won′〉}, [8] where F jackpot_won′ is a factor from set { f alse, true} to the reals: jackpot_won() value f alse 0.999999975 true 0.000000025 . We have J (Φ4) = Jground( jackpot_won())(Φ0). 3.5 Experiments In this section we compare how the performance of different ways of representing aggregation in directed first-order probabilistic models scales as the populations sizes of logical variables grow. 97 We compared the performance of variable elimination (VE), variable elim- ination with the noisy-MAX factorization [Díez and Galán, 2003] (VE-FCT), C-FOVE, C-FOVE with the lifted noisy-MAX factorization described in Sec- tion 3.4.1.2 (C-FOVE-FCT), and C-FOVE with aggregation parfactors (AC- FOVE). We used Java implementations of the above algorithms on an Intel Core 2 Duo 2.66GHz processor with 1GB of memory made available to the JVM. 3.5.1 Memory usage In the first experiment we investigated how memory usage changes as the popula- tion size of the aggregation logical variable increases. For our tests we used small first-order models introduced through this chapter. While they are definitely toy models by themselves, aggregation components that are present in these models could be parts of much bigger, more realistic models. If some of the tested algo- rithms cannot perform efficient inference in our small models, they will not be able to perform inference in bigger ones. We tested all five algorithms on the following test instances: (a) the model introduced in Example 3.1 (depicted in Figure 3.1), compute the marginal of the parameterized random variable jackpot_won(); (b) the model introduced in Example 3.2 (Figure 3.2), compute the marginal of the parameterized random variable best_match(); (c) the model introduced in Example 3.5 (Figure 3.5), compute the marginal of the parameterized random variable jackpot_winners()1; (d) the model introduced in Example 3.14 (depicted in Figure 3.7), compute the marginal of the parameterized random variable jackpot_won(). For all instances we varied the population size n of the logical variable Person from 1 to 20,000,000. We recorded the maximum value of n for which aggregation was possible given 1GB of memory. The results are presented in Figure 3.8. The space complexity for VE is exponential in n, and the algorithm could not handle models with large population sizes. The space complexity for VE-FCT is linear in n and it performed much better than standard VE. For models (a), (c) and 1The VE-FCT and C-FOVE-FCT algorithms could not be tested on this model as aggregation is based on the SUM|3 operator. 98 Model VE VE-FCT C-FOVE C-FOVE-FCT AC-FOVE (a) 25 ≈ 1.0E4 > 2.0E7 > 2.0E7 > 2.0E7 (b) 23 ≈ 1.0E4 ≈ 7.0E3 > 2.0E7 > 2.0E7 (c) 24 N/A > 2.0E7 N/A > 2.0E7 (d) 24 ≈ 1.0E4 > 2.0E7 > 2.0E7 > 2.0E7 Figure 3.8: The maximum size of the population size of the logical variable Person for which aggregation was possible. 100 102 104 106 100 102 104 n = |D(Person)| ti m e [m s] VE VE−FCT C−FOVE AC−FOVE C−FOVE−FCT Figure 3.9: Performance on model (a) (with OR-based aggregation). (d), C-FOVE is also linear in n, but C-FOVE does lifted inference and it achieved better results than VE-FCT, which performs inference at the propositional level. In the model (b), the space complexity for C-FOVE isO(n6), and C-FOVE could not handle as large populations as VE-FCT. C-FOVE-FCT and AC-FOVE, for which the space complexity is independent of n, performed best. Note that for C-FOVE-FCT and AC-FOVE the time complexity is logarith- mic in n, for other algorithms the time complexity is the same as the space com- plexity. 99 100 102 104 106 100 102 104 n = |D(Person)| ti m e [m s] VE VE−FCT C−FOVE AC−FOVE C−FOVE−FCT Figure 3.10: Performance on model (b) (with MAX-based aggregation). 100 102 104 106 100 102 104 n = |D(Person)| ti m e [m s] VE C−FOVE AC−FOVE Figure 3.11: Performance on model (c) (with SUM|3-based aggregation). 100 100 102 104 106 100 102 104 106 n = |D(Person)| ti m e [m s] VE VE−FCT C−FOVE AC−FOVE C−FOVE−FCT Figure 3.12: Performance on model (d) (generalized aggregation parfactors). For completeness, on Figures 3.9-3.12 we also present the average time over 10 runs of each algorithm for tested instances. While due to the small sizes of models parts of plots below 1ms are very noisy, we can see that the small memory footprint C-FOVE-FCT and AC-FOVE does not come at a cost of high computation time. 3.5.2 Social network experiment For this experiment we used an ICL theory [Poole, 2008] from Carbonetto et al. [2009] that explains how people alter their smoking habits within their social net- work. The theory (without a probability distribution) is shown in Figure 3.13. The population of logical variables X and Y represents the set of people. The theory ac- counts for various interdependencies between smoking and friendship within this group of people. For example, non-smokers might convince their friend to stop smoking, or two smokers might be more likely to become friends. Possible cyclic dependencies between people are resolved by “switch” parameterized random vari- able ind(X) with range { f alse, true}. 101 [00] C = {{ind(X), ¬ind(X)}, [01] {ns-fr(X,Y), ¬ns-fr(X,Y)}, [02] {diff-sm-fr(X,Y), ¬diff-sm-fr(X,Y)}, [03] {sm-fr(X,Y), ¬sm-fr(X,Y)}, [04] {fr-at-rnd-sm(X,Y), ¬fr-at-rnd-sm(X,Y)}, [05] {fr-at-rnd-nsm(X,Y), ¬fr-at-rnd-nsm(X,Y)}, [06] {fr-at-rnd(X,Y), ¬fr-at-rnd(X,Y)}, [06] {ind-sm(X), ¬ind-sm(X)}, [07] {no-adv-sm(X), ¬no-adv-sm(X)}, [08] {nsm-adv-sm(X), ¬nsm-adv-sm(X)}, [09] {sm-adv-sm(X), ¬sm-adv-sm(X)}, [10] {ctr-adv-sm(X), ¬ctr-adv-sm(X)}, [11] {noise-1(X,Y), ¬noise-1(X,Y)}, [12] {noise-2(X,Y), ¬noise-2(X,Y)}} [13] F = {friends(X,Y)← XY ∧ friends(Y,X), [14] friends(X,Y)← X≺Y ∧ ind(X) ∧ ind(Y) ∧ ¬smokes(X) ∧ ¬smokes(Y) ∧ ns-fr(X,Y), [15] friends(X,Y)← X≺Y ∧ ind(X) ∧ ind(Y) ∧ ¬smokes(X) ∧ smokes(Y) ∧ diff-sm-fr(X,Y), [16] friends(X,Y)← X≺Y ∧ ind(X) ∧ ind(Y) ∧ smokes(X) ∧ ¬smokes(Y) ∧ diff-sm-fr(X,Y), [17] friends(X,Y)← X≺Y ∧ ind(X) ∧ ind(Y) ∧ smokes(X) ∧ smokes(Y) ∧ sm-fr(X,Y), [18] friends(X,Y)← X≺Y ∧ ind(X) ∧ ¬ind(Y) ∧ ¬smokes(X) ∧ fr-at-rnd-nsm(X,Y), [19] friends(X,Y)← X≺Y ∧ ind(X) ∧ ¬ind(Y) ∧ smokes(X) ∧ fr-at-rnd-sm(X,Y), [20] friends(X,Y)← X≺Y ∧ ¬ind(X) ∧ ind(Y) ∧ ¬smokes(Y) ∧ fr-at-rnd-nsm(Y,X), [21] friends(X,Y)← X≺Y ∧ ¬ind(X) ∧ ind(Y) ∧ smokes(Y) ∧ fr-at-rnd-sm(Y,X), [22] friends(X,Y)← X≺Y ∧ ¬ind(X) ∧ ¬ind(Y) ∧ fr-at-rnd(X,Y), [23] smokes(X)← ind(X) ∧ ind-sm(X), [24] smokes(X)← ¬ind(X) ∧ ¬sm-adv-sm-fr(X) ∧ ¬nsm-adv-nsm-fr(X) ∧ no-adv-sm(X), [25] smokes(X)← ¬ind(X) ∧ ¬sm-adv-sm-fr(X) ∧ nsm-adv-nsm-fr(X) ∧ nsm-adv-sm(X), [26] smokes(X)← ¬ind(X) ∧ sm-adv-sm-fr(X) ∧ ¬nsm-adv-nsm-fr(X) ∧ sm-adv-sm(X), [27] smokes(X)← ¬ind(X) ∧ sm-adv-sm-fr(X) ∧ nsm-adv-nsm-fr(X) ∧ ctr-adv-sm(X), [28] sm-adv-sm-fr(X)← ∃Y friends(X,Y) ∧ ind(Y) ∧ smokes(Y) ∧ noise-1(X,Y), [29] nsm-adv-nsm-fr(X)← ∃Y friends(X,Y) ∧ ind(Y) ∧ ¬smokes(Y) ∧ noise-2(X,Y)} Figure 3.13: ICL theory (without a probability distribution) for the smoking- friendship model. If ind(X) is true, X makes an independent decision to smoke or not to smoke. If ind(X) is f alse, X’s decision may be influenced by X’s friends. The role of parame- terized random variable ind(X) is illustrated in Figure 3.14. Aggregation is present in the theory in lines [28] and [29] which model how a person aggregates advice from smoking and non-smoking friends. For the population size n, the equivalent propositional graphical model has 3n2 + n nodes and 12n2− 9n arcs. Parameters 102 (c) (d) true false smokes(alice) smokes(alice) smokes(alice) friends(alice,bob) smokes(bob) smokes(bob) smokes(bob) friends(alice,bob) friends(alice,bob) (a) (b)true false smokes(alice) smokes(bob) friends(alice,bob) ind(bob) ind(alice) Figure 3.14: Illustration of how ind(X) works. of the probability distribution forming the theory were learned from data of smok- ing and drug habits among teenagers attending a school in Scotland [Pearson and Michell, 2000] using methods described by Carbonetto et al. [2009]. In our experiment we varied the populations size n from 2 to 140 and for each value, we computed a marginal probability of a single individual being a smoker. Figure 3.15 shows the average time over 10 runs of tested algorithms for each pop- ulation size. The VE, VE-FCT and C-FOVE algorithms failed to solve instances with a population size greater than 8, 10, and 11, respectively, because they run out of available memory (1GB). AC-FOVE was able to handle efficiently much larger instances and it ran out of memory for a population size of 159. The AC- FOVE algorithm performed equally to the C-FOVE-FCT algorithm except for small populations. It is important to remember that the C-FOVE-FCT algorithm, unlike AC-FOVE, can only be applied to MAX and MIN-based aggregation. 103 101 102 100 102 104 n ti m e [m s] VE VE−FCT C−FOVE AC−FOVE C−FOVE−FCT Figure 3.15: Performance on the smoking-friendship model. 3.6 Conclusions In this chapter we demonstrated the use of aggregation parfactors to represent ag- gregation in directed first-order probabilistic models, and how aggregation parfac- tors can be incorporated into the C-FOVE algorithm. Theoretical analysis and empirical tests showed that in some cases, lifted inference with aggregation par- factors leads to significant gains in efficiency. 104 Chapter 4 Solver for #CSP with Inequality Constraints When angry count to ten before you speak. If very angry, count to one hundred. — Thomas Jefferson When angry, count to four; when very angry, swear. — Mark Twain 4.1 Introduction Lifted probabilistic inference requires counting the number of solutions to binary CSPs (i.e., solving #CSP) with inequality constraints (either between a pair of variables or between a variable and a constant). Variables in these CSP instances typically have large domain sizes. Instances of these problems are described in a lifted manner, that is, the only constants named explicitly are those, for which there exist unary constraints. In order to be efficient, a lifted probabilistic inference engine also requires a lifted answer from a #CSP solver. A lifted answer groups together constants which contribute to the same count. Existing algorithms for counting the number of solutions to constraint satisfac- tion problems do not accept lifted descriptions as input or produce lifted descrip- tions as output. Moreover, the complexity of these algorithms is dominated by the domain size, which also makes them unsuitable for lifted probabilistic inference 105 where we want to solve the whole problem in time logarithmic in the domain size where possible. In this chapter we design and analyze a counting algorithm that takes as an input a lifted description of a CSP and returns the answer described in a lifted manner and performs well in presence of large domain sizes. We provide background information in Section 4.2. In particular, we introduce relevant concepts in Section 4.2.1 and describe a #CSP algorithm from [Dechter, 2003, Section 13.3.3], which is a starting point for our algorithm, in Section 4.2.2. Our counting algorithm is described in Section 4.3.2 and analyzed theoreti- cally in Section 4.3.4. Empirical tests on random CSP instances are presented in Section 4.3.5. We analyze the impact of the presented algorithm on probabilistic inference in Chapter 5 in Section 5.4. Appendices A to D provide insights into our implementation of the algorithm. The scope of notation introduced in this chapter is limited to this chapter, Ex- ample 5.12 from Chapter 5 and Appendices B to D. 4.2 Background Constraint Satisfaction Problems (CSPs), first introduced by Montanari [1974], are used for representing problems in many areas. Besides the most widely studied de- cision and search variants, one can pose the question “How many solutions exist?” for a particular CSP. This counting variant of CSP is known as #CSP. It belongs to the #P class of problems introduced by Valiant [1979], which is the class of all counting problems associated with polynomially balanced, polynomial-time decid- able relations [Papadimitriou, 1994]. Binary #CSP was proven to be complete for the #P class [Roth, 1996]. Bulatov and Dalmau [2003] described some tractable subclasses of #CSPs, but these are very restrictive. Among counting problems, #SAT receives the most attention [Bayardo Jr. and Pehoushek, 2000; Birnbaum and Lozinskii, 1999; Dahllöf et al., 2002, 2005; Dubois, 1991; Zhang, 1996]. However, some approximate and exact algorithms for #CSP have recently been proposed. Meisels et al. [2000] rephrased #CSP in terms of probability updating in Bayesian networks, and applied methods for approximat- ing probabilities in Bayesian networks to approximate the number of solutions. 106 Angelsmark et al. [2002] represented binary CSP in terms of 2-SAT instances, and used the algorithm described in [Dahllöf et al., 2002] to obtain the number of so- lutions. In an improved version Angelsmark and Jonsson [2003] translated binary CSP to weighted 2-SAT, and the counting problem was solved with the algorithm described in [Dahllöf et al., 2005]. The translation was done using the partition- ing method, which works by partitioning the domains of variables in CSP into a number of disjoint subsets. The time complexity of the improved algorithm for n variables and domain size equal to d approaches O((0.6224d)n) as d grows. The space complexity is polynomial. The number of solutions to subproblems of a given CSP can be used as a heuristic for solving the whole problem. Dechter and Pearl [1987] counted so- lutions with a variant of the variable elimination algorithm. Horsch and Havens [2000] used solution probabilities, which can guide search algorithms for solv- ing CSPs. Kask et al. [2004a,b] approximated the number of solutions with the Iterative Join-Graph Propagation method [Dechter et al., 2002] and used it as a heuristic to solve CSPs. Refalo [2004] presented a generic search heuristic based on the impact of a variable. Pesant [2005] proposed a structural approach to #CSP. He derived polynomial- time evaluations of the number of solutions of individual constraints of several types, that can be used to approximate the total number of solutions or to guide search heuristics. Dechter [2003, Section 13.3.3] presented a method for solving #CSP with a variable elimination algorithm. The time and space complexity of the algorithm are equal toO(rdw∗(ρ)), where r is the number of constraints and w∗(ρ) is the induced width of the associated constraint graph as a function of the elimination ordering ρ . In this chapter we show how this variable elimination algorithm can be modified to count the number of solutions to binary CSPs with inequality constraints and large domains. The class of the problems needed for lifted probabilistic inference, that is the class of CSP with only inequality constraints is known as list-coloring problem [Biggs, 1993]. If values from the domains of the variables are interpreted as col- ors, the problem can be understood as the problem of coloring graph nodes such that two nodes with an edge between them have different colors. Björklund et al. 107 [2009] provide the algorithm with 2nnO(1) time and space complexity, where n is the number of variables. The more restricted class of the problem, where variables have the same do- main of size k is known as k-coloring problem [Biggs, 1993]. It can be interpreted as a problem of coloring a graph nodes using k colors such that two nodes with an edge between them have different colors. It only applies to lifted probabilistic infer- ence, if the encountered CSP does not involve unary constraints. The partitioning method mentioned earlier has been successfully used to solve this problem [An- gelsmark and Thapper, 2006]. The corresponding counting problem is known as the problem of computing chromatic polynomial [Biggs, 1993]. The fastest known algorithm due to Björklund et al. [2009] has 2nnO(1) time and space complexity. Given polynomial space, they can find the smallest k for which the original decision problem has positive answer (the chromatic number [Biggs, 1993]) in O(2.2461n) time. 4.2.1 Constraint satisfaction problems The content of this section is based on [Dechter, 2003]. A CSP instance is a triple P = (X,D,C), where X = {X1, . . . ,Xn} is a finite set of n variables, D is a function that maps each variable Xi to the set D(Xi) of possible values it can take (domain of Xi) and C = {C1, . . . ,Cr} is a finite set of constraints. Each constraint C j is a relation over a set S(C j) = {Y1, . . . ,Ym} of variables from X, C j ⊆ D(Y1)×·· ·×D(Ym). The set S(C j) is called the scope of C j and m is called the arity of the constraint C j. In a binary CSP instance, all the constraints are unary (m = 1) or binary (m = 2). A tuple 〈x1, . . . ,xi〉 ∈ D(Xl1)×·· ·×D(Xli) satisfies a constraint C j if S(C j) ⊆ {Xl1 , . . . ,Xli} and the projection of 〈x1, . . . ,xi〉 on S(C j) is an element of C j. A tuple 〈x1, . . . ,xn〉 ∈ D(X1)× ·· ·×D(Xn) is a solution of P = (X,D,C) if it satisfies all constraints in C. A tuple 〈x1, . . . ,xn〉 ∈ D(X1)×·· ·×D(Xn) is a consistent extension in P of the tuple 〈xi1 , . . . ,xim〉 ∈ D(Xi1)×·· ·×D(Xim) to the variables {X1, . . . ,Xn} \ {Xi1 , . . . , Xim}, if it is a solution of P and ∀ j ∈ {1, . . . ,m}∃l ∈ {1, . . . ,n} such that (xi j = xl)∧ (Xi j = Xl). 108 In this chapter, we restrict our focus to discrete, finite CSP instances, where all variables in P have discrete and finite domains. The CSP instance P= (X,D,C) can be represented by a constraint graph: each variable is represented by a node, and two nodes are connected if they are in the scope of the same constraint from C (in the case of a binary CSP, arcs correspond directly to the constraints). 4.2.2 Variable elimination for #CSP In this section, we describe the variable elimination algorithm for #CSP (#VE) presented in [Dechter, 2003, Section 13.3.3]. Assume we are given a CSP instance P = (X,D,C). Each constraint Ci with scope S(Ci) = {Xi1 , . . . ,Xim} is represented by a single factor FCi on variables Xi1 , . . . , Xim , which has the value 1 for satisfying tuples and 0 otherwise. The number of solutions to P, |P| is equal to: |P|=∑ X1 . . .∑ Xn FC1(S(C1))·· ·FCr(S(Cr)). Computing the product FC1(S(C1))·· ·FCr(S(Cr)) is not tractable, but the #VE algorithm takes advantage of the (possible) sparseness of the associated con- straint graph, and using the distribution law, distributes factors that are not func- tions of Xi outside of the sum ∑Xi , for i = n, . . . ,1. Figure 4.1 presents the pseudo- code involved. Note that this is exactly the same algorithms as the VE algorithm for inference in belief networks (see Section 2.3.2 and Figure 2.2 on page 10). The only difference is the way the initial factors are created. At each step of the computation, the product of all factors that exist at this step represents the number of consistent extensions associated with the previously eliminated variables. Initially, no variables are eliminated and, as described above, we have 0–1 valued factors corresponding to the original constraints. Their product simply enumerates all possible assignments of values to variables and assigns 1 to tuples that are solutions to the input CSP instance and 0 to other tuples. At the end, if we decide to eliminate all variables (i.e., if E=X), this algorithm returns a factor on the empty set of variables, which is simply a number equal to the 109 [00] procedure #CSP_VE(P,E,H) [01] input: CSP instance P= (X,D,C), [02] set of variables to eliminate E⊆ X; [03] elimination ordering heuristic H; [04] output: factor representing the solution for each value of X\E; [05] set F := initialize(P); [06] while there is a factor in F involving variable from E do [07] select variable Y ∈ E according to H; [08] set F :=eliminate(Y,F); [09] set E := E\{Y}; [10] end [11] return ⊙ Fi∈FFi; [12] end [13] procedure initialize(P) [14] input: CSP instance P= (X,D,C); [15] output: representation of P as set of factors F; [16] set F := /0; [17] for i := 1 to r do [18] create factor Fi on S(Ci) with value 1 for tuples satisfying Ci and [19] with value 0 otherwise; [20] set F := F∪{Fi}; [21] end [22] return F; [23] end [24] procedure eliminate(Y,F) [25] input: variable to be eliminated Y , [26] set of factors F; [27] output: set of factors F with Y summed out; [28] partition F= {F1, . . . ,Fn} into {F1, . . . ,Fm} that do not contain Y and [29] {Fm+1, . . . ,Fn} that do contain Y ; [30] return {F1, . . . ,Fm,∑Y Fm+1·· ·Fn}; [31] end Figure 4.1: #VE algorithm for #CSP from Dechter [2003]. number of solutions to the input CSP instance. If we decide to eliminate only some of the variables (E⊂ X), this algorithm returns a factor representing the number of solutions for each combination of values of variables X\E. Assume that we have eliminated all variables (E = X), and that domains of the variables have the same size d = |D(X1)|= · · ·= |D(Xn)|. The time and space 110 complexity of the algorithm are determined by the size of the biggest factor, which depends on the induced width w∗(ρ) of the associated constraint graph O(rdw∗(ρ)) . (4.1) 4.2.3 Set partitions A partition of a set S is a collection B1, . . . ,Bk of nonempty, pairwise disjoint sub- sets of S such that S = ⋃k i=1 Bi. The sets Bi are called blocks of the partition. Example 4.1. Consider set S = {1,2,3}. The collection of blocks B1 = {1,3}, B2 = {2} is an example of a partition of S. Using a standard notation for set partitions it can be written down as {{1,3},{2}}. There are four other partitions of set S: {{1,2,3}}, {{1},{2,3}}, {{1,2},{3}}, and {{1},{2},{3}}. Set partitions are intimately connected to equality. For any consistent set of equality assertions on variables, there exists one or more partitions in which the variables that are equal are in the same block, and the variables that are not equal are in different blocks. If we consider a semantic mapping from variables to individuals in the world, the inverse of this mapping, where two variables that map to the same individual are in the same block, forms a partition of the variables. Given a partition pi , we denote by C(pi) a set of equality assertions correspond- ing to pi . Example 4.2. Consider set of variables {B,C,D}. Equality assertions B 6=C, B 6= D, C = D correspond to a partition {{B},{C,D}}. We have C({{B},{C,D}}) = {B 6=C,B 6= D,C = D}. The number of partitions of the set of size n is equal to the n-th Bell number ϖn, named after Eric T. Bell, who wrote several papers on the subject [Bell, 1934a,b, 1938]. Bell numbers satisfy the following recurrence: ϖ0 = 1, ϖn+1 = n ∑ k=0 ϖk ( n k ) . (4.2) 111 0 5 10 15 20 25 30 100 105 1010 ϖn 2n 3n5 n10n100n n Figure 4.2: Comparison of ϖn and exponential functions. According to Knuth [2005], Equation 4.2 was discovered by Toshiaki Honda in the early 1800s, and William A. Whitworth [Whitworth, 1878] first pointed out the connection between Bell numbers and set partitions. The first few Bell numbers are: n = 0 1 2 3 4 5 6 7 8 9 10 . . . ϖn = 1 1 2 5 15 52 203 877 4140 21147 115975 . . . Bell numbers grow faster than any exponential function (see Lovász [2003]), but for small n’s they stay much smaller than exponential functions with a moderate base (see Figure 4.2). We end this section with a proof of a property of Bell numbers which we will use later on. Proposition 4.1. Let i1, i2, . . . , ik ≥ 0. Then ϖi1ϖi2 . . .ϖik ≤ ϖi1+i2+···+ik . Proof. The right side of the inequality represents the number of all partitions of the set of size i1+ i2+ · · ·+ ik. Assume we have a set of size i1+ i2+ · · ·+ ik, whose elements are painted with k colors and for 1 ≤ j ≤ k, there are i j elements painted with the color j. The left side of the inequality represents the number of all partitions of this set, such that elements with different colors are always in different blocks. It is easy to see, that such a number is smaller or equal to the number of all partitions of the set of size i1+ i2+ · · ·+ ik. 112 DB E 6= 6= 6= C6=A Figure 4.3: Constraint graph with tree structure. 4.3 Counting solutions to CSP instances with inequality constraints For the rest of this chapter, we restrict our attention to CSP instances with only inequality constraints (either between a pair of variables or between a variable and constants) as only such constraints arise in lifted probabilistic inference. Moreover, for simplicity of the presentation but without loss of generality, we only consider instances for which the constraint graph consists of a single connected component. The number of solutions to CSP with a disconnected constraint graph is simply the product of the numbers of solutions for the connected components of the constraint graph. Note that, unlike the rest of this thesis, in this chapter we do not assume that variables from the same connected component of the constraint graph have the same domain. Given two variables A and B and an inequality constraint between them, we do not need to consider individual values from their domains in order to calculate the number of solutions to such CSP. If we know the sizes of the variables’ domains and the size of the intersection of the domains, we can calculate the number of solutions: |A| |B|−|A∩B|. We show below how this simple idea can be generalized to an arbitrary CSP with inequality constraints and develop a modified variable elimination algorithm that does not need to enumerate values from the domains. 4.3.1 Analysis of the problem Let us start with a very simple constraint graph. Example 4.3. Consider the constraint graph presented in Figure 4.3, where all variables have the same domain, the domain size is d, and there are no unary con- 113 (a) (b) A B D 6= 6= 6= A B C D 6= 6= 6= 6= B = C 6= 6= A D C 6= 6= Figure 4.4: Constraint graph with a cycle (a). The two cases: B = C and B 6=C (b). straints. The graph has a tree structure, which allows us to immediately solve the problem: we can assign the value to A in d ways, and are left with d− 1 possible values for B, d− 1 possible values for C and d− 1 possible values for D and E. Hence, there are d ·(d−1) ·(d−1) ·(d−1) ·(d−1) solutions to this CSP instance. In the next example, we analyze a constraint graph with a cycle. Example 4.4. Consider the constraint graph presented in Figure 4.4 (a). As in the previous example, all variables have the same domain, the domain size is d, and there are no unary constraints. The graph has a cycle, which makes the calculation more complicated. We can assign the value to A in d ways, and are left with d−1 possible values for B and d− 1 possible values for C. For D we need to consider two cases: B =C and B 6=C, as is shown in Figure 4.4 (b). In the B =C case, D can take d−1 values, while in the B 6=C case, D can have d−2 values. Hence, the number of solutions to this CSP instance is d ·(d−1) ·((d−1)+(d−2) ·(d−2)). The two cases correspond to two partitions of a set {B,C}: a partition {{B,C}} and a partition {{B},{C}}. Let us compare our simple reasoning to the computation that would be per- formed by the #VE algorithm. Considered CSP can be represented with four fac- tors: f (A,B), f (A,C), f (B,D) and f (C,D), each of size d2. To eliminate A, the #VE algorithm multiplies factors f (A,B) and f (A,C). Next, it sums out A from the factor representing the product and obtains a factor on variables B and C of size d2. The elimination process continues, but of interest to us is the fact, that 114 6= A (a) 6= A C 6= E D 6= 6= B 6= 6= 6= B E C = D (b) DB = C 6= 6= 6= 6= E C B = D 6= 6= 6= 6= 6= C 6= E D6= 6= 6= 6= 6= B AA E A 6= 6= E B = C = D A 6= 6= 6= 6= Figure 4.5: Constraint graph discussed in Example 4.5 (a). Cases corre- sponding to the respective partitions of the set {B,C,D} (b). (a) 6= A 6= E D 6= 6= B 6= 6= 6= C 6= A 6= B E 6= 6= 6= C = D 6= 6= C 6= E D6= 6= 6= 6= 6= B A 6= (b) 6= A 6= E 6= 6= 6= B = D C Figure 4.6: Constraint graph discussed in Example 4.5 (a). Cases corre- sponding to the respective partitions of the set {B,C,D} that are con- sistent with inequality B 6=C (b). #VE computed d2 assignments of values to variables B and C, while above we just needed to consider the two partitions: {{B,C}} and {{B},{C}}. We further examine the above observation in the next example. Example 4.5. Consider the graph from Figure 4.5 (a). Again, assume that all variables have the same domain, the domain size is d, and there are no unary constraints. If we count possible assignments to variables in a way described in Example 4.4 following order ρ = 〈A,B,C,D,E〉, we need to consider ϖ3 = 5 parti- tions of set {B,C,D}: {{B,C,D}}, {{B},{C,D}}, {{B,C},{D}}, {{B,D},{C}}, {{B},{C},{D}}. Each partition corresponds to a different case as to whether the 115 variables are equal or not; these cases are shown on Figure 4.5 (b). The #VE algo- rithm while following the elimination ordering ρ would create a factor on variables B, C, D of size dw ∗(ρ) = d3. If we add a constraint B 6= C to the constraint graph (see Figure 4.6 (a)), we need to consider only partitions that are consistent with this constraint, that is, partitions in which B and C are in different blocks. There are three such partitions (see Figure 4.6 (b)). The #VE algorithm still creates a factor on B, C, D of size d3. Notice that what we have done in Example 4.5 is to consider at most ϖ3 par- titions of variables, rather than d3 assignments of values to these variables. Since we do not care about empty partitions, we will never have to consider more parti- tions than there are assignments of values. As we mentioned in Section 4.2.3, for small n’s (which in our case is equal to the induced width of a constraint graph w∗(ρ), see Section 4.3.4.2) ϖn stays much smaller than exponential functions with a moderate base (in our case equal to the domain size d). In the problems induced during first-order probabilistic inference we consider, we do not expect w∗(ρ) to be very large, but we are likely work with large domains; therefore, considering ϖw∗(ρ) cases instead of dw ∗(ρ) can be a big gain. In practice, variables can have different domains or different values from their domains might be excluded by unary constraints. In such a situation, we can apply the above reasoning to any set of values that are indistinguishable as far as counting is concerned. For example, the intersection of all domains is a set of values for which we only need the size; there is no point in reasoning about each individual value separately. Similarly, the values from the domain of a variable that do not belong to the domain of any other variable can be grouped and treated together. All we need is to know how many there are. Example 4.6. Consider again the constraint graph from Figure 4.4. Assume that all variables but B have the same domain D(A) = D(C) = D(D) of size d, and that B has a domain of size d+d′, where |D(B)∩D(A)| = d. In the case where B has a value from D(B)∩D(A) = D(A), as before, the number of solutions to this CSP instance is equal to d · (d− 1) · ((d− 1)+ (d− 2) · (d− 2)). In the case where B has a value from D(B)\D(A), where |D(B)\D(A)| = d′, the number of solutions 116 #VE6= inference #V E in fere nce grou n d in g #VE6= factors #VE factors solution Figure 4.7: Relationship between #VE 6= and #VE. is equal to d ·d′ · (d−1) · (d−1). The overall number of solutions is equal to the sum of these two quantities. Example 4.7. If we were to extend Example 4.6 so that D has the same domain as B, we would then only need to consider how many more solutions would be in the final answer. In this case, we can consider the other values from the domain of D and how these add to the total count of models. We would like to do this locally when summing out variables, rather than globally, as implied in this example. 4.3.2 The #VE 6= algorithm In this section we describe the #VE 6= algorithm for counting the number of solu- tions to CSPs with inequality constraints. The core of the #VE 6= algorithm is the same as the #VE algorithm (see Section 4.2.2), but #VE 6= is a lifted algorithm, that is, it reasons at a higher level of abstraction than does #VE. In particular, a #VE 6= factor (Section 4.3.2.2) is more complicated than the corresponding #VE factor, but one tuple in a #VE 6= factor represents many tuples in a #VE factor. Assume we are given the CSP instance P = (X,D,C), X = {X1, . . . ,Xn}, C = {C1, . . . , Cl,Cl+1, . . . ,Cr} where C1, . . . ,Cl are unary constraints and Cl+1, . . . ,Cr are binary constraints. We use D̂(X j) to denote the domain D(X j) without those values that are excluded by the unary constraints C1, . . . ,Cl . 117 4.3.2.1 S-constants Following the analysis presented in Section 4.3.1 we partition domains of variables into disjoint sets of values from these domains. We use s-constants to represent such sets. Each s-constant denotes a (non-empty) set of domain values. The sets of domain values associated with different s-constants are assumed to be disjoint. With each s-constant, we have the size of the set it denotes. Instead of reasoning with individual domain values, we can reason with these s-constants. In the rest of this chapter, we will at times treat an s-constant as a set (as is done in normal mathematics); in this case, we mean the set the s-constant denotes. Note that the algorithm never deals with the sets that the s-constants denote (we don’t assume that it has access to these sets). Example 4.8. In Example 4.7 variables A and C have the same domain of size d, let D(A) = D(C) = {x1, . . . ,xd}. Variables B and D have the same domain of size d+ d′, such thatD(B)∩D(A) =D(A), letD(B) =D(D) = {x1, . . . ,xd ,xd+1, . . . ,xd+d′}. We need two s-constants to represent values from domains of these four variables: c1 that represents values in domains of all four variables, {x1, . . . ,xd}, and c2 that denotes the d′ extra values in domains of B and D, {xd+1, . . . ,xd+d′}. For the purpose of our algorithm we can represent domains of the variables as follows: D(A) = D(C) = c1 and D(B) = D(D) = c1 ∪ c2. The only additional information we will require is that c1 represents d values and c2 represents d′ values. 4.3.2.2 #VE 6= factors A #VE 6= factor F on variables Y1, . . . ,Ym is a function from a set of #VE 6= tuples into the natural numbers. A #VE 6= tuple 〈c1, . . . ,ck, [pic1 . . .pick ]〉 consists of: • an s-constant ci for each variable; • a set of partitions that contains for each set of variables represented by the same s-constant ci, a partition pici of these variables. In text we use square brackets to form a set of partitions to avoid confusion with curly brackets of partitions within the set. For the same reason we do not separate partitions with commas. We skip the brackets when displaying #VE 6= factors. 118 Example 4.9. Let us continue Examples 4.7 and 4.8. Constraints A 6= B and B 6=D can be represented by the following #VE 6= factors: A B Partition(s) # c1 c1 {{A,B}} 0 c1 c1 {{A},{B}} 1 c1 c2 {{A}} {{B}} 1 B D Partition(s) # c1 c1 {{B,D}} 0 c1 c1 {{B},{D}} 1 c1 c2 {{B}} {{D}} 1 c2 c1 {{B}} {{D}} 1 c2 c2 {{B,D}} 0 c2 c2 {{B},{D}} 1 The #VE 6= factor representing the constraint A 6= B, FA6=B, contains three #VE 6= tuples. The first one, 〈c1,c1, [{{A,B}}]〉, represents the set of tuples from the Carte- sian product of subsets of domains of A and B represented by c1, namely c1×c1 = {x1, . . . ,xd}×{x1, . . . ,xd}, that satisfy the constraint A= B, which is implicit in the partition {{A,B}}. Such tuples do not satisfy the constraint A 6= B represented by the factor and are assigned value 0. The second #VE 6= tuple, 〈c1,c1, [{{A},{B}}]〉, represents the set of tuples from c1× c1 = {x1, . . . ,xd}×{x1, . . . ,xd} that satisfy the constraint represented by the partition {{A},{B}}, that is A 6= B. These tuples are assigned value 1. Finally, the third #VE 6= tuple, 〈c1,c2, [{{A}} {{B}}]〉, repre- sents the set of tuples from the Cartesian product of subsets of domains of A and B represented by s-constants c1 and c2, c1× c2 = {x1, . . . ,xd}×{xd+1, . . . ,xd+d′}. These subsets are disjoint and each variable is in a partition by itself, meaning that there is no constraint encoded. All tuples from the product satisfy the constraint A 6= B and are assigned value 1. Suppose s-constant ci denotes the set Si. The number associated with the #VE 6= tuple t = 〈 c j1 , . . . ,c jm ,Π 〉 in a #VE 6= factor F will be the same as the number in the corresponding #VE factor on Y1, . . . ,Ym associated with each tuple from S j1 × ·· ·× S jm that satisfies the equality and inequality constraints implicit in the partitions Π (each of these tuples is associated with the same number). We call the corresponding #VE factor a grounding of the factor F, and denote it as G(F). We denote the tuples from G(F) corresponding to t by G(t) and call them ground tuples. 119 Example 4.10. Consider the #VE 6= factor representing constraint A 6= B from Ex- ample 4.9. Below we show its grounding: A B # x1 x1 0 ... ... ... x1 xd 1 x1 xd+1 1 ... ... ... x1 xd+d′ 1 ... ... ... xd x1 1 ... ... ... xd xd 0 xd xd+1 1 ... ... ... xd xd+d′ 1 As with implementation of matrices, we can have either dense representations, for example, using 1-dimensional arrays where we can quickly index any value but need to store zeros, or sparse representations that allow us to avoid storing zeros or repeated structure but are slower when there are few zeros. The examples will show zeros when we think it makes it clearer, but an implementation should do whichever is more efficient. Appendix B shows how to implement the dense representation of factors using a hierarchy of 1-dimensional arrays, so that instead of storing both #VE 6= tuples and values in memory, we only need to store values. To describe the #VE 6= algorithm, we need to modify multiplication and sum- ming out operators so they can handle a richer representation of #VE 6= factors. In the example below we show a CSP represented with s-constants and #VE 6= factors. We will use this CSP to illustrate operations on #VE 6= factors in Sec- tions 4.3.2.3 and 4.3.2.4. 120 D(A) = {x1,x2,x3,x4,x5,x6} D(B) = {x1,x2,x3,x4,x5,x6,x7,x8} D(C) = {x1,x2,x3,x4,x5} C= {A 6= x1,A 6= x6,A 6= B,A 6=C B 6= x2,B 6= x5,B 6= x6,B 6= x7, C 6= x1} A B C 6=6= Figure 4.8: A CSP used in Examples 4.11–4.15. Example 4.11. Consider the CSP presented in Figure 4.8 with D̂(A) = {x2,x3, x4,x5}, D̂(B) = {x1,x3,x4,x8} and D̂(C) = {x2,x3,x4,x5}. Let S0 = {x3,x4}, S1 = {x1,x8}, S2 = {x2,x5}. Then D̂(A) = S0∪S2, D̂(B) = S0∪S1, and D̂(B) = S0∪S2. Let s-constant ci denote Si. When counting the number of solutions, we are not concerned with values; all we need are the counts. We can thus represent this example using two factors, FA6=B and FA 6=C, and three numbers: A B Partition(s) # c0 c0 {{A,B}} 0 c0 c0 {{A},{B}} 1 c0 c1 {{A}} {{B}} 1 c2 c0 {{A}} {{B}} 1 c2 c1 {{A}} {{B}} 1 A C Partition(s) # c0 c0 {{A,C}} 0 c0 c0 {{A},{C}} 1 c0 c2 {{A}} {{C}} 1 c2 c0 {{A}} {{C}} 1 c2 c2 {{A,C}} 0 c2 c2 {{A},{C}} 1 size(c0) = 2 size(c1) = 2 size(c2) = 2 #VE 6= tuples in the above #VE 6= factors that are typeset in bold could be pruned as they are assigned value 0. 4.3.2.3 Multiplication Example 4.12. Consider the factors presented in Example 4.11. The third #VE 6= tuple from the FA 6=B factor, 〈c0,c1, [{{A}} {{B}}]〉, represents all tuples from c0× c1. The second #VE 6= tuple from theFA 6=C factor, 〈c0,c0, [{{A},{C}}]〉, represents all tuples from c0× c0 such that A 6= C. The product of these two #VE 6= tuples represents all tuples from c0× c1× c0 such that A 6=C and can be represented by a #VE 6= tuple 〈c0,c1,c0, [{{A}{C}} {{B}}]〉. The second #VE 6= tuple from theFA 6=B factor, 〈c0,c0, [{{A},{B}}]〉, represents all tuples from c0× c0 such that A 6= B. The product of this #VE 6= tuple with the 121 second #VE 6= tuple from the FA 6=C factor represents all tuples from c0× c0× c0 such that A 6= B and A 6= C. This is not present in the form of a #VE 6= tuple in a product factor, as constraints A 6= B and A 6= C do not uniquely identify a partition of the set {A,B,C}. There are two cases: B = C and B 6= C. The first case corresponds to the partition {{A},{B,C}}, and the second to the partition {{A},{B},{C}}. The resulting #VE 6= factor has one #VE 6= tuple for each of these two cases: 〈c0,c0,c0, [{{A},{B,C}}]〉 and 〈c0,c0,c0, [{{A},{B},{C}}]〉, respec- tively. We can multiply #VE 6= factors as we do standard factors (see Equation 2.1), treating the s-constants as domain values, except for the case where the same s- constant is used for multiple variables in the product. In this case, we need to create new #VE 6= tuples for each partition of the variables that is consistent with the partitions of the #VE 6= tuples being multiplied (consistency is defined treating a partition as a set of equality and inequality statements). As a special case, if the partitions are inconsistent, no #VE 6= tuples are produced. We can also prune any #VE 6= tuple that has more blocks in the partition for a s-constant than there are values in the set represented by the s-constant. We denote a multiplication operator described above by 6= and define it formally below. Suppose F1 is a #VE 6= factor on variables X1, . . . ,Xi,Y1, . . . ,Yj, and F2 is a #VE 6= factor on variables Y1, . . . ,Yj,Z1, . . . ,Zl , where sets {X1, . . . ,Xi}, {Y1, . . . ,Yj} and {Z1, . . . ,Zl} are pairwise disjoint. The product of F1 and F2 is a #VE 6= fac- tor F16=F2 on the union of the variables, namely X1, . . . ,Xi,Y1, . . . ,Yj,Z1, . . . ,Zl , defined by: (F16=F2)(〈cX ,cY ,cZ,Π〉) = F1(〈cX ,cY ,Π1〉)F2(〈cY ,cZ,Π2〉) , (4.3) where • cX , cY , and cZ represent s-constants corresponding to variables X1, . . . ,Xi, Y1, . . . ,Yj, and Z1, . . . ,Zl , respectively; • Π is a set of partitions, one partition per each subset of variables X1, . . . ,Xi,Y1, . . . ,Yj,Z1, . . . ,Zl assigned the same s-constant, Π1 is a set of partitions, one partition per each subset of variables X1, . . . ,Xi,Y1, . . . ,Yj assigned the same 122 s-constant, and Π2 is a set of partitions, one partition per each subset of variables Y1, . . . ,Yj,Z1, . . . ,Zl assigned the same s-constant; • Π is consistent with Π1 and Π2, that is ⋃ pi∈Π C(pi)⊇ ⋃ pi1∈Π1 C(pi1)∪ ⋃ pi2∈Π2 C(pi2). (4.4) If we do not prune any #VE 6= tuples, for each #VE 6= tuple from F16=F2, there exists exactly one #VE 6= tuple from F1 and exactly one #VE 6= tuple from F2 that satisfies condition (4.4). If we allow pruning, these #VE 6= tuples might not exist and in such case the corresponding #VE 6= tuple in the product F16=F2 is not created. Example 4.13. Let us multiply the two #VE 6= factors from Example 4.11. Assume that we have pruned 0-valued #VE 6= tuples from the input factors. We have num- bered the input #VE 6= tuples and shown where the resulting #VE 6= tuples came from: A B Partition(s) # [1] c0 c0 {{A},{B}} 1 [2] c0 c1 {{A}} {{B}} 1 [3] c2 c0 {{A}} {{B}} 1 [4] c2 c1 {{A}} {{B}} 1 A C Partition(s) # [5] c0 c0 {{A},{C}} 1 [6] c0 c2 {{A}} {{C}} 1 [7] c2 c0 {{A}} {{C}} 1 [8] c2 c2 {{A},{C}} 1 6=−−−→ A B C Partition(s) # [1 ·5] c0 c0 c0 {{A},{B,C}} 1 [1 ·5] c0 c0 c0 {{A},{B},{C}} 1 [1 ·6] c0 c0 c2 {{A},{B}} {{C}} 1 [2 ·5] c0 c1 c0 {{A},{C}} {{B}} 1 [2 ·6] c0 c1 c2 {{A}} {{B}} {{C}} 1 [3 ·7] c2 c0 c0 {{A}} {{B,C}} 1 [3 ·7] c2 c0 c0 {{A}} {{B},{C}} 1 [3 ·8] c2 c0 c2 {{A},{C}} {{B}} 1 [4 ·7] c2 c1 c0 {{A}} {{B}} {{C}} 1 [4 ·8] c2 c1 c2 {{A},{C}} {{B}} 1 Note that a #VE 6= tuple 〈c0,c0,c2, [{{A,B}} {{C}}]〉 is not present in the product factor. It is because a #VE 6= tuple 〈c0,c0, [{{A,B}}]〉 is not present in the FA 6=B as it has been pruned. Let us discuss the #VE 6= tuple products from Example 4.12 in context of Equa- tion 4.3. Consider a #VE 6= tuple 〈c0,c1,c0,Π〉, Π = [{{A}{C}} {{B}}] from the prod- uct factor. The value assigned to this #VE 6= tuple is the product of the value as- signed to a #VE 6= tuple 〈c0,c1,Π1〉 by FA 6=B and the value assigned to a #VE 6= 123 tuple 〈c0,c0,Π2〉 by FA 6=C, where Π1 = [{{A}} {{B}}] and Π2 = [{{A},{C}}]. Partitions Π1 and Π2 are the only partitions that are consistent with Π for #VE 6= tuples on A= c0,B= c1 fromFA 6=B and #VE 6= tuples on A= c0,C= c0 fromFA6=C, respectively. Consider a #VE 6= tuple 〈c0,c0,c0,Π〉, Π = [{{A},{B,C}}] from the product factor. The value assigned to this #VE 6= tuple is the product of the value assigned to a #VE 6= tuple 〈c0,c0,Π1〉 by FA 6=B and the value assigned to a #VE 6= tuple 〈c0,c0,Π2〉 〈c0,c0,Π2〉 byFA6=C, whereΠ1 = [{{A},{B}}] andΠ2 = [{{A},{C}}]. Partitions Π1 and Π2 are the only partitions that are consistent with Π for #VE 6= tuples on A= c0,B= c0 fromFA6=B and #VE 6= tuples on A= c0,C= c0 fromFA6=C, respectively. Finally, consider a #VE 6= tuple 〈c0,c0,c0,Π〉, Π= [{{A},{B},{C}}] from the product factor. The value assigned to this #VE 6= tuple is the product of the values assigned to the same #VE 6= tuples as above, namely 〈c0,c0,Π1〉 and 〈c0,c0,Π2〉. Partitions Π1 and Π2 are the only partitions that are consistent with Π for #VE 6= tuples on A= c0,B= c0 fromFA6=B and #VE 6= tuples on A= c0,C= c0 fromFA6=C, respectively. Note that we can prune the second #VE 6= tuple from the product factor as size(c0) = 2. There are two values in the set denoted by c0, and if there are more than two blocks in the partition, it is impossible to assign variables to values. If we do not prune the second #VE 6= tuple, it will eventually get multiplied by zero (in this case when A is summed out, see Example 4.14 and Equation 4.5). Theorem 4.2. Let f1 and f2 be two #VE 6= factors. Then G( f16= f2) = G( f1)G( f2). Proof. Suppose F1 is a #VE 6= factor on variables X1, . . . ,Xi,Y1, . . . ,Yj, and F2 is a #VE 6= factor on variables Y1, . . . ,Yj,Z1, . . . ,Zl , where sets {X1, . . . ,Xi}, {Y1, . . . ,Yj} and {Z1, . . . ,Zl} are pairwise disjoint. #VE 6= tuples in F1 and F2 represent exactly ground tuples in G(F1) and G(F2), respectively. While computing the product F16=F2, the #VE 6= algorithm attempts to multiply all of the #VE 6= tuples from F1 by all of the #VE 6= tuples from F2. We start by showing that G(F16=F2)⊇ G(F1)G(F2). 124 Suppose that t ′ ∈ G(F1)G(F2) where the value of t ′ is v. Then, by the defi- nition of , there exist tuples t ′1 ∈ G(F1) with value v1 and t ′2 ∈ G(F2) with value v2 such that t ′ = t ′1 t ′2 and v = v1 · v2. By the definition of G(), there exist #VE 6= tuples t1 ∈ F1 with value v1 and t2 ∈ F2 with value v2 such that t ′1 ∈ G(t1) and t ′2 ∈ G(t2). Tuple t ′1 is equal to t ′2 at positions of variables Y1, . . . ,Yj (since they were multiplied together by the #VE algorithm) and so t1 is equal to t2 at positions of variables Y1, . . . ,Yj (since s-constants in #VE 6= tuples denote disjoint sets of domain values). Also, partitions in t1 are consistent with partitions in t2; otherwise, partitions in one of the #VE 6= tuples t1, t2 would have variables Yn and Ym, 1 ≤ n,m ≤ j, n 6= m in one block while partitions from the other #VE 6= tuple have them in different blocks. This would imply that in one of the tuples t ′1, t ′ 2 elements at positions of variables Yn and Ym are the same, while in the other there are different elements at these positions, which we know is not the case. Thus t1 and t2 are multiplied together by the #VE 6= algorithm, and their product has the value v1v2 = v in F16=F2. It is easy to see that t ′ belongs to the grounding of the product of t1 and t2, hence t ′ ∈ G(F16=F2). Now we will show that G(F16=F2)⊆ G(F1)G(F2). Suppose t ′ ∈ G(F16=F2), where the value of t ′ is v. Then by the definition of G(), a #VE 6= tuple t ∈ F16=F2 exists such that t ′ ∈ G(t). By the definition of 6= there exists a #VE 6= tuple t1 from F1 with value v1 and a #VE 6= tuple t2 from F2 with value v2, such that t ∈ t16= t2 (multiplication of two #VE 6= tuples may result in more than one #VE 6= tuple) and v = v1v2. Let t ′1 be the element of G(t1) that is identical to t ′ at positions of variables X1, . . . ,Xi, Y1, . . . ,Yj. This element must exist because t1 is identical to t at the positions of variables X1, . . . ,Xi, Y1, . . . ,Yj, and the partitions of t1 are the subset of the partitions of t. In an analogous way, we can show that there is a tuple t ′2 ∈ G(t2) that is identical to t ′ at the positions of variables Y1, . . . ,Yj,Z1, . . . ,Zl . #VE 6= tuples t1 and t2 are equal at positions of variables Y1, . . . ,Yj, and parti- tions from t1 are consistent with partitions from t2; otherwise, they could not be multiplied. This means that the #VE algorithm would multiply each tuple from G(t1) by each tuple from G(t2). Thus, tuples t ′1 and t ′2 would be multiplied by the #VE algorithm. It is easy to see that t ′1 t ′2 = t ′, hence t ′ ∈ G(F1)G(F2). 125 4.3.2.4 Summing out To motivate the summation operation in the #VE 6= algorithm, we review the anal- ogous operator in the #VE algorithm: when summing out a variable X from a factor, each tuple contributes its count to the resulting tuple in the new factor. That is, each tuple 〈 X = x,Y = y 〉 with value v (where Y is the other variables), adds v to the resulting tuple 〈 Y = y 〉 . The complication with #VE 6= is that each #VE 6= tuple represents many different ground tuples. To sum out a variable X from a #VE 6= factor we go through each #VE 6= tuple in the factor, and determine which part of the resulting #VE 6= factor it contributes to and how much it contributes. Suppose the #VE 6= tuple under consideration is〈 X = cX ,Y = cY ,Π 〉 and its value is v. We want to determine the effective count of this #VE 6= tuple with respect to X . The effective count of a #VE 6= tuple 〈 X = cX ,Y = yY ,Π 〉 with respect to vari- able X is the number of ways X can be assigned to values represented by s-constant cX given assignments of values to variables Y . Consider a partition piX ∈ Π that contains X . If X is in the same block as another variable, the effective count is 1. If X is in a block by itself, the effective count is size(cX) minus the number of other blocks in piX unless the number of other blocks is greater than size(cX), in which case the effective count is 0. Example 4.14. Consider a #VE 6= tuple 〈c0,c0,c0, [{{A},{B,C}}]〉 from the prod- uct #VE 6= factor from Example 4.13. Recall that size(c0) = 2. In the only partition in this #VE 6= tuple, variable A is in a block by itself and there is one more block. Therefore the effective count of this #VE 6= tuple with respect to A is 2− 1 = 1. Variable B is in the same block as C. The effective count of this #VE 6= tuple with respect to B is 1. Consider another #VE 6= tuple, 〈c0,c0,c0, [{{A},{B},{C}}]〉, from the same #VE 6= factor. In this #VE 6= tuple, variable A is in a block by itself and there are two more blocks. The effective count of this #VE 6= tuple with respect to A is 2−2 = 0. 126 The #VE 6= tuple 〈 X = cX ,Y = cY ,Π 〉 , then, contributes v times the effective count of X to the #VE 6= tuple 〈 Y = cY ,Π′ 〉 from the resulting #VE 6= factor, where Π′ is the same as Π but with X removed from the appropriate partition. We assume that Π′ is simplified so that empty blocks are removed. We denote a summation operator described above by ∑6= and define it formally below. Suppose F is a #VE 6= factor on variables X1, . . . ,Xi−1,Xi,Xi+1, . . . ,Xn. The summing out of variable Xi from F, denoted as ∑6=XiF, is the #VE 6= factor on vari- ables X1, . . . ,Xi−1,Xi,Xi+1, . . . ,Xn such that:( ∑6=XiF )(〈 c1,cn,Π′ 〉) = ∑ ci∈D(Xi) (F(〈c1,ci,cn,Π〉) · ec(〈c1,ci,cn,Π〉 ,Xi)) , (4.5) where • c1 and cn represent s-constants corresponding to variables X1, . . . ,Xi−1 and Xi+1, . . . ,Xn, respectively; • Π′ is a set of partitions obtained by removing variable Xi from the appropriate partition in Π; • ec(〈c1,ci,cn,Π〉 ,Xi) is the effective count of #VE 6= tuple 〈c1,ci,cn,Π〉 with respect to variable Xi. Example 4.15. Let us sum out A from the product factor from Example 4.13. We have numbered the input #VE 6= tuples and shown where the resulting #VE 6= tuples came from: A B C Partition(s) # [1] c0 c0 c0 {{A},{B,C}} 1 [2] c0 c0 c2 {{A},{B}} {{C}} 1 [3] c0 c1 c0 {{A},{C}} {{B}} 1 [4] c0 c1 c2 {{A}} {{B}} {{C}} 1 [5] c2 c0 c0 {{A}} {{B,C}} 1 [6] c2 c0 c0 {{A}} {{B},{C}} 1 [7] c2 c0 c2 {{A},{C}} {{B}} 1 [8] c2 c1 c0 {{A}} {{B}} {{C}} 1 [9] c2 c1 c2 {{A},{C}} {{B}} 1 ∑6=A−−→ B C Partition(s) # [1+5] c0 c0 {{B,C}} 1+2=3 [6] c0 c0 {{B},{C}} 2 [2+7] c0 c2 {{B}} {{C}} 1+1=2 [3+8] c1 c0 {{B}} {{C}} 1+2=3 [4+9] c1 c2 {{B}} {{C}} 2+1=3 The #VE 6= tuple labeled [1] provides a (size(c0)− 1) · 1 = 1 contribution to the #VE 6= tuple labeled [1+ 5]. The #VE 6= tuple labeled [5] provides size(c2) · 1 = 2 127 contribution to the same #VE 6= tuple. Thus the #VE 6= tuple labeled [1+ 5] has a value of 3 in the resulting #VE 6= factor shown above. Notice that if the size of the sets associated with the s-constants was big- ger, there would have been one extra #VE 6= tuple resulting from Example 4.13, namely 〈c0,c0,c0, [{{A},{B},{C}}]〉, but otherwise we would just be multiplying and adding bigger numbers. Theorem 4.3. Let F be a #VE 6= factor and X be a variable. Then G(∑6=X F) =∑ X G(F). Proof. Suppose F is a #VE 6= factor on variables Y1, . . . ,X , . . . ,Yn (if F is not a factor on X , then the theorem is trivially true). We start by showing, that G(∑6=X F)⊇ ∑X G(F). Suppose that t ′ = 〈y1, . . . ,yn〉 ∈∑X G(F) and value of t ′ is v. Then, by the defi- nition of ∑ there exist tuples t ′1 = 〈y1, . . . ,x1, . . . ,yn〉 , . . . , t ′m = 〈y1, . . . ,xm, . . . ,yn〉 ∈ G(F), with values v1, . . . ,vm such that v = v1 + · · ·+ vm. Values x1, . . . ,xm belong to sets of domains values denoted by s-constants c1, . . . ,c j, where j ≤ m. By the definition of G() for each t ′i , 1≤ i≤m there exists a #VE 6= tuple tk ∈F, 1 ≤ k ≤ j with s-constant ck at the position of variable X such that t ′i ∈ G(tk). Tuples t1, . . . , t j are identical at all positions except for the position of variable X (because corresponding ground tuples are identical at those positions). Also, all of their partitions not involving variable X are identical; otherwise, partitions in one of the #VE 6= tuples t1, . . . , t j would have variables Yp and Yr, 1≤ p,r ≤ n, p 6= r in one block while partitions from the other #VE 6= tuple would have them in different blocks. This scenario would imply that in one of the tuples t ′1, . . . , t ′ m elements at positions of variables Yp and Yr are the same, while in the other there are different elements at these positions, which we know is not the case. The above conclusion means that the #VE 6= algorithm would add together #VE 6= tuples t1, . . . , t j during summing out of X . Such summation would yield a #VE 6= tuple t with the same s-constants at positions of variables Y1, . . . ,Yn as tu- ples t1, . . . , t j, and with overall contribution to the value of t from the s-constants c1, . . . ,c j equal to v. It is easy to see that t ′ ∈ G(t), hence t ′ ∈ G(∑6=X F). 128 Now we will show that G(∑6=X F)⊆ ∑X G(F). Consider a tuple t ′ ∈ G(∑6=X F) where the value of t ′ is v. By the definition of G(), there exists a #VE 6= tuple t = 〈cy1 , . . . ,cyn ,Π〉 ∈ ∑6=X F with value v such that t ′ ∈ t. Then, by the definition of∑6=, there exist tuples t1 = 〈cy1 , . . . ,cx1 , . . . ,cyn ,Π1〉 , . . . , t j = 〈 cy1 , . . . ,cx j , . . . ,cyn ,Π j 〉 ∈ F (for partitions Πi,1 ≤ i ≤ j, if we remove the partition containing X , we obtain partitions Π) with values v1, . . . ,v j, with t obtained by adding together t1, . . . , t j. Let us denote the effective count of ti with respect to X by ec(ti,X), 1≤ i≤ j. Then we have v = ∑ ji=1 vi · ec(ti,X). Tuple t ′ corresponds to the sum of ec(t1,X) tuples from G(t1) with value v1, ec(t2,X) tuples from G(t2) with value v2, . . . , ec(t j,X) tuples from G(t j) with value v j. All of these ground tuples were identical to t ′ at positions of variables Y1, . . . ,Yn; no other tuples in G(F) had this property. The #VE algorithm would add all of those tuples and obtain t ′ as a result, hence t ′ ∈ ∑X G(F). 4.3.2.5 The algorithm The #VE 6= algorithm is presented in Figure 4.9. It reassembles the #VE algorithm (see Section 4.2.2 and Figure 4.1 on page 110) as well as the VE algorithm for inference in belief networks (see Section 2.3.2 and Figure 2.2 on page 10). As in the #VE algorithm for #CSP, we maintain the following invariant: at each step of the computation, the product of all factors that exist at this step asso- ciates with its tuples the number of consistent extensions to the previously elim- inated variables. If, given a CSP instance P = (X,D,C), we use the procedure #CSP_VE 6=(P,E,H) presented in Figure 4.9 to eliminate all variables (E= X), we obtain a factor on the empty set of variables, which is simply a number equal to the number of solutions to the input CSP instance. As in the case of the #VE al- gorithm, if we decide to eliminate only some of the variables (E ⊂ X), we end up with a factor giving us the number of solutions for each combination of values of variables X\E. A procedure for constructing a #VE 6= factor-based representation of a CSP in- stance is shown in Figure 4.10. The procedure does not create 0-valued tuples. It also assumes that s-constants and sizes of the corresponding disjoint sets of domain values are given as the input data. In Section 4.3.4.1, we comment on the complex- 129 [00] procedure #CSP_VE6=(P,E,H) [01] input: CSP instance P= (X,D,C) with only inequality constraints [02] domains in D consist of s disjoint sets S1, . . . ,Ss [03] sets are represented through s s-constants c1, . . . ,cs [04] s-constants have counts size(c1), . . . ,size(cs), [05] set of variables to eliminate E⊆ X, [06] elimination ordering heuristic H; [07] output: factor representing the solution; [08] set F := initialize_VE6=(P); [09] while there is a factor in F involving a variable from E do [10] select variable Xi ∈ E according to H; [11] set F :=eliminate_VE6=(Xi,F,size(c1), . . . ,size(cs)); [12] set E := E\Xi; [13] end [14] return ⊙6= F∈FF; [15] end [16] procedure eliminate_VE6=(Xi,F,size(c1), . . . ,size(cs)) [17] input: variable to be eliminated Xi, [18] set of factors F, [19] counts size(c1), . . . ,size(cs); [20] output: set of factors F with Xi summed out; [21] partition F= {F1, . . . ,Fm} into {F1, . . . ,Fl} that do not contain Xi and [22] {Fl+1, . . . ,Fm} that do contain Xi; [23] return {F1, . . . ,Fl ,∑ 6=XiFl+16= . . .6=Fm}; [24] end Figure 4.9: #VE 6= algorithm for #CSP with inequality constraints. ity of constructing these data from the most basic, array-based representation of the input CSP instance. In Appendix C we show an example which illustrates how it is computed in our implementation of the lifted probabilistic inference algorithm. In the next section, we apply our #VE 6= algorithm to a problem with large domains. 130 [00] procedure initialize_VE6=(P) [01] input: CSP instance P= (X,D,C); [02] output: representation of P as a set of factors F; [03] set F := /0; [04] for every binary inequality constraint Ci in C, where S(Ci) = {Xu,Xv} do [05] create factor Fi on Xu,Xv: [06] if Si ⊂ D̂(Xu),S j ⊂ D̂(Xv) and Si 6= S j [07] create tuple 〈 ci,c j, [{{Xu}} {{Xv}}] 〉 with value 1; [08] if Si ⊂ D̂(Xu),Si ⊂ D̂(Xv) and size(ci)> 1 [09] create tuple 〈ci,ci, [{{Xu},{Xv}}]〉 with value 1; [10] set F := F∪{Fi}; [11] end [12] return F; [13] end Figure 4.10: Initialization procedure for the #VE 6= algorithm. A B C D 6= 6= 6= 6= D(A) = {x1,x2, . . . ,x10000} D(B) = D(C) = D(D) = {x1,x2, . . . ,x5000} C= {A 6= x1,A 6= x3,A 6= x4,A 6= x5,A 6= B,A 6=C, B 6= x1,B 6= x2,B 6= x3,B 6= x5,B 6= D, C 6= x1,C 6= x3,C 6= x5,C 6= D, D 6= x1,D 6= x2,D 6= x3,D 6= x5}. Figure 4.11: A CSP used in Section 4.3.3. 4.3.3 Example computation Consider the CSP instance presented in Figure 4.11. We want to compute the number of models for different values of D using our algorithm, with elimination ordering ρ = 〈A,B,C〉. After processing all unary constraints, we obtain: D̂(A) = {x2,x6, . . . ,x10000}, D̂(C) = {x2,x4,x6, . . . ,x5000}, and D̂(B) = D̂(D) = {x4,x6, . . . ,x5000}. 131 Let S0 = {x2}, S1 = {x4}, S2 = {x6, . . . ,x5000}, and S3 = {x5001, . . . ,x10000}. Then D̂(A) = S0∪S2∪S3, D̂(B) = S1∪S2, D̂(C) = S0∪S1∪S2 and D̂(D) = S1∪S2. Let s-constant ci denote Si, i = 0,1,2,3. The CSP instance can be described using four #VE 6= factors and four numbers shown below. In what follows, #VE 6= tuples that are typeset in bold are pruned, either because they are assigned value 0, or because the effective count of one of the s-constants in the #VE 6= tuple is 0. (i) A B Partition(s) # c0 c1 {{A}}{{B}} 1 c0 c2 {{A}}{{B}} 1 c2 c1 {{A}}{{B}} 1 c2 c2 {{A,B}} 0 c2 c2 {{A},{B}} 1 c3 c1 {{A}}{{B}} 1 c3 c2 {{A}}{{B}} 1 (iii) B D Partition(s) # c1 c1 {{B,D}} 0 c1 c1 {{B},{D}} 1 c1 c2 {{B}}{{D}} 1 c2 c1 {{B}}{{D}} 1 c2 c2 {{B,D}} 0 c2 c2 {{B},{D}} 1 size(c0) = 1 size(c1) = 1 size(c2) = 4995 size(c3) = 5000 (ii) A C Partition(s) # c0 c0 {{A,C}} 0 c0 c0 {{A},{C}} 1 c0 c1 {{A}}{{C}} 1 c0 c2 {{A}}{{C}} 1 c2 c0 {{A}}{{C}} 1 c2 c1 {{A}}{{C}} 1 c2 c2 {{A,C}} 0 c2 c2 {{A},{C}} 1 c3 c0 {{A}}{{C}} 1 c3 c1 {{A}}{{C}} 1 c3 c2 {{A}}{{C}} 1 (iv) C D Partition(s) # c0 c1 {{C}}{{D}} 1 c0 c2 {{C}}{{D}} 1 c1 c1 {{C,D}} 0 c1 c1 {{C},{D}} 1 c1 c2 {{C}}{{D}} 1 c2 c1 {{C}}{{D}} 1 c2 c2 {{C,D}} 0 c2 c2 {{C},{D}} 1 132 To eliminate A, we multiply factors (i) and (ii), and sum out A from their product. As a result we obtain factor (v): A B C Partition(s) # c0 c1 c1 {{A}}{{B,C}} 1 c0 c1 c1 {{A}}{{B},{C}} 1 c0 c1 c2 {{A}}{{B}}{{C}} 1 c0 c2 c1 {{A}}{{B}}{{C}} 1 c0 c2 c2 {{A}}{{B,C}} 1 c0 c2 c2 {{A}}{{B},{C}} 1 c2 c1 c0 {{A}}{{B}}{{C}} 1 c2 c1 c1 {{A}}{{B,C}} 1 c2 c1 c1 {{A}}{{B},{C}} 1 c2 c1 c2 {{A},{C}}{{B}} 1 c2 c2 c0 {{A},{B}}{{C}} 1 c2 c2 c1 {{A},{B}}{{C}} 1 c2 c2 c2 {{A},{B,C}} 1 c2 c2 c2 {{A},{B},{C}} 1 c3 c1 c0 {{A}}{{B}}{{C}} 1 c3 c1 c1 {{A}}{{B,C}} 1 c3 c1 c1 {{A}}{{B},{C}} 1 c3 c1 c2 {{A}}{{B}}{{C}} 1 c3 c2 c0 {{A}}{{B}}{{C}} 1 c3 c2 c1 {{A}}{{B}}{{C}} 1 c3 c2 c2 {{A}}{{B,C}} 1 c3 c2 c2 {{A}}{{B},{C}} 1 ∑6=A−−−→ (v) B C Partition(s) # c1 c0 {{B}}{{C}} 9995 c1 c1 {{B,C}} 9996 c1 c2 {{B}}{{C}} 9995 c2 c0 {{B}}{{C}} 9994 c2 c1 {{B}}{{C}} 9995 c2 c2 {{B,C}} 9995 c2 c2 {{B},{C}} 9994 To eliminate B, we multiply factors (iii) and (v), and sum out B from their product. As a result we obtain factor (vi): B C D Partition(s) # c1 c0 c2 {{B}}{{C}}{{D}} 9995 c1 c1 c2 {{BC}}{{D}} 9996 c1 c2 c2 {{B}}{{C,D}} 9995 c1 c2 c2 {{B}}{{C},{D}} 9995 c2 c0 c1 {{B}}{{C}}{{D}} 9994 c2 c0 c2 {{B},{D}}{{C}} 9994 c2 c1 c1 {{B},{{C,D}} 9995 c2 c1 c1 {{B},{{C},{D}} 9995 c2 c1 c2 {{B},{D}}{{C}} 9995 c2 c2 c1 {{B,C}}{{D}} 9995 c2 c2 c1 {{B},{C}}{{D}} 9994 c2 c2 c2 {{B},{C,D}} 9994 c2 c2 c2 {{B,C},{D}} 9995 c2 c2 c2 {{B},{C},{D}} 9994 ∑6=B−−−→ (vi) C D Partition(s) # c0 c1 {{C}}{{D}} 49920030 c0 c2 {{C}}{{D}} 49920031 c1 c1 {{C,D}} 49925025 c1 c2 {{C}}{{D}} 49925026 c2 c1 {{C}}{{D}} 49920031 c2 c2 {{C,D}} 49920031 c2 c2 {{C},{D}} 49920032 133 Finally, to eliminate C, we multiply factors (iv) and (vi), and sum out C from their product. As a result we obtain factor (vii): C D Partition(s) # c0 c1 {{C}}{{D}} 49920030 c0 c2 {{C}}{{D}} 49920031 c1 c2 {{C}}{{D}} 49925026 c2 c1 {{C}}{{D}} 49920031 c2 c2 {{C},{D}} 49920032 ∑6=C−−−→ (vii) D Partition(s) # c1 {{D}} 249400474875 c2 {{D}} 249400484865 To obtain the final result, we would normally multiply all the remaining factors, but for this example we are left only with factor (vii), so it provides our solution: for D = x4, the given CSP instance has 249400474875 solutions, and for each value xi from D = {x6,x7, . . . ,x5000}, it has 249400484865 solutions. Eliminating D from factor (vii) would give us the overall number of solutions: |P|= 249400474875+249400484865 ·4995 = 1246004822375550 . 4.3.4 Complexity of the algorithm In Section 4.3.4.1, we discuss the complexity of constructing s-constants and sizes of the corresponding disjoint sets of domain values. In Section 4.3.4.2, we analyze the complexity of inference in #VE 6=. 4.3.4.1 Preprocessing The complexity of the preprocessing phase depends highly on the representation of the input problem instance. One can expect that if the domains of the variables in a CSP instance are very large, then they will be represented using functions and relations. Such representation might allow for a very efficient construction of disjoint subsets without enumerating the values of any domain. (see Appendix C). To obtain a fair comparison of the preprocessing costs for #VE and #VE 6= we analyze below the most basic, array-based representation, which does not favor the #VE 6= algorithm. Assume that a CSP instance has n variables with maximum domain size dmax, r binary constraints and some number of unary constraints. Let U be a union of the domains of all n variables without values excluded by unary constraints. We will 134 A B C S1 S2 S3 S4 S5 S7 S6 A = S1∪S2∪S3∪S5 B = S1∪S2∪S4∪S6 C = S1∪S3∪S4∪S7 Figure 4.12: Domains of three variables. We need at most seven disjoint sub- sets, S1,S2, . . . ,S7, to specify domains of the variables. consider a representation, where binary constraints are stored as a list of r tuples and values of the domains and unary constraints are stored in the arrays. We need to process unary constraints and we need to divide set U into disjoint subsets so that domains of variables can be represented using s-constants corre- sponding to these subsets. In the worst case we need to split U into 2n− 1 such subsets, one subset of values per each non-empty subset of the set of variables (see Figure 4.12). In order to do the above task efficiently, we sort the n arrays storing domains and the n arrays storing unary constraints (time complexity O(ndmax log(dmax))). The choice of the ordering is irrelevant as long as it is a strict total ordering. With each array, we associate a pointer, initially set to the first element of the sorted array. We will refer to the elements pointed at as to current elements. We also create a data structure of size 2n− 1 for storing counts associated with each potential subset of U1. Next, we proceed in a manner reassembling the merging algorithm. We choose the smallest current element x from n domain arrays. We check which of other current elements of domain arrays are equal to x, which gives as a set of variables whose domains contain x. We check which of current elements of unary constraints arrays are equal to x, which gives as a set of variables for which x is excluded from their domains. This information allows us to update the count for the respective 1A sparse representation should be considered as one can expect many of the counts to be 0. 135 disjoint set. After the count is updated, we move forward the pointers associated with the elements and constraints equal to x. We repeat this step for each of at most ndmax values in U. The time complexity of this operation isO(ndmax(n+ log(2n−1)))=O(n2dmax). The space complexity is O(ndmax+2n). Given the disjoint subsets and their counts, we can create #VE 6= factors to represent all r binary constraints. There are at most 2n−1 s-constants correspond- ing to the disjoint subsets with non-zero counts. These s-constants are used to represent domains of variables. At the same time the domain of each variable is represented by at most dmax s-constants, as we do not use s-constants to represent empty subsets. Therefore the domain of each variable is represented by at most min({2n−1,dmax}) s-constants. Each #VE 6= factor has at most min({2n−1,dmax})2+min({2n−1,dmax}) #VE 6= tuples. This is because there are min({2n−1,dmax})2 possible pairs of s-constants and for min({2n−1,dmax}) pairs of identical s-constants, there are two possible par- titions of associated two variables: one in which variables are in the same block and one in which they are in different blocks2. Thus, the time and space complexity of creating the #VE 6=factors isO(r (min({2n−1,dmax})2+min({2n−1,dmax})22n−2))). The time complexity of the whole preprocessing phase for the array-based rep- resentation is O(ndmax(log(dmax)+n)+ r (min({2n−1,dmax})2+min({2n−1,dmax}))), and the space complexity is O(r+ndmax+2n+ r (min({2n−1,dmax})2+min({2n−1,dmax}))) . For the same CSP instance, a naive #VE implementation creates the represen- tation in time O(rd2max). However, most VE implementations first sort domains of the variables (as this allows for a 1-dimensional representation of factors as well as 2If we do not represent zero-valued #VE 6= tuples in the #VE 6= factors, the maximum size of the #VE 6= factor becomes min({2n−1,dmax})2 as for pairs of identical s-constants we then only represent these cases where variables are in different blocks of the partition. 136 speeding up the processing of constraints). In such cases, the time and space com- plexities are respectively O(ndmax log(dmax)+ rd2max) and O(r+ndmax+ rd2max). Therefore the cost of the preprocessing phase for #VE 6= does not have to be greater than the cost for #VE. In many cases, #VE 6= constructs a network much faster and is less likely to run out of memory (see Section 4.3.5). 4.3.4.2 Inference Assume that #VE 6= factors given as the input data to the #VE 6= algorithm involve s s-constants. As in the case of the standard #VE algorithm for #CSP, the time and space complexities of the inference phase of the #VE 6= algorithm are determined by the size of the biggest #VE 6= factor, which depends on the induced tree width w∗(ρ) of the associated constraint graph. For the elimination ordering ρ , the biggest #VE 6= factor represents a function on w∗(ρ)+1 variables. In the worst case, the domain of each variable in the biggest factor is represented by all s s-constants, and the factor may need to represent all sw ∗(ρ)+1 possible combinations of those s-constants. For each combination, there are possibly several #VE 6= tuples in the factor. For a combination containing s-constants c1,c2, . . . ,ck, if each s-constant occurs in the combination nc1 ,nc2 , . . . ,nck times, respectively (where nc1 + nc2 + · · ·+ nck = w∗(ρ)+ 1), then there may be up to ϖnc1ϖnc2 . . .ϖnck #VE 6= tuples in the factor. Proposition 4.1 tells us that this number varies between 0 and ϖw∗(ρ)+1. Thus, the size of the biggest #VE 6= factor can be at most: sw ∗(ρ)+1ϖw∗(ρ)+1. The total number of #VE 6= factors processed during the execution of the algo- rithm is bounded by 2r, where r is the number of constraints. Therefore the space complexity of our algorithm is equal to O ( rsw ∗(ρ)+1ϖw∗(ρ)+1 ) . (4.6) The time complexity of the algorithm is equal to the space complexity times some polynomial cost of manipulating partitions P(w∗(ρ)+1). For both space and time 137 complexities, the only direct domain-size dependency is the actual length of the numbers we store, multiply, sum and output. In comparison to the space complexity of the #VE algorithm (see Equation 4.1), the component dw ∗(ρ)+1 (where d is the size of the largest domain) is possibly greatly reduced to sw ∗(ρ)+1, but we have an additional, possibly large, component ϖw∗(ρ)+1. The plot from Figure 4.2 suggests that for moderate values of w∗(ρ) and large domains #VE 6= should achieve much lower space complexity than #VE. A comparison of time complexities of both algorithm leads to the same conclu- sion. There, #VE 6= has an additional, polynomial overhead related to the cost of manipulating partitions. 4.3.5 Empirical evaluation We implemented in Java both the #VE algorithm3 by Dechter [2003] presented in Section 4.2.2 and the #VE 6= algorithm4 introduced in Section 4.3.2, and compared their performances. We wrote the code using J2SDK 1.4.2.06 and ran it under JRE 1.5.0.01. We performed the experiments on an Intel Pentium IV 3.20GHz machine with 1GB of RAM was made available to the Java Virtual Machine. For accurate timing, we used the method described in [Gørtz, 2000]. The purpose of our tests was to answer the following questions. How does more complex preprocessing affects #VE 6= performance compared to #VE? How do rich data structures used by #VE 6= affect it performance compared to #VE? In the previous section we computed the asymptotic complexities of the preprocess- ing and inference phases of both algorithms. Even though the #VE 6= algorithm performs better asymptotically as the domain size increases, we do not know an- swers to these questions because we do not know the constants associated with these complexities. The constants for the #VE 6= algorithm could be so large as to make it impractical. To estimate the constants associated with each inference method, we performed tests on random CSP instances. We sampled instances with 5 to 50 variables. Each of possible binary inequality constraints was chosen independently (as it would be 3http://people.cs.ubc.ca/~kisynski/code/ve_hcsp/ 4http://people.cs.ubc.ca/~kisynski/code/ve_in_hcsp/ 138 done using standard generation models A and C, see Achlioptas et al. [1997]) with probability varying from 0.1 to 0.5. We only considered instances that theoretically could be solved by the #VE algorithm given 1GB of memory. As a result, the induced width varied from 2 to 32 and the domain size varied from 2 to 216 (all variables in one instance having the same domain). We generated two sets of CSPs, each containing 103 instances. In the first set each of possible unary constrains was chosen independently with the probability 0.1 (which resulted in big differences between the domains of variables after unary constraints were processed). In the second set the probability was equal to 0.01 (so domains were more similar). We considered four elimination-ordering heuristics – max-cardinality, min- degree, min-factor and min-fill (see Kjærulff [1990] for an overview of these heuris- tics). The last three achieved similar performance, superior to the max-cardinality scheme. We report results achieved with the min-degree heuristic, as it is the sim- plest and the fastest to compute. To allow for the variation in run time due to garbage collection and other co- variates, all computations were performed five times. We report mean run time and, where necessary, standard error. In all of our experiments values of the domains of the variables, unary constraints and binary constraints in input CSP instances were stored in the arrays in an arbitrary order. We analyzed the amount of time #VE and #VE 6= spent on constructing their internal representations given array-based descriptions of CSPs and the amount of time they spent doing inference. In Figure 4.13 we present counts of the outcomes of the experiment. The #VE 6= algorithm never failed during the preprocessing phase. During the inference phase, it failed only 3 times for instances for which the #VE algorithm succeeded. #VE 6= was faster than #VE for most instances during both preprocessing and inference. In Figure 4.14 we further summarize the results. For each set of instances we show the total time the algorithms spent on solving all 103 instances. If an algo- rithm failed to finish a computation for an instance, we included the time it spent on the computation until failure. For the instances with 0.1 probability of a value being excluded by a unary constraint, #VE was not only slower, but also failed to compute the result for 29 instances, while #VE 6= failed for only 11 instances. In 139 P(u) Cases Counts #VE fails #VE 6= fails #VE faster than #VE 6= Preprocessing Inference 0.1 Yes Yes N/A 0 9 Yes No N/A 8 12 No Yes N/A 0 2 No No Yes 25 21No 70 51 0.01 Yes Yes N/A 0 8 Yes No N/A 8 13 No Yes N/A 0 1 No No Yes 21 15No 74 58 Figure 4.13: Summary of experiments. P(u) - probability of a value being excluded by a unary constraint. P(u) Algor. Preprocessing Inference Total time [s] se [s] #f time [s] se [s] #f time [s] se [s] #f 0.10 #VE 21.85 0.16 8 99358.84 3475.86 21 99380.69 3475.79 29 #VE 6= 0.60 0.01 0 49175.77 781.37 11 49176.36 781.37 11 0.01 #VE 21.02 0.11 8 77749.75 2321.95 21 77770.78 2321.93 29 #VE 6= 0.45 0.01 0 31260.52 2133.07 9 31260.97 2133.08 9 Figure 4.14: Summary of experiments. P(u) - probability of a value being excluded by a unary constraint; #f - number of times a particular algo- rithm failed due to lack of memory. the second set, the probability of a value being excluded by a unary constraint was equal to 0.01; for those instances, #VE 6= also achieved much better performance than #VE did. The experiments showed that more complicated preprocessing in the case of #VE 6= does not significantly influence performance, as the total run time is dominated by the inference phase. The experiments also showed that #VE 6= is capable of solving more instances than #VE can. 140 101 102 103 104 105 0 5 10 15 20 25 30 35 100 101 102 103 104 105 domain size CSP network creation induced width ∇ #VE success × #VE failure ° #VE=/= success ∗ #VE=/= failure tim e [m s] 101 102 103 104 105 0 5 10 15 20 25 30 35 100 102 104 106 108 domain size inference induced width ∇ #VE success × #VE failure ° #VE=/= success ∗ #VE=/= failure tim e [m s] Figure 4.15: Results of experiments on CSP instances with the probability of a value being excluded by a unary constraint equal to 0.1. 141 101 102 103 104 105 0 5 10 15 20 25 30 35 100 101 102 103 104 105 domain size CSP network creation induced width ∇ #VE success × #VE failure ° #VE=/= success ∗ #VE=/= failure tim e [m s] 101 102 103 104 105 0 5 10 15 20 25 30 35 100 102 104 106 108 domain size inference induced width ∇ #VE success × #VE failure ° #VE=/= success ∗ #VE=/= failure tim e [m s] Figure 4.16: Results of experiments on CSP instances with the probability of a value being excluded by a unary constraint equal to 0.01. 142 Figure 4.15 visualizes the detailed results for the first set of instances, and Figure 4.16, for the second one. In both plots, each vertical line corresponds to one test instance. It is important to remember that for all instances for which #VE 6= succeeded, we could keep increasing the domain size and the #VE 6= algorithm would still be able to compute the answer, while the #VE algorithm would sooner or later run out of memory. 4.4 Conclusions We approached #CSP for a practical reason: we needed an efficient, lifted algo- rithm to solve #CSP induced during lifted probabilistic inference practical. Such CSP instances involve only inequality constraints (either between a pair of vari- ables or between a variable and a constant) and domains of variables might be very large. The first property turned out to be sufficient to allow for the development of an efficient, lifted method based on the variable elimination framework. The time and space complexities of our algorithm do not depend directly on the do- main size. Moreover, because our algorithm is a lifted one, it can inter-operate with lifted probabilistic inference engine in a natural way (see Appendix C and Appendix D). There has recently been work on coloring problems by Angelsmark and Thap- per [2006]; Björklund et al. [2009]. This work does not solve our problems as the inputs and outputs of these algorithms are not lifted. However, it is possible that our algorithm could be applied to their problems, which remains an intriguing possibility. 143 Chapter 5 Constraint Processing in Lifted Inference So I said to the Gym instructor “Can you teach me to do the splits?” He said “How flexible are you?”. I said “I can’t make Tuesdays”. — Tim Vine 5.1 Introduction In this chapter we analyze lifted inference from the perspective of constraint pro- cessing and, through this viewpoint, we analyze and compare existing approaches to constraint processing and expose their advantages and limitations. Our theoreti- cal results show that the wrong choice of constraint processing method can lead to exponential increase in computational complexity. Our empirical tests confirm the importance of constraint processing in lifted inference. In Section 5.2 we give an overview of constraint processing during lifted prob- abilistic inference. In Section 5.3 we compare the splitting as needed approach of Poole [2003] with the shattering approach of de Salvo Braz et al. [2007]. In Sec- tion 5.4 we compare two approaches to solving #CSPs encountered during lifted inference: the use of a specialized #CSP solver [de Salvo Braz et al., 2007; Poole, 2003] and the requirement that the parfactors used during inference be in normal 144 form [Milch et al., 2008], which simplifies #CSP solving, but requires additional splitting. 5.2 Overview of constraint processing in lifted inference Specification of a first-order probabilistic model consists of probabilistic state- ments that may involve inequalities between a logical variable (that represents an individual in a population) and a constant (an individual from the population) as well as between two logical variables. Due to prior knowledge or observations, we may know that some individual(s) should be treated differently from the rest of the population. In that case, state- ments about the rest of the population require the constraint that the logical variable is not one of the exceptional individuals. For example, if we know that everyone is Joe’s friend, for the parameterized random variable f riends(X ,Y ), we may treat the cases Y = joe and Y 6= joe as separate cases. Example 2.8 shows constraints induced by prior knowledge. There are also different cases where two logical vari- ables are equal or not. Example 5.1. We want to specify a conditional probability describing the likeli- hood that two people are friends, provided they like each other. It is natural to have two parameterized random variables: likes(X ,Y ) and f riends(X ,Y ), where X and Y are logical variables with the same population representing a group of people. Obviously, the case of whether someone likes themself (X = Y ) should be treated differently from the case of whether someone likes someone else (X 6= Y ). Inequality constraints can be introduced by observing. For example, if we observed that Joe and Peter are friends, we need to treat f riends( joe, peter) sep- arately from f riends(X ,Y ) for X 6= joe and Y 6= peter. Section 2.5.2.7 contains another example of constrains introduced by observing. Inequality constraints can also be introduced during inference. For example, if we have a probabilistic statement that contains the parameterized random variables p(X) and p(Y ), we need to treat the X = Y and X 6= Y cases separately: in the first case, there is one random variable in each grounding; in the second case, there are two random variables in each grounding. 145 As pointed out in Poole [2003], when performing probabilistic reasoning within such models we need to take into account the population sizes of logical variables. For each probabilistic statement (an original one or one created during inference) we need to know how many random variables are represented by parameterized random variables within that statement. Poole [2003] gave example, where the probability that someone is guilty of a crime depends on how many other people could have committed the crime (i.e., the population size). The probability that a system will have a component with a fault depends on how many components there are. Thus, for exact inference we need to count the number of solutions to the CSP associated with the individuals and the inequality constraints, that is we need to solve the #CSP associated with the individuals and the inequality constraints. In Section 2.5.2 we gave an overview of the C-FOVE algorithm [Milch et al., 2008]. In this section we look at it again, but this time we focus on constraint processing outlined above that is performed during lifted inference with C-FOVE. Let us recall the notation from Section 2.5.2. Φ denotes a set of parfactors and Q denotes queried random variables, that is, a subset of the set of all random vari- ables represented by parameterized random variables present in parfactors in Φ. Given Φ and Q, the C-FOVE algorithm computes the marginal JQ(Φ) by sum- ming out random variables from Q, where possible in a lifted manner. Evidence is handled by adding to Φ additional parfactors on observed random variables. As we discussed in the previous section, parfactors in Φ can contain inequality constraints and parfactors representing observations are likely to explicitly name particular individuals. This makes parameterized random variables sharing the same functor represent different sets of random variables. Example 5.2. Consider the first-order probabilistic model and its grounding pre- sented in Figure 5.1. Let A and B be logical variables typed with a population D(A) = D(B) = {x1, . . . ,xn}. Let g and h be functors with range { f alse, true}. Assume we do not have any specific knowledge about ground instances of g(A), but we have some specific knowledge about h(A,B) for the case where A = x1 and for the case where A 6= x1 and A = B. We would represent the model using the 146 FIRST-ORDER PROPOSITIONAL A B g(x1) h(x1, xn)h(x1, x1) h(xn, xn)h(xn, x1) g(xn) h(A,B) g(A) Figure 5.1: A first-order model from Example 5.2. following parfactors: Φ0 = {〈 /0,{g(A)},F0〉, [0] 〈 /0,{g(x1),h(x1,B)},F1〉, [1] 〈{A 6= x1},{g(A),h(A,A)},F2〉, [2] 〈{A 6= x1,A 6= B},{g(A),h(A,B)},F3〉}, [3] where F0 is a factor from range(g) to the reals and F1, F2, and F3 are factors from range(g)×range(h) to the reals, be a set of parfactors, such that J (Φ0) represents a joint probability distribution over random variables present in the model. The sets of random variables represented by g(A) and g(x1) in parfactor [0] and parfactor [1] are not disjoint and are not identical. The same applies to g(A) in parfactor [0] and parfactors [2] and [3]. We will use the set of parfactors Φ0 in a series of examples to follow. We will not compute a particular marginal, just highlight constraint processing involved in operations that can be performed within Φ0. 5.2.1 Splitting and expanding Before a ground instance of a parameterized random variable can be summed out, a number of conditions must be satisfied. One is that a ground instance of a param- eterized random variable can be summed out from a parfactor inΦ only if there are 147 no other parfactors in Φ involving this ground instance (condition (S1) of Propo- sition 2.1 and condition (SC1) of Proposition 2.2 ). To satisfy this condition, the inference procedure may need to multiply parfactors prior to summing out. Parfactor multiplication has a condition of its own: two parfactors 〈C1,V1,F1〉 and 〈C2,V2,F2〉 can be multiplied only if for each parameterized random variable from V1 and for each parameterized random variable from V2, the sets of random variables represented by these two parameterized random variables in respective parfactors are identical or disjoint (condition (M1) in Proposition 2.3). This condi- tion is trivially satisfied for parameterized random variables with different functors. In Section 2.5.2.3 we introduced parfactor splitting and expanding a counting formula, the two operations that are used during lifted inference to enable par- factor multiplication. Poole [2003] proposed a scheme in which splitting and ex- panding are performed as needed during inference when two parfactors are about to be multiplied and the precondition for multiplication is not satisfied. We call this approach splitting as needed. An alternative, called shattering, was proposed by de Salvo Braz et al. [2007]. The shattering operation performs all the splits and expansions that are required to ensure that for any two parameterized random variables present in parfactors, the sets of random variables represented by them are either identical or disjoint. We compare splitting as needed and shattering in Section 5.3. Shattering is used in the C-FOVE algorithm of Milch et al. [2008]. Shattering is performed as the first operation of the inference and might be also necessary in the middle of inference if propositionalization or full expansion of a counting formula is performed. The C-FOVE algorithm also requires all parfactors to be in normal form, and the shattering operation might perform additional splits and expansions to bring all parfactors to normal form. An example computation pre- sented in Section 2.5.2.7 includes a shattering operation. In Appendix E we show how to compute the same query in more efficient manner using splitting as needed. The following example illustrates how to use splitting to make the sets of ran- dom variables represented by two parameterized random variables in different par- factors be identical or disjoint and how to use splitting to convert a parfactor to normal form. 148 Example 5.3. Let us continue from Example 5.2. The sets of random variables represented by g(A) and g(x1) in parfactor [0] and parfactor [1] are not disjoint and are not identical: g(A) and g(x1) unify with MGU {{A/x1}} (see Section 2.5.2.5 for an overview of the role of unification in lifted probabilistic inference). We split parfactor [0] on a substitution {A/x1}, creating parfactors [4] and [5]: Φ1 = {〈 /0,{g(x1),h(x1,B)},F1〉, [1] 〈{A 6= x1},{g(A),h(A,A)},F2〉, [2] 〈{A 6= x1,A 6= B},{g(A),h(A,B)},F3〉, [3] 〈 /0,{g(x1)},F0〉, [4] 〈{A 6= x1},{g(A)},F0〉}. [5] We have J (Φ1) = J (Φ0). Sets of random variables represented by parameterized random variables present in Φ1 are disjoint or identical, but parfactor [3] is not in normal form as ECA \{B} = {x1} 6= /0 = ECB \{A}, where C = {A 6= x1,A 6= B}. To bring parfactor [3] to normal-from, we split on a substitution {B/x1}, creating parfactors [6] and [7]: Φ2 = {〈 /0,{g(x1),h(x1,B)},F1〉, [1] 〈{A 6= x1},{g(A),h(A,A)},F2〉, [2] 〈 /0,{g(x1)},F0〉, [4] 〈{A 6= x1},{g(A)},F0〉, [5] 〈{A 6= x1},{g(A),h(A,x1)},F3〉 [6] 〈{A 6= x1,A 6= B,B 6= x1},{g(A),h(A,B)},F3〉}. [7] We have J (Φ2) = J (Φ1) and all parfactors in Φ2 are in normal form. 5.2.2 Multiplication Once the preconditions for parfactor multiplication are satisfied, multiplication can be performed in a lifted manner as described in Section 2.5.2.2. The lifted infer- ence procedure needs to know how many factors each parfactor involved in the multiplication represents and how many factors their product will represent. These 149 numbers can be different because the product parfactor might involve more logical variables than a parfactor participating in the multiplication. Given a parfactor 〈C,V,F〉, the number of factors it represents is equal to the number of solutions to the constraint satisfaction problem (CSP, see Section 4.2.1) formed by logical variables from V and constraints from C, which means that we need to solve the associated #CSP. We compare existing approaches to this prob- lem in Section 5.4. Example 5.4. Assume that we want to multiply parfactors [4] and [1] from Φ2 (Example 5.3). Parfactor [4], 〈 /0,{g(x1)},F0〉, represents 1 factor while parfac- tor [1], 〈 /0,{g(x1),h(x1,B)},F1〉, represents n factors. Their product, a parfactor 〈 /0,{g(x1),h(x1,B)},F8〉, where F8 is a factor from range(g)×range(h) to the re- als, represents n factors. We need to bring values of the factor F0 to the power 1n (see Proposition 2.3) when computing F8: F8 = F0 1n F3 . Let Φ3 = {〈{A 6= x1},{g(A),h(A,A)},F2〉, [2] 〈{A 6= x1},{g(A)},F0〉, [5] 〈{A 6= x1},{g(A),h(A,x1)},F3〉 [6] 〈{A 6= x1,A 6= B,B 6= x1},{g(A),h(A,B)},F3〉, [7] 〈 /0,{g(x1),h(x1,B)},F8〉}. [8] We have J (Φ3) = J (Φ2) and all parfactors in Φ3 are in normal form. 5.2.3 Summing out During lifted summing out, a parameterized random variable is summed out from a parfactor 〈C,V,FF〉, which means that a random variable is eliminated from each factor represented by the parfactor in one inference step. Lifted inference will perform summing out only once on the factor F. If some logical variables only appear in the parameterized variable that is being eliminated, the resulting parfac- tor will represent fewer factors than the original one. As in the case of parfactor multiplication, the inference procedure needs to compensate for this difference. Values of the factor component in the resulting parfactor are brought to the power r, where the number r tells us how many times fewer factors the result of summing 150 out represents compared to the original parfactor. This is described formally in Equations 2.3 and 2.5 from Propositions 2.1 and 2.2 respectively. The number r is equal to the size of the set (D(X1)×·· ·×D(Xk)) : C, where X1, . . . ,Xk are logical variables that will disappear from the parfactor. If the parfac- tor is in normal form, the exponent r does not depend on values of logical variables remaining in the parfactor after summing out. In such case, computation reduces to solving #CSP and is not different from computation performed during parfactor multiplication. Example 5.5. Assume that we want to sum out ground(h(A,B)) : {A 6= x1,A 6= B,B 6= x1} from parfactor [7] from Φ3 (Example 5.4) i.e., we want to sum out all ground instances of h(A,B) that satisfy the constraints in [7]. The logical variable B will not appear in the resulting parfactor. We have |D(B) : {A 6= x1,A 6= B,B 6= x1}|= n−2. Let F9 be a factor from range(g) to the reals, F9 = (∑h(A,B)F3)n−2. As a result of summation we obtain a parfactor 〈{A 6= x1},{g(A)},F9〉. Let Φ4 = {〈{A 6= x1},{g(A),h(A,A)},F2〉, [2] 〈{A 6= x1},{g(A)},F0〉, [5] 〈{A 6= x1},{g(A),h(A,x1)},F3〉 [6] 〈 /0,{g(x1),h(x1,B)},F8〉, [8] 〈{A 6= x1},{g(A)},F9〉}. [9] We have J (Φ4) = ∑ground(h(A,B)):{A6=x1,A 6=B,B 6=x1}J (Φ3). If the parfactor is not in normal form, the exponent r may depend on values of remaining logical variables and it is necessary to compute all the sizes of the set X conditioned on values of logical variables remaining in the parfactor. In such case, the summing out operation creates multiple parfactors. Example 5.6. Consider an alternative joint probability distribution over random variables present in the model from Figure 5.1 to the distribution presented in the Example 5.2. Assume we do not have any specific knowledge about ground in- stances of g(A), but we have some specific knowledge about h(A,B) for the case where B = x1 and for the case where A = B. We would represent the model using 151 the following parfactors: Φi = {〈 /0,{g(A)},Fi〉, [i] 〈 /0,{g(A),h(A,x1)},Fii〉, [ii] 〈{A 6= x1},{g(A),h(A,A)},Fiii〉, [iii] 〈{A 6= B,B 6= x1},{g(A),h(A,B)},Fiv〉}, [iv] where Fi is a factor from range(h) to the reals and F1, F2, and F3 are factors from range(g)×range(h) to the reals. The sets of random variables represented by g(A) in parfactors [i] and [ii] and parfactors [iii] and [iv] are not disjoint and are not identical. The sets of random variables represented by h(A,x1), h(A,A) and h(A,B) in parfactors from Φi are disjoint. Parfactor [iv] is not in normal form, as E{A6=B,B 6=x1}A \{B} = /0 6= {x1} = E{A6=B,B 6=x1}B \{A}. Assume that we want to sum out ground(h(A,B)) : {A 6= B,B 6= x1} from Φi i.e., we want to sum out all ground instances of h(A,B) that satisfy the constraints in [iv]. Conditions (S1) and (S2) of Proposition 2.1 are satisfied. The requirement that parfactor [iv] is in normal-form is not satisfied. Nevertheless, lifted summation can be performed. The logical variable B will disappear from [iv]. We have |D(B) : {A 6= B,B 6= x1}|= n−1, if A = x1;n−2, if A 6= x1. (5.1) Let Fv be a factor from range(g) to the reals, Fv =∑h(A,B)Fiv. We obtain two par- factors as the result of summation: a parfactor 〈 /0,{g(x1)},Fvn−1 〉 and a parfactor〈{A 6= x1},{g(A)},Fvn−2〉. Let Φii = {〈 /0,{g(A)},Fi〉, [i] 〈 /0,{g(A),h(A,x1)},Fii〉, [ii] 〈{A 6= x1},{g(A),h(A,A)},Fiii〉, [iii]〈 /0,{g(x1)},Fvn−1 〉 , [v]〈{A 6= x1},{g(A)},Fvn−2〉}, [vi] We have J (Φii) = ∑ground(h(A,B)):{A6=B,B 6=x1}J (Φi). 152 The above example shows that normal-form requirement is not necessary, but if it is not satisfied, the solution of #CSP encountered during summing out is con- ditioned values of logical variables remaining in the parfactor. In Section 5.4 we compare two approaches to solving #CSPs during lifted probabilistic inference: one based on a #CSP solver [de Salvo Braz et al., 2007; Poole, 2003], which can compute the expression (5.1), and the other normal-form based [Milch et al., 2008]. Similar observations could be made for a summing out a parameterized random variable from an aggregation parfactor (see Section 3.4.2.3). The above overview of lifted inference, together with simple examples, shows that constraint processing is an integral, important part of lifted probabilistic infer- ence. It also points out that there are two choices regarding constraint processing during lifted inference: a choice between splitting as needed and shattering and a choice between using a #CSP solver and enforcing normal form. These choices are independent, and shattering can be used with a #CSP solver [de Salvo Braz et al., 2007] or with normal form parfactors [Milch et al., 2008]. Splitting as needed can be used together with a #CSP solver [Poole, 2003], one could also imagine us- ing splitting as needed but requiring normal-form for parfactors. The rest of this chapter is devoted to the comparison of these different strategies. 5.3 Splitting as needed vs. shattering In this section we compare the splitting as needed approach and the shattering approach. For clarity, we do not analyze here splits related to converting constraints sets to normal form. Shattering simplifies design and implementation of lifted inference procedures. Given a set of parfactors Φ, shattering performs all splits and expansions on sub- stitutions that are obtained from unification and analysis of constraints (see Sec- tion 2.5.2.5). After shattering, all sets of random variables represented by param- eterized random variables present in Φ are pairwise identical or disjoint. Lifted inference will not perform any additional splits or expansions, unless proposition- alization or full expansion is performed. Splitting as needed will not perform splits or expansions on other substitutions than those used during shattering (unless propositionalization or full expansion is 153 performed). In fact, it might perform much fewer splits and expansions as we demonstrate in the example below. Example 5.7. Consider the following set of parfactors: Φ= {〈 /0,{gQ(),g1(X1,X2, . . . ,Xk),g2(X2,X3, . . . ,Xk), . . . ,gk(Xk))},F0〉, [0] 〈 /0,{g1(a,X2, . . . ,Xk)},F1〉, [1] 〈 /0,{g2(a,X3, . . . ,Xk)},F2〉, [2] . . . , 〈 /0,{gk−1(a,Xk)},Fk−1〉, [k−1] 〈 /0,{gk(a)},Fk〉, [k] and let Q = ground(gQ()). Assume we want to compute the marginal JQ(Φ). Lifted inference with shattering will create exponentially more parfactors (in the number of logical variables in a parfactor) than lifted inference with splitting as needed. For i = 1, . . . ,k, a set of random variables represented by a parameterized ran- dom variable gi(Xi, . . . ,Xk) in a parfactor [0] is a proper superset of a set of random variables represented by a parameterized random variable gi(a,Xi+1, . . . ,Xk) in a parfactor [i]. Therefore lifted inference with shattering needs to perform several splits. Since the order of splits during shattering does not matter here, assume that the first operation is a split of the parfactor [0] on a substitution {X1/a} which creates a parfactor 〈 /0,{gQ(),g1(a,X2, . . . ,Xk),g2(X2,X3, . . . ,Xk)},F0〉 [k+1] and a residual parfactor 〈{X1 6= a},{gQ(),g1(X1,X2, . . . ,Xk),g2(X2,X3, . . . ,Xk), . . . ,gk(Xk))},F0〉 . [k+2] In both newly created parfactors, for i = 2, . . . ,k, a set of random variables represented by a parameterized random variable gi(Xi, . . . ,Xk) is a proper super- set of a set of random variables represented by a parameterized random variable gi(a,Xi+1, . . . ,Xk) in a parfactor [i] and shattering proceeds with further splits of 154 both parfactors. Assume that in the next step parfactors [k+1] and [k+2] are split on a substitution {X2/a}. The splits result in four new parfactors. The result of the split of the parfactor [k+ 1] on {X2/a} contains a parameterized random variable g1(a,a, . . . ,Xk) and a parfactor [1] needs to be split on a substitution {X2/a}. The shattering process continues following a scheme described above. It terminates after 2k+1− k− 2 splits and results in 2k+1− 1 parfactors (each original parfactor [i], i = 0, . . . ,k, is shattered into 2k−i parfactors). Assume that after initial shatter- ing, lifted inference proceeds with the optimal elimination ordering g1, . . . ,gk (this elimination ordering does not introduce counting formulas; whereas other order- ings do). To compute the marginal JgQ()(Φ), 2k lifted multiplications and 2k+1−2 lifted summations are performed. Consider lifted inference with splitting as needed. Assume lifted inference fol- lows an elimination ordering g1, . . . ,gk. A set of random variables represented by a parameterized random variable g1(X1, . . . ,Xk) in a parfactor [0] is a proper super- set of a set of random variables represented by a parameterized random variable g1(a,X2, . . . ,Xk) in a parfactor [1] and the parfactor [0] is split on a substitution {X1/a}. The split results in parfactors identical to the parfactors [k+1] and [k+2] from the description of shattering above. The parfactor [k+ 1] is multiplied by the parfactor [1] and all ground instances of g1(a,X1, . . . ,Xk) are summed out from their product while all ground instances of g1(X1,X2, . . . ,Xk) (subject to a con- straint X1 6= a) are summed out from the parfactor [k+2]. The summations create two parfactors: 〈 /0,{gQ(),g2(X2,X3, . . . ,Xk), . . . ,gk(Xk))},FFk+3〉, [k+3] 〈 /0,{gQ(),g2(X2,X3, . . . ,Xk), . . . ,gk(Xk))},FFk+4〉 . [k+4] Ground instances of g2 are eliminated next. Parfactors [k+3] and [k+4] are split on a substitution {X2/a}, the results of the splits and a parfactor [2] are multiplied together and the residual parfactors are multiplied together. Then, all ground in- stances of g2(a,X3, . . . ,Xk) are summed out from the first product while all ground instances of g2(X2, . . . ,Xk) (subject to a constraint X2 6= a) are summed out from the second product. The elimination of g3, . . . ,gk looks the same as for g2. In total, 155 2k−1 splits, 3k−2 lifted multiplications and 2k lifted summations are performed. At any moment, the maximum number of parfactors is k+3. The above example shows that shattering approach is sometimes much worse than splitting as needed. Even though shattering creates a lot of additional parfactors, parfactors result- ing from the same split share the same factor component. If factors are imple- mented as an immutable data structure, then they can be shared between different parfactors inside the implementation. This might help reduce overhead of shatter- ing. We demonstrate this in the following example. Example 5.8. Consider the following set of parfactors: Φ= {〈 /0,{gQ(),g1(a)},F0〉, [0] 〈{X 6= a},{gQ(),g1(X)},F1〉, [1] 〈 /0,{g1(X),g2(X)},F2〉, [2] 〈 /0,{g2(X),g3(X)},F3〉, [3] . . . , 〈 /0,{gk−1(X),gk(X)},Fk〉, [k] 〈 /0,{gk(X)},Fk+1〉} [k+1]. Assume that all functors have the range size 10, Q = ground(gQ()) and that we want to compute the marginal JQ(Φ). Because of the presence of parameterized random variable g1(a) in parfactor [0], lifted inference with shattering splits parfactor [2] on substitution {X/a}, which creates a parfactor 〈 /0,{g1(a),g2(a)},F2〉 and a residual parfactor. This in turn causes a split of parfactor [3] on a substitution {X/a}. Splits propagate until the last split of parfactor [k+1] on a substitution {X/a}, to a total of k splits, which create k additional parfactors. Afterward probabilistic inference proceeds with 2k+ 1 multiplications and k+1 summations regardless of the elimination ordering. Lifted inference with splitting as needed with elimination ordering g1,g2, . . . ,gk would perform exactly the same splits, multiplications, and summations as lifted 156 10 20 30 40 50 60 70 80 90 100 0 0.5 1 1.5 Figure 5.2: Speedup of splitting as needed over shattering for Example 5.8. inference with shattering. Lifted inference with splitting as needed and ordering gk,gk−1, . . . ,g1 performs just 1 split, k+2 multiplication,s and k+1 summations. As we said in the introduction to this example, even though shattering creates a lot of additional parfactors, parfactors resulting from the same split share the same factor component, so overhead of shattering might be smaller than expected. We used a Java implementation of C-FOVE with factors implemented as an immutable data structure shared between different parfactors to verify this point. Tests were performed on an Intel Core 2 Duo 2.66GHz processor with 1GB of memory made available to the JVM. Figure 5.2 shows the results of the experiment where we varied k from 1 to 100. We report an average speedup of splitting as needed with elimination ordering gk,gk−1, . . . ,g1 over shattering over 10 runs. Even though lifted inference with shattering created nearly twice as many parfactors, it used virtually the same amount of memory as lifted inference with splitting. It was slower because it performed more arithmetic operations, but it was not slower by a factor of two. While minimizing the number of splits might result in faster inference, the size of factor components created during inference has a decisive influence on infer- ence’s speed. Consider the following example. 157 Example 5.9. Φ= {〈 /0,{gQ(),g1(X)},F0〉, [0] 〈 /0,{g1(X),g2(X)},F1〉, [1] . . . , 〈 /0,{gk−2(X),gk−1(X)},Fk−2〉, [k−2] 〈 /0,{gk−1(X),gk(X)},Fk−1〉, [k−1] 〈 /0,{gk(a)},Fk〉, [k] 〈{X 6= a},{gk(X)},Fk+1〉} [k+1] Assume that functors have the range size 10, Q = ground(gQ()) and that we want to compute the marginal JQ(Φ). Because of the presence of gk(a) in a parfactor [k], lifted inference ordering with shattering splits a parfactor [k− 1] on a substitution {X/a}, which creates a parfactor 〈 /0,{gk−1(a),gk(a)},Fk−1〉 (and a residual parfactor). This in turn causes a split of a parfactor [k− 2] on a substitution {X/a}. Splits propagate until the last split of a parfactor [0] on a substitution {X/a}, to a total of k splits, which create k additional parfactors. Afterward probabilistic inference proceeds with 2k multiplications and 2k summations regardless of the elimination ordering. The maximum size among factors created during inference is 100. Lifted inference with splitting as needed and elimination ordering gk,gk−1, . . . ,g1 would achieve identical performance. Lifted inference with splitting as needed and elimination ordering g1,g2, . . . ,gk first performs k− 1 multiplications and summations and is left with three parfac- tors: 〈 /0,{gQ(),gk(X)},F〉 and parfactors [k] and [k+ 1]. Then it splits the first parfactor on a substitution {X/a}. The result of a split is multiplied by the par- factor [k] and the residual is multiplied by the parfactor [k− 1]. Two additional summations eliminate ground instances of gk from obtained products. The final result is obtained by multiplying together two resulting parfactors. Inference per- formed 1 split, k+ 2 multiplications and k+ 1 summations. The maximum size among factors created during inference is 1000. 158 50 55 60 65 70 75 80 85 90 95 100 0 0.5 1 1.5 Figure 5.3: Splitting as needed vs. shattering speedup for Example 5.9. We compared the shattering approach to splitting as needed with elimination ordering g1,g2, . . . ,gk under the same conditions as in Example 5.8. Figure 5.3 shows the results of the experiment where we varied k from 50 to 100. Even though lifted inference with the splitting as needed approach with elimination or- dering g1,g2, . . . ,gk performs approximately only half of operations on parfactors compared to the shattering approach, it is slower because it manipulates much larger factors. Thus, it performed many more arithmetic operations. An elimina- tion ordering heuristic should be able to detect that the above elimination ordering is undesired. From the above examples we can see that with a good elimination ordering heuristic, the splitting as needed approach can be faster than the shattering ap- proach. It is worth pointing out though, that splitting as needed complicates the design of an elimination ordering heuristic. With the shattering approach it is easy to compute the total size of parfactors that would be created by a potential infer- ence step (see Section 2.5.2.6). With the splitting as needed approach, for each step under consideration we first need to determine the potentially necessary splits. 5.4 Normal form parfactors vs. #CSP solver In Section 5.2 we pointed out, that during lifted probabilistic inference, we may en- counter arbitrarily complicated #CSPs with inequality constraints because of the model’s complexity, as well as the fact that the inference itself introduces many new inequality constraints. First-order probabilistic models usually involve logi- cal variables with large populations, which means that we need to be able to solve #CSPs with large domains. Moreover, one run of a first-order probabilistic infer- 159 ence algorithm might involve solving many #CSPs, so an efficient algorithm for solving #CSP is required. We introduced such algorithm in Chapter 5. Milch et al. [2008] avoid the need to use a constraint solver by requiring all par- factors to be in normal form (Section 2.5.1.1). Below we present two propositions which give insights into structure of constraints in normal-form parfactors. Proposition 5.1. Let 〈C,V,F〉 be a parfactor in normal form. Then each con- nected component of the constraint graph corresponding to CSP formed by logical variables from V and constraints from C is fully connected. Proof. The proposition is trivially true for components with one or two logical variables. Let us consider a connected component with more than two logical variables. Suppose, contrary to our claim, that there are two logical variables X and Y with no edge between them. Since the component is connected, there exists a path X ,Z1,Z2...,Zm,Y . As C is in normal form, ECZi \{Zi+1} = ECZi+1 \{Zi}, i = 1, . . . ,m−1 and ECZm \{Y}= ECY \{Zm}. We have X ∈ECZ1 , and consequently X ∈ECY . This contradicts our assumption that there is no edge between X and Y . Proposition 5.2. Let 〈C,V,F〉 be a parfactor in normal form. Let P be the CSP formed by logical variables from V and constraints from C. Then for logical vari- ables in the same connected component of the constraint graph corresponding to P sets of constants excluded by unary constraints are identical. Proof. The proposition is trivially true for components with one logical variable. Let us consider a connected component with more than one logical variable. Sup- pose, contrary to our claim, that there are two logical variables X and Y and a constant c such that c ∈ ECX and c /∈ ECY . Since the parfactor is in normal-form from Proposition 5.1 we know that the component is fully connected and (X 6= Y ) ∈ C. Therefore, because the parfactor is in normal-form, we have ECX \{Y} = ECY \{X}. This contradicts our assumption that c ∈ ECX and c /∈ ECY . The following corollary is a direct consequence of Propositions 5.1 and 5.2 and the definition of a normal-form parfactor from Section 2.5.1.1. Corollary 5.3. A parfactor is in normal form 〈C,V,F〉 if and only if each con- nected component of the constraint graph corresponding to CSP formed by logical 160 variables from V and constraints from C is fully connected and each logical variable within the same connected component is subject to the same unary constraints. The above characteristic of normal-form parfactors is the basis for a straightfor- ward computation of the number of factors represented by a normal-form parfactor. We describe it in the following proposition. Proposition 5.4. Let 〈C,V,F〉 be a normal-form parfactor. Assume that a con- straint graph corresponding to CSP formed by logical variables present in V and constraints from C consist of one connected component. Let m be the number of logical variables present in V , n be the size of population of these logical variables, and l be the number of different constants present in C, that is l = |{c : ∃X ∈V (X 6= c) ∈ C}|. Then | 〈C,V,F〉|= (n− l)!(n− l−m)! . Proof. From the assumption that the underlying constraint graph consists of a sin- gle connected component we know that the graph has m nodes, one node for each logical variable present in V . Since the parfactor is in normal-form, by Proposi- tion 5.2 for each logical variable the set of constants excluded by unary constraints in C is identical and has size l. From Proposition 5.1 we know that the constraint graph is fully connected. Let us traverse the constraint graph in an arbitrary order and construct all possible ground substitutions to all logical variables in V that sat- isfy the constraints in C. The first logical variable can have n− l values, the second one can have n− l− 1 values, and the process continues until we reach the last, m-th, logical variable, which can have n− l−m+1 values. Therefore the number of ground substitutions is as follows: (n− l)(n− l−1) . . .(n− l−m+1) = (n− l)! (n− l−m)! . The above proposition can be easily generalized to the case where there are multiple connected components. While Proposition 5.4 shows that for normal-form parfactors solving #CSP is straightforward, the normal form has also negative consequences. The requirement 161 [00] procedure convert(〈C,V,F〉) [01] input: parfactor 〈C,V,F〉; [02] output: set of normal-form parfactors Ψ created from 〈C,V,F〉 through splitting; [03] add 〈C,V,F〉 to the queue; [04] set Ψ := {}; [05] while queue not empty do [06] remove parfactor g = 〈Ci,Vi,Fi〉 from the queue; [07] for each logical variable X from Ci do [08] for each logical variable Y from the same component of Ci as X do [09] if (X 6= Y ) /∈ Ci [10] split g on {X/Y}; [11] add the result to the queue; [12] set g to the residual; [13] for each unary constraint Y 6= t from Ci do [14] if (X 6= t) /∈ Ci [15] split g on {X/t}; [16] add the result to the queue; [17] set g to the residual; [18] end [19] end [20] end [21] add g to Ψ; [22] end [23] return Ψ; [24] end Figure 5.4: Algorithm for converting a parfactor to a set of normal-form par- factors. that all parfactors be in normal from is enforced by splitting parfactors that are not in normal form on appropriate substitutions. Milch et al. [2008], who intro- duced the concept of normal-form parfactors, do not provide any details how to do this conversion. Nevertheless, Corollary 5.3 provides us with a clear recipe for a conversion algorithm: perform all the splits required to make each connected com- ponent of the associated constraint graph be fully connected and perform all the splits required to make logical variables in the same connected component be sub- ject to the same unary constraints; repeat the process for all by-product parfactors created by the above splits. The algorithm is presented in Figure 5.4. It is clear, that a conversion of a single parfactor to normal form can create several parfactors. We illustrate this point with two examples provided below. 162 (a) (b) A B C D 6= 6= 6= 6= B = C 6= A = D A B = C D 6= 6= 6= A = D B C 6=6= 6= A B D 6= 6= 6= C 6= 6= 6= Figure 5.5: A simple constraint graph from Example 5.10 (a) and constraint graphs obtained through a conversion to normal form (b). Example 5.10. Consider a parfactor 〈C,V,F〉, where C = {A 6= B,A 6= C,B 6= D,C 6=D} and there are no other logical variables present in V . The corresponding constraint graph is presented in Figure 5.5 (a). The parfactor is not in normal form, for example ECA \{B} 6= ECB \{A}. To convert the parfactor to a set of parfactors in normal form we need to perform splits on substitutions {A/D} and {B/C} in arbi- trary order. After we split on the first substitution, we split both resulting parfactors on the second substitution. Thus we perform three splits and obtain four parfactors. Constraint graphs corresponding to these parfactors are presented Figure 5.5 (b). Note that it is the same constraint graph as the one discussed in Example 4.4, where we needed to consider only two cases to get the number of solutions. If the underlying graph is sparse, conversion might be very expensive as we show in the example below. Example 5.11. Consider a parfactor 〈{X0 6= a,X0 6= X1, . . . ,X0 6= Xk},{g0(X0),g1(X1), . . . ,gn(Xk)},F〉, where D(X0) = D(X1) = · · · = D(Xk). Let C denote a set of constraints from this parfactor. We have ECX0 = {a,X1, . . . ,Xk} and ECXi = {X0}, i= 1, . . . ,k. The parfactor is not in normal form because ECX0 \{Xi} 6= ECXi \{X0}, i = 1, . . . ,k. As a result the size of the set D(X0) : C depends on other logical variables in the parfactor. For instance, it differs for X1 = a and X1 6= a or for X1 = X2 and X1 6= X2. A conversion of the considered parfactor to set of parfactors in normal form involves 2k − 1 splits on substitutions of the form {Xi/a}, 1≤ i≤ k and ∑ki=2 (k i ) (ϖi−1) splits on 163 substitutions of the form {Xi/X j}, 1 ≤ i, j ≤ k, where ϖi− 1 is i-th Bell number (see Section 4.2.3). The conversion creates ∑ki=0 (k i ) ϖi parfactors in normal form. In Example 5.13 we analyze how this conversion affects parfactor multiplication compared to the use of a #CSP solver. From the above example we can see that the cost of converting a parfactor to normal form can be worse than exponential. Moreover, converting parfactors to normal form may be very inefficient when analyzed in context of parfactor multi- plication (see Section 5.4.1) or summing out a parameterized random variable from a parfactor (see Section 5.4.2). Our empirical tests (see Section 5.4.3) confirm this observation. While parfactors that involve counting formulas must be in normal form (see Section 2.5.1.1), this is not necessary for parfactors without counting formulas. An alternative to converting all parfactors to normal form is to use a #CSP solver. We presented an algorithm for solving #CSPs encountered during lifted probabilistic inference in Chapter 4. Details of the interaction between the solver and a proba- bilistic inference engine depend on the implementation of the solver, in particular on data structures used. In Appendix C we explain how to represent #CSPs en- countered during lifted probabilistic inference using these data structures. In Ap- pendix D we explain how to translate answers from the #CSP solver to data struc- tures used by a probabilistic inference engine. In the example below we present a simple interaction with the solver. Example 5.12. In Example 5.6 we need to know the number |D(B) : {A 6= B,B 6= x1}|, whereD(A) =D(B) and |D(A) |= n. Let s-constant a1 denote set {x1} and s- constant a2 denote setD(A)\{x1} (s-constants were introduced in Section 4.3.2.1). The following #VE 6= factor has value 1 for substitutions to logical variables A,B that are solutions to the above CSP and 0 otherwise: A B Partition(s) a1 a2 {{A}} {{B}} 1 a2 a2 {{A,B}} 0 a2 a2 {{A},{B}} 1 . 164 The #CSP solver eliminates B from the above factor and returns: A Partition(s) a1 {{A}} n−1 a2 {{A}} n−2 . The two cases used in Example 5.6 are obtained through analysis of the resulting factor and knowledge that a1 denotes set {x1} and a2 denotes set D(A)\{x1}. We can infer that |D(B) : {A 6= B,B 6= x1}| equals n−1 if A = x1 and n−2 if A 6= x1. 5.4.1 Multiplication In the example below we demonstrate how the normal form requirement might lead to a lot of, otherwise unnecessary, parfactor multiplications. Example 5.13. Assume we would like to multiply the parfactor from Example 5.11 by a parfactor p f = 〈 /0,{g1(X1)},F1〉. First, let us consider how it is done with a #CSP solver. A #CSP solver computes the number of factors the parfactor from Example 5.11 represents, (|D(X0) |−1)k+1. Next the solver computes the number of factors represented by the parfactor p f , which is trivially |D(X1) |. A correction is applied to values of the factor F1 to compensate for the difference between these two numbers. Finally the two parfactors are multiplied. The whole operation in- volved two calls to a #CSP solver, one correction and one parfactor multiplication. Now, let us see how it can be done without the use of #CSP solver. The first par- factor is converted to a set Φ of ∑ki=0 (k i ) ϖi parfactors in normal form, as presented in Example 5.11. Some of the parfactors in Φ contain a parameterized random variable g1(a), the rest contains a parameterized random variable g1(X) and a con- straint X1 6= a, so the parfactor p f needs to be split on a substitution {X1/a}. The split results in a parfactor 〈 /0,{g1(a)},F1〉 and a residual 〈{X1 6= a},{g1(X1)},F1〉. Next, each parfactor from Φ is multiplied by either the result of the split or the residual. Thus ∑ki=0 (k i ) ϖi parfactor multiplications need to be performed and most of these multiplication require a correction prior to the actual parfactor multiplica- tion. There is an opportunity for some optimization, as factor components of parfac- tors multiplications for different corrections could be cached and reused instead of being recomputed. Still, even with such a caching mechanism, multiple parfactor 165 multiplications would be performed compared to just one multiplication when a #CSP solver is used. 5.4.2 Summing out Examples 5.6 and 5.12 demonstrate how summing out a parameterized variable from a parfactor that is not in normal form can be done with a help of a #CSP solver. In the example below we show how this operation would look if we convert the parfactor to a set of parfactors in normal form (which does not require a #CSP solver). Example 5.14. Assume that we want to sum out ground(h(A,B)) : {A 6=B,B 6= x1} from the parfactor 〈{A 6= B,B 6= x1},{g(A),h(A,B)},Fiv〉 from the Example 5.6. First, we convert the parfactor to a set of parfactors in normal form by splitting on a substitutions {A/x1}. We obtain two parfactors in normal form: 〈{B 6= x1},{g(x1),h(x1,B)},Fiv〉, which represents n−1 factors, and 〈{A 6= x1,A 6= B,B 6= x1},{g(A),h(A,B)},Fiv〉, which represents (n−1)(n−2) factors. Next we sum out ground(h(x1,B)) : {B 6= x1} from the first parfactor and ground(h(A,B)) : {A 6= x1,A 6= B,B 6= x1} from the second parfactor. In both cases a correction will be necessary, as B will no longer be among logical variables present in the resulting parfactors and these parfactors will represent fewer factors than the original parfactors. In general, as illustrated by Examples 5.6, 5.12 and 5.14, a lifted inference procedure that enforces conversion to normal form and a lifted inference that uses a #CSP solver create the same number of parfactors. The difference is, that the first approach computes a factor component for the resulting parfactors once and then applies a different correction for each resulting parfactor based on the an- swer from the #CSP solver. The second approach computes the factor component multiple times, once for each resulting parfactor, but does not use a #CSP solver. As these factor components (before applying a correction) are identical, redundant 166 computations could be eliminated by caching. We successfully adopted a caching mechanism in our empirical test (Section 5.4.3), but expect it to be less effective for larger problems. As in the case of splitting as needed, it might be difficult to design an efficient elimination ordering heuristic that would work with a #CSP solver. This is because we do not known in advance how many parfactors will be obtained as a result of summing out. We need to run a #CSP solver to obtain this information. 5.4.3 Experiment In this experiment we summed out a parameterized random variable from a parfac- tor. We compared summing out with a help of a #CSP solver presented in Chap- ter 4 (#CSP-SUM) to summing out achieved by converting a parfactor to a set of parfactors in normal form and summing out a parameterized random variable from each obtained parfactor without a #CSP solver. (We cached factor components as suggested in Section 5.4.2). We randomly generated sets of parfactors. There were up to 5 parameterized random variables in each parfactor with range sizes varying from 2 to 10. There were up to 10 logical variables present in each parfactor. Logical variables were typed with the same population. We varied the size of this population from 5 to 1000 to verify how well #CSP solver scaled for larger populations. The prob- ability of presence of a binary constraint between a logical variable and another logical variable varied from 0.05 to 0.25 and each logical variable on average par- ticipated in 3 unary constraints. The above settings resulted in simple parfactors being generated. For each population size we generated 100 parfactors and re- ported a cumulative time. We used Java implementations of tested lifted inference methods. Tests were performed on an Intel Core 2 Duo 2.66GHz processor with 1GB of memory made available to the JVM. The results are presented in Figure 5.6. For small population sizes, summing out with the help of a #CSP solver (#CSP-SUM) performs worse than summing out by converting to normal form (CONV-NFM-SUM). #CSP-SUM prevails for larger populations. For the second approach, we also report time ex- cluding (NFM-SUM) conversion to normal form. The difference between CONV- 167 101 102 103 102 104 106 fffi fl ffi CONV−NFM−SUM NFM−SUM #CSP−SUM Figure 5.6: Summing out with and without a #CSP solver. NFS-SUM and NFM-SUM shows the significant cost of conversion to normal form. 5.5 Conclusions In this chapter we analyzed the impact of constraint processing on the efficiency of lifted inference and explained why we cannot ignore its role in lifted infer- ence. We showed that a choice of constraint processing strategy has a big im- pact on efficiency of lifted inference. In particular, we discovered that shatter- ing [de Salvo Braz et al., 2007] is never better—and sometimes worse—than split- ting as needed [Poole, 2003], and that the conversion of parfactors to normal form [Milch et al., 2008] is an expensive alternative to using a specialized #CSP solver. Although in this chapter we focused on exact lifted inference, our results are potentially applicable to the approximate lifted inference algorithms which use parfactors, as even approximate methods might require the exact number of factors represented by a parfactor. 168 Chapter 6 Conclusions Prediction is very difficult, especially about the future. — Niels Bohr 6.1 Summary This thesis concerns exact lifted probabilistic inference in first-order probabilistic models. In particular, we focused on two problems: lifted aggregation in directed first-order probabilistic models (Chapter 3) and constraint processing during lifted probabilistic inference (Chapters 4 and 5). Aggregation occurs naturally in non-trivial directed first-order models. Lifted inference algorithms focused on undirected first-order models and lacked data structures suitable for representing aggregation. We introduced a new data struc- ture, aggregation parfactors, and defined operations on aggregation parfactors that allow them to be part of lifted inference algorithms. We demonstrated usefulness and effectiveness of our solution using a model from the social networks domain. First-order probabilistic models involve inequality constraints on logical vari- ables. Additional inequality constraints are introduced during inference. Con- straints allow models to capture properties of particular individuals in a modeled domain. Lifted probabilistic inference has to process these constraints. One task is to count solutions to constraint satisfaction problems induced during inference. These CSPs might involve logical variables with large domains, but constraints are restricted to unary and binary inequality constraints. In Chapter 4 we presented 169 a lifted algorithm for counting solutions to such CSPs. The computational com- plexity of our algorithm does not directly depend on the domain sizes of logical variables. Because our algorithm is lifted, it inter-operates with a lifted probabilis- tic inference engine in a natural and efficient manner. To date, constraint processing in lifted probabilistic inference has not received much attention in the literature and various researchers made seemingly arbitrary decisions about constraint processing strategies. In Chapter 5 we compared differ- ent approaches to constraint processing during lifted probabilistic inference. Our theoretical and empirical results stress the great importance of informed constraint processing. 6.2 Future work There are many opportunities for future research in the area of lifted probabilistic inference. Below we outline open problems directly related to this thesis. While it is difficult to design an elimination ordering heuristic that works well with the splitting as needed approach and a #CSP solver, it is worth pursuing. In this thesis we used parfactors to describe first-order probabilistic models. Parfactors are data structures and hence not best suited for specifying models by humans. Moreover, sets of parfactors cannot directly represent all models that can be defined using first-order probabilistic modeling languages. For example, only simple ICL programs can be directly translated to sets of parfactors. Nevertheless, an inference procedure for ICL, could use the C-FOVE algorithm as a subroutine. Development of such procedure is an interesting open problem. The framework presented in this thesis allows us only to reason about particu- lar individuals from the population of a logical variable and about the rest of this population. A natural extension is to allow reasoning about sets of individuals belonging to some population. The calculus of parfactors would not be greatly affected by such generalization. The most important changes would be required in the unification process. Some changes would also be necessary in constraint processing, but not in the #CSP solver presented in Chapter 4. The representational power of parfactors could be increased by allowing par- factors to contain other types of constraints, not just inequality constraints. For ex- 170 ample, ’less-than’ constraint could be useful when used together with logical vari- ables that naturally exhibit linear order, like space dimensions and time. Increased expressiveness comes at the higher cost of constraint processing. Balancing this tradeoff is a challenging task. Finally, variable elimination-based lifted inference algorithms require lifted data structures for storing the intermediate results of a computation. If an appropri- ate lifted data structure is not available, such algorithms use propositionalization and store the results in factors. We believe that a search-based lifted inference algorithm could avoid unnecessary propositionalization. 171 Bibliography D. Achlioptas, L. M. Kirousis, E. Kranakis, D. Krizanc, M. S. O. Molloy, and Y. C. Stamatiou [1997]. Random constraint satisfaction: A more accurate picture. In Proceedings of the 3rd International Conference on Principles and Practice of Constraint Programming (CP 1997), 107–120. → pp. 139 O. Angelsmark and P. Jonsson [2003]. Improved algorithms for counting solu- tions in constraint satisfaction problems. In Proceedings of the 9th International Conference on Principles and Practice of Constraint Programming (CP 2003), 81–95. → pp. 107 O. Angelsmark, P. Jonsson, S. Linusson, and J. Thapper [2002]. Determining the number of solutions to binary CSP instances. In Proceedings of the 8th Interna- tional Conference on Principles and Practice of Constraint Programming (CP 2002), 327–347. → pp. 107 O. Angelsmark and J. Thapper [2006]. Partitioning based algorithms for some colouring problem. In Recent Advances in Constraints, Joint ERCIM/CoLogNET International Workshop on Constraint Solving and Con- straint Logic Programming, CSCLP 2005, Uppsala, Sweden, June 20-22, 2005, Revised Selected and Invited Papers, volume 3978 of Lecture Notes in Computer Science, 44–58. Springer. → pp. 108, 143 K. R. Apt and M. Bezem [1991]. Acyclic programs. New Generation Computing, 9(3–4):335–363. → pp. 17 S. Arnborg, D. G. Corneil, and A. Proskurowski [1987]. Complexity of finding embeddings in a k-tree. SIAM Journal on Algebraic and Discrete Methods, 8(2):277–284. → pp. 12 R. J. Bayardo Jr. and J. D. Pehoushek [2000]. Counting models using connected components. In Proceedings of the 17th National Conference on Artificial Intel- ligence (AAAI 2000), 157–162. → pp. 106 172 E. T. Bell [1934a]. Exponential numbers. The American Mathematical Monthly, 41(7):411–419. → pp. 111 E. T. Bell [1934b]. Exponential polynomials. The Annals of Mathematics, 2nd Ser., 35(2):258–277. → pp. 111 E. T. Bell [1938]. The iterated exponential integers. The Annals of Mathematics, 2nd Ser., 39(3):539–557. → pp. 111 U. Bertelè and F. Brioschi [1972]. Nonserial Dynamic Programming, volume 91 of Mathematics in Science and Engineering. Academic Press. → pp. 9 N. Biggs [1993]. Algebraic Graph Theory. Cambridge University Press, 2nd edi- tion. → pp. 107, 108 E. Birnbaum and E. L. Lozinskii [1999]. The good old Davis-Putnam procedure helps counting models. Journal of Artificial Intelligence Research, 10:457–477. → pp. 106 A. Björklund, T. Husfeldt, and M. Koivisto [2009]. Set partitioning via inclusion- exclusion. SIAM Journal on Computing, 39(2):546–563. → pp. 107, 108, 143 J. S. Breese [1992]. Construction of belief and decision networks. Computational Intelligence, 8(4):624–647. → pp. 2, 12, 21 A. A. Bulatov and V. Dalmau [2003]. Towards a dichotomy theorem for the count- ing constraint satisfaction problem. In Proceedings of 44rd IEEE Symposium on Foundations of Computer Science (FOCS’03), 562–571. → pp. 106 W. L. Buntine [1994]. Operations for learning with graphical models. Journal of Artificial Intelligence Research, 2:159–225. → pp. 20 P. Carbonetto, J. Kisyński, M. Chiang, and D. Poole [2009]. Learning a contin- gently acyclic, probabilistic relational model of a social network. Technical Re- port TR-2009-08, The University of British Columbia, Department of Computer Science. → pp. 101, 103 M. Chavira, A. Darwiche, and M. Jaeger [2006]. Compiling relational Bayesian networks for exact inference. International Journal of Approximate Reasoning, 42(1–2):4–20. → pp. 21 V. Dahllöf, P. Jonsson, and M. Wahlström [2002]. Counting satisfying assignments in 2-SAT and 3-SAT. In Proceedings of the 8th Annual International Computing and Combinatorics Conference (COCOON 2002), 535–543. → pp. 106, 107 173 V. Dahllöf, P. Jonsson, and M. Wahlström [2005]. Counting models for 2SAT and 3SAT formulae. Theoretical Computer Science, 332(1-3):265 – 291.→ pp. 106, 107 A. Darwiche [2009]. Modeling and Reasoning with Bayesian Networks. Cam- bridge University Press. → pp. 54 L. De Raedt, P. Frasconi, K. Kersting, and S. H. Muggleton, eds. [2008]. Prob- abilistic Inductive Logic Programming, volume 4911 of Lecture Notes in Com- puter Science. Springer. → pp. 2, 55 R. de Salvo Braz, E. Amir, and D. Roth [2005]. Lifted first-order probabilistic inference. In Proceedings of the 19th International Joint Conference on Artificial Intelligence (IJCAI 2005), 1319–1125. → pp. 3, 21 R. de Salvo Braz, E. Amir, and D. Roth [2006]. MPE and partial inversion in lifted probabilistic variable elimination. In Proceedings of the 21st National Conference on Artificial Intelligence (AAAI 2006), 1124–1130. → pp. 3, 21 R. de Salvo Braz, E. Amir, and D. Roth [2007]. Lifted first-order probabilistic inference. In L. Getoor and B. Taskar, eds., Introduction to Statistical Relational Learning, chapter 15, 433–450. MIT Press. → pp. ii, 3, 4, 15, 21, 22, 25, 31, 38, 66, 144, 148, 153, 168 R. de Salvo Braz, S. Natarajan, H. Bui, J. Shavlik, and S. Russell [2009]. Any- time lifted belief propagation. In Proceedings of the International Workshop on Statistical Relational Learning (SRL 2009). → pp. 55 R. Dechter [1999]. Bucket elimination: A unifying framework for reasoning. Ar- tificial Intelligence, 113(1):41–85. → pp. 9 R. Dechter [2003]. Constraint Processing. Morgan Kaufmann Publishers. → pp. ix, 106, 107, 108, 109, 110, 138 R. Dechter, K. Kask, and R. Mateescu [2002]. Iterative join-graph propagation. In Proceedings of the 18th Annual Conference on Uncertainty in Artificial Intelli- gence (UAI 2002), 128–136. → pp. 107 R. Dechter and J. Pearl [1987]. Network-based heuristics for constraint satisfaction problems. Artificial Intelligence, 34(1):1–38. → pp. 107 F. J. Díez [1993]. Parameter adjustment in Bayes networks. The generalized noisy OR-gate. In Proceedings of the 9th Annual Conference on Uncertainty in Artifi- cial Intelligence (UAI 1993), 99–105. → pp. 59 174 F. J. Díez and S. F. Galán [2003]. Efficient computation for the noisy MAX. Inter- national Journal of Intelligent Systems, 18(2):165–177. → pp. 69, 70, 98 O. Dubois [1991]. Counting the number of solutions for instances of satisfiability. Theoretical Computer Science, 81(1):49–64. → pp. 106 L. Getoor and B. Taskar, eds. [2007]. Introduction to Statistical Relational Learn- ing. Adaptive Computation and Machine Learning. MIT Press. → pp. 2, 55 J. Gørtz [2000]. Java tip 92: Use the JVM profiler interface for accurate timing. http://www.javaworld.com/javaworld/javatips/jw-javatip92.html. → pp. 138 R. Gupta, A. A. Diwan, and S. Sarawagi [2007]. Efficient inference with cardinality-based clique potentials. In Proceedings of the 24th Annual Inter- national Conference on Machine Learning (ICML 2007), 329–336. → pp. 15 M. Horsch and D. Poole [1990]. A dynamic approach to probabilistic inference using Bayesian networks. In Proceedings of the 6th Annual Conference on Un- certainty in AI (UAI 1990), 155–161. → pp. 2, 12 M. C. Horsch and W. S. Havens [2000]. Probabilistic arc consistency: A connec- tion between constraint reasoning and probabilistic reasoning. In Proceedings of the 16th Conference on Uncertainty in Artificial Intelligence (UAI 2000), 282– 290. → pp. 107 M. Jaeger [2002]. Relational Bayesian networks: a survey. Electronic Transactions in Artificial Intelligence, 6. → pp. 60 K. Kask, R. Dechter, and V. Gogate [2004a]. Counting-based look-ahead schemes for constraint satisfaction. In Proceedings of the 10th International Conference on Principles and Practice of Constraint Programming (CP 2004), 317–331. → pp. 107 K. Kask, R. Dechter, and V. Gogate [2004b]. New look-ahead schemes for con- straint satisfaction. In The 8th International Symposium on Artificial Intelligence and Mathematics (AI&M 2004). → pp. 107 K. Kersting, B. Ahmadi, and S. Natarajan [2009]. Counting belief propagation. In Proceedings of the 25th Annual Conference on Uncertainty in Artificial Intelli- gence (UAI 2009), 277–284. → pp. 55 J. Kisyński and D. Poole [2009a]. Constraint processing in lifted probabilistic inference. In Proceedings of the 25th Annual Conference on Uncertainty in Artificial Intelligence (UAI 2009), 293–302. → pp. 5 175 J. Kisyński and D. Poole [2009b]. Lifted aggregation in directed first-order prob- abilistic models. In Proceedings of the 21st International Joint Conference on Artificial Intelligence (IJCAI 2009), 1922–1929. → pp. 5 U. Kjærulff [1990]. Triangulation of graphs - algorithms giving small total state space. Technical Report R90-09, Aalborg University, Department of Mathemat- ics and Computer Science, Aalborg, Denmark. → pp. 12, 139 D. E. Knuth [2005]. The Art of Computer Programming, Volume 4: Combinatorial Algorithms, Fascicle 3: Generating All Combinations and Partitions. Addison- Wesley. → pp. 112, 184 D. Koller and N. Friedman [2009]. Probabilistic Graphical Models: Principles and Techniques. Adaptive Computation and Machine Learning. MIT Press. → pp. 2, 54 D. Koller and A. Pfeffer [1997]. Object-oriented Bayesian networks. In Proceed- ings of the 13th Annual Conference on Uncertainty in AI (UAI 1997), 302–313. → pp. 21 J. W. Lloyd [1987]. Foundations of Logic Programming. Springer, 2nd edition. → pp. 17 L. Lovász [2003]. Combinatorial Problems and Exercises. North-Holland, 2nd edition. → pp. 112 A. K. Mackworth [1977]. Consistency in networks of relations. Artificial Intelli- gence, 8(1):99–118. → pp. 40 A. Meisels, S. E. Shimony, and G. Solotorevsky [2000]. Bayes networks for esti- mating the number of solutions to a CSP. Annals of Mathematics and Artificial Intelligence, 28(1-4):169–186. → pp. 106 B. Milch [2006]. Probabilistic Models with Unknown Objects. Ph.D. thesis, Uni- versity of California, Berkeley, Computer Science Division. → pp. 55 B. Milch, L. S. Zettlemoyer, K. Kersting, M. Haimes, and L. P. Kaelbling [2008]. Lifted probabilistic inference with counting formulas. In Proceedings of the 23rd AAAI Conference on Artificial Intelligence (AAAI 2008), 1062–1068. → pp. ii, 3, 4, 15, 21, 22, 25, 26, 31, 33, 35, 36, 37, 38, 46, 50, 66, 145, 146, 148, 153, 160, 162, 168 U. Montanari [1974]. Networks of constraints: Fundamental properties and appli- cations to picture processing. Information Sciences, 7(2):95–132. → pp. 106 176 C. H. Papadimitriou [1994]. Computational complexity. Addison Wesley. → pp. 106 J. Pearl [1986]. Fusion, propagation and structuring in belief networks. Artificial Intelligence, 29(3):241–288. → pp. 59 J. Pearl [1988]. Probabilistic Reasoning in Intelligent Systems: Networks of Plau- sible Inference. Morgan Kaufmann. → pp. 6 M. Pearson and L. Michell [2000]. Smoke Rings: social network analysis of friend- ship groups, smoking and drug-taking. Drugs: education, prevention and policy, 7:21–37. → pp. 103 G. Pesant [2005]. Counting solutions of CSPs: A structural approach. In Proceed- ings of the 19th International Joint Conference on Artificial Intelligence (IJCAI 2005), 260–265. → pp. 107 A. Pfeffer and D. Koller [2000]. Semantics and inference for recursive probability models. In Proceedings of the 17th National Conference on Artificial Intelli- gence (AAAI 2000), 538–544. → pp. 21 Piṅgala [200 B.C.]. Chandah-sûtra. → pp. 88 D. Poole [1993]. Probabilistic Horn abduction and Bayesian networks. Artificial Intelligence, 64(1):81–129. → pp. 16 D. Poole [1997]. The Independent Choice Logic for modeling multiple agents under uncertainty. Artificial Intelligence, 94(1–2):7–56. → pp. 16 D. Poole [2000]. Abducting through negation as failure: Stable models with the Independent Choice Logic. Journal of Logic Programming, 44:5–35. → pp. 16, 18 D. Poole [2003]. First-order probabilistic inference. In Proceedings of the 18th International Joint Conference on Artificial Intelligence (IJCAI 2003), 985–991. → pp. ii, 2, 3, 4, 21, 22, 25, 38, 43, 144, 146, 148, 153, 168 D. Poole [2008]. The Independent Choice Logic and beyond. In L. De Raedt, P. Frasconi, K. Kersting, and S. H. Muggleton, eds., Probabilistic Inductive Logic Programming, volume 4911 of Lecture Notes in Computer Science, 222– 243. Springer. → pp. 18, 101 D. Poole and A. Mackworth [2010]. Artificial Intelligence: foundations of compu- tational agents. Cambridge University Press. → pp. 1, 55 177 P. Refalo [2004]. Impact-based search strategies for constraint programming. In Proceedings of the 10th International Conference on Principles and Practice of Constraint Programming (CP 2004), 557–571. → pp. 107 D. Roth [1996]. On the hardness of approximate reasoning. Artificial Intelligence, 82(1-2):273–302. → pp. 106 S. J. Russell and P. Norvig [2009]. Artificial Intelligence - A modern approach. Prentice Hall, 3rd edition. → pp. 1, 55 P. Savicky and J. Vomlel [2007]. Exploiting tensor rank-one decomposition in probabilistic inference. Kybernetika, 43(5):747–764. → pp. 70 P. Sen, A. Deshpande, and L. Getoor [2009]. Bisimulation-based approximate lifted inference. In Proceedings of the 25th Annual Conference on Uncertainty in Artificial Intelligence (UAI 2009), 496–505. → pp. 55 P. Singla and P. Domingos [2008]. Lifted first-order belief propagation. In Pro- ceedings of the 23rd National Conference on Artificial Intelligence (AAAI 2008), 1094–1099. → pp. 5, 55 L. Sterling and E. Shapiro [1994]. The Art of Prolog. The MIT Press, 2nd edition. → pp. 38, 42 N. Taghipour, W. Meert, J. Struyf, and H. Blockeel [2009]. First-order Bayes- Ball for CP-Logic. In Proceedings of the International Workshop on Statistical Relational Learning (SRL 2009). → pp. 48 L. G. Valiant [1979]. The complexity of enumeration and reliability problems. SIAM Journal on Computing, 8(3):410–421. → pp. 106 W. A. Whitworth [1878]. Choice and Chance: An Elementary Treatise on Per- mutations, Combinations, and Probability, with 300 Exercises (3rd, revised and enlarged edition). Cambridge: Deighton Bell. → pp. 112 N. L. Zhang and D. Poole [1994]. A simple approach to Bayesian network com- putations. In Proceedings of the 10th Biennial Canadian Artificial Intelligence Conference (AI 1994), 171–178. → pp. 7, 9 N. L. Zhang and D. Poole [1996]. Exploiting causal independence in Bayesian network inference. Journal of Artificial Intelligence Research, 5:301–328. → pp. 58 W. Zhang [1996]. Number of models and satisfiability of sets of clauses. Theoret- ical Computer Science, 155(1):277–288. → pp. 106 178 Appendix A 1-dimensional Representation of VE Factors Appendix. Hmm. A-Anything else? — Lt. Father Francis John Patrick Mulcahy (M*A*S*H) In this appendix, we present a 1-dimensional representation of factors. It is based on David Poole’s Java implementation of VE for belief networks. Besides sav- ing memory when we want a dense representation, this representation allows for efficient implementation of the summing-out operator. Let us consider factor f on variables X1,X2, . . . ,Xn, where each variable Xi has a domain {xi0,xi1, . . . ,xidi−1} ordered according to some total ordering <i. Assume we are given a total ordering <X of the variables. The ordering <X is arbitrary. This situation induces a lexicographic ordering of the tuples of elements from the domains of the variables so that factors can be implemented as 1-dimensional ar- rays. Assume that we have X1 <X X2 <X · · · <X Xn and xi0 <i xi1 <i · · · <i xidi−1, for i = 1,2, . . . ,n. Ordering <T of the tuples in f is defined as follows: (x1i1 ,x 2 i2 , . . . ,x n in)<T (x 1 j1 ,x 2 j2 , . . . ,x n jn) ⇐⇒ ∃l∈{1,2,...,n} ( (xlil <l x l jl )∧∀k∈{1,2,...,l−1}(xkik =k xkjk) ) . 179 X1 X2 . . . Xn−1 Xn f () x10 x 2 0 . . . x n−1 0 x n 0 v0 x10 x 2 0 . . . x n−1 0 x n 1 v1 ... ... ... ... ... ... ... ... x10 x 2 0 . . . x n−1 0 x n dn−1 vdn−1 x10 x 2 0 . . . x n−1 1 x n 0 vdn x10 x 2 0 . . . x n−1 1 x n 1 vdn+1 ... ... ... ... ... ... ... ... x10 x 2 0 . . . x n−1 1 x n dn−1 v2dn−1 ... ... ... ... ... ... ... ...... ... ... ... ... ... ... ... x10 x 2 0 . . . x n−1 dn−1−1 x n 0 vdn(dn−1−1) x10 x 2 0 . . . x n−1 dn−1−1 x n 1 vdn(dn−1−1)+1 ... ... ... ... ... ... ... ... x10 x 2 0 . . . x n−1 dn−1−1 x n dn−1 vdndn−1−1 ... ... ... ... ... ... ... ...... ... ... ... ... ... ... ...... ... ... ... ... ... ... ... x1d1−1 x 2 d2−1 . . . x n−1 dn−1−1 x n 0 vdndn−1...d2(d1−1)+dndn−1...(d2−1)+···+dn(dn−1−1) x1d1−1 x 2 d2−1 . . . x n−1 dn−1−1 x n 1 vdndn−1...d2(d1−1)+dndn−1...(d2−1)+···+dn(dn−1−1)+1 ... ... ... ... ... ... ... ... x1d1−1 x 2 d2−1 . . . x n−1 dn−1−1 x n dn−1 vdndn−1...d2d1−1 Figure A.1: Structure of a VE factor. Figure A.1 shows the structure of factor f . The factor consists of d1d2 . . .dn tuples ordered according to <T with values v0,v1, . . . ,vd1d2...dn . Consider tuple (x1i1 ,x 2 i2 , . . . ,x n in) from the factor f . Given indexes i1, i2, . . . , in we can compute the tuple’s index (and thus, the index of its value) in f : (x1i1 ,x 2 i2 , . . . ,x n in)→ v((...(i1d2+i2)d3+...)dn−1+in−1)dn+in . Given the index of the tuple (the index of its value) in f , we can recover the tuple’s elements with the procedure indexToTuple( f , t) presented in Table A.2. Therefore, we do not need to store tuples in factors but only their values, which saves memory. 180 [00] procedure indexToTuple( f , t) [01] input: factor f on variables X1,X2, . . . ,Xn, [02] index t of the tuple; [03] output: tuple with index t in factor f ; [04] for j := n downto 2 do [05] set i j := t mod d j; [06] set t := t div d j; [07] end [08] set i1 := t; [09] return (x1i1 ,x 2 i2 , . . . ,x n in); [10] end Figure A.2: Procedure indexToTuple( f , t). 181 Appendix B Hierarchical Representation of #VE 6= Factors I’m afraid I have a bad appendix. — Maj. Margaret ‘Hot Lips’ O’Houlihan (M*A*S*H) In this appendix, we show how to implement the dense representation of #VE 6= factors as a hierarchy of 1-dimensional arrays, so that instead of storing both #VE 6= tuples and values in memory, we only need to store values. For simplicity, we will describe our representation using a factor on three vari- ables as an example. Consider Figure B.1, which illustrates domains of the three variables A, B and C. We need at most seven disjoint subsets, S1,S2, . . . ,S7, to spec- ify domains of the variables. In our example, we assume that all seven subsets are not empty; thus, the domain of each variable consists of four subsets. In the #VE 6= factor we represent subsets using seven s-constants, c1,c2, . . . ,c7, as described in Section 4.3.2.2. We represent a #VE 6= factor on A, B and C as a hierarchy of factors. The hi- erarchy consists of two levels. At the top level, there is a factor representing all combinations of s-constants describing the domain of each variable, and which maps them via pointers to factors from the bottom level of the hierarchy (see Fig- ure B.2. If we introduce a total ordering among s-constants, then we can represent 182 A B C S1 S2 S3 S4 S5 S7 S6 A = S1∪S2∪S3∪S5 B = S1∪S2∪S4∪S6 C = S1∪S3∪S4∪S7 Figure B.1: Domains of three variables represented with disjoint subsets. A B C → c1 c1 c1 − c1 c1 c3 − ... ... ... ... c1 c6 c7 − ... ... ... ...... ... ... ... c5 c6 c7 − {A,B,C} # {{A,B,C}} v0 {{A,B},{C}} v1 {{A,C},{B}} v2 {{A},{B,C}} v3 {{A},{B},{C}} v4 {A,B} {C} # {{A,B}} {{C}} v5 {{A},{B}} {{C}} v6 {A} {B} {C} # {{A}} {{B}} {{C}} v27 {A} {B} {C} # {{A}} {{B}} {{C}} v88 Figure B.2: Structure of a #VE 6= factor. the factor from the top level as a 1-dimensional array, as described in Appendix A. The disadvantage of such dense representation is that we have to store all of the pointers in the array, even if they are null. At the bottom level, there are factors mapping partitions of the variables A, B and C to the values of the #VE 6= factor. A combination of s-constants pointing to a factor from the bottom level determines the structure of the factor. For each subset of the variables with the same s-constant, we have some number of partitions. 183 For example, for the tuple of s-constants 〈c1,c1,c2〉, we have two partitions of variables A and B (namely {{A,B}} and {{A},{B}} and one partition of variable C ({{C}}). In the factor from the bottom level, we represent all of their combinations and map them to the appropriate values of the #VE 6= factor (see Figure B.2). If we use a standard lexicographic ordering of partitions (see [Knuth, 2005]), we can represent the factors from the bottom level as 1-dimensional arrays (as described in Appendix A) and a list of partitions for each subset of variables. The disadvantage of such dense representation is that we have to store values for all combinations of partitions in the array, even if they are 0 (which can happen sometimes after summing out). The combinatorial properties of set partitions allow us to efficiently recover the partition structure from the position of the partition in the ordering, and to compute the position of the partition in the ordering given its structure. Therefore, we do not need to store lists of partitions associated with factors from the bottom level of the hierarchy, but only lists of their indexes in the ordering. Java methods that implement necessary operations on set partitions and Bell numbers are part of the Bell package1. As it is mainly a programming exercise, we do not describe those methods. It is important to mention that the hierarchical, dense representation is not the only possibility. An empirical evaluation is necessary to decide whether it is better than a flat, sparse representation or a hierarchical, sparse representation. Similarly, one could use partitions themselves instead of indexes of set partitions. 1http://people.cs.ubc.ca/~kisynski/code/bell/ 184 Appendix C From Parfactors to #VE 6= Factors Well, I figured I would go after the appendix while I’m in the area. — Maj. Frank Marion ‘Ferret Face’ Burns (M*A*S*H) In this appendix, we show how to represent a CSP induced by a parfactor in terms of #VE 6= factors. We use the dense representation of #VE 6= factors described in Appendix B. For simplicity we will analyze a CSP consisting of a single connected compo- nent with three variables. Consider the following parfactor: 〈C,{ f (A,B,C),g(A,C),g(x2,x9)},F〉, [0] where C= {A 6= x2,B 6= x3,B 6= x7,C 6= x2,A 6= B,B 6=C}, D(A) =D(B) =D(C) and |D(A) |= 10. Constraints in the parfactor form a CSP instance P = ({A,B,C},D,C), where D(A) = D(B) = D(C). We know that D(A) contains ten elements. We know only those elements of D(A), which are explicitly present in the parfactor: x2, x3, x7, x9. Let us represent the instance P using #VE 6= factors. First, we exclude elements participating in unary constraints from the domains of the variables A, B, and C and obtain pruned domains D̂(A), D̂(B), and D̂(C). Then, we partition pruned domains into disjoint sets of elements, and represent these sets as s-constants (see 185 Section 4.3.2.1). There are three variables, so we will need at most 23− 1 = 7 s-constants (see Figure B.1). In our implementation we create a sparse data structure that maps potential s- constants to the sets of elements they represent. We pick an arbitrary total ordering < of D(A), sort unary constraints for each variable according to <, and process the elements known to us in order of <. This allows us to generate sets of indistin- guishable individuals represented by s-constants through a single sweep of unary constraints and elements that are known to us. Each set of elements represented by an s-constant can be defined by listing all of its elements or by listing all elements from the domain that do not belong to it. For each set we choose a more compact representation. For simplicity, let as assume that x2 < x3 < x7 < x9. Element x2 is excluded from the domain of A and C, therefore it is represented by the s-constant S6. El- ement x3 is excluded from the domain of B, therefore it is represented by the s- constant S3. Element x7 is also represented by S3. Element x9 belongs to the domains of all variables and is represented by the s-constant S1. The remaining six elements belong to the domains of all variables and are also represented by S1. S1 represents seven elements, S3 represents two elements, and S6 represents one element. We have D̂(A) = S1∪S3, D̂(B) = S1∪S6, and D̂(C) = S1∪S3. Although the #VE 6= algorithm only needs to know the sizes of the sets denoted by each s-constant, we need to know the elements of these sets so that we can interpret answers returned by the #VE 6= algorithm. The s-constant S1 represents the set of elements {x ∈ D(A)|A 6= x2 ∧A 6= x3 ∧A 6= x7}, S3 represents the set {x3,x7} and S6 represents the set {x2}. The length of the descriptions of each of these sets is independent of the size of D(A). Once we process unary constraints and obtain s-constants, we can use the pro- cedure from Figure 4.10 to construct the following representation of the CSP in- stance: A B Partition(s) # S1 S1 {{A,B}} 0 S1 S1 {{A},{B}} 1 S1 S6 {{A}} {{B}} 1 S3 S1 {{A}} {{B}} 1 S3 S6 {{A}} {{B}} 1 B C Partition(s) # S1 S1 {{B,C}} 0 S1 S1 {{B},{C}} 1 S1 S3 {{B}} {{C}} 1 S6 S1 {{B}} {{C}} 1 S6 S3 {{B}} {{C}} 1 186 The first #VE 6= factor represents the binary constraint A 6= B and the second #VE 6= factor represents the binary constraint B 6=C. If the domains of logical variables present in the parfactor were larger, we would perform exactly the same computation, only the size of the set represented by the s-constant S1 would be larger. 187 Appendix D From #VE 6= Factors to Parfactors That’s right up my alley, I wrote the book on the appendix. I even wrote the appendix, but they took that out. — Capt. Benjamin Franklin ‘Hawkeye’ Pierce (M*A*S*H) In this appendix, we show how an answer from the #VE 6= algorithm is pro- cessed by a lifted inference procedure. Consider the following parfactor from Appendix C: 〈C,{ f (A,B,C),g(A,C),g(x2,x9)},F〉, [0] where C = {A 6= x2,B 6= x3,B 6= x7,C 6= x2,A 6= B,B 6=C}, D(A) =D(B) =D(C) and |D(A) |= 10. Assume that a lifted inference procedure is about to sum out the parameterized random variable f (A,B,C) from the parfactor [0]. The logical variable B appears only in f (A,B,C) and will be eliminated from the parfactor. Therefore the resulting parfactor will represent fewer factors than the parfactor [0] and the lifted probabilis- tic inference procedure needs to compensate for this difference. To do so, it needs to compute the size of the set D(B) : C, which tells how many times fewer factors the resulting parfactor will represent. The parfactor [0] is not in normal form and it is necessary to compute all the sizes of the D(B) : C set conditioned on values of logical variables remaining in the resulting parfactor, namely A and C. In our im- 188 plementation, the lifted inference procedure uses the #VE 6= algorithm to perform this task. First, we represent the CSP instance formed by constraints in the parfactor [0]. This is described in Appendix C. Then, the #VE 6= algorithm multiplies the two #VE 6= factors that represent the CSP instance and sums out B from the product. The #VE 6= algorithm returns the following answer: A C Partition(s) # S1 S1 {{A,C}} 7 S1 S1 {{A},{C}} 6 S1 S3 {{A}} {{C}} 7 S3 S1 {{A}} {{C}} 7 S3 S3 {{A,C}} 8 S3 S3 {{A},{B}} 8 We also know that the s-constant S1 represents the set of elements {x ∈ D(A)|A 6= x2 ∧A 6= x3 ∧A 6= x7} and the s-constant S3 represents the set {x3,x7} (see Ap- pendix C). The answer from the #VE 6= algorithm needs to be translated to sets of sub- stitutions and constraints accompanying each #VE 6= tuple and its value. We start with computing the generic result of summation, parfactor [00], by summing out f (A,B,C) from the parfactor [0] without compensating for disappearance of B: 〈{A 6= x2,C 6= x2},{g(A,C),g(x2,x9)},F f 〉, [00] where F f = ∑ f (...) F Next, for each #VE 6= tuple we generate one or more parfactors by modifying the parfactor [00]: • 〈S1,S1, [{{A,C}}]〉 – A and C are equal, their domain is {x ∈ D(A)|A 6= x2∧ A 6= x3 ∧A 6= x7}. We add the description of the domain to the parfactor [00], apply substitution {A/C} to the parfactor [00], and bring the factor component to the power 7: 〈{C 6= x2,C 6= x3,C 6= x7},{g(C,C),g(x2,x9)},F f 7〉; [01] 189 • 〈S1,S1, [{{A},{C}}]〉 – A and C are different, their domains are respectively {x ∈ D(A)|A 6= x2∧A 6= x3∧A 6= x7} and {x ∈ D(C)|C 6= x2∧C 6= x3∧C 6= x7}. We add the descriptions of the domains to the parfactor [00], add con- straint A 6=C, and bring the factor component to the power 6: 〈{A 6=x2,A 6=x3,A 6=x7,C 6=x2,C 6=x3,C 6=x7,A 6=C},{g(A,C),g(x2,x9)},F f 6〉; [02] • 〈S1,S3, [{{A}} {{C}}]〉 – A and C have disjoint domains, their domains are respectively {x ∈ D(A)|A 6= x2 ∧ A 6= x3 ∧ A 6= x7} and {x3,x7}. We add the description of the domain of A to the parfactor [00], apply substitution {C/x3}, and bring the factor component to the power 7; we repeat the process for substitution {C/x7}: 〈{A 6= x2,A 6= x3,A 6= x7},{g(A,x3),g(x2,x9)},F f 7〉, [03] 〈{A 6= x2,A 6= x3,A 6= x7},{g(A,x7),g(x2,x9)},F f 7〉; [04] • 〈S3,S1, [{{A}} {{C}}]〉 – A and C have disjoint domains, their domains are respectively {x3,x7} and {x ∈ D(C)|C 6= x2 ∧C 6= x3 ∧C 6= x7}. We add the description of the domain of C to the parfactor [00], apply substitution {A/x3}, and bring the factor component to the power 7; we repeat the process for substitution {A/x7}: 〈{C 6= x2,C 6= x3,C 6= x7},{g(x3,C),g(x2,x9)},F f 7〉, [05] 〈{C 6= x2,C 6= x3,C 6= x7},{g(x7,C),g(x2,x9)},F f 7〉; [06] • 〈S3,S3, [{{A,C}}]〉 – A and C are equal, their domain is {x3,x7}. We apply substitutions {A/x3} and {C/x3} to the parfactor [00] and bring the factor component to the power 8; we repeat the process for substitutions {A/x7} and {C/x7}: 〈 /0,{g(x3,x3),g(x2,x9)},F f 8〉, [07] 〈 /0,{g(x7,x7),g(x2,x9)},F f 8〉; [08] 190 • 〈S3,S3, [{{A},{B}}]〉 – A and C are different, their domain is {x3,x7}. We apply substitutions {A/x3} and {C/x7} to the parfactor [00] and bring the factor component to the power 8; we repeat the process for substitutions {A/x7} and {C/x3}: 〈 /0,{g(x3,x7),g(x2,x9)},F f 8〉, [09] 〈 /0,{g(x7,x3),g(x2,x9)},F f 8〉; [10] The summation created many parfactors, but significantly fewer than would be created by a #CSP solver that does not produced lifted description as output. The above example strongly suggests that an extension to the calculus of par- factors that would allow reasoning about sets of individuals belonging to some population is worth pursuing. 191 Appendix E Splitting as Needed It isn’t necessary. It isn’t a hot appendix. It’s chronic. — Maj. Margaret ‘Hot Lips’ O’Houlihan (M*A*S*H) In this appendix we apply propositions introduced in Section 2.5.2 and present a simple lifted computation which illustrates the splitting as needed approach (Sec- tion 5.2.1). We use the same model and compute the same query as in Sec- tion 2.5.2.7, where we demonstrated how the C-FOVE algorithm performs in- ference with the use of the shattering operation (Section 5.2.1). . Consider the parfactors from Example 2.7 (page 23), which represent the ICL theory from Example 2.6 (page 18) and Figure 2.5 (page 19). Assume D(Lot) = {lot1, lot2, . . . , lotn} and that it is observed that grass is wet on lot1, which can be represented by the following parfactor: 〈 /0,{wet_grass(lot1)}, P(wet_grass(lot1) = f alse) P(wet_grass(lot1) = true)0.0 1.0 〉 . 192 LetΦ be a set of the three parfactors from Example 2.7 and the above parfactor (in what follows, we don’t show details of factor components of parfactors): Φ= {〈 /0,{rain()},F1〉, [01] 〈 /0,{sprinkler(Lot)},F2〉, [02] 〈 /0,{rain(),sprinkler(Lot),wet_grass(Lot)},F3〉, [03] 〈 /0,{wet_grass(lot1)},F4〉}. [04] Assume we want to compute Jground(wet_grass(Lot)):{Lot 6=lot1}(Φ). Note that this is the joint on wet_grass(Lot) for all lots except lot1. Let us first eliminate the parameterized random variable sprinkler(Lot). We apply Proposition 2.3 and multiply the two parfactors that involve sprinkler(Lot), namely [02] and [03]. Both parfactors represent the same number of factors, namely n, and no correction is necessary. We obtain the product 〈 /0,{rain(),sprinkler(Lot),wet_grass(Lot)},F5〉, [05] where F5 = F2F3. The new set of parfactors is as follows: Φ1 = {〈 /0,{rain()},F1〉, [01] 〈 /0,{wet_grass(lot1)},F4〉, [04] 〈 /0,{rain(),sprinkler(Lot),wet_grass(Lot)},F5〉}. [05] Next, we apply Proposition 2.1 and sum out sprinkler(Lot) from parfactor [05]. No logical variable disappears from the parfactor and we do not need to compensate for it. We obtain the following parfactor: 〈 /0,{rain(),wet_grass(Lot)},F6〉, [06] 193 where F6 = ∑sprinkler(Lot)F5. The new set of parfactors is as follows: Φ2 = {〈 /0,{rain()},F1〉, [01] 〈 /0,{wet_grass(lot1)},F4〉 [04] 〈 /0,{rain(),wet_grass(Lot)},F6〉}. [06] Next, we again apply Proposition 2.3 and multiply the parfactors involving parameterized random variable rain(), [01] and [06], and obtain the following par- factor: 〈 /0,{rain(),wet_grass(Lot)},F7〉, [07] where F7 = F1 1n F6. Parfactor [01] represents one factor, while parfactor [06] represents n factors, and we needed to compensate for this when computing par- factor [07]. The new set of parfactors is as follows: Φ3 = {〈 /0,{wet_grass(lot1)},F4〉 [04] 〈 /0,{rain(),wet_grass(Lot)},F7〉}. [07] We cannot eliminate rain() from parfactor [07], because param(rain()) + param(wet_grass(Lot)). Instead, we apply Proposition 2.6 to parfactor [07] and perform counting on the logical variable Lot. We obtain 〈 /0,{rain(),#Lot [wet_grass(Lot)]},F8〉, [08] where F8 is defined as in Equation 2.10. The new set of parfactors is as follows: Φ4 = {〈 /0,{wet_grass(lot1)},F4〉 [04] 〈 /0,{rain(),#Lot [wet_grass(Lot)]},F8〉}. [08] Now, we can sum out rain() from parfactor [08] (Proposition 2.1). We obtain 〈 /0,{#Lot [wet_grass(Lot)]},F9〉, [09] 194 where F9 = ∑rain()F8. The new set of parfactors is as follows: Φ5 = {〈 /0,{wet_grass(lot1)},F4〉 [04] 〈 /0,{#Lot [wet_grass(Lot)]},F9〉}. [09] Before we can multiply the two remaining parfactors, we need to apply Propo- sition 2.5 to parfactor [09] and expand the counting formula #Lot [wet_grass(Lot)]. We obtain the following parfactor: 〈 /0,{wet_grass(lot1),#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F10〉, [10] where F10 is defined as in Equation 2.8. The new set of parfactors is as follows: Φ6 = {〈 /0,{wet_grass(lot1)},F4〉 [04] 〈 /0,{wet_grass(lot1),#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F10〉}. [10] Next, we multiply parfactor [04] by parfactor [10] (Proposition 2.3) and obtain: 〈 /0,{wet_grass(lot1),#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F11〉, [11] where F11 = F10F4. The new set of parfactors is as follows: Φ7 = {〈 /0,{wet_grass(lot1),#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F11〉}. [11] We sum out wet_grass(lot1) from parfactor [11] (Proposition 2.1) and obtain 〈 /0,{#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F12〉, [12] where F12 = ∑wet_grasslot1F11. The new set of parfactors is as follows: Φ8 = {〈 /0,{#Lot:{Lot 6=lot1}[wet_grass(Lot)]},F12〉}. [12] We have Jground(wet_grass(Lot)):{Lot 6=lot1}(Φ) = J (Φ8) . 195 During computation, constants lot2, lot3, . . . , lotn were not explicitly enumer- ated, we only needed to know that D(Lot) = n. The biggest factor created during inference had size 8 (factor F3) for n ≤ 4 and 2(n+ 1) (factor F8) for n > 4. We performed 1 expansion, 3 multiplications, 1 counting operation, and 3 summations. During inference presented in Section 2.5.2.7, the C-FOVE algorithm performed 2 splits, 5 multiplications, 1 counting operation, and 4 summations. 196
- Library Home /
- Search Collections /
- Open Collections /
- Browse Collections /
- UBC Theses and Dissertations /
- Aggregation and constraint processing in lifted probabilistic...
Open Collections
UBC Theses and Dissertations
Featured Collection
UBC Theses and Dissertations
Aggregation and constraint processing in lifted probabilistic inference Kisynski, Jacek Jerzy 2010
pdf
Notice for Google Chrome users:
If you are having trouble viewing or searching the PDF with Google Chrome, please download it here instead.
If you are having trouble viewing or searching the PDF with Google Chrome, please download it here instead.
Page Metadata
Item Metadata
Title | Aggregation and constraint processing in lifted probabilistic inference |
Creator |
Kisynski, Jacek Jerzy |
Publisher | University of British Columbia |
Date Issued | 2010 |
Description | Representations that mix graphical models and first-order logic - called either first-order or relational probabilistic models — were proposed nearly twenty years ago and many more have since emerged. In these models, random variables are parameterized by logical variables. One way to perform inference in first-order models is to propositionalize the model, that is, to explicitly consider every element from the domains of logical variables. This approach might be intractable even for simple first-order models. The idea behind lifted inference is to carry out as much inference as possible without propositionalizing. An exact lifted inference procedure for first-order probabilistic models was developed by Poole [2003] and later extended to a broader range of problems by de Salvo Braz et al. [2007]. The C-FOVE algorithm by Milch et al. [2008] expanded the scope of lifted inference and is currently the state of the art in exact lifted inference. In this thesis we address two problems related to lifted inference: aggregation in directed first-order probabilistic models and constraint processing during lifted inference. Recent work on exact lifted inference focused on undirected models. Directed first-order probabilistic models require an aggregation operator when a parent random variable is parameterized by logical variables that are not present in a child random variable. We introduce a new data structure, aggregation parfactors, to describe aggregation in directed first-order models. We show how to extend the C-FOVE algorithm to perform lifted inference in the presence of aggregation parfactors. There are cases where the polynomial time complexity (in the domain size of logical variables) of the C-FOVE algorithm can be reduced to logarithmic time complexity using aggregation parfactors. First-order models typically contain constraints on logical variables. Constraints are important for capturing knowledge regarding particular individuals. However, the impact of constraint processing on computational efficiency of lifted inference has been largely overlooked. In this thesis we develop an efficient algorithm for counting the number of solutions to the constraint satisfaction problems encountered during lifted inference. We also compare, both theoretically and empirically, different ways of handling constraints during lifted inference. |
Genre |
Thesis/Dissertation |
Type |
Text |
Language | eng |
Date Available | 2010-03-31 |
Provider | Vancouver : University of British Columbia Library |
Rights | Attribution-NonCommercial-NoDerivatives 4.0 International |
DOI | 10.14288/1.0051829 |
URI | http://hdl.handle.net/2429/23170 |
Degree |
Doctor of Philosophy - PhD |
Program |
Computer Science |
Affiliation |
Science, Faculty of Computer Science, Department of |
Degree Grantor | University of British Columbia |
GraduationDate | 2010-05 |
Campus |
UBCV |
Scholarly Level | Graduate |
Rights URI | http://creativecommons.org/licenses/by-nc-nd/4.0/ |
AggregatedSourceRepository | DSpace |
Download
- Media
- 24-ubc_2010_spring_kisynski_jacek.pdf [ 1.47MB ]
- Metadata
- JSON: 24-1.0051829.json
- JSON-LD: 24-1.0051829-ld.json
- RDF/XML (Pretty): 24-1.0051829-rdf.xml
- RDF/JSON: 24-1.0051829-rdf.json
- Turtle: 24-1.0051829-turtle.txt
- N-Triples: 24-1.0051829-rdf-ntriples.txt
- Original Record: 24-1.0051829-source.json
- Full Text
- 24-1.0051829-fulltext.txt
- Citation
- 24-1.0051829.ris
Full Text
Cite
Citation Scheme:
Usage Statistics
Share
Embed
Customize your widget with the following options, then copy and paste the code below into the HTML
of your page to embed this item in your website.
<div id="ubcOpenCollectionsWidgetDisplay">
<script id="ubcOpenCollectionsWidget"
src="{[{embed.src}]}"
data-item="{[{embed.item}]}"
data-collection="{[{embed.collection}]}"
data-metadata="{[{embed.showMetadata}]}"
data-width="{[{embed.width}]}"
data-media="{[{embed.selectedMedia}]}"
async >
</script>
</div>
Our image viewer uses the IIIF 2.0 standard.
To load this item in other compatible viewers, use this url:
https://iiif.library.ubc.ca/presentation/dsp.24.1-0051829/manifest