Skip to content

Commit

Permalink
Add Mental Images Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Apr 5, 2022
1 parent 236e99b commit af07c93
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
44 changes: 44 additions & 0 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ s = count(classify(wnn, test_x) .== test_y)
println("Accuracy: $(100. * s / 10_000)%")
```

```@example mnist
using Images
images = WiSARD.images(wnn)
img = images[0]
RGB.([img[(i - 1) * 28 + j] for i = 1:28, j = 1:28])
```

```@example mnist
img = images[1]
RGB.([img[(i - 1) * 28 + j] for i = 1:28, j = 1:28])
```

```@example mnist
img = images[2]
RGB.([img[(i - 1) * 28 + j] for i = 1:28, j = 1:28])
```

## Fashion MNIST
```@example fashion-mnist
using WiSARD
Expand All @@ -60,4 +82,26 @@ train!(wnn, train_y, train_x)
s = count(classify(wnn, test_x) .== test_y)
println("Accuracy: $(100. * s / 10_000)%")
```

```@example fashion-mnist
using Images
images = WiSARD.images(wnn)
img = images[0]
RGB.([img[(i - 1) * 28 + j] for i = 1:28, j = 1:28])
```

```@example fashion-mnist
img = images[1]
RGB.([img[(i - 1) * 28 + j] for i = 1:28, j = 1:28])
```

```@example fashion-mnist
img = images[2]
RGB.([img[(i - 1) * 28 + j] for i = 1:28, j = 1:28])
```
6 changes: 3 additions & 3 deletions src/images/images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ function images(wnn::WNN{S, T}, y::S) where {S, T}
return if M == 0
Float64.(img)
else
Float64.(img / M)
Float64.(img ./ M)
end
end

function images(wnn::WNN)
return Dict{S, Array{Int}}(y => images(wnn, y) for y in keys(wnn.cls))
function images(wnn::WNN{S, T}) where {S, T}
return Dict{S, Array{Float64}}(y => images(wnn, y) for y in keys(wnn.cls))
end

0 comments on commit af07c93

Please sign in to comment.