-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseLine.js
More file actions
121 lines (110 loc) · 2.92 KB
/
baseLine.js
File metadata and controls
121 lines (110 loc) · 2.92 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
var pos4=0;var neg4=0;
function basePredict(){
if(rList.length!=0){
return rList[Math.floor(Math.random()*rList.length)];
}
else
return null;
}
function positiveUpdate4(){
counter++;pos4++;
if(counter==subG.length){
document.getElementById("current").value = document.getElementById("current").value+'-->'+rNode.order.toString();
error = "You aced it!";
document.getElementById("error").innerHTML = error;
$('#error_modal').modal('show');
return;
}
rNode.taught = time;
//works on rNode and cNode
time = time + 1;
if(rNode.depth == (cNode.depth+1))
dbfg+="d";
else if(rNode.depth == cNode.depth)
dbfg+="b";
else if(rNode.depth > cNode.depth)
dbfg+="f";
else
dbfg+="g";
rList.splice(rList.indexOf(rNode),1);
var arg={visited:[]};
var a = dfsLimited(rNode,arg,considerDepth);
for(var i=0;i<a.length;i++){
a[i].features.inTime = time;
a[i].features.parentTaught = mostRecent(a[i].parents); //last time when its parent was taught
var b=mostRecent(a[i].unlinkedParents);
if(b>a[i].features.parentTaught)
a[i].features.parentTaught = b;
if(rList.indexOf(a[i])<0)
rList.push(a[i]);
}
for(kk=0;kk<unvisited.length;kk++){
if(rList.indexOf(unvisited[kk])<0)
rList.push(unvisited[kk]);
}
unvisited=[];
rListFilter(rList);
cNode = rNode;
document.getElementById("current").value = document.getElementById("current").value+'-->'+cNode.order.toString();
}
function negativeUpdate4(){
neg4++;
var ind=rList.indexOf(rNode);
unvisited.push(rList[ind]);
rList.splice(ind,1);
}
function initRec4(){
rList = [];counter=1;
var begin = document.getElementById("startNode").value;
var node = search(linearGraph,begin);
document.getElementById("current").value = node.order;
if(node){
node.taught = 1;
node.features.inTime = 1;
cNode = node;
}
else
return null;
var sem = document.getElementById("sem_no").value;
if(node.depth == 0 && sem==1)
subG = linearGraph;
else
subG = subgraph(begin);
if(subG){
var arg = {visited:[]};
var a = dfsLimited(node,arg,considerDepth);
for(var i=0;i<a.length;i++){
rList.push(a[i]);
}
dList = depthList(subG);
if(dList[0][0].depth == 0){
for(var mm=0;mm<dList[0].length;mm++){
if(node!=dList[0][mm])
rList.push(dList[0][mm]);
}
}
rListFilter(rList);
rNode = basePredict();
document.getElementById("recc").value = rNode.order;
}
}
function train4(choice){
if(choice == 1){
positiveUpdate4();
}
else{
negativeUpdate4();
}
if(counter==subG.length)
return;
if(counter!=subG.length && rList.length==0){
//alert("No more recommendations.");
error = "You have not fulfilled pre-requisites for unread predicates.";
document.getElementById("error1").innerHTML = error;
$('#error_modal1').modal('show');
return;
}
var output=basePredict();
document.getElementById("recc").value=output.order;
rNode = output;
}