forked from syclik/stan-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear_model.html
More file actions
139 lines (115 loc) · 3.45 KB
/
linear_model.html
File metadata and controls
139 lines (115 loc) · 3.45 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
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<script type="text/javascript" src="d3/d3.min.js"></script>
<style>
.chart {
}
.main text {
font: 10px sans-serif;
}
.axis line, .axis path {
shape-rendering: crispEdges;
stroke: black;
fill: none;
}
circle {
fill: steelblue;
}
</style>
</head>
<body>
<div class='content'>
<!-- /the chart goes here -->
</div>
<script>
//sample();
var allSamples;
var size = 400;
var chart = d3.select("body").append("svg")
.attr("width", size)
.attr("height", size)
.style("border", "1px solid black");
var x = d3.scale.linear()
.domain([-1,1])
.range([0,size]);
var y = d3.scale.linear()
.domain([-1,1])
.range([size,0]);
var dat;
var points = d3.range(0);
var dragged = null,
selected = points[0];
chart.on("mousedown",mousemove);
d3.csv("models/clean_samples.csv", function(error,data) {
data.forEach(function(d) {
d.lp__ = parseFloat(d.lp__);
d.treedepth__ = parseFloat(d.treedepth__);
d.stepsize__ = parseFloat(d.stepsize__);
d.alpha = parseFloat(d.alpha);
d.beta = parseFloat(d.beta);
d.sigma_noise = parseFloat(d.sigma_noise);
});
allSamples = data;
dat = d3.range(1).map(next);
setInterval(function() {
dat.shift();
if (index < allSamples.length) {
dat.push(next());
}
redraw();
}, 10);
});
var index = 0;
function next() {
return allSamples[index++];
}
function redraw() {
var lines = chart.selectAll("line")
.data(dat);
lines.enter().append("line");
var lineAttributes
= lines
.attr("x1", x(-1))
.attr("y1", function(d) {return y(d.alpha - d.beta); })
.attr("x2", x(1))
.attr("y2", function(d) {return y(d.alpha + d.beta); })
.style("stroke-width", 1)
.style("stroke", "blue")
.style("opacity", function(d,i) {return ((i+1) / dat.length)});
lines.exit().remove();
var circle = chart.selectAll("circle")
.data(points, function(d) { return d; });
circle.enter().append("circle")
.attr("r", 1e-6)
.on("mousedown", function(d) { selected = dragged = d; redraw(); })
.transition()
.duration(750)
.ease("elastic")
.attr("r", 4);
circle
.classed("selected", function(d) { return d === selected; })
.attr("cx", function(d) { return x(d[0]); })
.attr("cy", function(d) { return y(d[1]); });
circle.exit().remove();
if (d3.event) {
d3.event.preventDefault();
d3.event.stopPropagation();
}
}
function mousemove(d, i) {
var m = d3.mouse(this);
points.push([x.invert(m[0]), y.invert(m[1])]);
console.log(points);
sample();
}
function sample() {
console.log("should resample here");
var oShell = new ActiveXObject("terminal");
var commandtoRun = "./models/linear_model --data=linear_model.data.R";
oShell.ShellExecute(commandtoRun,"","","open","1");
}
</script>
</body>
</html>