Basically, I have a test function which I call from a main script in Atom.
However, the function returns NaN array as mA. Whereas, if I copy paste and run parts of the code inside REPL it runs without any issue. Where is the problem?
I even tried running test() function as a script (not a function) and I have the same problem.
function test()
matrixSize=30;
mX = randn(matrixSize, matrixSize);
# Assuming Samples are slong Columns (Rows are features)
numClusters = Int64( max( round(matrixSize / 100), 1 ) ); # % max between 1 and round(...)
numIterations = 10;
# http://stackoverflow.com/questions/36047516/julia-generating-unique-random-integer-array
mA = mX[:, randperm(matrixSize)[1:numClusters]] ; #<! Cluster Centroids
for ii = 1:numIterations
vMinDist, mClusterId = findmin( transpose(sum(mA .^ 2, dims=1)) .- (2 .* transpose(mA)* mX), dims=1); #<! Is there a `~` equivalent in Julia?
vClusterId=dropdims(mClusterId, dims=1); # to be able to access it later
for jj = 1:numClusters
mA[:, jj] = mean( mX[:, vClusterId .== jj ], dims=2 );
end
end
mA = mA[:, 1] .+ transpose(mA[:, end]);
return mA
end
I call the function from a main script like this:
using Statistics
using LinearAlgebra
using Random # for randperm
include("test.jl");
mA=test();