Skip to content

Commit

Permalink
add data and modify linear-and-polynomial-regression.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
WHQWHQWHQ committed Sep 11, 2023
1 parent 5664feb commit 4d47f63
Show file tree
Hide file tree
Showing 20 changed files with 1,402 additions and 2 deletions.

Large diffs are not rendered by default.

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
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
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
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
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;
}
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;
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);
}

Large diffs are not rendered by default.

Loading

0 comments on commit 4d47f63

Please sign in to comment.