Skip to content

Commit de47da1

Browse files
linked octave to the experiment
1 parent f602b1e commit de47da1

File tree

11 files changed

+8697
-136
lines changed

11 files changed

+8697
-136
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

experiment-descriptor.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"unit-type": "lu",
33
"label": "",
44
"basedir": ".",
5+
"services": ["VLAB_SVC_OCTAVE_ANN"],
56
"units": [
67
{
78
"unit-type": "aim"
@@ -13,7 +14,7 @@
1314
"unit-type": "task",
1415
"content-type": "text"
1516
},
16-
17+
1718
{
1819
"target": "procedure.html",
1920
"source": "procedure.md",
@@ -28,7 +29,7 @@
2829
"unit-type": "task",
2930
"content-type": "simulation"
3031
},
31-
{
32+
{
3233
"target": "observations.html",
3334
"source": "observations.md",
3435
"label": "Observations",
@@ -42,7 +43,7 @@
4243
"unit-type": "task",
4344
"content-type": "text"
4445
},
45-
46+
4647
{
4748
"target": "references.html",
4849
"source": "references.md",

experiment/simulation/css/main.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
/* You CSS goes in here */
1+
#heading {
2+
text-align: center;
3+
font-family: 'Roboto Slab', serif;
4+
}

experiment/simulation/exp.css

Lines changed: 0 additions & 4 deletions
This file was deleted.

experiment/simulation/exp.html

Lines changed: 0 additions & 53 deletions
This file was deleted.

experiment/simulation/exp.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

experiment/simulation/index.html

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,66 @@
11
<!DOCTYPE html>
2-
<html>
2+
<html lang="en">
3+
34
<head>
4-
<!-- Add CSS at the head of HTML file -->
5-
<link rel="stylesheet" href="./css/main.css">
5+
<meta charset="UTF-8">
6+
<title>MLFNN</title>
7+
<link rel="stylesheet" href="./css/main.css">
68
</head>
9+
710
<body>
8-
<!-- Your code goes here-->
9-
<a href="Codes/exp4.html">Click here to perform the experiment</a>
10-
<!-- Add JS at the bottom of HTML file -->
11-
<iframe src="exp.html" width="1200" height="1000"></iframe>
12-
<script src="./js/main.js"></script>
11+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
12+
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" />
13+
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
14+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
15+
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
16+
crossorigin="anonymous"></script>
17+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
18+
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
19+
crossorigin="anonymous"></script>
20+
<div class="container-fluid p-4">
21+
<div class="row no-gutters">
22+
<div class="col">
23+
<div class="row no-gutters">
24+
<ol>
25+
<li>This is a 3 layer MLFFNN with one hidden layer, one input layer, and one output layer.</li>
26+
<li>Select the problem type and the number of nodes in the hidden layer, and click in train MLFFNN.</li>
27+
<li>Now click on test MLFFNN.</li>
28+
</ol>
29+
<img width="500" src="structure.png" alt="Structure of MLFNN">
30+
</div>
31+
<div class="row no-gutters">
32+
<form name="myform" method="post">
33+
<div class="form-group">
34+
<label>
35+
Problem type
36+
<select class="custom-select" id="numberOfBits" name="numberOfBits">
37+
</select>
38+
</label>
39+
40+
<label>
41+
Number of nodes in hidden layer
42+
<select class="custom-select" name="numberOfhiddenNodes" id="numberOfhiddenNodes">
43+
</select>
44+
</label>
45+
</div>
46+
47+
<div class="form-group">
48+
<button class="btn btn-primary" type="submit" name="trainMLFFNN" value="Train MLFFNN"
49+
onclick="setType('train');">Train MLFFNN</button>
50+
<button class="btn btn-primary" type="submit" name="testMLFFNN" value="Test MLFFNN"
51+
onclick="setType('test');">Test MLFFNN</button>
52+
</div>
53+
</form>
54+
</div>
55+
</div>
56+
<div class="col">
57+
<div class="image-container"></div>
58+
<div id="result"></div>
59+
</div>
60+
</div>
61+
</div>
62+
<script src="js/utils.js"></script>
63+
<script src="./js/main.js"></script>
1364
</body>
14-
</html>
65+
66+
</html>

experiment/simulation/js/main.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
//Your JavaScript goes in here
1+
window.EXP_NAME = "mlfnn";
2+
const numberOfBits = {
3+
2: "2-bit XOR",
4+
3: "3-bit XOR", 4: "4-bit XOR", "-1":
5+
"Linearly separable", "-2":
6+
"Linearly inseparable"
7+
},
8+
numberOfhiddenNodes = {2: "2", 3: "3", 4: "4", 6: "6", 8: "8", 10: "10", 15: "15", 25: "25"};
9+
10+
let isTrain = true;
11+
12+
window.extraArgs = function(){
13+
return {isTrain: isTrain ? "1" : "0"};
14+
};
15+
16+
/**
17+
* @param type {String}
18+
*/
19+
function setType(type) {
20+
isTrain = type === "train";
21+
}
22+
23+
window.appenditure = {
24+
"numberOfBits": numberOfBits,
25+
"numberOfhiddenNodes": numberOfhiddenNodes
26+
};

experiment/simulation/js/utils.js

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
1-
window.SERVER =
2-
"svc-test.vlabs.ac.in/octave-ann";
1+
// window.SERVER =
2+
// "svc-test.vlabs.ac.in/octave-ann";
33

44
function submitForm() {
5+
const SERVER = window.vlabsConfig.service["VLAB_SVC_OCTAVE_ANN"];
56
const $form = $('form[name="myform"]');
67

78
let args = $form.serializeArray().reduce((prev, cur) => {
89
return { ...prev, [cur.name]: cur.value };
910
}, {});
1011

1112
if (window.extraArgs) args = { ...args, ...window.extraArgs() };
13+
console.log(SERVER.url + "/exp-" + window.EXP_NAME),
14+
$.ajax({
15+
url: SERVER.url + "/exp-" + window.EXP_NAME,
16+
type: "POST",
17+
headers: {
18+
token: localStorage.getItem("token"),
19+
},
20+
dataType: "json",
21+
data: JSON.stringify(args),
22+
contentType: "application/json",
23+
success: function (data, status, xhr) {
24+
if (status === "success") {
25+
if (data.error) console.error(data.error);
26+
else {
27+
const $container = document.querySelector(".image-container");
28+
while ($container.firstElementChild)
29+
$container.removeChild($container.firstElementChild);
30+
const $result = $("#result");
31+
$result.html("");
1232

13-
$.ajax({
14-
url: SERVER + "/exp-" + window.EXP_NAME,
15-
type: "POST",
16-
headers: {
17-
token: localStorage.getItem("token"),
18-
},
19-
dataType: "json",
20-
data: JSON.stringify(args),
21-
contentType: "application/json",
22-
success: function (data, status, xhr) {
23-
if (status === "success") {
24-
if (data.error) console.error(data.error);
25-
else {
26-
const $container = document.querySelector(".image-container");
27-
while ($container.firstElementChild)
28-
$container.removeChild($container.firstElementChild);
29-
const $result = $("#result");
30-
$result.html("");
33+
if (data.images) {
34+
for (let i = 1; i <= data.images.length; i++) {
35+
const img = document.createElement("img");
36+
img.setAttribute("width", "600");
37+
img.classList.add("my-2");
38+
img.src = "data:image/png;base64," + data.images[i - 1];
39+
$container.appendChild(img);
40+
}
41+
}
3142

32-
if (data.images) {
33-
for (let i = 1; i <= data.images.length; i++) {
34-
const img = document.createElement("img");
35-
img.setAttribute("width", "600");
36-
img.classList.add("my-2");
37-
img.src = "data:image/png;base64," + data.images[i - 1];
38-
$container.appendChild(img);
43+
if (data.result) {
44+
$result.html(data.result);
45+
}
3946
}
4047
}
41-
42-
if (data.result) {
43-
$result.html(data.result);
44-
}
45-
}
46-
}
47-
},
48-
error: function (err) {
49-
console.log(err);
50-
},
51-
});
48+
},
49+
error: function (err) {
50+
console.log(err);
51+
},
52+
});
5253
}
5354

5455
function submit(e) {
@@ -71,10 +72,13 @@ function appendOptions(elm, list) {
7172
}
7273

7374
function onload() {
75+
const SERVER = window.vlabsConfig.service["VLAB_SVC_OCTAVE_ANN"];
76+
console.log(onload);
77+
console.log(SERVER.url + "/exp-" + window.EXP_NAME);
7478
if (document.readyState === "complete") {
7579
if (!localStorage.getItem("token")) {
7680
$.get(
77-
`${SERVER}/get_token`,
81+
`${SERVER.url}/get_token`,
7882
(success = function (data) {
7983
localStorage.setItem("token", data);
8084
})

0 commit comments

Comments
 (0)