Hey all. I’ve been trying to write some functions in Julia, but I’ve been getting many errors of the
UndefVarError: variable not defined type. The main source of the errors is this part here (which is inside my function):
global pi = rand(C) global pi = pi/sum(pi) global mu = reshape(randn(C * d), (C, d)) sigma = zeros(Float64, (d, d, C)) for c in 1:C sigma[:, :, c] = Diagonal(ones(d)) end global lloss = -Inf not_saturated = true for i in 1:max_iter former_loss = copy(lloss) gamma = E_step(X, pi, mu, sigma) pi, mu, sigma = M_step(X, gamma) lloss = compute_vlb(X, pi, mu, sigma, gamma) if(former_loss > lloss) print("bug") end not_saturated = abs((lloss/former_loss) - 1) > rtol end
where I get that my pi, mu, and sigma are not defined (I even tried making it global but no success so far). I know this is not reproducible (sorry for that), so I’ll try to explain. The E_step, M_step and compute_vlb functions will receive the parameters inside the
for loop there, and what I expect is that the parameters can be updated at each iteration (as is written there). I’m imagining that there’s something very simple that I’m missing here. Does anyone have any idea?