This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Authors: Mathieu Blondel, Vlad Niculae | |
# License: BSD 3 clause | |
import numpy as np | |
def _gen_pairs(gen, max_iter, max_inner, random_state, verbose): | |
rng = np.random.RandomState(random_state) | |
# if tuple, interpret as randn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Latex engine test" | |
author: "William May" | |
date: "December 1, 2019" | |
output: pdf_document | |
--- | |
```{r setup, include=FALSE} | |
library(knitr) | |
opts_chunk$set(echo = TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
functions { | |
real matrix_f_lpdf(matrix cov, real nu, real delta){ | |
int k = cols(cov); | |
return(lmgamma(k, (nu + delta + k - 1)/2) - (lmgamma(k, nu/2) + lmgamma(k, (delta + k - 1)/2) + log(1)) + log_determinant(cov)*((nu -k - 1)/2) - (nu + delta + k - 1)/2 * log_determinant(cov + diag_matrix(rep_vector(1, k)))); | |
} | |
real matrix_f_fast_lpdf(matrix cov, real nu, real delta){ | |
int k = cols(cov); | |
real log_det_cov = 2*sum(log(diagonal(cholesky_decompose(cov)))); | |
real I_Sig_log_det = 2*sum(log(diagonal(cholesky_decompose(diag_matrix(rep_vector(1,k)) + cov)))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data { | |
int N; // number of individuals | |
int T; // number of time periods | |
matrix[N, T] Y; // outcome matrix; missing entries set to -9.0 | |
int K; // rank of matrix | |
} | |
parameters { | |
matrix[N, K] M; // individual loadings | |
matrix[T, K] U; // time factors | |
real<lower = 0> sigma; // error scale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rstanarm); library(tidyverse) | |
options(mc.cores = parallel::detectCores()) | |
set.seed(42) | |
data("radon") | |
head(treatment_sample) | |
# Some levels have no variance in the outcomes, making likelihood estimates impossible | |
# Adding a tiny bit of noise fixes the problem | |
radon$log_uranium <- rnorm(nrow(radon), radon$log_uranium, 0.05) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import spacy | |
nlp = spacy.load("en_core_web_lg") | |
with open("scraped.json", "r") as f: | |
news = json.load(f) | |
news = [i['body'] for i in news] | |
processed_docs = list(nlp.pipe(news)) | |
verb_list = ["launch", "begin", "initiate", "start"] | |
dobj_list = ["attack", "offensive", "operation", "assault"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Template for running and plotting a very simple agent-based model in R | |
# Professor Bear Braumoeller, Department of Political Science, Ohio State | |
# This code creates a 20x20 grid of 0s and 1s, which represent values of some | |
# variable held by agents in those cells. It then chooses two adjacent cells, | |
# the first at random and the second at random from among the first cell's | |
# neighbors, and applies a simple rule -- the first cell takes on the value | |
# of the second. It iterates this cell selection and rule application 1,000 | |
# times, displays the result, and tracks the fraction of 1s in the matrix | |
# over time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# functions for plotting garden of forking data plots | |
library(rethinking) | |
polar2screen <- function( dist, origin, theta ) { | |
## takes dist, angle and origin and returns x and y of destination point | |
vx <- cos(theta) * dist; | |
vy <- sin(theta) * dist; | |
c( origin[1]+vx , origin[2]+vy ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simulation script for factor analysis ala Leung & Drton (2016) ---------- | |
library(rstan) | |
library(bayesplot) | |
m <- 5 # dimension of observed data (e.g., # traits) | |
k <- 2 # number of latent factors | |
n <- 100 # number of sample units (e.g., # species) | |
# residual variance matrix (is diagonal) | |
Omega <- diag(.3 + abs(rnorm(m, sd = .3))) |