Lesson 8/11 and fixed spelling error in prev lesson

This commit is contained in:
elvis
2023-11-12 18:20:31 +01:00
parent 33d89b6bba
commit 32b455888e
6 changed files with 223375 additions and 2361 deletions

31
11-8/interactiverec.jl Normal file
View File

@ -0,0 +1,31 @@
using LinearAlgebra, Plots, Statistics
include("../11-3/readyalefaces_to_tensor.jl")
function interactiverec(F, iterstop::Union{Nothing, Integer}=nothing)
# given a 243x320 image F, displays it as sum of components
stdsize = (243, 320)
(X, _) = readyalefaces_to_tensor()
X = reshape(X, (prod(stdsize), Integer(prod(size(X)) / prod(stdsize))))
avg = mean(X, dims=2)
Xs = X .- avg
(U,S,V) = svd(X)
h = Plots.heatmap(reshape(avg, stdsize), yflip=true)
display(h)
if iterstop == nothing
upto = size(U, 2)
else
upto = min(size(U, 2), iterstop)
end
# no fancy slider, not enough time
for d 0:upto
h = heatmap(reshape(avg .+ U[:, 1:d] * U[:, 1:d]' * F, stdsize), yflip=true)
IJulia.clear_output(true)
display(h)
end
end