Frames

Untitled

0
1//key : count

2var map = new Map();
3
4function cycle(){
5
6 // the current cycle's data
7 // full analysis only for 3-grams
8 // (data - 1) for 2-grams
9 // (data - 2) for 1-grams
10 for (var i = 0; i < random.length-2; i++) {
11 analysis(map, random[i]);
12 analysis(map, random[i]+random[i+1]);
13 analysis(map, random[i]+random[i+1]+random[i+2]);
14 }
15 // analysis of remaining data
16 analysis(map, random[i]);
17 analysis(map, random[i+1]);
18 analysis(map, random[i]+random[i+1]);
19
20 for(let entry of map) {
21 console.log(entry);
22 }
23
24}
25
26function analysis(map, ngram){
27 let bitCount = +0;
28 //if map already has key
29 if (map.has(ngram)) {
30 bitCount = map.get(ngram);
31 bitCount++;
32 } else {
33 bitCount = 1;
34 }
35// console.log(random[i]+ ' = ' + bitCount);
36 map.set(ngram, bitCount);
37}
38
39
40function result() {
41
42 // script.js
43 var count = NUM*CYCLES;
44
45 document.getElementById("0").innerHTML = 'Number of 0s = ' + map.get('0') + ', % = ' + map.get('0')/(count)*100;
46 document.getElementById("1").innerHTML = 'Number of 1s = ' + map.get('1') + ', % = ' + map.get('1')/(count)*100;
47 document.getElementById("00").innerHTML = 'Number of 00s = ' + map.get('00') + ', % = ' + map.get('00')/(count - 1)*100;
48 document.getElementById("01").innerHTML = 'Number of 01s = ' + map.get('01') + ', % = ' + map.get('01')/(count - 1)*100;
49 document.getElementById("10").innerHTML = 'Number of 10s = ' + map.get('10') + ', % = ' + map.get('10')/(count - 1)*100;
50 document.getElementById("11").innerHTML = 'Number of 11s = ' + map.get('11') + ', % = ' + map.get('11')/(count - 1)*100;
51 document.getElementById("000").innerHTML = 'Number of 000s = ' + map.get('000') + ', % = ' + map.get('000')/(count - 2)*100;
52 document.getElementById("001").innerHTML = 'Number of 001s = ' + map.get('001') + ', % = ' + map.get('001')/(count - 2)*100;
53 document.getElementById("010").innerHTML = 'Number of 010s = ' + map.get('010') + ', % = ' + map.get('010')/(count - 2)*100;
54 document.getElementById("011").innerHTML = 'Number of 011s = ' + map.get('011') + ', % = ' + map.get('011')/(count - 2)*100;
55 document.getElementById("100").innerHTML = 'Number of 100s = ' + map.get('100') + ', % = ' + map.get('100')/(count - 2)*100;
56 document.getElementById("101").innerHTML = 'Number of 101s = ' + map.get('101') + ', % = ' + map.get('101')/(count - 2)*100;
57 document.getElementById("110").innerHTML = 'Number of 110s = ' + map.get('110') + ', % = ' + map.get('110')/(count - 2)*100;
58 document.getElementById("111").innerHTML = 'Number of 111s = ' + map.get('111') + ', % = ' + map.get('111')/(count - 2)*100;
59}
60