Skip to content

Instantly share code, notes, and snippets.

@kersulis
kersulis / MatpowerCases.jl.cov
Created July 23, 2015 21:59
Code coverage file for MatpowerCases.jl. Something about this file may be causing this: https://github.com/IainNZ/Coverage.jl/issues/75
- module MatpowerCases
- using MAT
-
- export loadcase,casenames
-
- """ Return a Dict containing power system data
- in MATPOWER's format.
- Return this list of cases by running casenames().
- """
- function loadcase(caseName::ASCIIString; describe=true)
@kersulis
kersulis / surfer.jl
Last active August 29, 2015 14:27
Translate a portion of the web into a directed graph. Similar to surfer.m. https://www.math.washington.edu/~greenbau/Math_498/surfer.m
using Requests, Graphs, ProgressMeter
function surfer(root,n=100)
# Crawling mechanics: hyperlink regex and
# filter used for skipping certain links
rexp = r"https?://[^\"|<|>|;|'|)| |…]+"
# Focus on links that contribute to the graph by skipping
# all links that contain the following strings:
skip = [".gif";".jpg";".jpeg";".pdf";".css";".js";".asp";".mwc";".ram";
".cgi";"lmscadsi";"cybernet";"w3.org";"google";"yahoo";
@kersulis
kersulis / createY.jl
Last active November 12, 2015 21:23
Generate an admittance matrix from a set of real vectors.
"""
createY(f,t,x [,r,b]) -> Y
Create an admittance matrix for AC power flow.
All inputs are real. The output matrix is real if no line
resistances are provided (DC case), and complex otherwise.
* `f`,`t`: vectors encoding all lines (fi,ti)
* `x`: per-unit reactance xi for all lines
* `r`: per-unit resistance ri for all lines
* `b`: per-unit susceptance bi for all lines
@kersulis
kersulis / isf.jl
Last active November 12, 2015 21:25
Injection shift factors for DC power flow. Accommodates both single slack and distributed slack (droop response).
"""
Calculate injection shift factor matrix.
Each row corresponds to a line in the network.
Each column corresponds to a node.
Credit to Jonathon Martin for derivation.
Inputs:
* `Y`: full admittance matrix
* `lines`: vector of tuples; each tuple encodes a line as (i,j)
* `ref`: index of angle reference bus
@kersulis
kersulis / naive_lu.jl
Created December 7, 2015 22:39
Naive LU decomposition.
"""
Naive LU decomposition (no pivoting) from
[Bindel's CS6210 class notes](http://www.cs.cornell.edu/~bindel/class/cs6210-f12/notes/lec09.pdf).
Beware A[1,1] = 0...
"""
function mylu(A)
m,n = size(A)
for j = 1:n-1
A[j+1:n,j] = A[j+1:n,j]/A[j,j]
@kersulis
kersulis / pvec2mat.jl
Last active December 7, 2015 22:45
Convert a permutation vector to its corresponding matrix.
"""
Given a permutation vector, return the corresponding permutation matrix such that
`A[p,:] = P*A`.
See [Wikipedia](https://en.wikipedia.org/wiki/Permutation_matrix#Definition).
"""
function pvec2mat(p)
n = length(p)
P = zeros(n,n)
for i in 1:n
P[i,:] = ej(n,p[i])
@kersulis
kersulis / dbode.jl
Last active April 21, 2016 19:54
LTC model described in section 5.3.2 of http://deepblue.lib.umich.edu/handle/2027.42/113584
"""
LTC model used by [Baghsorkhi2015](http://deepblue.lib.umich.edu/handle/2027.42/113584)
(see section 5.3.2).
"""
type DBODE
"index of bus whose voltage is regulated"
bus::Int64
"index of line whose tap is influenced"
line::Int64
"voltage setpoint [pu]"
@kersulis
kersulis / procrustes.py
Last active September 28, 2016 16:11
Align shape data using SVD.
import numpy as np
def procrustes(shapes):
"""
Syntax: ashapes, sm = procrustes(shapes)
Inputs: shapes is a n x p x d array, where n is the number of
shapes, p is the number of points per shape, and d is
the dimension of each point (d=2 for xy plane, etc.).
Thus, shapes[0,5,:] contains the d coordinates for the
# Sonic Pi v2.10
use_bpm 130
notes = (ring :b3, :fs3, :g3, :c4)
notes_sliced = (ring :b3, :as3, :a3, :as3)
define :long do
4.times do
with_fx :bitcrusher, mix: 0.2 do
with_synth :hoover do
using Optim
import Optim.retract!
import Optim.project_tangent!
struct SphereSubspaceComplementIntersection <: Manifold
U::Matrix
proj::Matrix
end
function SphereSubspaceComplementIntersection(U)