• Stars
    star
    230
  • Rank 168,741 (Top 4 %)
  • Language
    Julia
  • License
    MIT License
  • Created over 2 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple chains

SimpleChains

Stable Dev Build Status codecov-img

SimpleChains.jl only supports simple chains, but it intends to be fast for small problems on the CPU. Currently, valgrad! is the only means of extracting gradient information.

using SimpleChains, BenchmarkTools

# 24 covariates each per 200 observations
x = rand(24, 200); # 24 inputs per 200 observations

# 2 responses each per 200 observations
y = Matrix{Float64}(undef, 2, 200) .= randn.() .* 10;

schain = SimpleChain(
  static(24), # input dimension (optional)
  TurboDense{true}(tanh, 8), # dense layer with bias that maps to 8 outputs and applies `tanh` activation
  SimpleChains.Dropout(0.2), # dropout layer
  TurboDense{false}(identity, 2), # dense layer without bias that maps to 2 outputs and `identity` activation
  SquaredLoss(y)
);

p = SimpleChains.init_params(schain)
g = similar(p);

# Entirely in place evaluation
@benchmark valgrad!($g, $schain, $x, $p) # dropout active

For comparison, using Flux, we would write:

using Flux

chain = Chain(
  Dense(24, 8, tanh; bias = true),
  Flux.Dropout(0.2),
  Dense(8, 2, identity; bias = false)
);
chain.layers[2].active = true # activate dropout

ya = Array(y);

@benchmark gradient(Flux.params($chain)) do
  Flux.mse($chain($x), $ya)
end

Benchmark results:

julia> @benchmark valgrad!($g, $schain, $x, $p) # dropout active
BechmarkTools.Trial: 10000 samples with 6 evaluations.
 Range (min … max):  5.274 μs …  33.075 μs  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     5.657 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   5.646 μs ± 349.777 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%
 Memory estimate: 0 bytes, allocs estimate: 0.
  
julia> @benchmark gradient(Flux.params($chain)) do
         Flux.mse($chain($x), $ya)
       end
BechmarkTools.Trial: 10000 samples with 1 evaluations.
 Range (min … max):   83.674 μs …   4.865 ms  ┊ GC (min … max): 0.00% … 93.21%
 Time  (median):      96.430 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   106.897 μs ± 197.689 μs  ┊ GC (mean ± σ):  7.96% ±  4.22%
 Memory estimate: 182.55 KiB, allocs estimate: 316.

More Repositories

1

QuartoNotebookRunner.jl

Julia
43
star
2

SummaryTables.jl

A Julia package for creating publication-ready summary tables in HTML, docx, LaTeX and Typst
Julia
42
star
3

WriteDocx.jl

A Julia package to create docx files for Microsoft Word from scratch
Julia
14
star
4

Bayesian-Workshop

Slides for Bayesian Workshops across the world
TeX
13
star
5

sensitivity_analysis_paper

Julia
5
star
6

WCoP2022_Pumas_Workshop

HTML
5
star
7

add-private-registry

This GitHub Action adds a private Julia package registry from a Pkg Server
Julia
4
star
8

ACoP13_NLME_Workshop

Pumas NLME workshop material for ACoP 13
Julia
3
star
9

nm_highlighter

3
star
10

Pumas_Workshop_Tokyo_2022

Pumas workshop for our friends in Japan.
Julia
3
star
11

PackageBundler.jl

Experimental bundling of Julia packages and environments.
Julia
2
star
12

Optimal-Design-Workshop

Workshop for Optimal Design in Pumas - Slides and Code
TeX
2
star
13

Git-Tutorial

Temporary Git Repository for a Git/GiHub Workshop
Julia
1
star
14

MBDD-MCC-135

The sample size calculation using modeling & simulation approach is considered to be more efficient than conventional modeling. The proposal is to compare the power of defining the exposure-response, and thereby establishing efficacy, using model-based approaches. Specifically, a base exposure-IGA score (ordinal scale) relationship will be assumed. Data will be simulated and subjected to conventional and model-based analyses. The model-based approach can test single-point (end of the study) and longitudinal models. The power of the two approaches will be compared. The process will be repeated for different ‘what-if’ scenarios from the base model. Several details of the simulations are provided by MTPC during the exploratory meeting.
HTML
1
star