Skip to content

Commit

Permalink
add autoformatter
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdfish committed Mar 24, 2024
1 parent d2efc4f commit d6edf15
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 23 deletions.
29 changes: 29 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
always_use_return = false
annotate_untyped_fields_with_any = true
conditional_to_if = false
import_to_using = false
join_lines_based_on_source = true
normalize_line_endings = "unix"
pipe_to_function_call = false
remove_extra_newlines = true
short_to_long_function_def = false
long_to_short_function_def = false
whitespace_in_kwargs = true
whitespace_ops_in_indices = true
whitespace_typedefs = true
indent = 4
margin = 92
format_docstrings = false
align_struct_field = false
align_assignment = false
align_conditional = false
align_pair_arrow = false
align_matrix = false
trailing_comma = false
trailing_zero = true
indent_submodule = false
separate_kwargs_with_semicolon = false
surround_whereop_typeparameters = true
variable_call_indent = []
yas_style_nesting = false
disallow_single_arg_nesting = true
8 changes: 8 additions & 0 deletions .github/workflows/Format-PR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Format Suggestions
on:
pull_request:
jobs:
code-style:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/julia-format@v2
43 changes: 43 additions & 0 deletions .github/workflows/Format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Formatter
on:
schedule:
- cron: '0 0 * * *'
push:
branches:
- 'master'
tags: ['*']
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: '1'
arch: x64
show-versioninfo: true
- uses: julia-actions/cache@v1
- name: Install JuliaFormatter and format
shell: julia --color=yes {0}
run: |
using Pkg
Pkg.add("JuliaFormatter")
using JuliaFormatter
format(".")
# https://github.com/marketplace/actions/create-pull-request
# https://github.com/peter-evans/create-pull-request#reference-example
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Format .jl files
title: 'Automatic JuliaFormatter.jl run'
branch: auto-juliaformatter-pr
delete-branch: true
labels: formatting, automated pr, no changelog
- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d"

[compat]
AbstractMCMC = "0.5, 1.0.0, 2.0, 3.0, 4.0"
AbstractMCMC = "4.0,5.0"
ConcreteStructs = "0.2.0"
Distributions = "0.22, 0.23, 0.24, 0.25"
MCMCChains = "4.0, 5.0, 6.0"
Parameters = "0.12"
ProgressMeter = "1.2"
SafeTestsets = "0.0.1, 0.1"
SequentialSamplingModels = "0.1.0"
SequentialSamplingModels = "0.8.0"
StatsBase = "0.32,0.33, 0.34"
ThreadsX = "0.1.0"
Turing = "0.20,0.21,0.22.0,0.23.0,0.24.0,0.25.0,0.26.0"
Turing = "0.26.0 - 0.29.0"
julia = "1"

[extras]
Expand Down
38 changes: 18 additions & 20 deletions test/lognormal_race_tests.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
using DifferentialEvolutionMCMC, Test, Random, Turing, Parameters, Distributions
using DifferentialEvolutionMCMC, Test, Random, Parameters, Distributions
using SequentialSamplingModels, LinearAlgebra
using Turing
Random.seed!(9918)

dist = LNR(μ=[-2.,-2.,-3.,-3], σ=1.0, ϕ=.5)
dist = LNR(ν=[-2.,-2.,-3.,-3], σ=fill(1.0, 4), τ=.5)
data = rand(dist, 100)

function loglike(data, μ, σ, ϕ)
dist = LNR(μ, σ, ϕ)
return sum(logpdf.(dist, data))
function loglike(data, ν, τ)
dist = LNR(;ν, τ)
return sum(logpdf(dist, data))
end

function prior_loglike(μ, σ, ϕ)
function prior_loglike(ν, τ)
LL = 0.0
LL += sum(logpdf.(Normal(0, 3), μ))
LL += logpdf(truncated(Cauchy(0, 1), 0.0, Inf), σ)
LL += logpdf(Uniform(0., min_rt), ϕ)
LL += sum(logpdf.(Normal(0, 3), ν))
LL += logpdf(Uniform(0., min_rt), τ)
end

function sample_prior()
LL = 0.0
μ = rand(Normal(0, 3), 4)
σ = rand(truncated(Cauchy(0, 1), 0.0, Inf))
ϕ = rand(Uniform(0, min_rt))
return as_union([μ,σ,ϕ])
ν = rand(Normal(0, 3), 4)
τ = rand(Uniform(0, min_rt))
return as_union([ν, τ])
end

min_rt = minimum(x -> x[2], data)

bounds = ((-Inf,0.),(1e-10,Inf),(0.,min_rt))
names = (:μ,,)
bounds = ((-Inf,Inf),(0.,min_rt))
names = (:ν, )

model = DEModel(;
sample_prior,
Expand All @@ -53,17 +52,16 @@ loglikelihood(d::LNR, data::Vector{<:Tuple}) = sum(logpdf.(d, data))

@model model1(data) = begin
min_rt = minimum(x -> x[2], data)
μ ~ MvNormal(zeros(4), I * 3^2)
σ ~ truncated(Cauchy(0, 1), 0.0, Inf)
ϕ ~ Uniform(0.0, min_rt)
data ~ LNR=μ, σ=σ, ϕ=ϕ)
ν ~ MvNormal(zeros(4), I * 3^2)
τ ~ Uniform(0.0, min_rt)
data ~ LNR(;ν, τ)
end

Random.seed!(68541)
chn = sample(model1(data), NUTS(1500, .85), 4000)
μ_nuts = describe(chn)[1][:,:mean]
σ_nuts = describe(chn)[1][:,:std]

@test all(isapprox.(rhat, fill(1.0, 6), atol=.05))
@test all(isapprox.(rhat, fill(1.0, 5), atol=.05))
@test all(isapprox.(μ_nuts, μ_de, rtol=.05))
@test all(isapprox.(σ_nuts, σ_de, rtol=.05))

0 comments on commit d6edf15

Please sign in to comment.