Skip to content

Instantly share code, notes, and snippets.

View caseykneale's full-sized avatar
😴

Casey Kneale caseykneale

😴
  • Massachusetts, USA
View GitHub Profile
@caseykneale
caseykneale / gist:fb5503d95b29c1e3bf167a192bf17420
Created October 30, 2021 19:01
RMSRosas termux julia install instructions 2021
rmsrosa
10/27/2021
I essentially followed the instructions here, which is a pretty recent post: https://www.linkedin.com/pulse/running-julia-my-android-phone-paresh-mathur, except I didn't install Ubuntu, but Fedora, for which I used https://github.com/nmilosev/termux-fedora.
1. Install Termux on your Android phone from the F-Droid (don't use the one from the App Store, it is outdated and not maintained). See https://termux.com/
2. Update Termux just in case: pkg update && pkg upgrade
3. Install a linux distro. I used Fedora, but can be anything:
function NNLS_CD(X, Y; ϵ = 1e-9, max_iters = 300)
rows,vars = size(X)
XTX,XTY = transpose(X) * X, transpose(X) * Y
x = zeros(vars)
μ = -XTY
Hxf = similar(XTY)
@inbounds for iter in 1:max_iters
Hxf = XTX * x - XTY
all(>=(-ϵ), Hxf) && break
for v in 1:vars
# uses Flux.v11
using Plots, Flux
function update!(opt, x, x̄)
x[:] .-= apply!(opt, x, x̄)[:]
end
function update!(opt, xs::Flux.Params, gs)
for x in xs
(gs[x] === nothing) && continue
using GeometryBasics
x(a::AbstractVector) = first(a)
y(a::AbstractVector) = last(a)
x(a::AbstractMatrix) = a[ :, 1 ]
y(a::AbstractMatrix) = a[ :, 2 ]
function orientation(p::AbstractVector, q::AbstractVector, r::AbstractVector)::Int
val = ( y(q) - y(p) ) * ( x(r) - x(q) ) - ( x(q) - x(p) ) * ( y(r) - y(q) )
return (val 0) ? 0 : ( (val > 0) ? 1 : 2 )
using GeometryBasics
x(a::Point{2, T}) where { T <: Number } = first(a)
y(a::Point{2, T}) where { T <: Number } = last(a)
#Ewy
Matrix(z::Vector{Point{2, T}}) where { T <: Number } = hcat( z .|> x, z .|> y )
to_points(z) = [ Point(z[:,r][:]...) for r in 1:size(z,2)]
function orientation(p::Point{2, T}, q::Point{2, T}, r::Point{2, T})::Int where {T <: Number }
val = ( y(q) - y(p) ) * ( x(r) - x(q) ) - ( x(q) - x(p) ) * ( y(r) - y(q) )
import DSP: conv
using LinearAlgebra
function boundaries( ::Val{:zeros}, x::Vector, half_width::Int )
return (padded = true, z = vcat( zeros(half_width), x, zeros(half_width) ) )
end
function boundaries( ::Val{:repeating}, x::Vector, half_width::Int )
return (padded = true, z = vcat( repeat( [ first(x) ], half_width), x, repeat( [ last(x) ], half_width) ) )
end
function boundaries( ::Val{:mirroring}, x::Vector, half_width::Int )
@caseykneale
caseykneale / Kasemiir.R
Created May 16, 2020 12:45
Helping Kasemiir Alice with Tensors
kasemiir <- as.data.frame(read.csv2("/mydata2.csv"))
#i batches(BatchID), j variables and k time(Time)
batch_part <- split(kasemiir, f=kasemiir$BatchID)
#now we have a list of dataframes split over batchid
#z[[2]] #is batch2 etc...
#make sure each subdf is ordered by time and convert to matrix
for( subdf in batch_part){
subdf <- data.matrix( subdf[order("Time")] )
}
@caseykneale
caseykneale / forjesse.jl
Created May 15, 2020 23:57
oldschool example new school api
using DiffEqFlux, OrdinaryDiffEq, Flux, MLDataUtils, NNlib
using Flux: logitcrossentropy
using MLDatasets: MNIST
function loadmnist(batchsize = bs)
# Use MLDataUtils LabelEnc for natural onehot conversion
onehot(labels_raw) = convertlabel(LabelEnc.OneOfK, labels_raw, LabelEnc.NativeLabels(collect(0:9)))
# Load MNIST
imgs, labels_raw = MNIST.traindata();
# Process images into (H,W,C,BS) batches
using Gtk, Plots, Cairo
using DataStructures
function replaceBiggest!(a,b)
selinds = abs.(a) .< abs.(b)
a[ selinds ] .= b[ selinds ]
end
mutable struct ClickablePlot