-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
358 lines (303 loc) · 12.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Rules Engines: Logic As Data Structure</title>
<meta name="description" content="Business rules engines provide a highly flexible and surprisingly scalable approach to expressing complex and changing business logic. Descended from inference engines used in artificial intelligence applications, rules engines offer unique trade-offs compared with statically coded logic. In this talk, we’ll dive into the mechanisms behind rules engines, discuss circumstances in which they might be a good option, and elaborate on distinct features they bring to the table. Looking at an open source rules engine, we’ll examine how common logic can be expressed, traced, and visualized. Finally, we’ll delve into the performance characteristics and scalability of rules engines used in a production capacity.">
<meta name="author" content="Jarrell Waggoner">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="reveal.js/css/reveal.css">
<link rel="stylesheet" href="reveal.js/css/theme/solarized.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'reveal.js/css/print/pdf.css' : 'reveal.js/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="reveal.js/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Rules Engines:</h1>
<h3><span style="opacity:0.50">Logic As Data Structure</span></h3>
<p>
<small><a href="http://www.malloc47.com">Jarrell Waggoner</a> / <a href="http://twitter.com/malloc47">@malloc47</a></small>
</p>
<br />
<p><small>Online: <a href="http://www.malloc47.com/posscon2015/">malloc47.com/posscon2015/</a></small></p>
</section>
<section>
<section>
<h1><span style="opacity:0.5">About</span> Me</h1>
</section>
<section>
<img src="img/groupon.png" style="border: none; box-shadow: none;" width="500px" alt="Groupon">
<p class="fragment face">Big Data<span style="opacity:0.5">-○-</span>Software Development<span style="opacity:0.5">-○-</span>Clojure</p>
</section>
<section>
<h1><span style="opacity:0.5">I do</span> <span style="font-family:Open Sans;">A.I.</span></h1>
<p class="fragment face">Computer
Vision<span style="opacity:0.5">-○-</span>Image
Processing<span style="opacity:0.5">-○-</span>Machine
Learning</p>
</section>
</section>
<section>
<section>
<img src="img/beeker.gif" style="border: none; box-shadow: none;" alt="what is this I don't even">
<h3>What is a Rules Engine?</h3>
</section>
<section>
<h3>Related Terms</h3>
<ul>
<li>Expert Systems (1970s-1980s)
<ul>
<li>Knowledge Base</li>
<li>Inference Engine</li>
</ul>
</li>
<li>Business Rules</li>
<li>Rete Algorithm (1974-2010)</li>
</ul>
</section>
<!-- <section> -->
<!-- <h3><span style="opacity:0.50">Business Rules Engine</span></h3> -->
<!-- <ul> -->
<!-- <li>Knowledge Base: Business Rules</li> -->
<!-- <li>Inference Engine: Rete Algorhtm</li> -->
<!-- </ul> -->
<!-- </section> -->
<!-- <section> -->
<!-- <h3><span style="opacity:0.50">What is a rules engine?</span></h3> -->
<!-- </section> -->
<section>
<h3>A Rules Engine is an...</h3>
<p><strong>Expert system</strong> that applies an <strong>inference engine</strong> to a <strong>knowledge base</strong> consisting of <strong>if/then
rules</strong> and <strong>facts</strong>, executing <strong>arbitrary actions</strong> or inserting <strong>new facts</strong> when a rule matches.</p>
</section>
<section>
<h3>In practical terms</h3>
<ul>
<li><strong>If/then rules</strong>: specified in a DSL and "compiled" into the knowledge base</li>
<li><strong>Fact</strong>: base language object (Java object, Ruby hash, Clojure defrecord, etc.)</li>
<li><strong>Knowledge base</strong>: special graph that connects rules and facts together</li>
<li><strong>Inference Engine</strong>: Rete Algorhtm</li>
</ul>
</section>
<section>
<h3>Rete Algorithm</h3>
<ul>
<li>Latin for 'net' or 'comb'</li>
<li>Represents rules as a (directed acyclic) graph</li>
<li>Trades memory for increased speed</li>
<li>Performance is (theoretically) independent of the total number of rules</li>
<li>Forward chaining vs. backward chaining used by Prolog</li>
</ul>
</section>
<section>
<h3>Rete Algorithm Visualization</h3>
<img src="img/rete1.png" style="border: none; box-shadow: none;" height="500px" alt="rete1">
<p>
<small>
<a href="http://www.drdobbs.com/architecture-and-design/the-rete-matching-algorithm/184405218">http://www.drdobbs.com/architecture-and-design/the-rete-matching-algorithm/184405218</a>
</small>
</p>
</section>
<section>
<p>Popular rules engines:</p>
<ul>
<li><a href="http://www.drools.org/">Drools</a></li>
<li><a href="http://herzberg.ca.sandia.gov/">Jess</a></li>
<li class="fragment grow"><a href="https://github.com/rbrush/clara-rules/">Clara</a></li>
</ul>
</section>
</section>
<section>
<section>
<h3><span style="opacity:0.50">Rules Engine</span></h3>
<h1>Example</h1>
<img src="img/learn-your-rules.gif" style="border: none; box-shadow: none;" height="200px" alt="learn your rules">
</section>
<section>
<h3>College Application Processor</h3>
<ul>
<li>Facts: applicant, parents, grades</li>
<li>Rules: acceptance criteria, financial aid criteria</li>
</ul>
</section>
<section>
<h3>Facts</h3>
<pre><code data-trim>
(defrecord Applicant [name age])
(defrecord Grade [type score])
(defrecord Parents [income alumni?])
(defrecord Accept [])
(defrecord Aid [amount])
</code></pre>
<p>Must use facts for input and output</p>
</section>
<section>
<h3>Rule 1</h3>
<pre><code data-trim>
(defrule good-enough-grades
[Grade (= type :gpa) (> score 3.0)]
[:or
[Grade (= type :sat) (> score 1500)]
[Grade (= type :act) (> score 20)]]
=>
(insert! (->Accept)))
</code></pre>
</section>
<section>
<img src="diagram/rule1.png" style="border: none; box-shadow: none;" height="600px" alt="rule1">
</section>
<section>
<img src="diagram/network1.png" style="border: none; box-shadow: none;" alt="network1">
</section>
<section>
<h3>Rule 2</h3>
<pre><code data-trim>
(defrule rich-parents
[Parents (> income 2000000)]
=>
(insert! (->Accept)))
</code></pre>
</section>
<section>
<img src="diagram/rule2.png" style="border: none; box-shadow: none;" height="600px" alt="rule2">
</section>
<section>
<img src="diagram/network2.png" style="border: none; box-shadow: none;" alt="network2">
</section>
<section>
<h3>Rule 3</h3>
<pre><code data-trim>
(defrule aid-package
[Accept]
[Applicant (< age 26)]
[Parents (< income 60000)]
=>
(insert! (->Aid 20000)))
</code></pre>
</section>
<section>
<img src="diagram/rule3.png" style="border: none; box-shadow: none;" height="700px" alt="rule3">
</section>
<section>
<img src="diagram/network3.png" style="border: none; box-shadow: none;" alt="network3">
</section>
<section>
<h3>Run Rules Engine</h3>
<pre><code data-trim>
(def facts
[(->Applicant "Phil" 22)
(->Parents 50000 false)
(->Grade :gpa 3.1)
(->Grade :sat 1650)])
(defn run-rules []
(let [session
(-> (mk-session 'examples.college :cache false)
(insert-all facts)
(fire-rules))]
#_(print results here))
</code></pre>
<p>=></p>
<pre><code data-trim>
Accepted: true
Aid : 20000
</code></pre>
</section>
</section>
<section>
<h1>Performance</h1>
<img src="img/fractical-gears.gif" style="border: none; box-shadow: none;" height="300px" alt="fractical-gears">
</section>
<section>
<section>
<h1>Why?</h1>
<img src="img/why.gif" style="border: none; box-shadow: none;" alt="why">
</section>
<section>
<h3>Rationale for Rules Engines</h3>
<ul>
<li>Rules as first class
<ul>
<li>Composable</li>
<li>Testable</li>
<li>Serializable</li>
</ul>
</li>
<li>Clean separation of data and logic</li>
<li>Logic aggregation</li>
<li>Scalable both horizontally and vertically</li>
<li>Auditable (rule triggers can be "explained")</li>
<li>Visualizable (rules are data; can be graphed)</li>
</ul>
</section>
<section>
<h3>When to use a rules engine?</h3>
<ul>
<li>Lots of branching logic in rules</li>
<li>New entities may be introduced/removed</li>
<li>Rules constantly changing (commit hot-spots)</li>
<li>Non-technical stakeholders need to change rules</li>
<li>Your system has <a href="https://github.com/rbrush/clara-rules/wiki/Introduction#logical-knots">logical knots</a>: complex dependencies on arbitrary logic and data</li>
</ul>
</section>
</section>
<section>
<h1>Resources</h1>
<small>
<ul>
<li><a href="http://www.jessrules.com/docs/71/rete.html">http://www.jessrules.com/docs/71/rete.html</a></li>
<li><a href="http://herzberg.ca.sandia.gov/guidelines.shtml">http://herzberg.ca.sandia.gov/guidelines.shtml</a></li>
<li><a href="http://www.oracle.com/technetwork/articles/geminiuc-097530.html">http://www.oracle.com/technetwork/articles/geminiuc-097530.html</a></li>
<li><a href="https://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html_single/">https://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html_single/</a></li>
<li><a href="http://www.infoq.com/articles/Rule-Engines">http://www.infoq.com/articles/Rule-Engines</a></li>
<li><a href="http://en.wikipedia.org/wiki/Rete_algorithm">http://en.wikipedia.org/wiki/Rete_algorithm</a></li>
<li><a href="http://martinfowler.com/bliki/RulesEngine.html">http://martinfowler.com/bliki/RulesEngine.html</a></li>
<li><a href="http://dwhbp.com/post/2011/10/30/Implementing-a-Business-Rule-Engine.aspx">http://dwhbp.com/post/2011/10/30/Implementing-a-Business-Rule-Engine.aspx</a></li>
<li><a href="http://reports-archive.adm.cs.cmu.edu/anon/1995/CMU-CS-95-113.pdf">http://reports-archive.adm.cs.cmu.edu/anon/1995/CMU-CS-95-113.pdf</a></li>
</ul>
</small>
</section>
<section>
<h1>=> The End</h1>
</section>
</div>
</div>
<script src="reveal.js/lib/js/head.min.js"></script>
<script src="reveal.js/js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true },
{ src: 'reveal.js/plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>