Did you run the code twice to not time the JIT compiler? For me, my version runs in 0.24 and Daniels in 0.34.
Anyway, adding this to Daniels version: https://gist.github.com/KristofferC/c19c0ccd867fe44700bd makes it run in 0.13 seconds for me. On Sunday, September 20, 2015 at 7:28:09 PM UTC+2, Adam wrote: > > Thanks for the comments! Daniel and Kristoffer, I ran each of your code on > my machine. Daniel's ran in 2.0 seconds on my laptop (~26% of time in gc); > Kristoffer's ran in about 7 seconds on my laptop (~21% of time in gc). I'm > not sure why Kristoffer's took so much longer to run for me than it did for > him-- perhaps his machine is significantly better. Or maybe it's because > I'm running in Juno and not from the command line? > > As it stands, I can get the code to perform nearly as well as Matlab with > Daniel's code and my latest version: > https://gist.github.com/anonymous/cee196ee43cb9bf1c8b6 (note, when > running I fixed the omission of "Prob_o" as an argument for "update_w", > which is the right thing to do but saw no speed improvement). I think the > primary difference is that Daniel defines types to store the parameters > etc. (which more closely matches my original code), while my latest version > passes all function arguments directly. On my laptop, these run in the > neighborhood of 2-3 seconds (vs. 1.4 seconds for the Matlab code). > > Any thoughts on how I can beat the Matlab code? I would prefer to not > (yet) get into possibilities like parallelization of the "i" for loop in > "simulation.jl", since while I'm sure any parallelization would speed up > the code, my impression is that Julia should be able to trump Matlab even > before getting into anything like that. > > P.S.- In my latest version of the code (again, here: > https://gist.github.com/anonymous/cee196ee43cb9bf1c8b6), in line 44 of > run_sim() I have: > #return s_array, w_array, b_array > when I uncomment that line and run the code, I receive an error saying > s_array doesn't exit. Can someone tell me why? I checked, and the > "simulation" function indeed creates s_array as output, so I'm not sure why > "run_sim" won't return it. > > > On Sunday, September 20, 2015 at 10:49:06 AM UTC-5, Daniel Carrera wrote: >> >> >> On 20 September 2015 at 17:39, STAR0SS <[email protected]> wrote: >> >>> The biggest problem right now is that Prob_o is global in calc_net. You >>> need to pass it as an argument too. It's one of the drawback of having >>> everything global by default, this kind of mistakes are sometimes hard to >>> spot. >>> >> >> But... calc_net does not use Prob_o ... ? >> >> >> >>> >>> Otherwise the # get things in right dimensions for calculation below at >>> line 55 is not necessary anymore. >>> >>> In these zeros(numO, 1) you don't need to put a 1, zeros(numO) gives >>> you a vector of length numO, unlike in matlab where is gives you a matrix. >>> >>> >> >> I cleaned up the code and updated Github. No speed difference though. >> >> Cheers, >> Daniel. >> >> >>
