Skip to content

Commit 4df2542

Browse files
fix scaling (#33)
* fix scaling * Update src/distributions/README.md Co-Authored-By: Raphael Saavedra <[email protected]>
1 parent bfb7e39 commit 4df2542

File tree

14 files changed

+87
-83
lines changed

14 files changed

+87
-83
lines changed

Project.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
99
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
1010
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1111

12-
[extras]
13-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
14-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
15-
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
12+
[compat]
13+
Distributions = "~0.21"
14+
Optim = "~0.19"
15+
SpecialFunctions = "~0.8"
16+
julia = "~1"
1617

1718
[targets]
1819
test = ["Test", "Random", "HypothesisTests"]
1920

20-
[compat]
21-
julia = "~1"
22-
Distributions = "~0.21"
23-
Optim = "~0.19"
24-
SpecialFunctions = "~0.8"
21+
[extras]
22+
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
23+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
24+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/distributions/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ Each distribution must have the following methods:
99
* link interface
1010
* param_to_param_tilde
1111
* param_tilde_to_param
12-
* jacobian_param_tilde
12+
* jacobian_link
1313
* update_dist
1414
* num_params

src/distributions/beta.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ function param_tilde_to_param(::Type{Beta}, param_tilde::Vector{T}) where T
4646
param_tilde_to_param(ExponentialLink, param_tilde[2], zero(T))
4747
]
4848
end
49-
function jacobian_param_tilde(::Type{Beta}, param_tilde::Vector{T}) where T
49+
function jacobian_link(::Type{Beta}, param_tilde::Vector{T}) where T
5050
return Diagonal([
51-
jacobian_param_tilde(ExponentialLink, param_tilde[1], zero(T));
52-
jacobian_param_tilde(ExponentialLink, param_tilde[2], zero(T))
51+
jacobian_link(ExponentialLink, param_tilde[1], zero(T));
52+
jacobian_link(ExponentialLink, param_tilde[2], zero(T))
5353
])
5454
end
5555

5656
# utils
5757
function update_dist(::Type{Beta}, param::Vector{T}) where T
58+
small_threshold!(param, T(1e-8))
5859
return Beta(param[1], param[2])
5960
end
6061

src/distributions/common_interface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ end
2323
function param_tilde_to_param(D::Type{<:Distribution}, param_tilde::Vector{T}) where T
2424
return error("param_tilde_to_param not implemented for $D distribution")
2525
end
26-
function jacobian_param_tilde(D::Type{<:Distribution}, param_tilde::Vector{T}) where T
27-
return error("jacobian_param_tilde not implemented for $D distribution")
26+
function jacobian_link(D::Type{<:Distribution}, param_tilde::Vector{T}) where T
27+
return error("jacobian_link not implemented for $D distribution")
2828
end
2929
function update_dist(D::Type{<:Distribution}, param::Vector{T}) where T
3030
return error("update_dist not implemented for $D distribution")

src/distributions/gamma.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ function param_tilde_to_param(::Type{Gamma}, param_tilde::Vector{T}) where T
4343
param_tilde_to_param(ExponentialLink, param_tilde[2], zero(T))
4444
]
4545
end
46-
function jacobian_param_tilde(::Type{Gamma}, param_tilde::Vector{T}) where T
46+
function jacobian_link(::Type{Gamma}, param_tilde::Vector{T}) where T
4747
return Diagonal([
48-
jacobian_param_tilde(ExponentialLink, param_tilde[1], zero(T));
49-
jacobian_param_tilde(ExponentialLink, param_tilde[2], zero(T))
48+
jacobian_link(ExponentialLink, param_tilde[1], zero(T));
49+
jacobian_link(ExponentialLink, param_tilde[2], zero(T))
5050
])
5151
end
5252

src/distributions/log_normal.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ function param_tilde_to_param(::Type{LogNormal}, param_tilde::Vector{T}) where T
4040
param_tilde_to_param(ExponentialLink, param_tilde[2], zero(T))
4141
]
4242
end
43-
function jacobian_param_tilde(::Type{LogNormal}, param_tilde::Vector{T}) where T
43+
function jacobian_link(::Type{LogNormal}, param_tilde::Vector{T}) where T
4444
return Diagonal([
45-
jacobian_param_tilde(IdentityLink, param_tilde[1]);
46-
jacobian_param_tilde(ExponentialLink, param_tilde[2], zero(T))
45+
jacobian_link(IdentityLink, param_tilde[1]);
46+
jacobian_link(ExponentialLink, param_tilde[2], zero(T))
4747
])
4848
end
4949

src/distributions/normal.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ function param_tilde_to_param(::Type{Normal}, param_tilde::Vector{T}) where T
4343
param_tilde_to_param(ExponentialLink, param_tilde[2], zero(T))
4444
]
4545
end
46-
function jacobian_param_tilde(::Type{Normal}, param_tilde::Vector{T}) where T
46+
function jacobian_link(::Type{Normal}, param_tilde::Vector{T}) where T
4747
return Diagonal([
48-
jacobian_param_tilde(IdentityLink, param_tilde[1]);
49-
jacobian_param_tilde(ExponentialLink, param_tilde[2], zero(T))
48+
jacobian_link(IdentityLink, param_tilde[1]);
49+
jacobian_link(ExponentialLink, param_tilde[2], zero(T))
5050
])
5151
end
5252

src/distributions/poisson.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626
# Links
2727
param_to_param_tilde(::Type{Poisson}, param::Vector{T}) where T = param_to_param_tilde.(ExponentialLink, param, zero(T))
2828
param_tilde_to_param(::Type{Poisson}, param_tilde::Vector{T}) where T = param_tilde_to_param.(ExponentialLink, param_tilde, zero(T))
29-
jacobian_param_tilde(::Type{Poisson}, param_tilde::Vector{T}) where T = Diagonal(jacobian_param_tilde.(ExponentialLink, param_tilde, zero(T)))
29+
jacobian_link(::Type{Poisson}, param_tilde::Vector{T}) where T = Diagonal(jacobian_link.(ExponentialLink, param_tilde, zero(T)))
3030

3131
# utils
3232
function update_dist(::Type{Poisson}, param::Vector{T}) where T

src/distributions/weibull.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ function param_tilde_to_param(::Type{Weibull}, param_tilde::Vector{T}) where T
4040
param_tilde_to_param(ExponentialLink, param_tilde[2], zero(T))
4141
]
4242
end
43-
function jacobian_param_tilde(::Type{Weibull}, param_tilde::Vector{T}) where T
43+
function jacobian_link(::Type{Weibull}, param_tilde::Vector{T}) where T
4444
return Diagonal([
45-
jacobian_param_tilde(ExponentialLink, param_tilde[1], zero(T));
46-
jacobian_param_tilde(ExponentialLink, param_tilde[2], zero(T))
45+
jacobian_link(ExponentialLink, param_tilde[1], zero(T));
46+
jacobian_link(ExponentialLink, param_tilde[2], zero(T))
4747
])
4848
end
4949

src/link_functions.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ struct IdentityLink <: Link end
44

55
param_to_param_tilde(::Type{IdentityLink}, param::T) where T = param
66
param_tilde_to_param(::Type{IdentityLink}, param_tilde::T) where T = param_tilde
7-
jacobian_param_tilde(::Type{IdentityLink}, param_tilde::T) where T = one(T)
7+
jacobian_link(::Type{IdentityLink}, param_tilde::T) where T = one(T)
88

99
struct ExponentialLink <: Link end
1010

1111
param_to_param_tilde(::Type{ExponentialLink}, param::T, lower_bound::T) where T = log(param - lower_bound)
1212
param_tilde_to_param(::Type{ExponentialLink}, param_tilde::T, lower_bound::T) where T = exp(param_tilde) + lower_bound
13-
jacobian_param_tilde(::Type{ExponentialLink}, param_tilde::T, lower_bound::T) where T = exp(param_tilde)
13+
jacobian_link(::Type{ExponentialLink}, param_tilde::T, lower_bound::T) where T = 1/(param_tilde - lower_bound)
1414

1515
struct LogitLink <: Link end
1616

0 commit comments

Comments
 (0)