Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / id3.R
Last active December 26, 2019 21:15
Decision Tree with ID3 in R, machine learning, information gain, entropy.
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 December 25, 2019 22:41
Information Gain and Entropy calculation for usage with building Decision Trees with machine learning, AI. Demo https://repl.it/repls/ParchedCompetentLegacysystem
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 June 24, 2020 17:33
Monty Hall Problem and probability, simulated in R, Bayes Nets, bayesian nets.
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 December 18, 2019 17:36
A summary of weak supervision and Snorkel.

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 January 11, 2020 21:02
Isolation 3x3 with game tree generation and AI Minimax with Alpha-Beta Pruning algorithm. https://codepen.io/primaryobjects/pen/QWWGgmR
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
.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 April 9, 2022 20:16
Example 3x3 grid of clickable cells for game board, cells change color with alternating clicks to simulate player 1 and player 2 (isolation).
$(function() {
ReactDOM.render(
<div>
<App></App>
</div>,
document.getElementById('root')
);
});
class Cell extends React.Component {
@primaryobjects
primaryobjects / selectLastCell.gs
Last active February 25, 2025 23:16
Automatically scroll to the last row in a Google Sheets spreadsheet upon opening the file. Google Docs. Google Drive.
//
// Automatically scroll to the last row.
//
function selectLastRow() {
const sheets = SpreadsheetApp.getActive().getSheets();
// Set focus to the last active row on the first two sheets.
for (var sheetIndex = 0; sheetIndex < 2; sheetIndex++) {
// Get the sheet.
var sheet = sheets[sheetIndex];
@primaryobjects
primaryobjects / ghc-2019.md
Last active January 7, 2020 09:14
GHC19: Quantum Computing @ Grace Hopper Conference 2019

Quantum Computing @ Grace Hopper Conference 2019 GHC19

I had recently attended the Grace Hopper 2019 conference in Orlando, and had the opportunity to speak with researchers from IBMQ and Qiskit about the current state of quantum computing. Although, I did not get a chance to obtain a ticket to IBMQ's Universal Studios event at The Wizarding World of Harry Potter (the line was extremely long!), I still wanted to share some of the topics surrounding the emerging tech of quantum computing.

I spoke with Cihan Kurter, Research Scientist at IBM Watson, after her presentation titled, "Near-Term Applications of Quantum Computers", and asked, how exactly does the mysterious IBMQ qubit work?

IBMQ Quantum Computer

How does a qubit work?

@primaryobjects
primaryobjects / sync.md
Created September 25, 2019 14:35
How to synchronize a forked GitHub repository with the upstream repository.

How to synchronize a forked GitHub repository with the upstream repository

To sync a forked github repo with the upstream repository, use the following steps:

  1. Go to your forked repository on github.com.
  2. Click the Compare button.
  3. Change the base fork to your repository.
  4. Click Compare across forks.
  5. Change the head fork to the upstream repository.