Skip to content

Instantly share code, notes, and snippets.

Kory Becker primaryobjects

Block or report user

Report or block primaryobjects

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@primaryobjects
primaryobjects / linear-regression.R
Created Jan 31, 2020
Linear regression with gradient descent in R.
View linear-regression.R
#
# An example of calculating linear regression with gradient descent for a single variable.
# Kory Becker
# 1/31/2020
#
# Calculate linear regression with gradient descent.
linearRegression <- function(x, y, alpha, iterations) {
# initialize coefficients
theta <- matrix(c(0,0), nrow=2)
@primaryobjects
primaryobjects / udacity-submit.md
Last active Jan 20, 2020
How to submit a project to Udacity in Windows with a Google or Facebook login.
View udacity-submit.md

How to submit a project to Udacity in Windows

When submitting a project to Udacity with a login on Google or Facebook, you will need to copy a jwt file to your PC in order for the login to work. Here's how.

  1. Save the link https://project-assistant.udacity.com/auth_tokens/new to C:\Users\YOUR_USER_NAME\AppData\Roaming\udacity-pa
  2. Open a CMD in Windows.
  3. Navigate to your project source code folder:
    cd c:\projects\aind-sudoku
@primaryobjects
primaryobjects / 1-sudoku-box.py
Last active Jan 19, 2020
Sudoku puzzle convert string of values into a dictionary of key/value pairs. Udacity Artificial Intelligence nanodegree project 1, quiz 1: Encoding the Board.
View 1-sudoku-box.py
from utils import *
# `grid` is defined in the test code scope as the following:
# (note: changing the value here will _not_ change the test code)
# grid = '..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..'
def grid_values(grid):
"""Convert grid string into {<box>: <value>} dict with '.' value for empties.
Args:
@primaryobjects
primaryobjects / id3.R
Last active Dec 26, 2019
Decision Tree with ID3 in R, machine learning, information gain, entropy.
View id3.R
library(data.tree)
entropy <- function(q) {
# Calculate the entropy for a value.
-1 * (q * log2(q) + (1 - q) * log2(1 - q))
}
positiveRatio <- function(data, outcomeCol = ncol(data)) {
# Calculate the ratio of T by the total samples.
positiveCount <- length(which(data[, outcomeCol] == T))
@primaryobjects
primaryobjects / informationGain.R
Last active Dec 25, 2019
Information Gain and Entropy calculation for usage with building Decision Trees with machine learning, AI. Demo https://repl.it/repls/ParchedCompetentLegacysystem
View informationGain.R
entropy <- function(q) {
# Calculate the entropy for a value.
-1 * (q * log2(q) + (1 - q) * log2(1 - q))
}
positiveRatio <- function(data) {
# Calculate the ratio of positives by the total measurements.
sum(data$positives) / (sum(data$positives) + sum(data$negatives))
}
@primaryobjects
primaryobjects / montyHall.R
Last active Jan 26, 2020
Monty Hall Problem and probability, simulated in R, Bayes Nets, bayesian nets.
View montyHall.R
library(ggplot2)
montyHall <- function(maxDoors = 3, switch = T, tries = 10) {
plays <- data.frame()
for (i in 1:tries) {
# Create the doors.
doors <- 1:maxDoors
# Choose a winning door.
@primaryobjects
primaryobjects / weak-supervision.md
Created Dec 18, 2019
A summary of weak supervision and Snorkel.
View weak-supervision.md

Weak Supervision

Programmatically label millions of data points. See also here.

How does it work?

Ask domain experts for weak supervision signals (heuristics) to use as labeling functions, which can be programatically implemented for automatic labeling.

Examples of labeling functions: regular expressions, dependency trees, knowledge bases, crowdsourcing.

@primaryobjects
primaryobjects / includes.txt
Last active Jan 11, 2020
Isolation 3x3 with game tree generation and AI Minimax with Alpha-Beta Pruning algorithm. https://codepen.io/primaryobjects/pen/QWWGgmR
View includes.txt
Styles
https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css
https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css
Libraries
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js
https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js
https://cdnjs.cloudflare.com/ajax/libs/react/16.10.2/umd/react.production.min.js
View index.css
.cell {
width: 50px;
height: 50px;
border: 1px solid black;
transition: background-color 0.25s;
}
.player {
font-size: 40px;
position: absolute;
@primaryobjects
primaryobjects / app.js
Last active Oct 18, 2019
Example 3x3 grid of clickable cells for game board, cells change color with alternating clicks to simulate player 1 and player 2 (isolation).
View app.js
$(function() {
ReactDOM.render(
<div>
<App></App>
</div>,
document.getElementById('root')
);
});
class Cell extends React.Component {
You can’t perform that action at this time.