Skip to content

Instantly share code, notes, and snippets.

View lendle's full-sized avatar

Sam Lendle lendle

  • UC Berkeley
  • Berkeley, CA
View GitHub Profile
@lendle
lendle / KernSmooth_example.ipynb
Last active July 4, 2016 13:57
KernSmooth.jl example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lendle
lendle / PAM in julia.ipynb
Created February 5, 2014 09:29
Example of the `pam` clustering algorithm in julia. http://nbviewer.ipython.org/gist/lendle/8820029
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lendle
lendle / projectsimplex.jl
Last active March 28, 2016 19:56
Project a vector of reals onto a simplex in julia
# Figure 1 algorithm from http://icml2008.cs.helsinki.fi/papers/361.pdf
# project a real vector onto a simplex in nlogn time
# v is the vector to project
# z is the value to which the projected vector must sum, one by default
function projectsimplex{T <: Real}(v::Array{T, 1}, z::T=one(T))
n=length(v)
µ = sort(v, rev=true)
#finding ρ could be improved to avoid so much temp memory allocation
ρ = maximum((1:n)[µ - (cumsum(µ) .- z) ./ (1:n) .> zero(T)])
θ = (sum(µ[1:ρ]) - z)/ρ