-
Notifications
You must be signed in to change notification settings - Fork 14
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 #48 from PumasAI/densesubset
tests pass locally...
- Loading branch information
Showing
15 changed files
with
536 additions
and
99 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
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 |
---|---|---|
@@ -1,3 +1,69 @@ | ||
# Small Multi-Layer Perceptron | ||
|
||
Here, we'll fit a simple network: | ||
```julia | ||
using SimpleChains | ||
|
||
mlpd = SimpleChain( | ||
static(4), | ||
TurboDense(tanh, 32), | ||
TurboDense(tanh, 16), | ||
TurboDense(identity, 4) | ||
) | ||
``` | ||
|
||
Our goal here will be to try and approximate the matrix exponential: | ||
```julia | ||
function f(x) | ||
N = Base.isqrt(length(x)) | ||
A = reshape(view(x, 1:N*N), (N,N)) | ||
expA = exp(A) | ||
vec(expA) | ||
end | ||
|
||
T = Float32; | ||
X = randn(T, 2*2, 10_000); | ||
Y = reduce(hcat, map(f, eachcol(X))); | ||
Xtest = randn(T, 2*2, 10_000); | ||
Ytest = reduce(hcat, map(f, eachcol(Xtest))); | ||
``` | ||
|
||
Now, to train our network: | ||
```julia | ||
@time p = SimpleChains.init_params(mlpd); | ||
G = SimpleChains.alloc_threaded_grad(mlpd); | ||
|
||
mlpdloss = SimpleChains.add_loss(mlpd, SquaredLoss(Y)); | ||
mlpdtest = SimpleChains.add_loss(mlpd, SquaredLoss(Ytest)); | ||
|
||
report = let mtrain = mlpdloss, X=X, Xtest=Xtest, mtest = mlpdtest | ||
p -> begin | ||
let train = mlpdloss(X, p), test = mlpdtest(Xtest, p) | ||
@info "Loss:" train test | ||
end | ||
end | ||
end | ||
|
||
report(p) | ||
for _ in 1:3 | ||
@time SimpleChains.train_unbatched!( | ||
G, p, mlpdloss, X, SimpleChains.ADAM(), 10_000 | ||
); | ||
report(p) | ||
end | ||
``` | ||
I get | ||
```julia | ||
┌ Info: Loss: | ||
│ train = 0.012996411f0 | ||
└ test = 0.021395735f0 | ||
0.488138 seconds | ||
┌ Info: Loss: | ||
│ train = 0.0027068993f0 | ||
└ test = 0.009439239f0 | ||
0.481226 seconds | ||
┌ Info: Loss: | ||
│ train = 0.0016358295f0 | ||
└ test = 0.0074498975f0 | ||
``` | ||
|
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
Oops, something went wrong.
913cee0
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
913cee0
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.
Error while trying to register: Register Failed
@chriselrod, it looks like you are not a publicly listed member/owner in the parent organization (PumasAI).
If you are a member/owner, you will need to change your membership to public. See GitHub Help
913cee0
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()
913cee0
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.
Error while trying to register: Changing package repo URL not allowed, please submit a pull request with the URL change to the target registry and retry.
913cee0
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.
JuliaRegistries/General#58494
913cee0
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()
913cee0
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 created: JuliaRegistries/General/58495
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:
Also, note the warning: Version 0.2.1 skips over 0.2.0
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.
913cee0
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()
913cee0
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/58495
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: