Skip to content

Instantly share code, notes, and snippets.

View danielhaim1's full-sized avatar

Daniel Haim danielhaim1

View GitHub Profile

ARIMA (Autoregressive Integrated Moving Average)

ARIMA (Autoregressive Integrated Moving Average) is a time series forecasting method that combines autoregression, differencing, and moving average techniques to model time series data. ARIMA models are commonly used in fields such as finance, economics, and engineering to make predictions about future values based on historical data.

@danielhaim1
danielhaim1 / README.md
Last active March 8, 2024 14:14
Advanced Sequence Predictive w/ Linear Regression

Advanced Sequence Prediction

This guide offers examples into predicting sequences with JS, Python, and C implementations, with refining prediction accuracy through advanced methodologies.

$$m = \frac{n\sum xy - \sum x\sum y}{n\sum x^2 - (\sum x)^2} b = \frac{\sum y - m\sum x}{n}$$
@danielhaim1
danielhaim1 / README.md
Last active March 31, 2023 09:04
Improved debounce function for JavaScript

Debounce Method

This function creates a debounced version of a function that delays invoking the original function until after a specified amount of time has elapsed since the last invocation of the debounced function.

const debouncedFunc = methodDebounce(func, wait, immediate, context);

Parameters

  • func (required): The function to debounce.
@danielhaim1
danielhaim1 / format_uk_phone_number.js
Last active March 25, 2023 11:17
This function formats UK phone numbers, adds missing national trunk codes, and returns an error message if invalid.
/**
format_uk_phone_number - A function to format UK phone numbers
This function takes in a phone number string and formats it according to UK phone number conventions.
@param {string} phone_number - The phone number to be formatted.
@returns {string} The formatted UK phone number string, or "Invalid UK phone number" if the input is invalid.
**/
function format_uk_phone_number(phone_number) {
@danielhaim1
danielhaim1 / DecisionTreeNode.js
Last active March 29, 2023 09:18
Decision Tree Classification in JavaScript
class DecisionTreeNode {
constructor(featureIndex, threshold, leftNode, rightNode, prediction) {
this.featureIndex = featureIndex;
this.threshold = threshold;
this.leftNode = leftNode;
this.rightNode = rightNode;
this.prediction = prediction;
}
isLeaf() {
@danielhaim1
danielhaim1 / holtWinters.js
Last active March 29, 2023 09:20
Holt-Winters Forecasting Algorithm
function holtWinters(alpha, beta, gamma, period, data) {
let seasonals = {};
let r = [];
let initialSeasonals = [];
let detrended = [];
let forecast = [];
let dataPoints = data.length;
let avgSmooth = [];
let trendSmooth = [];
let seasonalSmooth = [];
@danielhaim1
danielhaim1 / inversePermutation.js
Last active March 29, 2023 09:17
Inverse Permutation Algorithm
function inversePermutation(permutation) {
const n = permutation.length;
const result = Array(n);
for (let i = 0; i < n; i++) {
result[permutation[i] - 1] = i + 1;
}
return result;
}
// const permutation = [3, 1, 4, 5, 2];
@danielhaim1
danielhaim1 / sattolosAlgorithm.js
Created March 19, 2023 22:28
Sattolo's Algorithm
function sattolosAlgorithm(array) {
const len = array.length;
for (let i = len - 1; i > 0; i--) {
const j = Math.floor(Math.random() * i);
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
@danielhaim1
danielhaim1 / knuthShuffle.js
Created March 19, 2023 22:27
Knuth Shuffle algorithm
function knuthShuffle(arr) {
let currentIndex = arr.length;
let temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
temporaryValue = arr[currentIndex];
arr[currentIndex] = arr[randomIndex];
@danielhaim1
danielhaim1 / getImageFormat.js
Last active November 15, 2022 13:15
Return the format of an image.
/**
* Return the natural dimensions of an image.
* @string img - The image to get the dimensions of.
* @return {object} - The natural width of the image.
* @return {null} - If the image has no natural dimensions.
*/
function getNaturalDimensions({ naturalWidth, naturalHeight }) {
// get the image format from the src attribute.
let width = naturalWidth;