-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
758 lines (608 loc) · 20.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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Markov Chains for Fun and Profit</title>
<meta name="description" content="Twitter bots are fun">
<meta name="author" content="Jeremy Green">
<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="css/reveal.css">
<link rel="stylesheet" href="css/theme/sky.css" id="theme">
<link rel="stylesheet" href="css/custom.css">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="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 ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="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>
<h2>Markov chains for fun<br/><span class="strike-outer"><span class="strike-inner">and profit</span></span></h2><br/>
<blockquote>
"It is fatal to enter any war without the software."
<br/><br/>
- GenMacArthurC.Clarke <a href="http://twitter.com/GenMcArtCClarke">@GenMcArtCClarke</a>
</blockquote>
</section>
<section>
<blockquote>
"People respond in accordance to how you relate to them and play the guitar."
<br/><br/>
- Willie Nelson Mandela <a href="http://twitter.com/WillieNelMan">@WillieNelMan</a>
</blockquote>
</section>
<section>
<table border="0" class="vert-middle" width="100%">
<tr>
<td colspan="2">
<h4>About me</h4>
</td>
</tr>
<tr>
<td colspan="2">
<h4>Jeremy Green - Consultant, Author, SaaS Guy, Techlahomer</h4>
</td>
</tr>
<tr class="">
<td>
<img src="images/octologo.png" class="no-border">
</td>
<td>
@jagthedrummer <br />
[email protected] <br />
<a href="http://www.octolabs.com/">http://www.octolabs.com/</a>
</td>
</tr>
<tr>
<td colspan="2">
<br/>
<h4 class="fragmentno fade-in">Things I Enjoy : Dopamine, Serotonin</h4>
<h4 class="fragmentno fade-in">Other Interests : Drumming, Photography, and Brewing</h4>
<!--h4 class="fragment fade-in">okc dev community enthusiast - okcruby.org, okcjs.org</h4-->
</td>
</tr>
</table>
<aside class="notes">
These items are in chronological order.<br />
I've been drumming much more than half my life.<br />
Coding, just about half.<br />
* next fragment * <br />
Thanks to Jesse and Vance of okcjs for organizing Thunder Plains.
* next fragment * <br />
I'm historically bad at Twitter, but trying to get better.<br />
Contacting me through OctoLabs is more reliable.
</aside>
</section>
<section>
<h1>Quote Masher</h1>
<a href="http://quote-masher.herokuapp.com">quote-masher.herokuapp.com</a>
</section>
<section>
<h1>These Slides</h1>
<a href="http://octo-labs.github.io/markov_chains_for_fun_and_profit_java_version/">http://octo-labs.github.io<br/>/markov_chains_for_fun_and_profit_java_version/</a>
</section>
<section>
<h1>What are Markov Chains?</h1>
</section>
<section>
<h2>According to WikiPedia</h2>
<h3>"A Markov Chain is a random process that undergoes transitions from one state to another on a state space"</h3>
</section>
<section>
<h2>State Machines</h2>
<h2>Behaving Randomly</h2>
<img src="images/markov_chain.jpg" class="no-border"/>
</section>
<section>
<h1>Deterministic State Machines</h1>
</section>
<section>
<img src="images/orders.png"/>
</section>
<section>
<h3>Markov Chains are Non-Deterministic</h3>
<h3>"memoryless"</h3>
<img src="images/markov_chain.jpg" class="no-border"/>
</section>
<section>
<h2>Applications for<br/>Markov Chains</h2>
</section>
<section>
<img src="images/applications.png" class="no-border" style="max-height:600px"/>
</section>
<section>
<h2>Simulating Moods</h2>
<img src="images/moods.gif"/>
</section>
<section>
<h2>Simulating Stocks</h2>
<img src="images/stocks.png"/>
</section>
<section>
<h2>Simulating Weather</h2>
<img src="images/weather.png"/>
</section>
<section>
<h2>Complex Chains</h2>
<img src="images/complex.png"/>
</section>
<section>
<h2>Text processing</h2>
<blockquote>
"George Lucas doesn't have the duty to do good."
<br/><br/>
- PopeFranFordCoppola <a href="http://twitter.com/PopeFranFordCop">@PopeFranFordCop</a>
</blockquote>
</section>
<section>
<h2>An Example Deconstructed</h2>
</section>
<section>
<blockquote class="reg">
"Never tell people how to make<br/>good fried rice."
<br/><br/>
- GeorgePattonOswalt <a href="http://twitter.com/GeorgePattonOz">@GeorgePattonOz</a>
</blockquote>
<blockquote class="reg fragment fade-in">
"Never tell people how to do things."
<br/><br/>
- General George Patton
</blockquote>
<blockquote class="reg fragment fade-in">
"I know how to make good fried rice."
<br/><br/>
- Patton Oswalt
</blockquote>
</section>
<section>
<img src="markov1.png"/>
</section>
<section>
<img src="markov2.png"/>
</section>
<section>
<h2>Probability Function</h2>
<img src="markov3.png"/>
<code>rand(2)</code>
</section>
<section>
<h2>Choose your own adventure</h2>
<hr />
<h3>Quote Masher Admin Demo</h3>
<a href="http://quote-masher.herokuapp.com/admin/accounts">quote-masher.herokuapp.com</a>
<h2>OR</h2>
<h3>Let's see some code!</h3>
</section>
<section>
<h2>How would you code this?</h2>
</section>
<section>
<h2>Starting with tests, of course!</h2>
</section>
<section>
<pre><code class="plain">
Feature: Markov Chainer
As chainer
I need to take sentences for training
And combine them randomly
So that I can create comedy
Scenario: Accept a sentence for training
Given a MarkovChainer
Then it should be trainable
</code></pre>
</section>
<section>
<pre><code class="java">
public class MarkovChainerStepDefs {
private MarkovChainer myChainer;
@Given("^a MarkovChainer$")
public void a_MarkovChainer() throws Throwable {
myChainer = new MarkovChainer();
}
@Then("^it should be trainable$")
public void it_should_be_trainable() throws Throwable {
String sentence = "Just a test sentence";
myChainer.train(sentence);
}
}
</code></pre>
</section>
<section>
<pre><code class="text">
Scenario: Regurgitating a sentence
Given a MarkovChainer
When I train it with "Heloooo there!"
Then it should generate "Heloooo there!"
</code></pre>
</section>
<section>
<pre><code class="text">
@When("^I train it with \"([^\"]*)\"$")
public void i_train_it_with(String arg1) throws Throwable {
myChainer.train(arg1);
}
@Then("^it should generate \"([^\"]*)\"$")
public void it_should_generate(String arg1) throws Throwable {
String sentence = myChainer.generate();
assertThat(sentence, is(arg1));
}
</code></pre>
</section>
<section>
<pre><code class="text">
Scenario: Mixing two sentences
Given a MarkovChainer
When I train it with "Ryan brews JAVA"
When I train it with "Jeremy brews beer"
And call generate 20 times
Then it should generate "Ryan brews beer" at least once
</code></pre>
</section>
<section>
<pre><code class="java">
private Hashtable<String, Integer> results = new Hashtable<String, Integer>();
@When("^call generate (\\d+) times$")
public void call_generate_times(int arg1) throws Throwable {
for(int i=1; i<arg1; i++){
String sentence = myChainer.generate();
Integer score = results.get(sentence);
if(score == null){
score = 0;
}
score++;
results.put(sentence,score);
}
}
</code></pre>
</section>
<section>
<pre><code class="java">
@Then("^it should generate \"([^\"]*)\" at least once$")
public void it_should_generate_at_least_once(String arg1) throws Throwable {
Integer score = results.get(arg1);
if(score == null){
score = 0;
}
boolean greaterThanZero = score > 0;
assertThat("greaterThanZero",greaterThanZero);
}
</code></pre>
</section>
<section>
<pre><code class="ruby">
# results
{
"Ryan brews JAVA" => 7,
"Jeremy brews beer" => 5,
"Ryan brews beer" => 4,
"Jeremy brews JAVA" => 4
}
</code></pre>
</section>
<section>
<h1>Make with the live coding already!</h1>
</section>
<section>
<h3>Just a <code>train</code> method</h3>
<pre><code class="java">
public class MarkovChainer {
public void train(String s) { }
}
</code></pre>
<h3>One passing scenario!</h3>
</section>
<section>
<h3>Regurgitating a sentence</h3>
<pre><code class="java">
public class MarkovChainer {
private String sentence;
public void train(String s) {
sentence = s;
}
public String generate() {
return sentence;
}
}
</code></pre>
<h3>Two passing scenarios!</h3>
</section>
<section>
<h3>A simple linked list</h3>
</section>
<section>
<pre><code class="java">
private class Word {
private Word nextWord;
private String word;
public Word(String word, Word nextWord){
this.word = w;
this.nextWord = nextWord;
}
public Word nextWord(){
return nextWord;
}
public String toString(){
return word;
}
}
</code></pre>
</section>
<section>
<pre><code class="java">
private ArrayList<Word> beginnings;
public MarkovChainer(){
beginnings = new ArrayList<Word>();
}
</code></pre>
</section>
<section>
<pre><code class="java">
public void train(String s) {
String[] swords = s.split(" ");
Word previousWord = null;
for(int i = swords.length -1; i>=0; i--){
Word word = new Word(swords[i],previousWord);
previousWord = word;
}
beginnings.add(previousWord);
}
</code></pre>
</section>
<section>
<pre><code class="java">
public String generate() {
StringJoiner words = new StringJoiner(" ");
Word word = beginnings.get(0);
while(word != null){
words.add(word.toString());
word = word.nextWord();
}
String sentence = words.toString();
return sentence;
}
</code></pre>
</section>
<section>
<h3>Still only two passing scenarios...</h3>
<h1>:(</h1>
</section>
<section>
<pre><code class="java">
private class Word {
private ArrayList<Word> nextWords;
private String word;
public Word(String w, Word nextWord){
word = w;
nextWords = new ArrayList<Word>();
nextWords.add(nextWord);
}
public void addNextWord(Word w){
nextWords.add(w);
}
}
</code></pre>
</section>
<section>
<pre><code class="java">
private class Word {
public Word nextWord(){
if(nextWords.size() > 0){
Collections.shuffle(nextWords);
return nextWords.get(0);
}else{
return null;
}
}
public String toString(){
return word;
}
}
</code></pre>
</section>
<section>
<pre><code class="java">
private ArrayList<Word> beginnings;
private Hashtable<String,Word> words;
public MarkovChainer(){
beginnings = new ArrayList<Word>();
words = new Hashtable<String,Word>();
}
</code></pre>
</section>
<section>
<pre><code class="java">
public void train(String s) {
String[] swords = s.split(" ");
Word previousWord = null;
for(int i = swords.length -1; i>=0; i--){
Word word = words.get(swords[i]);
if(word != null){
word.addNextWord(previousWord);
}else{
word = new Word(swords[i],previousWord);
words.put(swords[i],word);
}
previousWord = word;
}
beginnings.add(previousWord);
}
</code></pre>
</section>
<section>
<pre><code class="java">
public String generate() {
StringJoiner words = new StringJoiner(" ");
Collections.shuffle(beginnings);
Word word = beginnings.get(0);
while(word != null){
words.add(word.toString());
word = word.nextWord();
}
String sentence = words.toString();
return sentence;
}
</code></pre>
</section>
<section>
<h3>Finally! 3 passing scenarios!</h3>
<h1>:)</h1>
</section>
<section>
<h3>Sample Code</h3>
<a href="https://github.com/Octo-Labs/markov_quotes_java">https://github.com/Octo-Labs/markov_quotes_java</a>
</section>
<section>
<h2>Quote Masher<br/>Admin Demo</h2>
<a href="http://quote-masher.herokuapp.com/admin/accounts">quote-masher.herokuapp.com</a>
</section>
<section>
<blockquote>
"In war you win or lose live or die - and half the things a man knows at 40 hadn't been discovered when he is very probably wrong"
<br/><br/>
- GenMacArthurC.Clarke <a href="http://twitter.com/GenMcArtCClarke">@GenMcArtCClarke</a>
</blockquote>
</section>
<section>
<blockquote>
"Every revolutionary idea is just returned from visiting the stars."
<br/><br/>
- GenMacArthurC.Clarke <a href="http://twitter.com/GenMcArtCClarke">@GenMcArtCClarke</a>
</blockquote>
</section>
<section>
<blockquote>
"Any sufficiently advanced technology is very probably wrong"
<br/><br/>
- GenMacArthurC.Clarke <a href="http://twitter.com/GenMcArtCClarke">@GenMcArtCClarke</a>
</blockquote>
</section>
<section>
<blockquote>
"The greatest tragedy in mankind's entire history may be summed up by the press and other forms of nationalism."
<br/><br/>
- GenMacArthurC.Clarke <a href="http://twitter.com/GenMcArtCClarke">@GenMcArtCClarke</a>
</blockquote>
</section>
<section>
<blockquote>
"Our government has kept us in a world where half the things a man knows at 40 hadn't been discovered when he is very probably wrong"
<br/><br/>
- GenMacArthurC.Clarke <a href="http://twitter.com/GenMcArtCClarke">@GenMcArtCClarke</a>
</blockquote>
</section>
<section>
<blockquote>
"The best luck of all is the fact that flags do not wave in a constant conspiracy against the stars."
<br/><br/>
- GenMacArthurC.Clarke <a href="http://twitter.com/GenMcArtCClarke">@GenMcArtCClarke</a>
</blockquote>
</section>
<section>
<blockquote>
"Reading computer manuals without the hardware is as frustrating as reading sex manuals without the support of public opinion."
<br/><br/>
- GenMacArthurC.Clarke <a href="http://twitter.com/GenMcArtCClarke">@GenMcArtCClarke</a>
</blockquote>
</section>
<section>
<blockquote>
"Americans accept judicial supervision of their income so that the political class will not respect the boundaries he is pushing as Borat."
<br/><br/>
- George Will Ferrel <a href="http://twitter.com/GeorgeWilFerrel">@GeorgeWilFerrel</a>
</blockquote>
</section>
<section>
<blockquote>
"I mean it's tough for me to play Simon Cowell in a position where you can make choices regardless of money."
<br/><br/>
- George Will Ferrel <a href="http://twitter.com/GeorgeWilFerrel">@GeorgeWilFerrel</a>
</blockquote>
</section>
<section>
<blockquote>
"Often times I'm confronted with a limited budget and we really felt strongly that we could live with a slice of processed cheese."
<br/><br/>
- George Will Ferrel <a href="http://twitter.com/GeorgeWilFerrel">@GeorgeWilFerrel</a>
</blockquote>
</section>
<section>
<blockquote>
"The internet in hotels should be free - and it's the fundamental thing - the mercy of God has no limits."
<br/><br/>
- PopeFranFordCoppola <a href="http://twitter.com/PopeFranFordCop">@PopeFranFordCop</a>
</blockquote>
</section>
<section>
<blockquote>
"I don't want to be particularly clear you've probably misunderstood what I've said."
<br/><br/>
- WoodyAllenGreenspan <a href="http://twitter.com/WoodyAGreenspan">@WoodyAGreenspan</a>
</blockquote>
</section>
<section>
<blockquote>
"Seventy percent of success in life is that I am not afraid of death I just don't want to be there when it happens."
<br/><br/>
- WoodyAllenGreenspan <a href="http://twitter.com/WoodyAGreenspan">@WoodyAGreenspan</a>
</blockquote>
</section>
<section>
<blockquote>
"In Beverly Hills they turn out to 'freedom-kiss' my music business on the corporate sector."
<br/><br/>
- WoodyAllenGreenspan <a href="http://twitter.com/WoodyAGreenspan">@WoodyAGreenspan</a>
</blockquote>
</section>
<section>
<blockquote>
"My one regret in life is showing up."
<br/><br/>
- WoodyAllenGreenspan <a href="http://twitter.com/WoodyAGreenspan">@WoodyAGreenspan</a>
</blockquote>
</section>
<section>
<blockquote>
"You're going to go through life defeated and not having enough money."
<br/><br/>
- Billy Joel Osteen <a href="http://twitter.com/BillyJoelOsteen">@BillyJoelOsteen</a>
</blockquote>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="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: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>