-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some benchmark for
logdensity
computations (#172)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
811724e
commit 2d0d743
Showing
9 changed files
with
211 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Section 6 of the Law School Aptitude Test (LSAT) | ||
|
||
Section 6 of the Law School Aptitude Test (LSAT) is a 5-item multiple choice test; students score 1 on each item for the correct answer and 0 otherwise, giving R = 32 possible response patterns. Boch and Lieberman (1970) present data on LSAT for N = 1000 students, part of which is shown below. | ||
|
||
| Response Pattern | Item 1 | Item 2 | Item 3 | Item 4 | Item 5 | Frequency | | ||
|------------------|--------|--------|--------|--------|--------|-----------| | ||
| 1 | 0 | 0 | 0 | 0 | 0 | 3 | | ||
| 2 | 0 | 0 | 0 | 0 | 1 | 6 | | ||
| 3 | 0 | 0 | 0 | 1 | 0 | 2 | | ||
| . | . | . | . | . | . | . | | ||
| . | . | . | . | . | . | . | | ||
| . | . | . | . | . | . | . | | ||
| 30 | 1 | 1 | 1 | 0 | 1 | 61 | | ||
| 31 | 1 | 1 | 1 | 1 | 0 | 28 | | ||
| 32 | 1 | 1 | 1 | 1 | 1 | 298 | | ||
|
||
The above data may be analysed using the one-parameter Rasch model (see Andersen (1980), pp.253-254; Boch and Aitkin (1981)). The probability $p_{jk}$ that student $j$ responds correctly to item $k$ is assumed to follow a logistic function parameterized by an 'item difficulty' or threshold parameter $a_k$ and a latent variable $q_j$ representing the student's underlying ability. The ability parameters are assumed to have a Normal distribution in the population of students. That is: | ||
|
||
$$logit(p_{jk}) = q_j - a_k, j = 1,...,1000; k = 1,...,5$$ | ||
|
||
$$q_j \sim Normal(0, \tau)$$ | ||
|
||
The above model is equivalent to the following random effects logistic regression: | ||
|
||
$$logit(p_{jk}) = \beta q_j - a_k, j = 1,...,1000; k = 1,...,5$$ | ||
|
||
$$q_j \sim Normal(0, 1)$$ | ||
|
||
where $\beta$ corresponds to the scale parameter ($\beta^2 = \tau$) of the latent ability distribution. We assume a half-normal distribution with small precision for $\beta$; this represents vague prior information but constrains $\beta$ to be positive. Standard vague normal priors are assumed for the $a_k$'s. Note that the location of the $a_k$'s depend upon the mean of the prior distribution for $q_j$ which we have arbitrarily fixed to be zero. Alternatively, Boch and Aitkin ensure identifiability by imposing a sum-to-zero constraint on the $a_k$'s. Hence we calculate $a_k = a_k - \bar{a}$ to enable comparision of the BUGS posterior parameter estimates with the Boch and Aitkin marginal maximum likelihood estimates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using BenchmarkTools | ||
|
||
using JuliaBUGS | ||
using JuliaBUGS: BUGSExamples | ||
|
||
suite = BenchmarkGroup() | ||
|
||
for name in keys(BUGSExamples.VOLUME_1) | ||
@info "Adding benchmark for $name" | ||
model_def = BUGSExamples.VOLUME_1[name].model_def | ||
data = BUGSExamples.VOLUME_1[name].data | ||
|
||
non_data_scalars, non_data_array_sizes = JuliaBUGS.determine_array_sizes( | ||
model_def, data | ||
) | ||
|
||
eval_env = JuliaBUGS.compute_data_transformation( | ||
non_data_scalars, non_data_array_sizes, model_def, data | ||
) | ||
|
||
_suite = BenchmarkGroup() | ||
|
||
_suite["CollectVariables"] = @benchmarkable JuliaBUGS.determine_array_sizes( | ||
$model_def, $data | ||
) | ||
|
||
_suite["DataTransformation"] = @benchmarkable JuliaBUGS.compute_data_transformation( | ||
$non_data_scalars, $non_data_array_sizes, $model_def, $data | ||
) | ||
|
||
model_def = JuliaBUGS.concretize_colon_indexing(model_def, eval_env) | ||
_suite["GraphCreation"] = @benchmarkable JuliaBUGS.create_graph($model_def, $eval_env) | ||
|
||
tune!(_suite) | ||
suite[string(name)] = _suite | ||
end | ||
|
||
results = run(suite; verbose=false) | ||
result_dict = create_result_dict(results) | ||
print_markdown_table(result_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using JuliaBUGS | ||
using LogDensityProblems, LogDensityProblemsAD | ||
using AdvancedHMC, AbstractMCMC, MCMCChains, ReverseDiff | ||
using BenchmarkTools | ||
|
||
suite = BenchmarkGroup() | ||
|
||
for m in keys(JuliaBUGS.BUGSExamples.VOLUME_1) | ||
exempl = JuliaBUGS.BUGSExamples.VOLUME_1[m] | ||
(; model_def, data, inits) = exempl | ||
model = compile(model_def, data, inits) | ||
ad_model = ADgradient(:ReverseDiff, model; compile=Val(false)) | ||
ad_model_compiled = ADgradient(:ReverseDiff, model; compile=Val(true)) | ||
θ = rand(LogDensityProblems.dimension(model)) | ||
|
||
sub_suite = BenchmarkGroup() | ||
|
||
sub_suite["logdensity"] = @benchmarkable LogDensityProblems.logdensity($model, $θ) | ||
sub_suite["AD logdensity"] = @benchmarkable LogDensityProblems.logdensity($ad_model, $θ) | ||
sub_suite["AD logdensity_and_gradient"] = @benchmarkable LogDensityProblems.logdensity_and_gradient( | ||
$ad_model, $θ | ||
) | ||
sub_suite["AD compiled logdensity"] = @benchmarkable LogDensityProblems.logdensity( | ||
$ad_model_compiled, $θ | ||
) | ||
sub_suite["AD compiled logdensity_and_gradient"] = @benchmarkable LogDensityProblems.logdensity_and_gradient( | ||
$ad_model_compiled, $θ | ||
) | ||
|
||
suite[m] = sub_suite | ||
end | ||
|
||
tune!(suite) | ||
results = run(suite; verbose=false) | ||
result_dict = create_result_dict(results) | ||
print_markdown_table(result_dict) |
Oops, something went wrong.
2d0d743
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
2d0d743
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request updated: JuliaRegistries/General/103662
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: