18

I started with the Julia code you had and also got ~20 seconds, so I think my timings are similar to yours. Let me give a step by step breakdown on how to do this. To start, notice that if you are running code in the REPL that variables defined there are global. This incurs a good performance cost. There are two ways to deal with this: 1) Wrap it all in a ...


6

in your MATLAB code, some unnecessary steps can be skipped. Here's a modification of your doStep function that should improve performance quite a bit. Each modif is explained in the comments within the code. doStep2.m function file: function [ newtv ] = doStep2( tv, fitnessf, mutrate, stdev ) % Function to calculate new offspring trait values from parent ...


5

It's difficult to address the question you're most interested in without more comments (or documentation for the library you're using). However, the differences between the two functions do seem very minor (especially once I rename curves to curve in the second one). Comments There are three comments in each function: //implementation start /*main ...


5

Regarding the rpois function, I think the preferred way of simulating a single value from a Poisson distribution with mean λ is using Distributions rand(Poisson(λ)) To fill out, a vector of Ints, with Poisson simulated values from a vector of means, p, you can use the mutating version of map. In v0.4 it is best to write a helper function r1(λ) = rand(...


3

Firstly, practical comments regarding Julia implementation. The line: numberoffspring = [rand(Poisson(theta)) for theta in fitnessfunc(tv, n, k)] consumes a lot of time because fitnessfunc is a user defined function about which not enough is known during compilation. This can be fixed by adding a type assertion to the result thus: numberoffspring = [...


3

Here are a few methods for your consideration and feedback. This one uses the core of my "Dynamic Partition" function. It is the fastest method I know for this problem. Also, perhaps refactoring the code like this makes it more intelligible. dynP[l_, p_] := MapThread[l[[# ;; #2]] &, {{0}~Join~Most@# + 1, #} &@Accumulate@p] #~PadRight~s & /@...


2

MATLAB I don't have the Statistical Toolbox, so unfortunately I can't do any benchmarking to test this, but I believe the following points will increase the performance of your implementation. It will still be far slower than R though. My guess is that the functions that are part of the toolbox are the slow ones: normrnd, poissrnd (and possibly datasample) ...


2

As of Mathematica 9.0 we have the function AdjacencyList[g,v]. Since this is built into Mathematica, I would assume that it is the fastest implementation. In[1]:= g = CompleteGraph[7]; In[2]:= AdjacencyList[g, 4] Out[2]= {1, 2, 3, 5, 6, 7} In[3]:= g = CompleteGraph[{3,4}]; In[4]:= EdgeList[g] Out[4]= {1 <-> 4, 1 <-> 5, 1 <-> 6, 1 <-> ...


Only top voted, non community-wiki answers of a minimum length are eligible