-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand.html
329 lines (262 loc) · 9.12 KB
/
rand.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Power Flow - Random Branch Flow</title>
<link rel="stylesheet" href="css/style.css" media="screen" type="text/css" />
<link rel="stylesheet" type="text/css" media="screen, print" href="css/slickmap.css" />
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</head>
<body>
<div id="title">Random Branch Flow</div>
<p>The linear shift factor will give you a sensitivity of power flow to random net injects. Assuming a subset of nodes has volatile net injects that are gaussian random variables, the linear shift factor for a fixed slack distribution hits the random vector and produces a translated and scaled gaussian. This gaussian of random power flows is scaled,translated, and truncated due to the piece-wise linear failure distribution of the line to find the probability of failure for each line flow.</p>
<p>There are two graphs, one which contains information about line failures given the piecewise linear function based off line flow. The second graph gives information about the random power flow on a branch. The top of each graph is a histogram of the samples to represent the approximate probability density function of each random variable. The middle is the points plotted on a 1 dimensional axis. The bottom of the graph is the cumulative distribution function for the given sample of points.</p>
<div id="tooltip" class="hidden">
<p><strong><span id="name">Important Label Heading</span></strong></p>
<p><span id="ex">100</span></p>
<p><span id="var">100</span></p>
<p><span id="min">100</span></p>
<p><span id="max">100</span></p>
<p><span id="dif">100</span></p>
<p><span id="neg">100</span></p>
</div>
<br/>
<div id="wrapper">
<div id="histgraph">
<center><div id="nodetitle">Line Failure Probability</div></center>
<div id="fail"></div>
<center>
<table>
<tr>
<td>
<br/>
<div id="controls">Mean:
<select id="selectmean">
<option value="1">0.5</option>
<option value="2">0.8</option>
<option value="3">0.9</option>
<option value="4" selected>1</option>
<option value="5">1.1</option>
<option value="6">1.2</option>
</select>
<br/>
Var:
<select id="selectvar">
<option value="1">0.001</option>
<option value="2">0.005</option>
<option value="3" selected>0.01</option>
<option value="4">0.025</option>
<option value="5">0.05</option>
<option value="6">0.1</option>
</select>
<br/>
<h3>Sample</h3>
<div id="samplecount">100</div><br/>
<u>Flow</u>
<div id="samplemean">100</div>
<div id="samplevar">100</div>
<div id="samplestdv">100</div><br/>
<u>Prob</u>
<div id="sampleprob">100</div>
</div>
</td>
<td> </td>
<td>
<center><div id="nodetitle">Power Flow</div></center>
<div id="flow"></div>
</td>
</tr>
</table>
</center>
</div>
</div>
</div>
<br/>
<p>
The 2 toggles for Mean and Var on the left middle of the graph display can be used to toggle through the 36 samples.
</p>
<br/>
<script type="text/javascript" src="js/d3.v3.js"></script>
<script type="text/javascript">
var flows = [];
var fails = [];
var selectionmean=4;
var selectionvar=3;
d3.select("#selectmean").attr("selectedIndex","-1");
d3.csv("data/fail43.csv",function(error, data) {
if (error) {
console.log(error);
}
else {
console.log(data);
for (var key in data) {
if(data[key].fail){
fails.push(data[key].fail);
flows.push(data[key].flow);
}
}
calcStat(flows);
generateVis("Line Failure Probability","#fail",fails,452,100);
generateVis("Power Flow","#flow",flows,327,75);
}
});
function generateVis(title,id,values,wt,ht) {
var numticks=27;
// A formatter for counts.
var formatCount = d3.format(",.0f");
var margin = {top: 10, right: 20, bottom: 30, left: 40},
width = wt - margin.left - margin.right,
height = ht - margin.top - margin.bottom;
var minx = d3.min(values);
var maxx = d3.max(values);;
var x = d3.scale.linear()
.domain([minx, maxx])
.range([0, width]);
// Generate a histogram using twenty uniformly-spaced bins.
var data = d3.layout.histogram()
.bins(x.ticks(numticks))
(values);
var y = d3.scale.linear()
.domain([0, d3.max(data, function(d) { return d.y; })])
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
d3.select("#histgraph")
.attr("width",width+margin.left+margin.right);
var svg = d3.select(id).append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", 3*height + margin.top + margin.bottom+157)
.style("border", "3px solid black")
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var bar = svg.selectAll(".bar")
.data(data)
.enter().append("g")
.attr("class", "bar")
.attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; });
bar.append("rect")
.attr("x", 1)
.attr("width", function(d) { return x(d.x+d.dx) -x(d.x) -1; })
.attr("height", function(d) { return height - y(d.y); });
bar.append("text")
.attr("dy", ".75em")
.attr("y", 6)
.attr("x", function(d){ return ( x(d.x+d.dx)-x(d.x) ) / 2; })
.attr("text-anchor", "middle")
.text(function(d) { return formatCount(d.y); });
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
console.log(minx,maxx);
var circles = svg.selectAll("circle")
.data(values)
.enter()
.append("circle");
circles
.attr("cx", function(d){ return x(d); })
.attr("cy", height+42)
.attr("r",5.72*width/800)
.style("opacity",100/values.length)
;
var htop=height+75;
var h2 = 2*ht;
var totalprob=0;
var numvals=values.length;
var probint=1/numvals;
var sorted=values.sort();
var y2 = d3.scale.linear()
.domain([0, 1])
.range([h2, 0]);
var yAxis = d3.svg.axis()
.scale(y2)
.orient("left");
svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(0,"+htop+")")
.call(yAxis);
var xAxis2 = d3.svg.axis()
.scale(x)
.orient("bottom");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0,"+(htop+h2)+")")
.call(xAxis2);
var pairs=[];
for( i in sorted){
pairs.push([probint*i,sorted[i]]);
if(id == "#fail") totalprob=totalprob+probint*sorted[i];
}
if(id == "#fail"){
console.log(totalprob);
d3.select("#sampleprob")
.text( " T Pr: "+ totalprob.toFixed(3));
}
var circles2 = svg.selectAll("square")
.data(pairs)
.enter()
.append("circle");
circles2
.attr("cx", function(d){ return x(d[1]); })
.attr("cy", function(d){ return htop+h2-y2(1-d[0]); } )
.attr("r",2.57*width/800)
.style("opacity",200/values.length)
;
selmean=d3.select("#selectmean").on("change",change);
selvar=d3.select("#selectvar").on("change",change);
function change(){
selectionmean=selmean.property("value");
selectionvar=selvar.property("value");
console.log(selectionmean,selectionvar);
var flows = [];
var fails = [];
d3.csv("data/fail"+selectionmean+""+selectionvar+".csv", function(data) {
for (var key in data) {
if(data[key].fail){
fails.push(data[key].fail);
flows.push(data[key].flow);
}
}
d3.selectAll("svg").remove();
calcStat(flows);
generateVis("Line Failure Probability","#fail",fails,452,100);
generateVis("Power Flow","#flow",flows,327,75);
});
}
}
function calcStat(values){
var sum = 0;
var mean = 0;
for (val in values) {
sum += parseFloat(values[val]); // must be a number
}
mean = sum/values.length;
var variance = 0;
for (var val in values) {
variance += (values[val]-mean)*(values[val]-mean);
}
variance = variance / (values.length-1)
var stdDeviation = 0;
stdDeviation = Math.sqrt(variance);
d3.select("#samplemean")
.text(" Mean: "+ mean.toFixed(2));
d3.select("#samplevar")
.text( " Var: " + variance.toFixed(4) );
d3.select("#samplestdv")
.text( " St Dv: "+ stdDeviation.toFixed(2));
d3.select("#samplecount")
.text( " Count: "+ values.length);
console.log(mean,variance,stdDeviation);
}
</script>
<!--#include file="footer.html" -->
</body>
</html>