-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add data and modify linear-and-polynomial-regression.ipynb
- Loading branch information
Showing
20 changed files
with
1,402 additions
and
2 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
open-machine-learning-jupyter-book/assets/html/polynomial-regression-demo/MathJax.js
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...ne-learning-jupyter-book/assets/html/polynomial-regression-demo/MathJax_Main-Regular.woff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No Content: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/fonts/HTML-CSS/TeX/woff/MathJax_Main-Regular.woff |
1 change: 1 addition & 0 deletions
1
...ine-learning-jupyter-book/assets/html/polynomial-regression-demo/MathJax_Math-Italic.woff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No Content: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/fonts/HTML-CSS/TeX/woff/MathJax_Math-Italic.woff |
1 change: 1 addition & 0 deletions
1
...e-learning-jupyter-book/assets/html/polynomial-regression-demo/MathJax_Size2-Regular.woff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No Content: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/fonts/HTML-CSS/TeX/woff/MathJax_Size2-Regular.woff |
1 change: 1 addition & 0 deletions
1
...-learning-jupyter-book/assets/html/polynomial-regression-demo/MathJax_Vector-Regular.woff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No Content: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/fonts/HTML-CSS/TeX/woff/MathJax_Vector-Regular.woff |
126 changes: 126 additions & 0 deletions
126
open-machine-learning-jupyter-book/assets/html/polynomial-regression-demo/basic.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
let screen_width = window.innerWidth, screen_height = window.innerHeight; | ||
let canvas_width, canvas_height; | ||
let fps = 24, paused = false; | ||
let mobile; | ||
|
||
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { | ||
mobile = true; | ||
} else { | ||
mobile = false; | ||
} | ||
|
||
let canvas = document.getElementById("canvas"); | ||
let context = canvas.getContext("2d"); | ||
|
||
let m_input = getElement("m-input"); | ||
let m_display = getElement("m-display"); | ||
let c_display = getElement("c-display"); | ||
|
||
let warn_display = getElement("warn-display"); | ||
if (mobile) { | ||
canvas_width = 0.8 * screen_width; | ||
} | ||
else { | ||
canvas_width = 0.4 * screen_width; | ||
} | ||
canvas_height = canvas_width; | ||
|
||
canvas.width = canvas_width; | ||
canvas.height = canvas_height; | ||
|
||
let animate = window.requestAnimationFrame | ||
|| window.webkitRequestAnimationFrame | ||
|| window.mozRequestAnimationFrame | ||
|| function (callback) { | ||
window.setTimeout(callback, 1000 / fps); | ||
}; | ||
|
||
function step() { | ||
if (!updated) { | ||
update(); | ||
render(); | ||
} | ||
animate(step); | ||
} | ||
|
||
window.onload = function () { | ||
initParams(); | ||
animate(step); | ||
} | ||
|
||
let click_x, click_y, pressed; | ||
|
||
if (mobile) { | ||
canvas.addEventListener("touchstart", function (e) { | ||
getTouchPosition(canvas, e); | ||
let touch = e.touches[0]; | ||
let mouseEvent = new MouseEvent("mousedown", { | ||
clientX: touch.clientX, | ||
clientY: touch.clientY | ||
}); | ||
canvas.dispatchEvent(mouseEvent); | ||
pressed = true; | ||
clicked(); | ||
}, false); | ||
|
||
canvas.addEventListener("touchmove", function (e) { | ||
getTouchPosition(canvas, e); | ||
let touch = e.touches[0]; | ||
let mouseEvent = new MouseEvent("mousemove", { | ||
clientX: touch.clientX, | ||
clientY: touch.clientY | ||
}); | ||
canvas.dispatchEvent(mouseEvent); | ||
moved(); | ||
}, false); | ||
|
||
canvas.addEventListener("touchend", function (e) { | ||
getTouchPosition(canvas, e); | ||
let touch = e.touches[0]; | ||
let mouseEvent = new MouseEvent("mouseup", { | ||
clientX: touch.clientX, | ||
clientY: touch.clientY | ||
}); | ||
canvas.dispatchEvent(mouseEvent); | ||
pressed = false; | ||
released(); | ||
}, false); | ||
} | ||
else { | ||
canvas.addEventListener("mousedown", function (e) { | ||
getMousePosition(canvas, e); | ||
pressed = true; | ||
clicked(); | ||
}); | ||
|
||
canvas.addEventListener("mousemove", function (e) { | ||
getMousePosition(canvas, e); | ||
moved(); | ||
}); | ||
|
||
canvas.addEventListener("mouseup", function (e) { | ||
getMousePosition(canvas, e); | ||
pressed = false; | ||
released(); | ||
}); | ||
|
||
window.addEventListener("keydown", function (e) { | ||
keyPressed(e.keyCode); | ||
}, false); | ||
|
||
window.addEventListener("keydown", function (e) { | ||
keyReleased(e.keyCode); | ||
}, false); | ||
} | ||
|
||
function getMousePosition(canvas, event) { | ||
rect = canvas.getBoundingClientRect(); | ||
click_x = event.clientX - rect.left; | ||
click_y = event.clientY - rect.top; | ||
} | ||
|
||
function getTouchPosition(canvas, event) { | ||
var rect = canvas.getBoundingClientRect(); | ||
click_x = event.touches[0].clientX - rect.left; | ||
click_y = event.touches[0].clientY - rect.top; | ||
} |
20 changes: 20 additions & 0 deletions
20
open-machine-learning-jupyter-book/assets/html/polynomial-regression-demo/global.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var g; | ||
|
||
// This works in non-strict mode | ||
g = (function() { | ||
return this; | ||
})(); | ||
|
||
try { | ||
// This works if eval is allowed (see CSP) | ||
g = g || new Function("return this")(); | ||
} catch (e) { | ||
// This works if the window reference is available | ||
if (typeof window === "object") g = window; | ||
} | ||
|
||
// g can still be undefined, but nothing to do about it... | ||
// We return undefined, instead of nothing here, so it's | ||
// easier to handle this case. if(!global) { ...} | ||
|
||
module.exports = g; |
84 changes: 84 additions & 0 deletions
84
open-machine-learning-jupyter-book/assets/html/polynomial-regression-demo/helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// DOM | ||
function getElement(id) { | ||
return document.getElementById(id); | ||
} | ||
|
||
// Math | ||
function getDistance(x1, y1, x2, y2) { | ||
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)); | ||
} | ||
|
||
function getMagn(x, y) { | ||
return Math.sqrt(x * x + y * y); | ||
} | ||
|
||
function toRadian(degrees) { | ||
return degrees * Math.PI / 180; | ||
} | ||
|
||
function toDegree(radian) { | ||
return radian * 180 / Math.PI; | ||
} | ||
|
||
// Random | ||
function randInt(lower, upper) { | ||
return Math.floor(lower + Math.random() * (upper - lower)); | ||
} | ||
|
||
function randomElement(array) { | ||
return array[Math.floor(Math.random() * array.length)] | ||
} | ||
|
||
function randomColor() { | ||
var letters = '0123456789ABCDEF'; | ||
var color = '#'; | ||
for (var i = 0; i < 6; i++) { | ||
color += letters[Math.floor(Math.random() * 16)]; | ||
} | ||
return color; | ||
} | ||
|
||
// Clean array generation | ||
function new1dArray(length) { | ||
let array = []; | ||
for(let i = 0; i < length; i++) { | ||
array.push(0); | ||
} | ||
return array; | ||
} | ||
|
||
function new2dArray(num_rows, num_cols) { | ||
let array_2d= []; | ||
for(let i = 0; i < num_rows; i++) { | ||
let array_1d = []; | ||
for(let j = 0; j < num_cols; j++) { | ||
array_1d.push(0); | ||
} | ||
array_2d.push(array_1d); | ||
} | ||
return array_2d; | ||
} | ||
|
||
// Array manipulation | ||
function removeElement(array, element) { | ||
return array.filter(function (dummy) { | ||
return dummy != element; | ||
}); | ||
} | ||
|
||
function shuffleKnuth(array) { | ||
let currentIndex = array.length, randomIndex; | ||
|
||
while (currentIndex != 0) { | ||
randomIndex = Math.floor(Math.random() * currentIndex); | ||
currentIndex--; | ||
|
||
[array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]]; | ||
} | ||
return array; | ||
} | ||
|
||
// rgb to hex | ||
function rgbToHex(r, g, b) { | ||
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); | ||
} |
19 changes: 19 additions & 0 deletions
19
open-machine-learning-jupyter-book/assets/html/polynomial-regression-demo/jax.js
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.