forked from htm-community/cell-viz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-sdr-1.html
88 lines (75 loc) · 2.67 KB
/
example-sdr-1.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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>2D SDR Drawing</title>
<style>
body { margin: 10px; }
svg {
border: solid 1px orange;
}
</style>
</head>
<body>
<svg id="receptiveFieldDemo"></svg>
<br/>
<input type="range" min="0" max="100" value="90" id="receptiveFieldPercSlider" />
receptive field: <span class="receptiveFieldPercDisplay"></span>%
<br/>
<input type="range" min="0" max="100" value="50" id="connectionThresholdSlider" />
connection threshold: <span class="connectionThresholdDisplay"></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.6.min.js"></script>
<script>
$(function() {
function getRandomReceptiveField(receptiveFieldPerc, dimensions) {
let n = dimensions
let w = parseInt(receptiveFieldPerc * n)
let potentialPool = SdrUtils.getRandom(n, w)
return potentialPool
}
let inputSpace = 1000
let $connectionThresholdSlider = $('#connectionThresholdSlider')
let $connectionThresholdDisplays = $('.connectionThresholdDisplay')
let $receptiveFieldPercSlider = $('#receptiveFieldPercSlider')
let $receptiveFieldPercDisplay = $('.receptiveFieldPercDisplay')
let drawOptions = {
width: 560,
height: 560,
gradientFill: true,
}
let pool = getRandomReceptiveField(.5, inputSpace)
let perms
function updatePerms() {
perms = d3.range(inputSpace)
.map(d3.randomBates(20))
.map((p, i) => {
if (pool[i] === 0) return null
return p
})
}
function renderDisplay() {
let threshold = parseInt($connectionThresholdSlider.val()) / 100
$connectionThresholdDisplays.html(threshold)
$receptiveFieldPercDisplay.html($receptiveFieldPercSlider.val())
let rcDrawing = new SdrDrawing(perms, 'receptiveFieldDemo')
drawOptions.threshold = parseInt($connectionThresholdSlider.val()) / 100
rcDrawing.draw(drawOptions)
}
updatePerms()
renderDisplay()
$receptiveFieldPercSlider.on('input', () => {
let targetDensity = parseInt($receptiveFieldPercSlider.val()) / 100
pool = SdrUtils.adjustTo(pool, targetDensity)
updatePerms()
renderDisplay()
})
$connectionThresholdSlider.on('input', () => {
updatePerms()
renderDisplay()
})
});
</script>
</body>
</html>