Skip to content

Instantly share code, notes, and snippets.

@ayota
ayota / audio_fun.py
Last active September 21, 2016 00:47
import numpy as np
import scikits.audiolab
import scipy
f = 440
fs = 11025 #22050
T = 0.1
x = scipy.cos((2*scipy.pi*f/fs)*scipy.arange(fs*T))
for y in range(0,1000):
2.
```{r}
#make matrices
set.seed(693)
A <- matrix(ceiling(runif(4, min=100, max=999)), nrow=2, ncol=2)
B <- matrix(ceiling(runif(4, min=-9, max=9)), nrow=2, ncol=2)
C <- matrix(ceiling(-runif(4, min=100, max=999)), nrow=2, ncol=2)
Z <- matrix(0, nrow=2, ncol=2)
M <- rbind(cbind(Z,Z,A), cbind(Z,B,Z), cbind(C,Z,Z))
2.
```{r}
#make matrices
set.seed(693)
A <- matrix(ceiling(runif(4, min=100, max=999)), nrow=2, ncol=2)
B <- matrix(ceiling(runif(4, min=-9, max=9)), nrow=2, ncol=2)
C <- matrix(ceiling(-runif(4, min=100, max=999)), nrow=2, ncol=2)
Z <- matrix(0, nrow=2, ncol=2)
M <- rbind(cbind(Z,Z,A), cbind(Z,B,Z), cbind(C,Z,Z))
2.
```{r}
#make matrices
set.seed(693)
A <- matrix(ceiling(runif(4, min=100, max=999)), nrow=2, ncol=2)
B <- matrix(ceiling(runif(4, min=-9, max=9)), nrow=2, ncol=2)
C <- matrix(ceiling(-runif(4, min=100, max=999)), nrow=2, ncol=2)
Z <- matrix(0, nrow=2, ncol=2)
M <- rbind(cbind(Z,Z,A), cbind(Z,B,Z), cbind(C,Z,Z))
This file has been truncated, but you can view the full file.
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.css'>
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'></script>
<script src='//d3js.org/d3.v3.min.js' type='text/javascript'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.js' type='text/javascript'></script>
<script src='//nvd3.org/assets/lib/fisheye.js' type='text/javascript'></script>
@ayota
ayota / index.html
Created April 13, 2015 04:26
Scatterplot
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href='//tenxer.github.io/xcharts/css/master.css'>
<script src='//d3js.org/d3.v2.min.js' type='text/javascript'></script>
<script src='//tenxer.github.io/xcharts/js/xcharts.min.js' type='text/javascript'></script>
<style>
power2 <- function(B1 = B1, B2 = B2, v1.old = u1, v2.old = u2, p = .15) {
N <- length(v1.old)
B1.p <- matrix(0, ncol=5242, nrow=5242)
B1.p <- sapply(1:5242, function(x) (1-p)/sum(B1[x,]) * B1[x,])
B2.p <- (p/N) * B2
v1.new <- B1.p %*% v1.old + B2.p %*% v1.old
v1.new <- v1.new / norm(v1.new)
v2.new <- B1.p %*% v2.old + B2.p %*% v2.old
@ayota
ayota / gist:0bfa8ebe18c78249c3e2
Created March 29, 2015 18:25
new power function
power <- function(B1 = B1, B2 = B2, v.old = v, tol = 10^-10, p = .15) {
N <- length(v)
B.p <- matrix(0, ncol=5242, nrow=5242)
B.p <- sapply(1:5242, function(x) (1-p)/sum(B1[x,]) * B1[x,])
v.old <- v
v.new <- B.p %*% v.old + (p/N) * B2 %*% v.old
v.new <- v.new / norm(v.new)
i <- 0
Elaine Ayo
Math 504 / Homework 10
March 29, 2015
```{r echo=FALSE, message=FALSE}
library(MASS)
library(Matrix)
library(ggplot2)
data <- read.table("~/Dropbox/numericalmethods/nonlinear.txt", header=TRUE, quote="\"")
#param order: d, r
fxn.4 <- list(
f.x = function(params, data) return( sum((data$y - params[1]*exp(-params[2] * data$x) )^2) ),
grad = function(params, data, f.x, h) {
d.d <- (f.x(params = c(params[1] + h, params[2]), data) - f.x(params, data)) / h
d.r <- (f.x(params = c(params[1], params[2] + h), data) - f.x(params, data)) / h
return(c(d.d,d.r))
},