{{ message }}

Instantly share code, notes, and snippets.

# Jiahao Chenjiahao

Last active Sep 24, 2020
Implementation of the stabilized Type-I Anderson acceleration (AA-I-S-m) algorithm of Zhang, O'Donoghue and Boyd (2018). This implementation solves g(x) = 0 as opposed to f(x) = x, which you obtain from g(x) = f(x) - x.
View aaism.jl
 using Dates: now using DataFrames import Base: *, push! mutable struct AAUpdate{Tu,Tv} # Matrix-free representation of the H matrix m::Int #:: Size of the AA subspace u::Vector{Tu} #:: The quantities s-Hỹ (note typo in paper) v::Vector{Tv} #:: The quantities (H'ŝ)/(ŝ'Hŷ) end
Last active Dec 4, 2019
Iterate over SparseMatrixCSC stored entries. Implements Julia's new iterator protocol (new as of v0.7) https://julialang.org/blog/2018/07/iterators-in-julia-0.7
View sparsematrixiterator.jl
 # Iterate over SparseMatrixCSC stored entries, ignoring stored zeros and # missing values. # # Implements Julia's new iterator protocol (new as of v0.7) # Ref: https://julialang.org/blog/2018/07/iterators-in-julia-0.7 # # Jiahao Chen 2019-12-03 # # MIT License available upon request #
Created Nov 22, 2019
Sparse logistic PCA in Julia - translated from @andland 's implementation https://github.com/andland/SparseLogisticPCA
View sparselogisticpca.jl
 using LinearAlgebra using StatsBase using StatsFuns using NaNMath "x->2x-1 in place" function twoxm1!(dat; val=0.0) @inbounds for (i,x) in enumerate(dat) dat[i] = ifelse(isnan(x), val, 2x-1) end
Created Nov 21, 2019
keybase.md
View gist:c662f104b1c9319058fe1e564ca54373
 ### Keybase proof I hereby claim: * I am jiahao on github. * I am jiahao (https://keybase.io/jiahao) on keybase. * I have a public key ASD8uXwFCTxC_HNYH0M6m_5niip3vql6gQ9nqYuUWnkiiQo To claim this, I am signing this object:
Last active Apr 28, 2019
Multinomial naive Bayes in Julia, allowing for generic numeric types for the conditional probabilities. When using rational numbers, you can calculate exact probabilities without roundoff error.
View naivebayes.jl
 struct MultinomialNaiveBayes{T, V<:AbstractVector} feature_ratios::V prior_ratio::T end """ fit(MultinomialNaiveBayes, [T,] features, labels, α = 1) -> MNB fits a `MultinomialNaiveBayes` classifier `MNB` using the `features` matrix and `labels` vector of `Bool`s.
Created Apr 27, 2019
Multinomial naive Bayes in Julia, allowing for generic numeric types for the conditional probabilities. (including rational numbers) that allow you to calculate exact probabilities.
View naivebayes.jl
 struct NaiveBayes{T, V<:AbstractVector, M<:AbstractMatrix} probabilities::M priors::V end train(::Type{NaiveBayes}, T::Type{R}, features, labels, α = 1) where R<:Real = train(NaiveBayes{T, Vector{T}, Matrix{T}}, features, labels, α) for (typ, op) in ((Rational, ://), (Real, :/)) @eval begin function train(::Type{NaiveBayes{T, S, R}},
Created Sep 25, 2018
View atiyah.jl
 # Compute the nth elementary symmetric function (elementary symmetric polynomial) of a a 1D iterable x # This is the THIRD esf function esf(n, x) summand = zero(eltype(x)) for j1 = 1:n, j2 = 1:j1-1, j3 = 1:j2-1 summand += x[j1]*x[j2]*x[j3] end return summand end
Created Jul 7, 2016
A simple interior point method implementation. Ref: http://www.maths.ed.ac.uk/~gondzio/reports/mfCS.pdf
View ipm.jl
 #Problem-specific thing dualitygap(x...) = nothing solveeq(x...) = rand() ############################ #Simple backtracking line search function linesearch(v, dv, α₀= 1.0, δ = 0.6) α = α₀ while v + α*dv ≤ 0
Created May 15, 2016