-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.xml
More file actions
3217 lines (2791 loc) · 313 KB
/
feed.xml
File metadata and controls
3217 lines (2791 loc) · 313 KB
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
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
<channel>
<atom:link href='http://salmanhossain.me' rel='self' type='application/rss+xml'/>
<title>
Physics. Computers. Code.
</title>
<link>
http://salmanhossain.me
</link>
<description>
A place to share my knowledge
</description>
<lastBuildDate>
Fri, 21 Apr 2017 23:08:03 -0400
</lastBuildDate>
<generator>
clj-rss
</generator>
<item>
<guid>
http://salmanhossain.me/posts/racket-intro2/
</guid>
<link>
http://salmanhossain.me/posts/racket-intro2/
</link>
<title>
Racket - Intro (2)
</title>
<description>
<p>This is continuing off of the previous blog post on racket. Make sure you have gone through that before going to this. In this section we'll cover <newcode>booleans</newcode>, <newcode>conditionals</newcode> and <newcode>apply</newcode>.</p><pre><code>;; Booleans
;; Racket uses #t and #f for true and false.
&#40;= 2 &#40;+ 1 1&#41;&#41;
&#40;= 2 &#40;+ 1 2&#41;&#41;
;; if statements in racket
;; First part is the conditional which is the &#40;= 2 &#40;+ 1 1&#41;&#41; which is #t
;; Second part is &#40;println &quot;True&quot;&#41; which is the true branch that'll execute if the condition is met.
;; Third part &#40;println &quot;False&quot;&#41; is the false branch which won't be executed.
&#40;if &#40;= 2 &#40;+ 1 1&#41;&#41;
&#40;println &quot;True&quot;&#41;
&#40;println &quot;False&quot;&#41;&#41;
;; Notice that and will return true if nothing provided.
;; and is #t if no arguments provided.
;; or is #f is no arguments provided.
;; and will return the argument if only one argument is provided.
;; or will do the same if one argument is provided.
&#40;define a 10&#41;
&#40;define b 5&#41;
&#40;and&#41;
&#40;and b&#41;
&#40;or&#41;
&#40;or b&#41;
&#40;and &#40;even? a&#41; &#40;odd? b&#41;&#41;
&#40;and &#40;odd? a&#41; &#40;odd? b&#41;&#41;
&#40;or &#40;odd? a&#41; &#40;odd? b&#41;&#41;
;; Conditionals in racket
;; Must start with a bracket to start a conditional.
;; Than there is the testing condition and if its met executes.
&#40;cond
&#91;&#40;positive? n&#41; &#40;println &quot;This number is positive&quot;&#41;&#93;
&#91;&#40;negative? n&#41; &#40;println &quot;This number is negative&quot;&#41;&#93;&#41;
;; There is also an else if none of the conditionals are met.
;; Tells us if the quadradic has 2 roots, 1 root or imaginary roots.
&#40;define &#40;roots a b c&#41;
&#40;let &#40;&#91;discriminant &#40;- &#40;expt b 2&#41; &#40;&#42; 4 a c&#41;&#41;&#93;&#41;
&#40;cond
&#91;&#40;positive? discriminant&#41; &#40;println &quot;This quadradic has 2 roots&quot;&#41;&#93;
&#91;&#40;negative? discriminant&#41; &#40;println &quot;This quadradic has imaginary roots&quot;&#41;&#93;
&#91;else &#40;println &quot;This quadradic has 1 root&quot;&#41;&#93;&#41;&#41;&#41;
;; Also note that racket makes a distinction between let and let&#42; like in lisp.
;; let won't allow you to use previous bindings as you would sometimes expect.
;; let&#42; however does let you use previous bindings.
;; First one with let will provide an error because of the difference between let and let&#42;
;; You'll find that num is undefined in the first one. Second one works fine.
&#40;let &#91;&#40;num 10&#41;
&#40;result &#40;+ 2 num&#41;&#41;&#93;
result&#41;
&#40;let&#42; &#91;&#40;num 10&#41;
&#40;result &#40;+ 2 num&#41;&#41;&#93;
result&#41;
;; Apply which will distribute the prodecure across the list.
;; Notice that the last argument for apply must be a list.
&#40;apply &#42; '&#40;1 2 3 4&#41;&#41;
&#40;apply &#42; 1 2 '&#40;3 4&#41;&#41;
&#40;apply &#42; 1 2 3 '&#40;4&#41;&#41;
&#40;apply &#42; 1 2 3 4&#41; ;; error: contract violation
</code></pre>
</description>
<enclosure>
</enclosure>
<pubDate>
Sat, 25 Mar 2017 00:00:00 -0400
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/racket-intro/
</guid>
<link>
http://salmanhossain.me/posts/racket-intro/
</link>
<title>
Racket - Intro (1)
</title>
<description>
<p>A little guide on Racket. Since I been playing around with it for a while. Pretty cool but doesn't have some of the nice functions that clojure has such as the range but you can easily make it in racket. So here are some things to get familiar with racket.</p><pre><code>
;; Needed to specify the language.
&#40;require racket&#41;
;; Addition similiar to clojure and other lisps
&#40;+ 2 2&#41;
;; accepts more than two arguments thats good.
&#40;+ 2 2 3&#41;
;; That works too.
&#40;+ 3 &#40;&#42; 2 2&#41;&#41;
;; What happens when mixing with floats. Oh a float or racket calls them inexact numbers.
&#40;inexact? &#40;+ 3 &#40;&#42; 2.0 2&#41;&#41;&#41;
;; How do we print strings now lets try println. Same as clojure.
&#40;println &quot;Hello&quot;&#41;
;; Do they have format? or something to concat strings? &#126;a
&#40;&#126;a &quot;2+2=&quot; &#40;+ 2 2&#41;&#41;
;; How do you define a top level variable in racket?
&#40;define x 10&#41;
x ;; 10
;; local variable within a scope.
;; Notice that x is 3 in that specific scope not 10.
&#40;let &#91;&#40;x 3&#41;&#93; x&#41;
;; just to check that x is actually still globally defined as 10.
x ;; still 10 cool.
;; Now how do you make a function? With define as well.
&#40;define &#40;greetings name&#41;
&#40;&#126;a &quot;Hello, &quot; name &quot;!&quot;&#41;&#41;
&#40;greetings &quot;salman&quot;&#41; ;; Yep works.
;; Oh it doesn't matter if you make them parantheses or brackets.
&#40;define &#91;greetings name&#93;
&#40;&#126;a &quot;Hello, &quot; name &quot;!&quot;&#41;&#41;
&#40;greetings &quot;salman&quot;&#41; ;; still works.
;; What about the lambda functions?
&#40;&#40;lambda &#40;x&#41; &#40;&#42; x x&#41;&#41; 10&#41;
;; lists? Either way works they have the short hand way and the quote function.
&#40;quote &#40;1 2 3 4&#41;&#41;
'&#40;1 2 3 4&#41;
;; Now how do I map functions to individual elements in a list.
;; Oh they have map.
&#40;map &#40;lambda &#40;x&#41; &#40;&#42; x x&#41;&#41; '&#40;1 2 3 4&#41;&#41;
</code></pre>
</description>
<enclosure>
</enclosure>
<pubDate>
Fri, 24 Mar 2017 00:00:00 -0400
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/clojure-reading-csv/
</guid>
<link>
http://salmanhossain.me/posts/clojure-reading-csv/
</link>
<title>
Clojure - Reading CSV files
</title>
<description>
<p>Lets have some fun today and analyze some data! Let us look at the S&P500 which is a index commonly used to see how well the stock market is doing. <br/><br/> We can get the data for the S&P500 from yahoo finances link to that below. Make sure you have the range from Jan 03, 1980 to recent. <br/><br/> <a href='https://finance.yahoo.com/quote/%5EGSPC/history?period1=315723600&period2=1488085200&interval=1d&filter=history&frequency=1d'>Link to the S&P500 Data from Yahoo Finances</a> <br/><br/></p><p>Let us go ahead and run a lein project by the following command you can skip this if you already have a project and you can just add incanter to the dependencies.</p><pre><code>$ lein new incantertut
</code></pre><p>After you have downloaded the cvs file go ahead and rename it to <newcode>data.csv</newcode> and move it to the directory where your project.clj is located. <br/><br/> Let us set up our project.clj file to be this so that we have incanter in our project so that we can read csv data and as well as display the data if we decide to do that.</p><pre><code>&#40;defproject incantertut &quot;0.1.0-SNAPSHOT&quot;
:description &quot;FIXME: write description&quot;
:url &quot;http://example.com/FIXME&quot;
:license {:name &quot;Eclipse Public License&quot;
:url &quot;http://www.eclipse.org/legal/epl-v10.html&quot;}
:dependencies &#91;&#91;org.clojure/clojure &quot;1.8.0&quot;&#93;
&#91;incanter &quot;1.5.5&quot;&#93;&#93;&#41;
</code></pre><p>Now we can move on to the good part and start in our core.clj that in our src directory when creating a lein project. <br/><br/> Go ahead and include the following for the namespaces. If you haven't seen incanter charts yet I recommend going through some of the previous guides I wrote on how to make graphs with incanter but otherwise I'll re-explain it briefly here as well. <br/><br/> <a href='http://salmanhossain.me/posts/clojure-incanter/'>Making Graphs With Incanter</a> <br/><br/></p><pre><code>&#40;ns incantertut.core
&#40;:use &#91;incanter.charts :only &#91;histogram scatter-plot pie-chart add-points add-lines xy-plot&#93;&#93;
&#91;incanter.core :only &#91;view&#93;&#93;
&#91;incanter.stats :only &#91;sample-normal linear-model&#93;&#93;
&#91;incanter.io :only &#91;read-dataset&#93;&#93;&#41;
&#40;:require &#91;clj-time.core :as tc&#93;
&#91;clj-time.periodic :as tp&#93;
&#91;clj-time.coerce :as tco&#93;&#41;&#41;
</code></pre>So the only new addition here will be the <newcode>incanter.io</newcode> which will allow us to read csv files!<br/><br/>Now to the good stuff. Add the following underneath the namespace in your core.clj file.<pre><code>&#40;def data &#40;read-dataset &quot;data.csv&quot; :header true&#41;&#41;
</code></pre>Now you can view all of the data using the following. Be warned that this is around 30+ years of data so it could take a while for the data to appear. <pre><code>&#40;:rows data&#41;
</code></pre>However that just shows you the entire data what if we are only interested in the opening price of the stock? Well we can use map :Open to find all the opening prices.<pre><code>&#40;map :Open &#40;:rows data&#41;&#41;
</code></pre>That will result in all the opening prices of the S&P500. Now lets say we want to view it we can do that using the view and xy-plot from incanter to do just that. However before that notice that when we do map :Open to the data it will return the opening prices from most recent to least recent. That is not what we want since incanter xy-plot takes least recent to most recent. So we need to use reverse to fix that. So we'll just create a function to do that.<pre><code>&#40;defn view-data &#91;selection data&#93;
&#40;let &#91;sel-data &#40;reverse &#40;map selection &#40;:rows data&#41;&#41;&#41;
counter &#40;count sel-data&#41;&#93;
&#40;view &#40;xy-plot &#40;range counter&#41; sel-data&#41;&#41;&#41;&#41;
&#40;view-data :Open data&#41;
</code></pre>Now running that should produce the following pretty graph below.<br/><br/><img src="https://defunsm.github.io/img/csvpic.png" alt="cvspic" /><br/><br/>That is about it you can fix it up a bit by using a time-series instead so that instead of numbers on the bottom you have dates. As well as overlapping it with close prices too. Prehaps in another blog post.
</description>
<enclosure>
</enclosure>
<pubDate>
Sun, 26 Feb 2017 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/clojure-r-squared/
</guid>
<link>
http://salmanhossain.me/posts/clojure-r-squared/
</link>
<title>
Clojure - R Squared
</title>
<description>
<p>We'll pick back up from where we left off in the linear regression post last time. So we'll be keeping pretty much the same dependency of incanter and the name space should still look like the following below more or less.<pre><code>&#40;ns incantertut.core
&#40;:use &#91;incanter.charts :only &#91;histogram scatter-plot pie-chart add-points add-lines&#93;&#93;
&#91;incanter.core :only &#91;view&#93;&#93;
&#91;incanter.stats :only &#91;sample-normal linear-model&#93;&#93;&#41;&#41;
</code></pre> </p><p>We are going to pick up where we left off and find some more interesting properties of the line of best fit such as the r squared value and other properties such as the residuals. So we know that the line of best fit we have which we constructed from the following data ...<pre><code>&#40;def x &#91;1 2 3 4 5&#93;&#41;
&#40;def y &#91;5 9 11 20 24&#93;&#41;
&#40;linear-model y x&#41;
&#40;:fitted &#40;linear-model y x&#41;&#41;
;; =&gt; &#91;4.000000000000011 8.900000000000013 13.800000000000015 18.700000000000017 23.60000000000002&#93;
</code></pre> So before getting to the R squared value which we'll get soon enough. Let's look at how far the points are from the line of best fit. To do this incanter has provided :residuals. The residuals are the distance away from the line of best fit. This is useful information to have when trying to understand how well our line of best fit 'fits' the data.<pre><code>&#40;:residuals &#40;linear-model y x&#41;&#41;
;; =&gt; &#91;0.9999999999999893 0.09999999999998721 -2.800000000000015 1.299999999999983 0.3999999999999808&#93;
</code></pre> So the residuals are nice but maybe you just want to see the absolute distance and not worry about the negatives in the residuals. Easy fix using map to just multiply it with a -1 to make it opposite like so...<pre><code>&#40;map &#40;fn &#91;x&#93; &#40;if &#40;neg? x&#41; &#40;&#42; x -1&#41; x&#41;&#41; &#40;:residuals &#40;linear-model y x&#41;&#41;&#41;
;; =&gt; &#40;0.9999999999999893 0.09999999999998721 2.800000000000015 1.299999999999983 0.3999999999999808&#41;
</code></pre> Now we have all of the distances as positive lets place them on the graph! <br/><br/> <img src="https://defunsm.github.io/img/incanter5.png" alt="incanter" /> <br/><br/><pre><code>&#40;view &#40;add-lines &#40;scatter-plot x y&#41;
x &#40;map &#40;fn &#91;x&#93; &#40;if &#40;neg? x&#41; &#40;&#42; x -1&#41; x&#41;&#41; &#40;:residuals &#40;linear-model y x&#41;&#41;&#41;&#41;&#41;
</code></pre> You'll see somewhat of a representation of those residuals below and seeing from a visual standpoint which datapoints appear to be most out of fit with the line of best fit. Here you can see that the third point seems to be the most nearly 3 units away from the line of best fit.</p><p>Now lets do something else with the residuals a common thing to do is that you can square the residuals which will get you the sse or the sum of squares due to error.<pre><code>&#40;reduce + &#40;map &#40;fn &#91;x&#93; &#40;&#42; x x&#41;&#41; &#40;:residuals &#40;linear-model y x&#41;&#41;&#41;&#41;
;; =&gt; 10.7
</code></pre> or actually in incanter you can just do the following instead of typing that entire thing out.<pre><code>&#40;:sse &#40;linear-model y x&#41;&#41;
;; =&gt; 10.7
</code></pre> So that value gives you some what of an idea of how well the data fits the line of best fit. However we can go and look further and get the R<sup>2</sup> value from the linear-model.<pre><code>&#40;:r-square &#40;linear-model y x&#41;&#41;
;; =&gt; 0.9573365231259969
</code></pre> So that is our line of best fit but how well does it fit our data well that is where the R squared value comes in and determines how well our line fits our data. Typically the closer the R squared value is to 1 the better. As well as the R squared value is only ranges from 0 to 1. So 0.95 is pretty good so that our data fits the line of best fit rather well.</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Wed, 01 Feb 2017 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/clojure-linear-regression/
</guid>
<link>
http://salmanhossain.me/posts/clojure-linear-regression/
</link>
<title>
Clojure - Linear Regression
</title>
<description>
<p><img src="https://defunsm.github.io/img/incanter4.png" alt="incanter" /></p><p>We will try to do a basic linear regression here with incanter. If you don't know what linear regression is it is essentially finding the line of best fit. I'll demonstrate how you can find the line of best fit using incanter with a neat function called linear-model which will do a lot of the numerical calculations for us. Make sure to note that the data for the y axis is the first argument and not the second argument since at least for me it appears to be more intuitive to place the x axis in the second argument of the function but that isn't the case for the linear-model function from incanter.stat so take note of that. Let us go ahead and add our dependencies. As well as make sure that incanter is in your project.clj and your namespace looks like the following below.<pre><code>&#40;ns incantertut.core
&#40;:use &#91;incanter.charts :only &#91;histogram scatter-plot pie-chart add-points add-lines&#93;&#93;
&#91;incanter.core :only &#91;view&#93;&#93;
&#91;incanter.stats :only &#91;sample-normal linear-model&#93;&#93;&#41;&#41;
</code></pre> What linear-model will do for us will do a bunch of calculations off hand so that we don't have to do them ourselves which is good. However if you are interested in the math computational part like I am you should probably go learn linear algebra and some statistics which will help you understand more of whats going on but it isn't absolutely necessary if you just want a line of best fit to be displayed. <br/><br/> I am not entirely sure why computer science and the machine learning community tend to like to call the line of best fit "linear regression" which sounds a bit scary to me but really all you are doing is fitting a line that happens to be stright to a bunch of points on a x and y axis graph. Nothing complicated really. However when introducing this topic of linear regression in textbooks the impression is that this is a huge big thing but anyways I digress too much and here you go with the easy and simple line of best fit.<pre><code>&#40;def x &#91;1 2 3 4 5&#93;&#41;
&#40;def y &#91;5 9 11 20 24&#93;&#41;
&#40;view &#40;add-lines &#40;scatter-plot x y&#41;
x &#40;:fitted &#40;linear-model y x&#41;&#41;&#41;&#41;
</code></pre> Let me go through with what is going on here. The view is again if you haven't read through the previous post on basic incanter on how to display a histogram, scatterplot and a pie chart I suggest looking at that. However I'll assume you know what view is doing and is the function that allows you to see the graphs hence view. The add-lines is a new function from the incanter.charts that I haven't shown before and allows you to plot lines you could use add-points instead as well but than it wouldn't be line.</p><pre><code>&#40;:coefs &#40;linear-model y x&#41;&#41;
;; =&gt; &#91;-0.8999999999999915 4.900000000000002&#93;
</code></pre><p>Now lets take a look using :coefs gives us two numbers in a persistent vector. So what do those numbers represent? Well one of is negative and the other positive and so judging from the graph you seen the negative number can't be the slope since the slope was clearly had a positive slope. So from that conclusion you can assume that the first number is the y-intercept which it is. The second number is the slope no surprise there. <br/><br/> This is going to be a pretty short post just showing you how to obtain slope and y-intercept but you may not satisfied and be left with questions such as how well fitted is my line of best fit? What is the R<sup>2</sup> value? How do I get that kind of information from my line of best fit well if you're curious you can check the documentation or wait for the next post.</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Mon, 30 Jan 2017 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/clojure-incanter/
</guid>
<link>
http://salmanhossain.me/posts/clojure-incanter/
</link>
<title>
Clojure - Basic Incanter
</title>
<description>
<p><a href='http://incanter.github.io/incanter/index.html'>Incanter</a> is similiar to R which has many uses for statistical computing. Incanter is a clojure based version of R which runs on the JVM. It has many useful functions to help aid in making graphs and analyze data. We'll only be looking on making graphs in this post but in a later post we'll look at analyzing data using incanter. For now lets make some graphs! <br/><br/> Go ahead make a new clojure project with leiningen. Add the following to your project.clj to include incanter into your dependencies.<pre><code>:dependencies &#91;&#91;org.clojure/clojure &quot;1.8.0&quot;&#93;
&#91;incanter &quot;1.5.5&quot;&#93;&#93;
</code></pre> Go ahead and run lein deps so that leiningen can get incanter as a dependency.<pre><code>lein deps
</code></pre> After that we are ready to go and start editing the core.clj and first examining how to create a neat little <newcode>histogram</newcode>. <br/><br/> So lets use the things we are going to need from incanter make your namespace as the following just replace the namespace to whatever project you created in my case I did lein new incantertut but yours will be different so rechange that part of what you did.<pre><code>&#40;ns incantertut.core
&#40;:use &#91;incanter.charts :only &#91;histogram scatter-plot pie-chart xy-plot&#93;&#93;
&#91;incanter.core :only &#91;view&#93;&#93;
&#91;incanter.stats :only &#91;sample-normal&#93;&#93;&#41;&#41;
</code></pre> In this post we'll only be looking at histograms, scatter-plots and pie-charts. (Plus xy-plot) <br/><br/> Next part is fun because it is literally one line to generate and view the graph and behold.<pre><code>&#40;view &#40;histogram &#40;sample-normal 10000 :mean 10&#41;&#41; :width 700 :height 700&#41;
</code></pre> After running that you should see the following graph pop up. <br/><br/> <img src="https://defunsm.github.io/img/incanter1.png" alt="incanter" /> <br/><br/> The above one-liner creates a histogram. The sample-normal function creates a normal gaussian distribution with 10,000 points. You can select the mean you want for the distribution in this case it was set to 10 by default it is 1. You can also set the :sd which is the standard deviation. <br/><br/> The view function takes other parameters such as a width and height so you can play around with those changing the starting height/width of the histogram. Note that the view function can do more than just graphs. It can view urls and images as well! <br/><br/> Next lets see how to make a scatter-plot which is pretty much a one liner as well and exactly the same as making a histogram expect we use <newcode>scatter-plot</newcode> instead and define some variables before hand.<pre><code>&#40;def x &#91;1 2 3 4 5&#93;&#41;
&#40;def y &#91;5 9 11 20 24&#93;&#41;
&#40;view &#40;scatter-plot x y&#41;&#41;
</code></pre> <img src="https://defunsm.github.io/img/incanter2.png" alt="incanter 2" /> <br/><br/> x and y defines the data for the x axis and the y variable contains the data for the y axis. Note that the x and y variables are of type persistentVector. <br/><br/> Notice that the data set is not perfectly linear but it looks like you could draw a line of best fit or a regression line which I'll go over on how to do that in clojure later. As well as find values such as the R<sup>2</sup> value telling us how well the data fits that line of best fit. <br/><br/> Now for the file graph we'll make a pie graph. <br/><br/> Piechart that we are about to make will include the elements making up earth's atmosphere and for that we'll define two variables called elements and percentages. Both persistent vectors however elements will consist of strings that will contain the name of the elements and percentages will contain the percentage of that element in the atmosphere. The main function here to create the pie-chart is called pie-chart which will be taking two arguments the elements and the percentages as well as you can add an additional parameter adding a :title as a string value such as "Composition of the Earth's Atmosphere".<pre><code>&#40;def elements &#91;&quot;Nitrogen&quot; &quot;Oxygen&quot; &quot;Argon&quot; &quot;Carbon&quot;&#93;&#41;
&#40;def percentages &#91;78 21 0.9 0.03&#93;&#41;
&#40;view &#40;pie-chart elements percentages :title &quot;Composition of the Earth's Atmosphere&quot;&#41;&#41;
</code></pre></p><p><img src="https://defunsm.github.io/img/incanter3.png" alt="incanter 3" /> Now say you wanted a scatter-plot but with the lines connected that is when you use a xy-plot.<pre><code>&#40;view &#40;xy-plot x y&#41;&#41;
</code></pre> <img src="https://defunsm.github.io/img/incanter6.png" alt="incanter 6" /> <br/><br/> There are more variations of graphs avaliable in incanter but I just went through some of the more basic ones that people tend to use so there you go now you can make histograms, scatter-plots, xy-plot and pie charts. All in a few lines of clojure code.</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Sun, 29 Jan 2017 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/python-pyqt5/
</guid>
<link>
http://salmanhossain.me/posts/python-pyqt5/
</link>
<title>
Python - Creating a Table using PyGt5
</title>
<description>
<p><img src="http://defunsm.github.io/img/pytable.png" alt="table" /></p><p><a href='http://pyqt.sourceforge.net/Docs/PyQt5/index.html'>PyGt5</a> is pretty nice when it comes to constructing some nice tables. I found that making tables in PyGt5 is easier than Gtk. So I thought I would just show you how to create a really quick python script to take a file such as the one below and create a table from it in a frame. Create the following text file below as example.txt and make sure you add those , because we are going to be later spliting by ',' to get each of the element and place them into the table.<pre><code>red,blue,yellow
c++,java,python
physics,chemistry,biology
1,2,3
</code></pre> So if you don't have pyqt5 yet go ahead and install that with pip or whatever you use to download python modules.<pre><code>pip install pyqt5
</code></pre> Now there's already some basic tutorials out there to make tables like the one from <a href='https://pythonspot.com/en/pyqt5-table/'>pythonspot</a>. However I wanna show how to make a more functional table of taking the example.txt and placing it into the table. So we'll just follow the example given and modify it. So go ahead and copy that code into the sample in pythonspot and we'll be modifying specifically the the <newcode>create_table()</newcode> part.<pre><code>#!/usr/bin/env python
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QAction, QTableWidget,QTableWidgetItem,QVBoxLayout
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
class App&#40;QWidget&#41;:
def &#95;&#95;init&#95;&#95;&#40;self&#41;:
super&#40;&#41;.&#95;&#95;init&#95;&#95;&#40;&#41;
self.title = 'PyQt5 table - pythonspot.com'
self.left = 0
self.top = 0
self.width = 300
self.height = 200
self.initUI&#40;&#41;
def initUI&#40;self&#41;:
self.setWindowTitle&#40;self.title&#41;
self.setGeometry&#40;self.left, self.top, self.width, self.height&#41;
self.createTable&#40;&#41;
# Add box layout, add table to box layout and add box layout to widget
self.layout = QVBoxLayout&#40;&#41;
self.layout.addWidget&#40;self.tableWidget&#41;
self.setLayout&#40;self.layout&#41;
# Show widget
self.show&#40;&#41;
def createTable&#40;self&#41;:
# Create table
self.tableWidget = QTableWidget&#40;&#41;
self.tableWidget.setRowCount&#40;4&#41;
self.tableWidget.setColumnCount&#40;2&#41;
self.tableWidget.setItem&#40;0,0, QTableWidgetItem&#40;&quot;Cell &#40;1,1&#41;&quot;&#41;&#41;
self.tableWidget.setItem&#40;0,1, QTableWidgetItem&#40;&quot;Cell &#40;1,2&#41;&quot;&#41;&#41;
self.tableWidget.setItem&#40;1,0, QTableWidgetItem&#40;&quot;Cell &#40;2,1&#41;&quot;&#41;&#41;
self.tableWidget.setItem&#40;1,1, QTableWidgetItem&#40;&quot;Cell &#40;2,2&#41;&quot;&#41;&#41;
self.tableWidget.setItem&#40;2,0, QTableWidgetItem&#40;&quot;Cell &#40;3,1&#41;&quot;&#41;&#41;
self.tableWidget.setItem&#40;2,1, QTableWidgetItem&#40;&quot;Cell &#40;3,2&#41;&quot;&#41;&#41;
self.tableWidget.setItem&#40;3,0, QTableWidgetItem&#40;&quot;Cell &#40;4,1&#41;&quot;&#41;&#41;
self.tableWidget.setItem&#40;3,1, QTableWidgetItem&#40;&quot;Cell &#40;4,2&#41;&quot;&#41;&#41;
self.tableWidget.move&#40;0,0&#41;
# table selection change
self.tableWidget.doubleClicked.connect&#40;self.on&#95;click&#41;
@pyqtSlot&#40;&#41;
def on&#95;click&#40;self&#41;:
print&#40;&quot;\n&quot;&#41;
for currentQTableWidgetItem in self.tableWidget.selectedItems&#40;&#41;:
print&#40;currentQTableWidgetItem.row&#40;&#41;, currentQTableWidgetItem.column&#40;&#41;, currentQTableWidgetItem.text&#40;&#41;&#41;
if &#95;&#95;name&#95;&#95; == '&#95;&#95;main&#95;&#95;':
app = QApplication&#40;sys.argv&#41;
ex = App&#40;&#41;
sys.exit&#40;app.exec&#95;&#40;&#41;&#41;
</code></pre></p><p>So you should have it like this so far. And if you run it you'll see a cell 4 by 2. So now lets get to editing this to make it take from the example.txt so we'll go stright to createTable and edit that method specifically since that is what we want. Change it to the following...<pre><code> def createTable&#40;self&#41;:
# Create table
elements = &#91;&#93;
f = open&#40;'example.txt','r'&#41;
for line in f.readlines&#40;&#41;:
elements.append&#40;line.split&#40;&quot;,&quot;&#41;&#41;
f.close&#40;&#41;
self.tableWidget = QTableWidget&#40;&#41;
self.tableWidget.setRowCount&#40;len&#40;elements&#41;&#41;
self.tableWidget.setColumnCount&#40;3&#41;
for i in range&#40;len&#40;elements&#41;&#41;:
self.tableWidget.setItem&#40;i, 0, QTableWidgetItem&#40;elements&#91;i&#93;&#91;0&#93;&#41;&#41;
self.tableWidget.setItem&#40;i, 1, QTableWidgetItem&#40;elements&#91;i&#93;&#91;1&#93;&#41;&#41;
self.tableWidget.setItem&#40;i, 2, QTableWidgetItem&#40;elements&#91;i&#93;&#91;2&#93;&#41;&#41;
# table selection change
self.tableWidget.doubleClicked.connect&#40;self.on&#95;click&#41;
</code></pre> Now if you run this you'll see that it will read from the example.txt and actually take those and put it into the table. Try it put more elements into the example.txt and you'll see it correctly places them into the table. Now let me explain what we did the method to do this.<pre><code>elements = &#91;&#93;
f = open&#40;'example.txt','r'&#41;
</code></pre> This part is creating a variable to store all the elements in the example.txt file to store into an array. After that we open the example.txt using the read param since all we are going to do is read the example.txt file. Of course we also close it later on which you should always remember to do with <newcode>f.close()</newcode>.<pre><code>for line in f.readlines&#40;&#41;:
elements.append&#40;line.split&#40;&quot;,&quot;&#41;&#41;
f.close&#40;&#41;
</code></pre> This is we loop through each line with a for statement and spliting based on the comma. If you're confused by this just place a print(elements[1]) in the table method to see how the array looks so that you can see how exactly we are going to put them into the tableWidget.<pre><code>self.tableWidget = QTableWidget&#40;&#41;
self.tableWidget.setRowCount&#40;len&#40;elements&#41;&#41;
self.tableWidget.setColumnCount&#40;3&#41;
</code></pre> This part is actually creating the QTableWidget which is the table. As well as stating how many rows we are going to have and this is determined by counting how using len on elements to count the amount of rows there is going to be and than since we already know the column amount it is hard coded into the code but we could've done a similiar thing for the column if there is a varity on the column. <pre><code>for i in range&#40;len&#40;elements&#41;&#41;:
self.tableWidget.setItem&#40;i, 0, QTableWidgetItem&#40;elements&#91;i&#93;&#91;0&#93;&#41;&#41;
self.tableWidget.setItem&#40;i, 1, QTableWidgetItem&#40;elements&#91;i&#93;&#91;1&#93;&#41;&#41;
self.tableWidget.setItem&#40;i, 2, QTableWidgetItem&#40;elements&#91;i&#93;&#91;2&#93;&#41;&#41;
</code></pre> This is the meat of the code so to speak. Where all of the major action is going on. The for statement is looping and placing the elements into its respective cell. This is done by using the <newcode>setItem</newcode> method and as you can see it is looped for the amount of arrays in elements using len to find that value. <br/><br/> The majority of the rest of the code is just to set up the frame which is not so vital but now you can create tables from a .txt file which is amazing and can extend this even further and create some graphs using matplotlib which is built into PyGt5.</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Sat, 14 Jan 2017 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/python-commands/
</guid>
<link>
http://salmanhossain.me/posts/python-commands/
</link>
<title>
Python - Running Commands
</title>
<description>
<p>If you want to run some shell commands from your python script. Often this is sometimes needed in your code and the way that this is done in python is with <newcode>subprocess</newcode> module. So to run a shell command using the subprocess module you import call.<pre><code>from subprocess import call
</code></pre> After that you can use call to pass the arguments and call the shell command like the following.<pre><code>call&#40;&#91;&quot;touch&quot;, &quot;newfile.txt&quot;&#93;&#41;
</code></pre> That is all there is to it. More about how to use the subprocess module you can check the <a href='https://docs.python.org/2/library/subprocess.html'>documentation</a>.</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Wed, 11 Jan 2017 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/python-posterior-probability/
</guid>
<link>
http://salmanhossain.me/posts/python-posterior-probability/
</link>
<title>
Python - Prior, Posterior Probability and Normalization
</title>
<description>
<p>When learning about Baye's theorem there is often talk about <newcode>Priors</newcode>, <newcode>Posterior Probability</newcode>, and <newcode>Normalization</newcode>. Those are fancy words when I first heard them but really they are simple concepts so I will try to explain them in the simplest terms I can. So lets start with trying to give a basic idea of a prior. <br/><br/> A way to think about a prior is as your belief in a certain event or information. If a person believes that theres equal chances for either event to occur such as maybe a coin flip than that person has a prior of 0.5 for heads and 0.5 for tails. One thing to note about the prior is that this is a value assigned before any evidence and before the coin is even flipped. Now lets say we flip the coin a thousand of times and it seems to favor heads slightly more than tails for whatever reason than your original prior can be updated to favor the evidence and so now you're prior could be 0.60 for heads and 0.40 for tails. <br/><br/> Normalization is done by first finding the probability of being heads and not being heads which is done by multiplying by the prior and than adding up the probabilities. Adding up the probability will give you the total probability which does not usually add up to one. In that case you have to normalize it by adding both probabilities and than dividing the probability of the event over the total probability. <br/><br/> The posterior probability is than determined by calculating the probability of the event by multiplying by the prior but this time dividing by the total probability so that the probability of not occuring will equal to 1. So you can think of the posterior probability as your updated probability after examining the data. <br/><br/> So lets look at an example of putting all this stuff into practice. Lets say we have two guys Jake and Tony who both like Emily. Lets say our belief/prior is that they both have a fifty-fifty chance of hooking up with Emily. Now the next part is a bit unrealistic as we are going to quantify personality, appearance, and intelligence which are things that are quite difficult to do so. However for now we'll just be using this example to demonstrate and look at a more realistic example later on. So lets say Tony has 0.5 appearance, 0.3 intelligence, and 0.2 personality. Notice we are making the character traits into a probabity adding to 1. Now the same for Jake but he may not be as appearance inclined as Tony but has slightly more intelligence. So Jake has 0.3 appearance, 0.5 intelligence, 0.2 personality. Now lets say Emily doesn't care about appearance since you know its overrated now a days. So she values intelligence and personality so how do we know who is more likely to hook up with Emily? From just common sense you could probably figure it out since it isn't really a close call but lets do the math. <br/><br/> So lets write a quick python script to figure it out or you could just do the math on a calculator if you want but I would rather create a small script so if you wanted to change the values you would do it rather quickly and easily.<pre><code>def main&#40;&#41;:
prior = 0.5
tony = {&quot;Appearance&quot;: 0.5, &quot;Intelligence&quot;: 0.3, &quot;Personality&quot;: 0.2}
jake = {&quot;Appearance&quot;: 0.3, &quot;Intelligence&quot;: 0.5, &quot;Personality&quot;: 0.2}
total&#95;probability = &#40;tony&#91;&quot;Intelligence&quot;&#93; &#42; tony&#91;&quot;Personality&quot;&#93; &#42; prior&#41; + &#40;jake&#91;&quot;Intelligence&quot;&#93; &#42; tony&#91;&quot;Personality&quot;&#93; &#42; prior&#41;
print&#40;total&#95;probability&#41;
tony&#95;posterior&#95;probability = &#40;tony&#91;&quot;Intelligence&quot;&#93; &#42; tony&#91;&quot;Personality&quot;&#93; &#42; prior&#41; / total&#95;probability
jake&#95;posterior&#95;probability = &#40;jake&#91;&quot;Intelligence&quot;&#93; &#42; jake&#91;&quot;Personality&quot;&#93; &#42; prior&#41; / total&#95;probability
print&#40;&quot;Tony's Posterior Probability: &quot;, tony&#95;posterior&#95;probability&#41;
print&#40;&quot;Jake's Posterior Probability: &quot;, jake&#95;posterior&#95;probability&#41;
if &#95;&#95;name&#95;&#95;==&quot;&#95;&#95;main&#95;&#95;&quot;:
main&#40;&#41;
</code></pre></p><p>After running the calculations you'll find that the results are that jake has a higher posterior probabilty and that makes sense since you put into consideration that Emily doesn't care about appearance. So you would get that Tony has a posterior probability of 0.375 and Jake has a posterior probability of 0.625. Sad news for Tony unfortunately. </p>
</description>
<enclosure>
</enclosure>
<pubDate>
Tue, 10 Jan 2017 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/python-entropy/
</guid>
<link>
http://salmanhossain.me/posts/python-entropy/
</link>
<title>
Python - Entropy in Machine Learning
</title>
<description>
<p> <newcode>Entropy</newcode> when talked about in information theory relates to the <newcode>randomness</newcode> in data. Another way to think about entropy is that it is the <newcode>unpredictability</newcode> of the data. So a high entropy is essentially saying that the data is scattered around while a low entropy means that nearly all the data is the same. So since in machine learning data is essentially the way that we build classifiers we often need to manage the entropy to be not too low nor too high and reach a nice balance. The <newcode>Pi</newcode> in the entropy equation below represents the probability of the event occuring. </p><p> <img src="https://defunsm.github.io/img/entropypic.png" alt="picture of entropy equation" /></p><p>So just a few things to note when calculating entropy we are using log 2 and not log 10 small distinction but does change your result. You may see different forms of this equation if you search up entropy but generally you'll find it'll look something like the above. <br/><br/> So what is the point of finding entropy? I mean yes its nice I guess to know if your data is more or less random but what can we do with entropy? Well entropy also tells us how much <newcode>information</newcode> we are going to get from a specific event. For example if we have a coin and say it isn't loaded in any way and has a 50/50 chance of either head or tails. This will result in lower entropy since the chances are fair which means more information. <br/><br/> We could create a nice python script to calculate the entropy for us. So lets go ahead and do that we'll need the <newcode>math module</newcode> for the log. After that we'll make a function that will take an <newcode>array of probabilities</newcode> of each event occuring. So our probability array will be [0.5, 0.5] since it is an equal chance of either heads or tails occuring.<pre><code>import math
def entropy&#95;cal&#40;array&#41;:
total&#95;entropy = 0
for i in array:
total&#95;entropy += -i &#42; math.log&#40;2, i&#41;
return total&#95;entropy
def main&#40;&#41;:
probabilities = &#91;0.5, 0.5&#93;
entropy = entropy&#95;cal&#40;probabilities&#41;
print&#40;entropy&#41;
if &#95;&#95;name&#95;&#95;==&quot;&#95;&#95;main&#95;&#95;&quot;:
main&#40;&#41;
</code></pre></p><p>One of the things you'll find out if you play around with the entropy equation is that equal chance events give out more information because there is less entropy. For example try changing the probability to [0.75, 0.25] in other words a rigged coin toss in which heads is 0.75 and tails is 0.25 or vise versa and you'll find that there is a higher entropy. Events that are more tilted have higher entropy than those with equal chances resulting in less information. So essentially more entropy is less information and less entropy is more information. You can also see this as reduced uncertainity means a lower entropy. Since a higher entropy means there is a higher uncertainity. <br/><br/> So that is about it as far as calculating entropies go and if you were wondering what the units are for entropy it is usally refered to as a 'bit' but this depends on the log base you are using but since we are using 2 which means it can either be 1 or 0. <br/><br/> Thats about it when it comes to just doing some basic calculations with the entropy equation.</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Mon, 09 Jan 2017 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/python-gtk/
</guid>
<link>
http://salmanhossain.me/posts/python-gtk/
</link>
<title>
Python - GTK 3.0
</title>
<description>
<p>If you're looking to make GUI's using python. You should take a look at GTK 3.0 which is a nice module for building GUIs. <br/><br/> <a href='http://python-gtk-3-tutorial.readthedocs.io/en/latest/install.html'>GTK 3.0</a> <br/><br/> After installing it they have a couple of example code to get started with. Put the following in a file called gtktut.py and go ahead and run the code below.</p><pre><code>import gi
gi.require&#95;version&#40;'Gtk', '3.0'&#41;
from gi.repository import Gtk
class MyWindow&#40;Gtk.Window&#41;:
def &#95;&#95;init&#95;&#95;&#40;self&#41;:
Gtk.Window.&#95;&#95;init&#95;&#95;&#40;self, title=&quot;Hello World&quot;&#41;
self.button = Gtk.Button&#40;label=&quot;Click Here&quot;&#41;
self.button.connect&#40;&quot;clicked&quot;, self.on&#95;button&#95;clicked&#41;
self.add&#40;self.button&#41;
def on&#95;button&#95;clicked&#40;self, widget&#41;:
print&#40;&quot;Hello World&quot;&#41;
win = MyWindow&#40;&#41;
win.connect&#40;&quot;delete-event&quot;, Gtk.main&#95;quit&#41;
win.show&#95;all&#40;&#41;
Gtk.main&#40;&#41;
</code></pre>I'll go through some of the code above. So the first line is the basic import you have probably seen it just imports gi which allows you to import GTK from the gi.repository specifically you have to require Gtk 3.0. <pre><code>Gtk.Window.&#95;&#95;init&#95;&#95;&#40;self, title=&quot;Hello World&quot;&#41;
</code></pre>This is the class constructor to set the window title.<pre><code>self.button = Gtk.Button&#40;label=&quot;Click Here&quot;&#41;
</code></pre>So in this code you're just inheriting from the Gtk.Window class and initializing some basic things on the 8th line. Also then setting up a button which you do by calling Gtk.Button().<pre><code>self.button.connect&#40;&quot;clicked&quot;, self.on&#95;button&#95;clicked&#41;
self.add&#40;self.button&#41;
</code></pre><p>Then you are connecting the button to a function called on&#95;button&#95;clicked which you define within the class.<pre><code>win = MyWindow&#40;&#41;
win.connect&#40;&quot;delete-event&quot;, Gtk.main&#95;quit&#41;
win.show&#95;all&#40;&#41;
Gtk.main&#40;&#41;
</code></pre></p><p>The first line is setting win as an object of the class MyWindow(). The second line allows you to close the window and without it you wont be able to close it. The second line shows the window and finally the Gtk.main() creates the main loop. <br/><br/> So we can easily make a menu launcher just by knowing how to make buttons, a grid, and running commands in python using call. So lets start with the example code that the documentation gives us to start with and make our own menu launcher. First we'll start off by importing call from subprocesses.<pre><code>from subprocess import call
</code></pre> Now using call you can exechute commands in python. So if we wanted to open firefox we could do something like the following and change on&#95;button&#95;clicked.<pre><code>def on&#95;button&#95;clicked&#40;self, widget&#41;:
call&#40;&#91;&quot;firefox&quot;&#93;&#41;
</code></pre> Now you can launch firefox by pressing the button and you change the label of the button to 'Firefox'.<pre><code>self.button = Gtk.Button&#40;label=&quot;Firefox&quot;&#41;
</code></pre> Now the button will be labeled as firefox and launches firefox. You could essentially make more of these buttons and make a launcher if you wanted to but I'll leave that up to you. So you're final code for gtktut.py should be something like this...</p><pre><code>import gi
gi.require&#95;version&#40;'Gtk', '3.0'&#41;
from gi.repository import Gtk
from subprocess import call
class MyWindow&#40;Gtk.Window&#41;:
def &#95;&#95;init&#95;&#95;&#40;self&#41;:
Gtk.Window.&#95;&#95;init&#95;&#95;&#40;self, title=&quot;Hello World&quot;&#41;
self.button = Gtk.Button&#40;label=&quot;Firefox&quot;&#41;
self.button.connect&#40;&quot;clicked&quot;, self.on&#95;button&#95;clicked&#41;
self.add&#40;self.button&#41;
def on&#95;button&#95;clicked&#40;self, widget&#41;:
call&#40;&#91;&quot;firefox&quot;&#93;&#41;
win = MyWindow&#40;&#41;
win.connect&#40;&quot;delete-event&quot;, Gtk.main&#95;quit&#41;
win.show&#95;all&#40;&#41;
Gtk.main&#40;&#41;
</code></pre><p>I just overviewed a small amount of what Gtk can do but you could look into comboboxs, entries, progressbars, and lists. Prehaps in a later blog post I'll go over a more complex project using GTK.</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Sun, 08 Jan 2017 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/python-reading-writing-files/
</guid>
<link>
http://salmanhossain.me/posts/python-reading-writing-files/
</link>
<title>
Python - Reading and Writing Files
</title>
<description>
<p> Reading and Writing to files in python is rather useful when you want to store down some of the results you get after running a program. So here is a simple stright forward guide to doing just that. <br/><br/> Go ahead and open up a file as ex1.py or whatever you prefer really.</p><pre><code>$ touch ex1.py
</code></pre>Also create a .txt file for our dummy text file that we'll read with python.<pre><code>$ echo &quot;This is a text file&quot; &gt;&gt; dummytext.txt
</code></pre>If doing that confuses you than you can just use a text editor and create the .txt file that way same thing but the above is just a command to send the string into a file in this case dummytext.txt. <br/><br/>Just as a sanity check I usually like to cat the file to make that the text is actually there so go ahead and do that.<pre><code>cat dummytext.txt
</code></pre>Alright we aren't crazy and text is there. If it's not there than go ahead and do it manually and use a text editor to type it into the file or whatever method you prefer.<br/><br/>Now on to the python part where we code up the program that will read the the .txt file. So go ahead and open up ex1.py. Write in the following into ex1.py...<pre><code>#!/usr/bin/env python
import sys, os
def main&#40;&#41;:
f = open&#40;'dummytext.txt', 'r'&#41;
text = f.read&#40;&#41;
print&#40;text&#41;
f.close&#40;&#41;
if &#95;&#95;name&#95;&#95;==&quot;&#95;&#95;main&#95;&#95;&quot;:
main&#40;&#41;
</code></pre>Run that and you'll see the text appears that appears in dummytext.txt file. So let me explain what exactly happened.<br/><br/>So using open() will open up the file you want so that you can read it which is told to the open function by passing the 'r' if you passed it 'w' it would write to the file and if you did 'a' it would append. <br/><br/>When calling read() on the f you are taking all the text in the file and placing it into the variable called text and than later printing it out.<br/><br/>Now lets do something else and write to a file. Note that when doing this you'll realize when using 'w' rather than 'r' in the open function it'll cause the original file to be trancated. This means whenever opening a file with the 'w' parameter it'll remove all the text in the file before hand. This is important to know if you're going to be using this on important files so be aware that using 'w' will remove the text in the file. So continuing on lets change the code we have to the following...<pre><code>#!/usr/bin/env python
import sys, os
def main&#40;&#41;:
f = open&#40;'dummytext.txt', 'w'&#41;
f.write&#40;&quot;New text in the file&quot;&#41;
f.write&#40;&quot;\n&quot;&#41;
f.close&#40;&#41;
if &#95;&#95;name&#95;&#95;==&quot;&#95;&#95;main&#95;&#95;&quot;:
main&#40;&#41;
</code></pre>After running that check the dummytext.txt file and you'll realize that the file has be changed to contain "New text in the file". This is because of the write() function that is avaliable for you to use when you open a file with 'w'. Also keep in mind to always close the file after opening it as this could lead to problems in more complex programs.<br/><br/>Now let me show you another way where you can preserve your file and insert other text into it. So change your code one more time to the following.<pre><code>#!/usr/bin/env python
import sys, os
def main&#40;&#41;:
f = open&#40;'dummytext.txt', 'a'&#41;
f.write&#40;&quot;The previous text will be preserved this time.&quot;&#41;
f.write&#40;&quot;\n&quot;&#41;
f.close&#40;&#41;
if &#95;&#95;name&#95;&#95;==&quot;&#95;&#95;main&#95;&#95;&quot;:
main&#40;&#41;
</code></pre>Now when you check the file you'll see the the previous text in the dummytext is still there and the new text that was writen into the file is also there. When opening a file with 'a' you are preserving the original text in the file but appending new strings into it thus 'a' stands for appending. <br/><br/>Thats pretty much it when it comes to all the basic reading and writing in python.
</description>
<enclosure>
</enclosure>
<pubDate>
Fri, 30 Dec 2016 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/python-web-scraper/
</guid>
<link>
http://salmanhossain.me/posts/python-web-scraper/
</link>
<title>
Python - Parsing HTML with BeautifulSoup
</title>
<description>
<p>I wanted to gather a collection of all the links on a wikipedia page so I decided to code something up real quick. Luckily it is rather easy in python using BeautifulSoup. You'll need to download the python module <newcode>bs4</newcode> first which you can do with pip...</p><pre><code>sudo pip install bs4
</code></pre><p>After the installing is completed. Go ahead and open up a file called webscraper.py and import requests and bs4. </p><pre><code>import requests
from bs4 import BeautifulSoup
</code></pre><p>To get the html of a document from the web we'll be using requests. The variable resp will contain all of the html for the site.</p><pre><code>link = 'https://en.wikipedia.org/wiki/Physics'
resp = requests.get&#40;link&#41;
</code></pre><p>Now that we have all the html we'll begin to parse it using BeautifulSoup.</p><pre><code>soup = BeautifulSoup&#40;resp.text, 'lxml'&#41;
</code></pre><p>soup is an object in which we can parse and manipulate to obtain all the href's that may be contained within the html like so.</p><pre><code>urls = &#91;&#93;
for h in soup.find&#95;all&#40;'p'&#41;:
a = h.find&#95;all&#40;'a'&#41;
for t in a:
urls.append&#40;t.attrs&#91;'href'&#93;&#41;
</code></pre><p>This will place all the hrefs in the urls array. So than you can print all the urls you find but say you want to write them to a file instead you can do the following...</p><pre><code>f = open&#40;'urls.txt', 'w'&#41;
for url in urls:
f.write&#40;link + url&#41;
f.write&#40;&quot;\n&quot;&#41;
</code></pre><p>The link is added in to the f.write so it shows the full url rather than just the /wiki/something. So now you have a bunch of urls in a file named urls.txt when you run the command. Of course you'll notice something when looking at the urls.txt is that there are citiation urls which you don't want. Well it is rather simple to remove that by filtering out based on "#". So rewriting your for statement like this will filter out the cititation urls.</p><pre><code> for url in urls:
if '#' in url:
pass
else:
f.write&#40;link + url&#41;
f.write&#40;&quot;\n&quot;&#41;
</code></pre><p>Oh and of course don't forget to close the file. Which I always do.</p><pre><code>f.close&#40;&#41;
</code></pre><p>And that is pretty much it. Of course you can use optparse python module to make it so it takes an argument which can be the link and then generates the site and add on to this. So the full file should look something like this.</p><pre><code>#!/usr/bin/env python
import requests
from bs4 import BeautifulSoup
def main&#40;&#41;:
link = 'https://en.wikipedia.org/wiki/Physics'
resp = requests.get&#40;link&#41;
soup = BeautifulSoup&#40;resp.text, 'lxml'&#41;
urls = &#91;&#93;
for h in soup.find&#95;all&#40;'p'&#41;:
a = h.find&#95;all&#40;'a'&#41;
for t in a:
urls.append&#40;t.attrs&#91;'href'&#93;&#41;
f = open&#40;'urls.txt', 'w'&#41;
for url in urls:
if '#' in url:
pass
else:
f.write&#40;link + url&#41;
f.write&#40;&quot;\n&quot;&#41;
f.close&#40;&#41;
if &#95;&#95;name&#95;&#95;==&quot;&#95;&#95;main&#95;&#95;&quot;:
main&#40;&#41;
</code></pre>Now you can just run that and it'll generate the urls.txt file. Enjoy scraping the web.<br/><br/><a href='https://github.com/defunSM/web-scraper'>WebScraper</a>
</description>
<enclosure>
</enclosure>
<pubDate>
Wed, 28 Dec 2016 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/python-color-in-terminal/
</guid>
<link>
http://salmanhossain.me/posts/python-color-in-terminal/
</link>
<title>
Python - Color in Terminal
</title>
<description>
<p>So say you have a script written and displays some sort of information. It isn't just enough to just display it in normal colors but you want to add color coded messages to help readability. So there is a few options such as the <a href='https://pypi.python.org/pypi/colorama/0.3.3'>colorama</a> module which helps you add color when you print. <br><br/> I wanted to create a small python file and make my own functions in order to quickly color in text being printed to the terminal. Set the colors as strings into variables.</p><pre><code>green = &quot;\033&#91;1;32;40m&quot;
red = &quot;\033&#91;1;31;40m&quot;
yellow = &quot;\033&#91;1;33;40m&quot;
purple = &quot;\033&#91;1;35;40m&quot;
cyan = &quot;\033&#91;1;36;40m&quot;
white = &quot;\033&#91;1;37;40m&quot;
</code></pre><p>Than put the variables into an array as c short handing it for color. </p><pre><code>c = &#91;green, red, yellow, purple, cyan, white&#93;
</code></pre>So you can call green just by doing c[0] infront of a string. So if you wanted to have a green colored text appear in the terminal you can do the following... <pre><code>print&#40;c&#91;0&#93;, &quot;Green text&quot;&#41;
</code></pre>I also made a function <newcode>display_colors</newcode> in case you want to see which default color you want to use. I also made a ctext function which takes in the style, textcolor and background color in case you want to use something else besides the default colors. <pre><code>def ctext&#40;style, textcolor, bgcolor&#41;:
return &quot;\033&#91;&quot; + str&#40;style&#41; + &quot;;&quot; + str&#40;textcolor&#41; + &quot;;&quot; + str&#40;bgcolor&#41; + &quot;m&quot;
</code></pre><p>The github Repo of <a href='https://github.com/defunSM/colormyterminal'>colormyterminal</a>.</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Tue, 27 Dec 2016 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/python-optparse/
</guid>
<link>
http://salmanhossain.me/posts/python-optparse/
</link>
<title>
Python - Optparse
</title>
<description>
<p>Optparse is pretty nice way to make command-line tools. It streamlines the process of making arguments. To add the parser from the optparse library in Python.<pre><code>from optparse import OptionParser
</code></pre> This will allow you to make a parser using OptionParser() like the following.</p><pre><code>parser = OptionParser&#40;&#41;
</code></pre>This will allow you to add options to it like the following.<pre><code>parser.add&#95;option&#40;&quot;-c&quot;, &quot;--cos&quot;, help=&quot;Calculates the cosine given the degree.&quot;, dest=&quot;cosdegree&quot;, action=&quot;store&quot;&#41;
</code></pre>The add_option is avaliable can allows you to store the value passed to the -c option. So on the command line you can do things like the following..<pre><code>&lt;scriptname&gt; -c 3
</code></pre>You can also add something like this...<pre><code>options, arguments = parser.parse&#95;args&#40;&#41;
</code></pre>so now you can put the values passed to each option as a variable. Like so...<pre><code>ans = options.cosine
</code></pre><p>and you can retrieve the value passed to -c using options.cosdegree since it was stored in that using the dest="cosdegree" like I showed you above. <br><br/> You will be able to change the dest= to something else by default if not specified it would be cos since that is the option it is being assigned to. <br><br/> So you can create some useful scripts to calculate the cos or sin from the command line without opening up a calculator. You could essentially make a command line for commonly used math functions on the command line using optparse. If you're too lazy to open up a calculator. <br><br/> Also have the classical &ndash;help or -h which will list a short description of each option. You can specify the help that'll be show for each option using the help= when creating the option using add_option. <br><br/> The documentation for <a href='https://docs.python.org/3/library/optparse.html'>Optparse</a>.</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Mon, 26 Dec 2016 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/udacity-machine-learning/
</guid>
<link>
http://salmanhossain.me/posts/udacity-machine-learning/
</link>
<title>
Python - Naive Bayes Algorithm
</title>
<description>
<p>Been trying to get into machine learning and found that the udacity courses are extremely well. Specially at their intro into machine learning course which is what I'm doing over the winter break to familiarize myself with different algorithms. They go step by step and don't really require much background besides some python programming as a prerequisite. <br/><br/> <a href='https://www.udacity.com/course/intro-to-artificial-intelligence&ndash;cs271'>Udacity Intro into Machine Learning Course</a></p><p><a href='https://github.com/udacity/ud120-projects'>Udacity Project Repo for Intro Into Machine Learning</a> <br/><br/></p><p>The udacity course goes through explaining the concepts of machine learning rather well. One of the first algorithms that the course introduces you to is the Naive Bayes algoirthm. <br/><br/> <a href='http://scikit-learn.org/stable/modules/naive_bayes.html'>Naive Bayes Algorithm Sklearn</a> <br/><br/></p><p>Python has a varity of libraries for machine learning like tensorflow, sklearn, and numpy. Sklearn has algorithms which is pretty stright forward to use and implement in your code. You can google it and sklearn will provide a short example code on how to use that particular algorithm and also displays the pros and cons of that particular algorithm. For example the Naive Bayes Algorithm shows a short example code in just 3 lines of code you can make your prediction dataset. Also using the <a href='http://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html'>sklearn.metrics</a> you can get a feel for how well your classifer does in predicting new data points.</p><pre><code>from sklearn.naive&#95;bayes import GaussianNB
gnb = GaussianNB&#40;&#41;
y&#95;pred = gnb.fit&#40;iris.data, iris.target&#41;.predict&#40;iris.data&#41;
</code></pre><pre><code>from sklearn.metrics import accuracy&#95;score
acc = accuracy&#95;score&#40;iris.data, y&#95;pred&#41;
</code></pre><p>As you continue through the udacity course you'll be introduced to two other algorithms the Support Vector Machines and the Decision Tree algorithm. The course is approximated to be 4 months but I started 2 days ago and finished about 1/4 of it getting up to Decision Trees in two days so it can definitely be finished in less than a month if you go through it really quickly.</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Sun, 25 Dec 2016 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/python-bokeh/
</guid>
<link>
http://salmanhossain.me/posts/python-bokeh/
</link>
<title>
Python - Bokeh to Graph Boot Times
</title>
<description>
<p> So I been playing around with Bokeh's graphing utilities which is always fun. So I wanted to make some graphs using the boot times that I keep using a script. So I made three different graphs 2 of which represent the total boot time and the other pie graph represents the total boot time into segments of firmware, loader, kernel and userspace. </p><p><img src="https://defunsm.github.io/img/bokeh3.png" alt="graph image" /></p><p>The one above demonstrates the total time as an area under the line. You can clearly see here that there was a spike in the boot time since that 40 second boot time is distinguishable from the other plots are around 12 seconds.</p><p><img src="https://defunsm.github.io/img/bokeh2.png" alt="graph pie graph" /></p><p>This one is a pie graph I couldn't figure out how to label them but it just demonstrates each part of the boot as a pie graph (Firmware, Loader, Kernel, Userspace).</p><p><img src="https://defunsm.github.io/img/bokeh1.png" alt="graph histogram" /></p><p>There is also a histogram showing the usual time it takes to boot up which you can see from this graph is around 12 seconds since that is the most frequent time it takes to boot up. <br/><br/></p><p>The data is collected from <newcode>systemd-analyze</newcode>. Which I have a script which just stores all the boot times into a file from time.txt.</p><pre><code>systemd-analyze time &gt;&gt; time.txt
</code></pre><p><a href='https://github.com/defunSM/visualize-my-boot-time'>Github Repo</a></p>
</description>
<enclosure>
</enclosure>
<pubDate>
Sat, 17 Dec 2016 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/special-relativity/
</guid>
<link>
http://salmanhossain.me/posts/special-relativity/
</link>
<title>
Python - SpaceTime Diagrams
</title>
<description>
<p> So I been playing around with numpy and matplotlib in python lately. Wonderful tools for numerical analysis and data ploting. So I played around with them and decided to use them to construct a script in order to generate spacetime graphs. For those that don't know what a space time graph or diagram is essentially a way to visualize an object moving or not moving through space and time. Looks something like that on the bottom. <br/><br/> <img src="https://defunsm.github.io/img/spacetimegraph.png" alt="spacetime" /> <br/><br/> One of the things you'll instantly maybe find alarming about spacetime diagrams is that time is on the y axis. I know I was since usually time is normally placed on the x axis. Placing time on the y axis as I been told is somewhat traditional not really done on purpose but thats the way spacetime diagrams should be done. <br/><br/> So since time is on the y axis this means a few things our y intercept, b is going to be a value with units of time usually seconds. However in spacetime diagrams you can essentially make the units whatever you want as long as they make sense so if you wanted you could make the units of time as meters using the speed of light constant c. So whatever the distance that light will cover in 1 second you can convert to that for meters and use that as a value of time since it is equivilant. Of course that might sound a bit wierd and probably I didn't explain that too well but your x axis is a measure of space. Space can be measured in meters. So now you have the same units for both x and y axis. <br/><br/> Now remember that time is onthe y axis so this brings about some consequences such as the slope of the line becomes 1 over the speed of the object. So we can write an equation for this line in the following way as t = (1/v)*x + b. <br/><br/> The t stands for the time (m), the v in this case is the velocity which is in units of c, the x is the position of the object (m), and the y intercept is b which remember would originally be seconds but we converted time to meters using the speed of light constant so b is in terms of meters. <br/><br/> In order to generate the script you need the <a href='https://github.com/defunSM/SpecialRel/blob/master/SpecialRel.py'>SpecialRel.py</a> and <a href='https://github.com/defunSM/SpecialRel/blob/master/SpaceTimeGraph.py'>SpaceTimeGraph.py</a>. <br/><br/> You can get those scripts by just cloning the entire repo or just downloading them individually. <br/><br/><h2><a name="usage"></a>Usage</h2> <br/><br/> The way you use the script is the following.</p><pre><code>$ python SpaceTimeGraph.py -v 0.2 -b 2
</code></pre>You are specifiying the speed as 0.2c and the y intercept as 2m. You should see a graph pop up hopefully if not you will probably need to install numpy and matplotlib if you do not have those.<br/><br/>There are other options that you can specify and to see all of them type the following.<pre><code>$ python SpaceTimeGraph.py -h
</code></pre>You should get something like the picture below.<br/><br/><img src="https://defunsm.github.io/img/options.png" alt="options" /><br/><br/>You can change the upper and lower limits of the graph and determine how far you want the graph to extend out to using the options <newcode>-u</newcode> and <newcode>-l</newcode>. As well as name the object with <newcode>-n</newcode> so the object's name will appear on the legend.
</description>
<enclosure>
</enclosure>
<pubDate>
Sun, 04 Dec 2016 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/Heroku/
</guid>
<link>
http://salmanhossain.me/posts/Heroku/
</link>
<title>
Clojure - How to start a web app using Heroku
</title>
<description>
<p>Heroku is a platform that allows developers to build web apps and run them on their servers. It is really nice that they do have documentation on how to start a server using clojure as well. I'll go over through some of the stuff that they tell you to do from their set up page. You can follow along here or just follow their <a href='https://devcenter.heroku.com/articles/getting-started-with-clojure#set-up'>instructions</a>. <br/><br/><h1><a name="make&#95;a&#95;heroku&#95;account"></a>Make a Heroku Account</h1> <br/><br/> First things first is that you will need an account to manage your web apps. Just go ahead and do that on <a href='https://signup.heroku.com/dc'>Heorku</a>. <br/><br/><h1><a name="installing&#95;the&#95;heroku&#95;cli"></a>Installing the Heroku CLI</h1> <br/><br/> Now let us go on ahead and install the <newcode>Heroku Command Line Interface</newcode> which you'll need to manage your web apps from the terminal. You can do that using the following command from the terminal.</p><pre><code>$ wget -qO- https://toolbelt.heroku.com/install.sh | sh
</code></pre>*You will need to make sure that you have ruby installed as well.<br/><br/><h1><a name="create&#95;the&#95;web&#95;app"></a>Create the web app</h1><p><br/><br/> Lets go ahead and clone a sample web app that heroku provides or you can clone the reagent heroku web app template either one.</p><pre><code>$ git clone https://github.com/heroku/clojure-getting-started.git
</code></pre>or<pre><code>$ git clone https://github.com/reagent-project/reagent-template.git
</code></pre><br/><br/><h1><a name="create&#95;the&#95;web&#95;app&#95;on&#95;heroku"></a>Create the web app on heroku</h1><p><br/><br/> Now lets create a heroku app to recieve the code. You can decide to specify the name or leave it blank and it'll give you a random name.<pre><code>$ heroku create
</code></pre> or<pre><code>$ heroku create heroku-app-name
</code></pre> <br/><br/><h1><a name="push&#95;the&#95;web&#95;app"></a>Push the web app</h1> <br/><br/> Now you can push the source code like you do for git. First make sure to add all files.<pre><code>$ git add .
</code></pre> Commit all the files with the message "init".<pre><code>$ git commit -m &quot;init&quot;
</code></pre> Push to the heroku web app.<pre><code>$ git push heroku master
</code></pre> Now you should be able to visit the site hosting the source code at heroku-app-name.herokuapp.com!</p>
</description>
<enclosure>
</enclosure>
<pubDate>
Wed, 30 Nov 2016 00:00:00 -0500
</pubDate>
</item>
<item>
<guid>
http://salmanhossain.me/posts/clojure-using-quil-4/
</guid>
<link>
http://salmanhossain.me/posts/clojure-using-quil-4/
</link>
<title>
Graphics using Quil in Clojure (Part 4)
</title>
<description>
<p>Once you have created something using quil the natural thing is to display it right? Doing that is easy if you follow the steps. There are some pitfalls you have to becareful of getting into. The best place to see how to include quil into the browser is the <a href='https://github.com/quil/quil/wiki/ClojureScript'>quil wiki</a>. <br/><br/> The guide shows you how to start a browser with the quil applet. I'll go through how to incorporate the quil applet in a reagent template which is pretty much the same thing expect it can be a bit confusing on where exactly to place the defsketch macro. <br/><br/> To start a reagent template go ahead and type the following...<pre><code>$ lein new reagent quilreagent
</code></pre> The first thing to do is to add quil as a dependency in the project.clj so lets do that.<pre><code> :dependencies &#91;&#91;org.clojure/clojure &quot;1.8.0&quot;&#93;
&#91;ring-server &quot;0.4.0&quot;&#93;
&#91;reagent &quot;0.6.0&quot;&#93;
&#91;reagent-forms &quot;0.5.25&quot;&#93;
&#91;reagent-utils &quot;0.2.0&quot;&#93;
&#91;ring &quot;1.5.0&quot;&#93;
&#91;ring/ring-defaults &quot;0.2.1&quot;&#93;
&#91;compojure &quot;1.5.1&quot;&#93;
&#91;hiccup &quot;1.0.5&quot;&#93;
&#91;yogthos/config &quot;0.8&quot;&#93;
&#91;org.clojure/clojurescript &quot;1.9.229&quot;
:scope &quot;provided&quot;&#93;
&#91;secretary &quot;1.2.3&quot;&#93;
&#91;venantius/accountant &quot;0.1.7&quot;
:exclusions &#91;org.clojure/tools.reader&#93;&#93;
&#91;quil &quot;2.4.0&quot;&#93;&#93; ;; add quil as a dependency
</code></pre> That is what your :dependencies should look like now just add quil as a dependency at the bottom. Now that is done. Go to the <newcode>core.cljs</newcode> file in your src directory. Open it up and lets add quil in the required place as q and the macros needed as well. So your name space should look like this.<pre><code>&#40;ns quilreagent.core
&#40;:require &#91;reagent.core :as reagent :refer &#91;atom&#93;&#93;
&#91;reagent.session :as session&#93;
&#91;secretary.core :as secretary :include-macros true&#93;
&#91;accountant.core :as accountant&#93;
&#91;quil.core :as q :include-macros true&#93; ;; add this
&#91;quil.middleware :as m&#93;&#41;&#41; ;; as well as this
</code></pre></p><p>As well as add all of the code needed for quil for now we'll use the basic quil example. So add all of this right after the name space.<pre><code>&#40;defn setup &#91;&#93;
; Set frame rate to 30 frames per second.
&#40;q/frame-rate 30&#41;
; Set color mode to HSB &#40;HSV&#41; instead of default RGB.
&#40;q/color-mode :hsb&#41;
; setup function returns initial state. It contains
; circle color and position.
{:color 0
:angle 0}&#41;
&#40;defn update-state &#91;state&#93;
; Update sketch state by changing circle color and position.
{:color &#40;mod &#40;+ &#40;:color state&#41; 0.7&#41; 255&#41;
:angle &#40;+ &#40;:angle state&#41; 0.1&#41;}&#41;
&#40;defn draw-state &#91;state&#93;
; Clear the sketch by filling it with light-grey color.