Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Chen ToucheSir

View GitHub Profile
View structintersect.jl
# courtesy of Mason Protter on the Julia Slack
@generated function structintersect(a::NamedTuple{a_names}, b::NamedTuple{b_names}) where {a_names, b_names}
names = Tuple(intersect(a_names, b_names))
fields = Expr(:tuple, (:(getproperty(a, $(QuoteNode(name))), getproperty(b, $(QuoteNode(name)))) for name in names)...)
quote
NamedTuple{$names}($fields)
end
end
@ToucheSir
ToucheSir / mwe.jl
Last active Dec 20, 2021
MWE from Flux.jl#1804
View mwe.jl
using Flux
include("weights.jl")
function gradtezt(x, weight, bias, act=selu)
gx = gpu(x)
ctc = ConvTranspose(weight, bias, act, groups=5)
gtc = gpu(ctc);
yc = Flux.withgradient(() -> sum(ctc(x)), params(ctc)) |> first
yg = Flux.withgradient(() -> sum(gtc(gx)), params(gtc)) |> first
View conv_mnist.jl
# Classifies MNIST digits with a convolutional network.
# Writes out saved model to the file "mnist_conv.bson".
# Demonstrates basic model construction, training, saving,
# conditional early-exit, and learning rate scheduling.
#
# This model, while simple, should hit around 99% test
# accuracy after training for approximately 20 epochs.
using Flux, MLDatasets, Random, Statistics
using Flux: unsqueeze, onehotbatch, onecold, logitcrossentropy
@ToucheSir
ToucheSir / conposcovidloc.csv
Last active Apr 2, 2020
Ontario Covid-19 Data Exploration
View conposcovidloc.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have columns, instead of 10. in line 5.
ACCURATE_EPISODE_DATE,Age_Group,CLIENT_GENDER,CASE_ACQUISITIONINFO,RESOLVED,Reporting_PHU,Reporting_PHU_Address,Reporting_PHU_City,Reporting_PHU_Postal_Code,Reporting_PHU_Website,Reporting_PHU_Latitude,Reporting_PHU_Longitude
2020-01-21,50s,MALE,Travel-Related,Yes,Toronto Public Health,"277 Victoria Street, 5th Floor",Toronto,M5B 1W2,www.toronto.ca/community-people/health-wellness-care/,43.65659125,-79.37935801
2020-01-22,50s,FEMALE,Travel-Related,Yes,Toronto Public Health,"277 Victoria Street, 5th Floor",Toronto,M5B 1W2,www.toronto.ca/community-people/health-wellness-care/,43.65659125,-79.37935801
2020-01-24,20s,FEMALE,Travel-Related,Yes,Middlesex-London Health Unit,50 King Street,London,N6A 5L7,www.healthunit.com,42.98146842,-81.25401572
2020-01-25,50s,MALE,Neither,Yes,Ottawa Public Health,100 Constellation Drive,Ottawa,K2G 6J8,www.ottawapublichealth.ca,45.3456651,-75.7639122
2020-02-05,20s,FEMALE,Travel-Related,Yes,Toronto Public Health,"277 Victoria Street, 5th Floor",Toronto,M5B 1W2,www.toronto.ca/commun