Hi there, I just ran your code, and everything worked for me without error. Some thoughts:
1. What version of julia are you on? (I'm on a 0.3.0 prerelease) 2. Have you run Pkg.update() recently? The error could be a package bug that was recently fixed. Generally, it's a good idea to include the version of julia you're using. Also, in the future, consider creating a gist of your work at gist.github.com. This makes it more convenient for others to test your code quickly. Cheers! Kevin On Sat, May 24, 2014 at 12:26 PM, St Elmo Wilken <[email protected]>wrote: > Hi (again), > > I have a weird issue where I need to run a much simpler version of my code > (test.jl) for the more "complicated" one to work (test2.jl). > > Suppose you have just started Julia then: > > If I run test.jl (this works without error), then test2.jl and then > test2.jl again my code works, note: the first test2.jl throws: error in > method definition: function Base.bytestring must be explicilty imported to > be extended... > > If just run test2.jl it throws error in method definition: function > Base.bytestring must be explicilty imported to be extended and then if I > run test2.jl again it throws no method getindex... This way around > nothing works... > > I think the error creeps in because I use a custom reducing function in my > parallel for loops but I have no idea why it would then work in the simpler > code? Also as far as I know I'm not extending any methods? > > Any help would be appreciated... > > Thanks! > > ****************test.jl******************************** > > @everywhere using Distributions > require("bandit.jl") > > a = bandit(0.0, 100) > > b = bandit(0.0, 100) > > c = bandit_red(a,b) # shows that my reducing function works > > > r = @parallel (bandit_red) for k=1:100 > > bandit(0.0, 100) > > end > > > ****************test2.jl******************************** > > using PyPlot > > > @everywhere using Distributions > > require("bandit.jl") > > > > plays = 2500 > > replicates = 2000 > > > run1 = @parallel (bandit_red) for k=1:replicates > > bandit(0.0, plays) > > end > > > run2 = @parallel (bandit_red) for k=1:replicates > > bandit(0.025, plays) > > end > > > run3 = @parallel (bandit_red) for k=1:replicates > > bandit(0.05, plays) > > end > > > # Plot the results > > figure() > > plot([1:plays], run1[1]/replicates,"b") > > hold(true) > > plot([1:plays], run2[1]/replicates,"r") > > plot([1:plays], run3[1]/replicates,"g") > > hold(false) > > legend(("Greedy = 0.0 ","Greedy = 0.025","Greedy = 0.05"),"lower right") > > > > figure() > > plot([1:plays], run1[2]/replicates,"b") > > hold(true) > > plot([1:plays], run2[2]/replicates,"r") > > plot([1:plays], run3[2]/replicates,"g") > > hold(false) > > legend(("Greedy = 0.0 ","Greedy = 0.025","Greedy = 0.05"),"lower right") > > > ****************bandit.jl******************************** > function bandit_red(a,b) > > c = a[1] + b[1] > > d = a[2] + b[2] > > return c,d > > end > > > > function bandit(epsilon::Float64, plays::Int64) > > > Nbandit = 10::Int64 #arms of the bandit > > Qtmeans = rand(Normal(), Nbandit) #true means of each arm > > Qemeans = rand(MvNormal(Qtmeans, eye(Nbandit))) #estimated means of each arm > > Qdraw(mean) = rand(Normal(mean)) #normal draw with mean > > meanUpdate = ones(Nbandit,2) # array creation > > meanUpdate[:,1] = Qemeans #update matrix of means of the bandit > > > # Play the game > > reward = zeros(plays,1) > > optim = zeros(plays,1) > > total = 0.0 > > for p=1:plays > > > # Epsilon-Greedy Player > > if rand() < epsilon > > gp_index = rand(DiscreteUniform(1, Nbandit)) #return random index > > else > > gp_index = indmax(Qemeans) #return the max estimated index > > end > > > # Update Step > > value = Qdraw(Qtmeans[gp_index]) #draw from true means > > reward[p] = value > > meanUpdate[gp_index, 2] = meanUpdate[gp_index, 2] + 1.0 > > meanUpdate[gp_index, 1] = meanUpdate[gp_index, 1] + value > > Qemeans[gp_index] = meanUpdate[gp_index, 1]/meanUpdate[gp_index, 2] > > > if gp_index == indmax(Qtmeans) > > total += 1.0 > > optim[p] = total/float(p) > > else > > optim[p] = total/float(p) > > end > > > end > > > return reward, optim > > end > > > > > > >
