Skip to content

Commit

Permalink
Merge pull request #74 from JuliaTrustworthyAI/73-add-format-check-to-ci
Browse files Browse the repository at this point in the history
added FormatCheck
  • Loading branch information
pat-alt authored Jul 6, 2023
2 parents 1ce5d76 + 34a64ed commit d3110db
Show file tree
Hide file tree
Showing 26 changed files with 616 additions and 600 deletions.
8 changes: 7 additions & 1 deletion .JuliaFormatter.jl
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
style = "blue"
using Pkg # Load package manager
Pkg.add("JuliaFormatter") # Install JuliaFormatter

using JuliaFormatter # Load JuliaFormatter
format("."; verbose=true) # Format all files

Pkg.rm("JuliaFormatter") # Remove JuliaFormatter
2 changes: 2 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
style = "blue"
pipe_to_function_call = false
34 changes: 34 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Format Check

on:
push:
branches:
- 'main'
- 'release-'
tags: '*'
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
with:
version: 1
- uses: actions/checkout@v1
- name: Install JuliaFormatter
run: |
using Pkg
Pkg.add("JuliaFormatter")
shell: julia --color=yes {0}
- name: Format code
run: |
using JuliaFormatter
format("."; verbose=true)
shell: julia --color=yes {0}
- name: Suggest formatting changes
uses: reviewdog/action-suggester@v1
if: github.event_name == 'pull_request'
with:
tool_name: JuliaFormatter
fail_on_error: true
85 changes: 42 additions & 43 deletions dev/logo/logo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const julia_colors = Dict(
:purple => Luxor.julia_purple,
)

function get_data(N = 500; xmax = 2.0, noise = 0.5, fun::Function = f)
function get_data(N=500; xmax=2.0, noise=0.5, fun::Function=f)
# Inputs:
d = Distributions.Uniform(-xmax, xmax)
x = rand(d, N)
Expand All @@ -32,21 +32,21 @@ function get_data(N = 500; xmax = 2.0, noise = 0.5, fun::Function = f)
end

function logo_picture(;
ndots = 3,
frame_size = 500,
ms = frame_size // 10,
mcolor = (:red, :green, :purple),
margin = 0.1,
fun = f(x) = x * cos(x),
xmax = 2.5,
noise = 0.5,
ged_data = get_data,
ntrue = 50,
gt_color = julia_colors[:blue],
gt_stroke_size = 5,
interval_color = julia_colors[:blue],
interval_alpha = 0.2,
seed = 2022,
ndots=3,
frame_size=500,
ms=frame_size//10,
mcolor=(:red, :green, :purple),
margin=0.1,
fun=f(x) = x * cos(x),
xmax=2.5,
noise=0.5,
ged_data=get_data,
ntrue=50,
gt_color=julia_colors[:blue],
gt_stroke_size=5,
interval_color=julia_colors[:blue],
interval_alpha=0.2,
seed=2022,
)

# Setup
Expand All @@ -55,8 +55,8 @@ function logo_picture(;
Random.seed!(seed)

# Data
x, y = get_data(xmax = xmax, noise = noise, fun = fun)
train, test = partition(eachindex(y), 0.4, 0.4, shuffle = true)
x, y = get_data(; xmax=xmax, noise=noise, fun=fun)
train, test = partition(eachindex(y), 0.4, 0.4; shuffle=true)
xtrue = range(-xmax, xmax, ntrue)
ytrue = fun.(xtrue)

Expand All @@ -65,31 +65,31 @@ function logo_picture(;
degree_polynomial = 5
polynomial_features(x, degree::Int) = reduce(hcat, map(i -> x .^ i, 1:degree))
pipe = (x -> MLJBase.table(polynomial_features(x, degree_polynomial))) |> Model()
conf_model = conformal_model(pipe; coverage = 0.95)
conf_model = conformal_model(pipe; coverage=0.95)
mach = machine(conf_model, x, y)
fit!(mach, rows = train)
fit!(mach; rows=train)
yhat = predict(mach, x[test])
y_lb = [y[1] for y in yhat]
y_ub = [y[2] for y in yhat]

# Logo
idx = sample(test, ndots, replace = false)
idx = sample(test, ndots; replace=false)
xplot, yplot = (x[idx], y[idx])
_scale = (frame_size / (2 * maximum(x))) * (1 - margin)

# Ground truth:
setline(gt_stroke_size)
sethue(gt_color)
true_points = [Point((_scale .* (x, y))...) for (x, y) in zip(xtrue, ytrue)]
poly(true_points[1:(end-1)], action = :stroke)
poly(true_points[1:(end - 1)]; action=:stroke)

# Data
data_plot = zip(xplot, yplot)
for i = 1:length(data_plot)
for i in 1:length(data_plot)
_x, _y = _scale .* collect(data_plot)[i]
color_idx = i % n_mcolor == 0 ? n_mcolor : i % n_mcolor
sethue(mcolor[color_idx]...)
circle(Point(_x, _y), ms, action = :fill)
circle(Point(_x, _y), ms; action=:fill)
end

# Prediction interval:
Expand All @@ -102,27 +102,26 @@ function logo_picture(;
Point((_scale .* (x, y))...) for (x, y) in zip(x[test][_order_ub], y_ub[_order_ub])
]
setcolor(sethue(interval_color)..., interval_alpha)
poly(vcat(lb, ub), action = :fill)

return poly(vcat(lb, ub); action=:fill)
end

function draw_small_logo(filename = "docs/src/assets/logo.svg"; width = 500)
function draw_small_logo(filename="docs/src/assets/logo.svg"; width=500)
frame_size = width
Drawing(frame_size, frame_size, filename)
origin()
logo_picture(frame_size = frame_size)
logo_picture(; frame_size=frame_size)
finish()
preview()
return preview()
end

function draw_wide_logo_new(
filename = "docs/src/assets/wide_logo.png";
_pkg_name = "Conformal Prediction",
font_size = 150,
font_family = "Tamil MN",
font_fill = "transparent",
font_color = Luxor.julia_blue,
bg_color = "transparent",
filename="docs/src/assets/wide_logo.png";
_pkg_name="Conformal Prediction",
font_size=150,
font_family="Tamil MN",
font_fill="transparent",
font_color=Luxor.julia_blue,
bg_color="transparent",
picture_kwargs...,
)

Expand All @@ -145,11 +144,11 @@ function draw_wide_logo_new(
# Picture:
@layer begin
translate(cells[1])
logo_picture(
frame_size = height,
margin = 0.1,
ms = ms,
gt_stroke_size = gt_stroke_size,
logo_picture(;
frame_size=height,
margin=0.1,
ms=ms,
gt_stroke_size=gt_stroke_size,
picture_kwargs...,
)
end
Expand All @@ -165,15 +164,15 @@ function draw_wide_logo_new(
translate(pos)
setline(Int(round(gt_stroke_size / 5)))
sethue(font_fill)
textoutlines(strs[n], O, :path, valign = :middle, halign = :center)
textoutlines(strs[n], O, :path; valign=:middle, halign=:center)
sethue(font_color)
strokepath()
end
end
end

finish()
preview()
return preview()
end

draw_wide_logo_new()
27 changes: 12 additions & 15 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ ex_meta = quote
model = DecisionTreeRegressor()
end

DocMeta.setdocmeta!(ConformalPrediction, :DocTestSetup, ex_meta; recursive = true)
DocMeta.setdocmeta!(ConformalPrediction, :DocTestSetup, ex_meta; recursive=true)

makedocs(;
modules = [ConformalPrediction],
authors = "Patrick Altmeyer",
repo = "https://github.com/juliatrustworthyai/ConformalPrediction.jl/blob/{commit}{path}#{line}",
sitename = "ConformalPrediction.jl",
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", "false") == "true",
canonical = "https://juliatrustworthyai.github.io/ConformalPrediction.jl",
edit_link = "main",
assets = String[],
modules=[ConformalPrediction],
authors="Patrick Altmeyer",
repo="https://github.com/juliatrustworthyai/ConformalPrediction.jl/blob/{commit}{path}#{line}",
sitename="ConformalPrediction.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", "false") == "true",
canonical="https://juliatrustworthyai.github.io/ConformalPrediction.jl",
edit_link="main",
assets=String[],
),
pages = [
pages=[
"🏠 Home" => "index.md",
"🫣 Tutorials" => [
"Overview" => "tutorials/index.md",
Expand All @@ -53,7 +53,4 @@ makedocs(;
],
)

deploydocs(;
repo = "github.com/JuliaTrustworthyAI/ConformalPrediction.jl",
devbranch = "main"
)
deploydocs(; repo="github.com/JuliaTrustworthyAI/ConformalPrediction.jl", devbranch="main")
Loading

0 comments on commit d3110db

Please sign in to comment.