-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from Juice-jl/qc6
Autodiff + Dice.jl!
- Loading branch information
Showing
45 changed files
with
1,610 additions
and
849 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#== | ||
"Dart target painting" | ||
- We can paint a target using red, green, and blue | ||
- Fixed numbers of red, green, and blue darts will randomly hit the target | ||
- What proportion of paint colors maximizes the probability that at least one | ||
dart of each color lands in it own color? | ||
==# | ||
|
||
using Dice | ||
import Base: all, any | ||
|
||
all(itr) = reduce(&, itr) | ||
any(itr) = reduce(|, itr) | ||
|
||
DARTS_PER_COLOR = [1, 2, 10] # number of red, green, and blue darts | ||
weights = [var!("r", 1), var!("g", 1), var!("b", 1)] | ||
|
||
all_colors_receive_own_dart = all( | ||
any(flip(weight / sum(weights)) for _ in 1:num_own_darts) | ||
for (num_own_darts, weight) in zip(DARTS_PER_COLOR, weights) | ||
) | ||
|
||
pr(all_colors_receive_own_dart) # 0.182 | ||
train_vars!([all_colors_receive_own_dart]; epochs=1000, learning_rate=0.3) | ||
|
||
# We've increased the chance of success! | ||
pr(all_colors_receive_own_dart) # 0.234 | ||
|
||
# Compute what ratio we actually need to paint the target: | ||
[compute(weight/sum(weights)) for weight in weights] | ||
# 3-element Vector{Float64}: | ||
# 0.46536681058883267 | ||
# 0.3623861813855715 | ||
# 0.17224700802559573 |
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 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
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
Oops, something went wrong.