forked from mmistakes/minimal-mistakes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile.html
885 lines (784 loc) · 37.9 KB
/
tile.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
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
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tilecoding — econlearn 1.0 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="top" title="econlearn 1.0 documentation" href="index.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> econlearn
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="simple">
</ul>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">econlearn</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Tilecoding</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/tile.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document">
<div class="section" id="module-econlearn.tile">
<span id="tilecoding"></span><h1>Tilecoding<a class="headerlink" href="#module-econlearn.tile" title="Permalink to this headline">¶</a></h1>
<p>Tilecoding based machine learning</p>
<dl class="class">
<dt id="econlearn.tile.TilecodeDensity">
<em class="property">class </em><code class="descclassname">econlearn.tile.</code><code class="descname">TilecodeDensity</code><span class="sig-paren">(</span><em>D</em>, <em>T</em>, <em>L</em>, <em>mem_max=1</em>, <em>offset='optimal'</em>, <em>cores=1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeDensity"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeDensity" title="Permalink to this definition">¶</a></dt>
<dd><p>Tile coding approximation of the pdf of X
Fits by averaging. Supports multi-core fit and predict.
Options for uniform, random or ‘optimal’ displacement vectors.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>D</strong> : integer</p>
<blockquote>
<div><p>Total number of input dimensions</p>
</div></blockquote>
<p><strong>T</strong> : list of integers, length D</p>
<blockquote>
<div><p>Number of tiles per dimension</p>
</div></blockquote>
<p><strong>L</strong> : integer</p>
<blockquote>
<div><p>Number of tiling ‘layers’</p>
</div></blockquote>
<p><strong>mem_max</strong> : double, (default=1)</p>
<blockquote>
<div><p>Proportion of tiles to store in memory: less than 1 means hashing is used.</p>
</div></blockquote>
<p><strong>min_sample</strong> : integer, (default=50)</p>
<blockquote>
<div><p>Minimum number of observations per tile</p>
</div></blockquote>
<p><strong>offset</strong> : string, (default=’uniform’)</p>
<blockquote class="last">
<div><p>Type of displacement vector, one of ‘uniform’, ‘random’ or ‘optimal’</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Attributes</p>
<table border="1" class="docutils">
<colgroup>
<col width="17%" />
<col width="83%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>tile</td>
<td>(Tilecode instance)</td>
</tr>
</tbody>
</table>
<p class="rubric">Methods</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%" />
<col width="90%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><code class="xref py py-obj docutils literal"><span class="pre">fit</span></code>(X[, cdf])</td>
<td></td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#econlearn.tile.TilecodeDensity.plot" title="econlearn.tile.TilecodeDensity.plot"><code class="xref py py-obj docutils literal"><span class="pre">plot</span></code></a>([xargs])</td>
<td>Plot the pdf along one dimension, holding others fixed</td>
</tr>
<tr class="row-odd"><td><code class="xref py py-obj docutils literal"><span class="pre">predict</span></code>(X)</td>
<td></td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="econlearn.tile.TilecodeDensity.plot">
<code class="descname">plot</code><span class="sig-paren">(</span><em>xargs=['x']</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeDensity.plot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeDensity.plot" title="Permalink to this definition">¶</a></dt>
<dd><p>Plot the pdf along one dimension, holding others fixed</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>xargs</strong> : list, length = D</p>
<blockquote class="last">
<div><p>List of variable default values, set plotting dimension to ‘x’
Not required if D = 1</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="econlearn.tile.TilecodeNearestNeighbour">
<em class="property">class </em><code class="descclassname">econlearn.tile.</code><code class="descname">TilecodeNearestNeighbour</code><span class="sig-paren">(</span><em>D</em>, <em>L</em>, <em>mem_max=1</em>, <em>cores=1</em>, <em>offset='optimal'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeNearestNeighbour"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeNearestNeighbour" title="Permalink to this definition">¶</a></dt>
<dd><p>Fast approximate nearest neighbour search using tile coding data structure</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>D</strong> : int,</p>
<blockquote>
<div><p>Number of input dimensions</p>
</div></blockquote>
<p><strong>L</strong> : int,</p>
<blockquote>
<div><p>Number of tilings or ‘layers’</p>
</div></blockquote>
<p><strong>mem_max</strong> : float, optional (default = 1)</p>
<blockquote>
<div><p>Tile array size, values less than 1 turn on hashing</p>
</div></blockquote>
<p><strong>cores</strong> : int, optional (default=1)</p>
<blockquote>
<div><p>Number of CPU cores to use (fitting stage is parallelized)</p>
</div></blockquote>
<p><strong>offset</strong> : {‘optimal’, ‘random’, ‘uniform’}, (default=’optimal’) optional</p>
<blockquote class="last">
<div><p>Type of displacement vector used</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Notes</p>
<p>This is an approximate method: it is possible that some points > than radius may be included
and some < than radius may be excluded.</p>
<p class="rubric">Methods</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%" />
<col width="90%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#econlearn.tile.TilecodeNearestNeighbour.fit" title="econlearn.tile.TilecodeNearestNeighbour.fit"><code class="xref py py-obj docutils literal"><span class="pre">fit</span></code></a>(X, radius[, prop])</td>
<td>Fit a tile coding data structure to X</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#econlearn.tile.TilecodeNearestNeighbour.predict" title="econlearn.tile.TilecodeNearestNeighbour.predict"><code class="xref py py-obj docutils literal"><span class="pre">predict</span></code></a>(X[, thresh])</td>
<td>Obtain nearest neighbors (points within distance radius)</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="econlearn.tile.TilecodeNearestNeighbour.fit">
<code class="descname">fit</code><span class="sig-paren">(</span><em>X</em>, <em>radius</em>, <em>prop=1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeNearestNeighbour.fit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeNearestNeighbour.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Fit a tile coding data structure to X</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>X</strong> : array of shape [N, D]</p>
<blockquote>
<div><p>Input data (unscaled)</p>
</div></blockquote>
<p><strong>radius</strong> : float</p>
<blockquote class="last">
<div><p>radius for nearest neighbor queries. Tile widths for each dimension
of X are int((b[i] - a[i]) / radius) where b and a are the
max and min values of X[:,i].</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="econlearn.tile.TilecodeNearestNeighbour.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>X</em>, <em>thresh=1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeNearestNeighbour.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeNearestNeighbour.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Obtain nearest neighbors (points within distance radius)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>X</strong> : array of shape [N, D]</p>
<blockquote>
<div><p>Query points</p>
</div></blockquote>
<p><strong>thresh</strong> : int, (default=1)</p>
<blockquote>
<div><p>Only include points if they are active in at least thresh layers (max is L)
Higher thresh values will tend to exclude the points furthest from the query point</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>Y</strong> : list of arrays (length = N)</p>
<blockquote class="last">
<div><p>Nearest neighbors for each query point</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="econlearn.tile.TilecodeQVIteration">
<em class="property">class </em><code class="descclassname">econlearn.tile.</code><code class="descname">TilecodeQVIteration</code><span class="sig-paren">(</span><em>D</em>, <em>T</em>, <em>L</em>, <em>radius</em>, <em>beta</em>, <em>ms=1</em>, <em>mem_max=1</em>, <em>cores=1</em>, <em>ASGD=True</em>, <em>linT=6</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeQVIteration"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeQVIteration" title="Permalink to this definition">¶</a></dt>
<dd><p>Solve a MDP with 1 policy variable and D state variables by Q-V Iteration</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>D</strong> : int,</p>
<blockquote>
<div><p>Number of state variables</p>
</div></blockquote>
<p><strong>T</strong> : list of integers, length D</p>
<blockquote>
<div><p>Number of tiles per dimension</p>
</div></blockquote>
<p><strong>L</strong> : int,</p>
<blockquote>
<div><p>Number of tilings or ‘layers’</p>
</div></blockquote>
<p><strong>radius</strong> : float,</p>
<blockquote>
<div><p>Radius for state space sample grid</p>
</div></blockquote>
<p><strong>beta</strong> : float in (0, 1),</p>
<blockquote>
<div><p>Discount rate</p>
</div></blockquote>
<p><strong>ms</strong> : int, optional (default = 1)</p>
<blockquote>
<div><p>Minimum samples per tile for the Q function</p>
</div></blockquote>
<p><strong>mem_max</strong> : float, optional (default = 1)</p>
<blockquote>
<div><p>Tile array size, values less than 1 turns on hashing</p>
</div></blockquote>
<p><strong>cores</strong> : int, optional (default=1)</p>
<blockquote>
<div><p>Number of CPU cores to use</p>
</div></blockquote>
<p><strong>ASGD</strong> : boolean, optional (default=True)</p>
<blockquote>
<div><p>Fit Q function by ASGD</p>
</div></blockquote>
<p><strong>offset</strong> : {‘optimal’, ‘random’, ‘uniform’}, (default=’optimal’)</p>
<blockquote>
<div><p>Type of displacement vector used</p>
</div></blockquote>
<p><strong>linT</strong> : integer, optional (default=6)</p>
<blockquote class="last">
<div><p>Number of linear spline knots per dimension</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Methods</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%" />
<col width="90%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#econlearn.tile.TilecodeQVIteration.iterate" title="econlearn.tile.TilecodeQVIteration.iterate"><code class="xref py py-obj docutils literal"><span class="pre">iterate</span></code></a>(XA, X1, R, A_low, A_high[, ITER, ...])</td>
<td>Perform QV iteration given a set of training data (N state-action and state transition samples)</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#econlearn.tile.TilecodeQVIteration.maximise" title="econlearn.tile.TilecodeQVIteration.maximise"><code class="xref py py-obj docutils literal"><span class="pre">maximise</span></code></a>(grid, A_low, A_high[, output])</td>
<td>Maximises current Q-function for a subset of state space points and returns new value and policy functions</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#econlearn.tile.TilecodeQVIteration.resetQ" title="econlearn.tile.TilecodeQVIteration.resetQ"><code class="xref py py-obj docutils literal"><span class="pre">resetQ</span></code></a>(D, T, L[, mem_max, ms])</td>
<td>Reset the Q function</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="econlearn.tile.TilecodeQVIteration.iterate">
<code class="descname">iterate</code><span class="sig-paren">(</span><em>XA</em>, <em>X1</em>, <em>R</em>, <em>A_low</em>, <em>A_high</em>, <em>ITER=50</em>, <em>plot=False</em>, <em>plotdim=0</em>, <em>output=True</em>, <em>a=0</em>, <em>b=0</em>, <em>pc_samp=1</em>, <em>eta=0.8</em>, <em>maxT=60000</em>, <em>tilesg=False</em>, <em>sg_points=100</em>, <em>sg_prop=0.96</em>, <em>sg_samp=1</em>, <em>sgmem_max=0.4</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeQVIteration.iterate"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeQVIteration.iterate" title="Permalink to this definition">¶</a></dt>
<dd><p>Perform QV iteration given a set of training data (N state-action and state transition samples)
to derive optimal value and policy functions</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>XA</strong> : array of shape [N, D + 1]</p>
<blockquote>
<div><p>State-action samples (i.e., actions in first column, then state variables)</p>
</div></blockquote>
<p><strong>X1</strong> : array of shape [N, D]</p>
<blockquote>
<div><p>State transition samples (i.e., state at t+1)</p>
</div></blockquote>
<p><strong>R</strong> : array of shape [N,]</p>
<blockquote>
<div><p>Payoff samples</p>
</div></blockquote>
<p><strong>A_low</strong> : array of shape [N,],</p>
<blockquote>
<div><p>Lower feasible bound for action A conditional on X</p>
</div></blockquote>
<p><strong>A_high</strong> : array of shape [N,],</p>
<blockquote>
<div><p>Upper feasible bound for action A conditional on X</p>
</div></blockquote>
<p><strong>ITER</strong> : int, optional (default = 50)</p>
<blockquote>
<div><p>Number of iterations</p>
</div></blockquote>
<p><strong>plot</strong> : boolean, optional (default = True)</p>
<blockquote>
<div><p>Whether to generate plots of the final value and policy function.</p>
</div></blockquote>
<p><strong>plotdim</strong> : int in [0, D], optional (default = 0)</p>
<blockquote>
<div><p>Which state dimension to plot
(other dimensions are held fixed at their mean values).</p>
</div></blockquote>
<p><strong>a</strong> : array, optional, shape=(D)</p>
<blockquote>
<div><p>Percentile to use for minimum tiling domain (if not provided set to 0)</p>
</div></blockquote>
<p><strong>b</strong> : array, optional, shape=(D)</p>
<blockquote>
<div><p>Percentile to use for maximum tiling domain (if not provided set to 100)</p>
</div></blockquote>
<p><strong>pc_samp</strong> : float, optional, (default=1)</p>
<blockquote>
<div><p>Proportion of sample to use when calculating percentile ranges</p>
</div></blockquote>
<p><strong>output</strong> : boolean, optional (default=True)</p>
<blockquote>
<div><p>Whether to print value function change updates each iteration</p>
</div></blockquote>
<p><strong>eta</strong> : float (default=.01)</p>
<blockquote>
<div><p>ASGD / SGD learning rate</p>
</div></blockquote>
<p><strong>maxT</strong> : int, default (default=60000)</p>
<blockquote>
<div><p>ASGD / SGD learning rate parameter</p>
</div></blockquote>
<p><strong>tilesg</strong> : boolean, (default=False)</p>
<blockquote>
<div><p>If True then will use tilecoding to build state space sample grid
else will use distance method. Tilecoding is preferred for large samples.</p>
</div></blockquote>
<p><strong>sg_points</strong> : int, (default=100)</p>
<blockquote>
<div><p>If tilesg=False, then the number of points in the state space sample grid</p>
</div></blockquote>
<p><strong>sg_prop</strong> : float, (default=0.96)</p>
<blockquote>
<div><p>If tilesg=True, then the proportion of points to include in the
state space sample grid (set less than 1 to exclude outliers)</p>
</div></blockquote>
<p><strong>sg_samp</strong> : float, (default=0.5)</p>
<blockquote>
<div><p>If tilesg=True, then the proportion of the sample points to use for the
state space sample grid</p>
</div></blockquote>
<p><strong>sgmem_max</strong> : float, (default = 0.4)</p>
<blockquote class="last">
<div><p>If tilesg=True, then the mem_max (hashing) parameter of the sample grid
tilecode scheme.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="econlearn.tile.TilecodeQVIteration.maximise">
<code class="descname">maximise</code><span class="sig-paren">(</span><em>grid</em>, <em>A_low</em>, <em>A_high</em>, <em>output=True</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeQVIteration.maximise"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeQVIteration.maximise" title="Permalink to this definition">¶</a></dt>
<dd><p>Maximises current Q-function for a subset of state space points and returns new value and policy functions</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>grid</strong> : array, shape=(N, D)</p>
<blockquote>
<div><p>State space grid</p>
</div></blockquote>
<p><strong>A_low</strong> : array, shape=(N,)</p>
<blockquote>
<div><p>action lower bound</p>
</div></blockquote>
<p><strong>A_high</strong> : array, shape=(N,)</p>
<blockquote>
<div><p>action upper bound</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">ERROR: float</p>
<blockquote class="last">
<div><p>Mean absolute deviation</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="econlearn.tile.TilecodeQVIteration.resetQ">
<code class="descname">resetQ</code><span class="sig-paren">(</span><em>D</em>, <em>T</em>, <em>L</em>, <em>mem_max=1</em>, <em>ms=1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeQVIteration.resetQ"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeQVIteration.resetQ" title="Permalink to this definition">¶</a></dt>
<dd><p>Reset the Q function</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>D</strong> : int,</p>
<blockquote>
<div><p>Number of state variables</p>
</div></blockquote>
<p><strong>T</strong> : list of integers, length D</p>
<blockquote>
<div><p>Number of tiles per dimension</p>
</div></blockquote>
<p><strong>L</strong> : int,</p>
<blockquote>
<div><p>Number of tilings or ‘layers’</p>
</div></blockquote>
<p><strong>mem_max</strong> : float, optional (default = 1)</p>
<blockquote>
<div><p>Tile array size, values less than 1 turns on hashing</p>
</div></blockquote>
<p><strong>ms</strong> : int, optional (default = 1)</p>
<blockquote class="last">
<div><p>Minimum samples per tile for the Q function</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="econlearn.tile.TilecodeRegressor">
<em class="property">class </em><code class="descclassname">econlearn.tile.</code><code class="descname">TilecodeRegressor</code><span class="sig-paren">(</span><em>D</em>, <em>T</em>, <em>L</em>, <em>mem_max=1</em>, <em>min_sample=1</em>, <em>offset='optimal'</em>, <em>lin_spline=False</em>, <em>linT=7</em>, <em>cores=4</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeRegressor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeRegressor" title="Permalink to this definition">¶</a></dt>
<dd><p>Tile coding for function approximation (Supervised Learning).
Fits by averaging and/or Stochastic Gradient Descent.
Supports multi-core fit and predict. Options for uniform, random or ‘optimal’ displacement vectors.
Provides option for linear spline extrapolation / filling</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>D</strong> : integer</p>
<blockquote>
<div><p>Total number of input dimensions</p>
</div></blockquote>
<p><strong>T</strong> : list of integers, length D</p>
<blockquote>
<div><p>Number of tiles per dimension</p>
</div></blockquote>
<p><strong>L</strong> : integer</p>
<blockquote>
<div><p>Number of tiling ‘layers’</p>
</div></blockquote>
<p><strong>mem_max</strong> : double, (default=1)</p>
<blockquote>
<div><p>Proportion of tiles to store in memory: less than 1 means hashing is used.</p>
</div></blockquote>
<p><strong>min_sample</strong> : integer, (default=50)</p>
<blockquote>
<div><p>Minimum number of observations per tile</p>
</div></blockquote>
<p><strong>offset</strong> : string, (default=’uniform’)</p>
<blockquote>
<div><p>Type of displacement vector, one of ‘uniform’, ‘random’ or ‘optimal’</p>
</div></blockquote>
<p><strong>lin_spline</strong> : boolean, (default=False)</p>
<blockquote>
<div><p>Use sparse linear spline model to extrapolate / fill empty tiles</p>
</div></blockquote>
<p><strong>linT</strong> : integer, (default=6)</p>
<blockquote class="last">
<div><p>Number of linear spline knots per dimension</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Attributes</p>
<table border="1" class="docutils">
<colgroup>
<col width="13%" />
<col width="87%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>tile</td>
<td>(Cython Tilecode instance)</td>
</tr>
</tbody>
</table>
<p class="rubric">Methods</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%" />
<col width="90%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#econlearn.tile.TilecodeRegressor.check_memory" title="econlearn.tile.TilecodeRegressor.check_memory"><code class="xref py py-obj docutils literal"><span class="pre">check_memory</span></code></a>()</td>
<td>Provides information on the current memory usage of the tilecoding scheme.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#econlearn.tile.TilecodeRegressor.fit" title="econlearn.tile.TilecodeRegressor.fit"><code class="xref py py-obj docutils literal"><span class="pre">fit</span></code></a>(X, Y[, method, score, copy, a, b, ...])</td>
<td>Estimate tilecode weights.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="#econlearn.tile.TilecodeRegressor.plot" title="econlearn.tile.TilecodeRegressor.plot"><code class="xref py py-obj docutils literal"><span class="pre">plot</span></code></a>([xargs, showdata])</td>
<td>Plot the function on along one dimension, holding others fixed</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="#econlearn.tile.TilecodeRegressor.predict" title="econlearn.tile.TilecodeRegressor.predict"><code class="xref py py-obj docutils literal"><span class="pre">predict</span></code></a>(X)</td>
<td>Return tilecode predicted value</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="econlearn.tile.TilecodeRegressor.check_memory">
<code class="descname">check_memory</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeRegressor.check_memory"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeRegressor.check_memory" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides information on the current memory usage of the tilecoding scheme.
If memory usage is an issue call this function after fitting and then consider rebuilding the scheme with a lower <cite>mem_max</cite> parameter.</p>
</dd></dl>
<dl class="method">
<dt id="econlearn.tile.TilecodeRegressor.fit">
<code class="descname">fit</code><span class="sig-paren">(</span><em>X</em>, <em>Y</em>, <em>method='A'</em>, <em>score=False</em>, <em>copy=True</em>, <em>a=0</em>, <em>b=0</em>, <em>pc_samp=1</em>, <em>eta=0.01</em>, <em>n_iters=1</em>, <em>scale=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeRegressor.fit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeRegressor.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Estimate tilecode weights.
Supports <a href="#id1"><span class="problematic" id="id2">`</span></a>Averaging’, Stochastic Gradient Descent (SGD) and Averaged SGD.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>X</strong> : array, shape=(N, D)</p>
<blockquote>
<div><p>Input data (unscaled)</p>
</div></blockquote>
<p><strong>Y</strong> : array, shape=(N)</p>
<blockquote>
<div><p>Output data (unscaled)</p>
</div></blockquote>
<p><strong>method</strong> : string (default=’A’)</p>
<blockquote>
<div><p>Estimation method, one of ‘A’ (for Averaging), ‘SGD’ or ‘ASGD’.</p>
</div></blockquote>
<p><strong>score</strong> : boolean, (default=False)</p>
<blockquote>
<div><p>Calculate R-squared</p>
</div></blockquote>
<p><strong>copy</strong> : boolean (default=False)</p>
<blockquote>
<div><p>Store X and Y</p>
</div></blockquote>
<p><strong>a</strong> : array, optional shape=(D)</p>
<blockquote>
<div><p>Percentile to use for minimum tiling range (if not provided set to 0)</p>
</div></blockquote>
<p><strong>b</strong> : array, optional, shape=(D)</p>
<blockquote>
<div><p>Percentile to use for maximum tiling range (if not provided set to 100)</p>
</div></blockquote>
<p><strong>pc_samp</strong> : float, optional, (default=1)</p>
<blockquote>
<div><p>Proportion of sample to use when calculating percentile ranges</p>
</div></blockquote>
<p><strong>eta</strong> : float (default=.01)</p>
<blockquote>
<div><p>SGD Learning rate</p>
</div></blockquote>
<p><strong>n_iters</strong> : int (default=1)</p>
<blockquote>
<div><p>Number of passes over the data set in SGD</p>
</div></blockquote>
<p><strong>scale</strong> : float (default=0)</p>
<blockquote class="last">
<div><p>Learning rate scaling factor in SGD</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="econlearn.tile.TilecodeRegressor.plot">
<code class="descname">plot</code><span class="sig-paren">(</span><em>xargs=['x'], showdata=True</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeRegressor.plot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeRegressor.plot" title="Permalink to this definition">¶</a></dt>
<dd><p>Plot the function on along one dimension, holding others fixed</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>xargs</strong> : list, length = D</p>
<blockquote>
<div><p>List of variable default values, set plotting dimension to ‘x’
Not required if D = 1</p>
</div></blockquote>
<p><strong>showdata</strong> : boolean, (default=False)</p>
<blockquote class="last">
<div><p>Scatter training points</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="econlearn.tile.TilecodeRegressor.predict">
<code class="descname">predict</code><span class="sig-paren">(</span><em>X</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeRegressor.predict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeRegressor.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Return tilecode predicted value</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>X</strong> : array, shape=(N, D) or (D,)</p>
<blockquote>
<div><p>Input data</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>Y</strong> : array, shape=(N,)</p>
<blockquote class="last">
<div><p>Predicted values</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="econlearn.tile.TilecodeSamplegrid">
<em class="property">class </em><code class="descclassname">econlearn.tile.</code><code class="descname">TilecodeSamplegrid</code><span class="sig-paren">(</span><em>D</em>, <em>L</em>, <em>mem_max=1</em>, <em>cores=1</em>, <em>offset='optimal'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeSamplegrid"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeSamplegrid" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a sample grid (sample of approximately equidistant points) from
a large data set, using a tilecoding data structure</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>D</strong> : int,</p>
<blockquote>
<div><p>Number of input dimensions</p>
</div></blockquote>
<p><strong>L</strong> : int,</p>
<blockquote>
<div><p>Number of tilings or ‘layers’</p>
</div></blockquote>
<p><strong>mem_max</strong> : float, optional (default = 1)</p>
<blockquote>
<div><p>Tile array size, values less than 1 turn on hashing</p>
</div></blockquote>
<p><strong>cores</strong> : int, optional (default=1)</p>
<blockquote>
<div><p>Number of CPU cores to use (fitting stage is parallelized)</p>
</div></blockquote>
<p><strong>offset</strong> : {‘optimal’, ‘random’, ‘uniform’}, optional</p>
<blockquote class="last">
<div><p>Type of displacement vector used</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric">Notes</p>
<p>This is an approximate method: it is possible that the resulting sample will contain
some points less than <code class="docutils literal"><span class="pre">radius</span></code> distance apart. The accuracy improves with the number
of layers <code class="docutils literal"><span class="pre">L</span></code>.</p>
<p>Currently the tile widths are defined as <code class="docutils literal"><span class="pre">int((b</span> <span class="pre">-</span> <span class="pre">a)</span> <span class="pre">/</span> <span class="pre">radius)**-1</span></code>, so small changes in
radius may have no effect.</p>
<p class="rubric">Methods</p>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%" />
<col width="90%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="#econlearn.tile.TilecodeSamplegrid.fit" title="econlearn.tile.TilecodeSamplegrid.fit"><code class="xref py py-obj docutils literal"><span class="pre">fit</span></code></a>(X, radius[, prop])</td>
<td>Fit a density function to X and return a sample grid with a maximum of M points</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="econlearn.tile.TilecodeSamplegrid.fit">
<code class="descname">fit</code><span class="sig-paren">(</span><em>X</em>, <em>radius</em>, <em>prop=1</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/econlearn/tile.html#TilecodeSamplegrid.fit"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#econlearn.tile.TilecodeSamplegrid.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Fit a density function to X and return a sample grid with a maximum of M points</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>X</strong> : array of shape [N, D]</p>
<blockquote>
<div><p>Input data (unscaled)</p>
</div></blockquote>
<p><strong>radius</strong> : float</p>
<blockquote>
<div><p>minimum distance between points. This determines tile widths.</p>
</div></blockquote>
<p><strong>prop</strong> : float in (0, 1), optional (default=1.0)</p>
<blockquote>
<div><p>Proportion of sample points to return (lowest density points are excluded)</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">GRID, array of shape [M, D]</p>
<blockquote class="last">
<div><p>The sample grid with M < N points</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2014, Neal Hughes.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'1.0',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>