-
Notifications
You must be signed in to change notification settings - Fork 7
/
example-sdr-lines.html
114 lines (98 loc) · 3.76 KB
/
example-sdr-lines.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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>2D SDR Drawing</title>
<style>
body { margin: 10px; }
svg {
border: solid 1px orange;
width: 560px;
height: 260px;
}
svg g {
border: solid 1px red;
}
</style>
</head>
<body>
<svg>
<g id="miniColumnPools"></g>
<g id="inputSpacePools"></g>
</svg>
<br/>
<input type="range" min="100" max="600" value="300" id="inputSpaceSizeSlider" />
input space size: <span class="inputSpaceSizeDisplay"></span> bits
<br/>
<input type="range" min="100" max="600" value="300" id="miniColumnCountSlider" />
mini-column count: <span class="miniColumnCountDisplay"></span> columns
<br/>
<input type="range" min="0" max="100" value="90" id="receptiveFieldPercSlider" />
receptive field: <span class="receptiveFieldPercDisplay"></span>%
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="dist/cell-viz-2d-1.4.8.min.js"></script>
<script>
$(function() {
let $receptiveFieldPercSlider = $('#receptiveFieldPercSlider')
let $receptiveFieldPercDisplay = $('.receptiveFieldPercDisplay')
let $inputSpaceSizeSlider = $('#inputSpaceSizeSlider')
let $inputSpaceSizeDisplay = $('.inputSpaceSizeDisplay')
let $miniColumnCountSlider = $('#miniColumnCountSlider')
let $miniColumnCountDisplay = $('.miniColumnCountDisplay')
let selectedMiniColumnIndex = 0
let potentialPools = []
let miniColumns = []
let drawOptions = {
width: 270,
height: 270,
}
function loadRandomPotentialPools() {
let inputSpaceDimensions = parseInt($inputSpaceSizeSlider.val())
let miniColumnCount = parseInt($miniColumnCountSlider.val())
potentialPools = []
for (let i = 0; i < miniColumnCount; i++) {
let pool = []
let receptiveFieldPerc = parseInt($receptiveFieldPercSlider.val()) / 100
for (let j = 0; j < inputSpaceDimensions; j++) {
if (Math.random() > receptiveFieldPerc) pool.push(0)
else pool.push(1)
}
potentialPools.push(pool)
}
}
function updateSelectedMiniColumn(index) {
selectedMiniColumnIndex = index
let miniColumnCount = parseInt($miniColumnCountSlider.val())
miniColumns = SdrUtils.getEmpty(miniColumnCount)
miniColumns[selectedMiniColumnIndex] = 1
}
function updateDisplays() {
let pool = potentialPools[selectedMiniColumnIndex]
let poolDrawing = new SdrDrawing(pool, 'inputSpacePools')
poolDrawing.draw(drawOptions)
let miniColumnsDrawing = new SdrDrawing(miniColumns, 'miniColumnPools')
let mcOpts = Object.assign({}, drawOptions)
mcOpts.onColor = 'khaki'
miniColumnsDrawing.draw(mcOpts)
miniColumnsDrawing.$drawing.attr('transform', 'translate(280)')
miniColumnsDrawing.onCell('mouseover', (d, i) => {
updateSelectedMiniColumn(i)
updateDisplays()
})
$receptiveFieldPercDisplay.html($receptiveFieldPercSlider.val())
$inputSpaceSizeDisplay.html($inputSpaceSizeSlider.val())
$miniColumnCountDisplay.html($miniColumnCountSlider.val())
}
loadRandomPotentialPools()
updateSelectedMiniColumn(0)
updateDisplays()
$('input').on('input', () => {
updateSelectedMiniColumn(selectedMiniColumnIndex)
loadRandomPotentialPools()
updateDisplays()
})
});
</script>
</body>
</html>