Skip to content

Instantly share code, notes, and snippets.

View thomasnield's full-sized avatar

Thomas Nield thomasnield

  • Frisco, Texas (United States)
View GitHub Profile
@thomasnield
thomasnield / squared_regression.csv
Last active April 14, 2019 22:43
Squared Regression Data (randomly generated around 4x^2 + 50)
13.68 781.65
12.49 722.25
13.04 721.65
18.26 1367.97
15.67 988.95
17.96 1267.92
6.92 295.66
6.96 355.72
16.93 1210.87
17.64 1360.34
@thomasnield
thomasnield / monty_hall.py
Created April 18, 2019 18:56
Monty Hall Python
from random import randint
def random_door():
return randint(1, 3)
trial_count = 10000
stay_wins = 0
@thomasnield
thomasnield / MultiDateRangeSelector.kt
Last active May 13, 2019 19:45
Mutli Date Range Selector JavaFX Control
import javafx.application.Application
import javafx.beans.property.SimpleStringProperty
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.scene.control.TextField
import tornadofx.*
import java.time.LocalDate
import java.time.format.DateTimeFormatter
@thomasnield
thomasnield / simple_logistic_regression.kt
Last active August 12, 2021 06:09
simple_logistic_regression
import org.apache.commons.math3.distribution.NormalDistribution
import org.nield.kotlinstatistics.randomFirst
import kotlin.math.exp
import kotlin.math.ln
// See graph
// https://www.desmos.com/calculator/6cb10atg3l
// Helpful Resources:
@thomasnield
thomasnield / k_means_from_scratch.kt
Last active August 12, 2021 06:09
K-Means Clustering from Scratch
import org.apache.commons.math3.distribution.NormalDistribution
import kotlin.math.pow
// Desmos graph: https://www.desmos.com/calculator/pb4ewmqdvy
val points = sequenceOf(
1.4,1.3,
3.1,2.3,
3.6,2.4,
1.7,1.5,
@thomasnield
thomasnield / kmath_linear_regression_hc.kt
Last active June 6, 2019 17:36
KMath Linear Regression
import org.ojalgo.random.Normal
import scientifik.kmath.linear.MatrixContext
import scientifik.kmath.linear.VirtualMatrix
import scientifik.kmath.structures.Matrix
import java.net.URL
import kotlin.math.pow
fun main() {
val points = URL("https://tinyurl.com/y58sesrr")
@thomasnield
thomasnield / normal_distribution_fitting_mle.kt
Last active June 28, 2019 21:18
normal_distribution_fitting_mle.kt
import java.util.concurrent.ThreadLocalRandom
import kotlin.math.exp
import kotlin.math.ln
import kotlin.math.pow
fun main() {
val observations = doubleArrayOf(
1.0,
@thomasnield
thomasnield / simple_language_interpreter.kt
Last active July 30, 2019 19:43
Simple Language Interpreter
fun main() {
val testCode = """
x = 3
print(x)
"""
val program = compile(testCode)
@thomasnield
thomasnield / plotly_3d_scatterplot.py
Created October 3, 2019 15:11
Plotly 3D scatterplot
import plotly.express as px
iris = px.data.iris()
fig = px.scatter_3d(iris, x='sepal_length', y='sepal_width', z='petal_width',
color='petal_length', symbol='species')
fig.show()
@thomasnield
thomasnield / purity_vs_impurity_split.py
Last active October 17, 2019 18:09
purity_vs_impurity_split.py
from typing import List
class Point:
def __init__(self, x: int, y: bool):
self.x = x
self.y = y
points: List[Point] = [