And here is the code for the solver:
function odesolve(p::Vector{Float64},tsample::Vector{Int64},obsv::Vector{
Int64},initp::Vector{Int64})

    t = linspace(0,maximum(tsample),maximum(tsample))
    const tnum = length(t)
    h = t[2]-t[1]
    error_flag = false
    
    # --- set initial values / free or defined---

    y = Array(Float64,length(initp),tnum)
    fun = Array(Float64,length(initp))

    y[:,1] = abs(p[initp])

    tnum = tnum-1
    
    for i = 1:tnum
        (fun,error_flag) = evaluate(y[:,i],p)
        y[:,i+1] = y[:,i] .+ (fun*h)

        if error_flag
            break;
        end
    end
    return (y[obsv,tsample],error_flag)
end





On Thursday, May 22, 2014 2:48:30 PM UTC+1, [email protected] wrote:
>
>
>
> Le jeudi 22 mai 2014 15:23:53 UTC+2, sam cooper a écrit :
>>
>> Hi,
>>
>> I have an inner loop function which uses a 'constant' tuple:
>>
>> fhandle = (expdat,obsv,expdev,t)
>>
>> with types
>>
>> fhandle::(Matrix{Float64},Vector{Int64},Float64,Vector{Int64})
>>
>> Currently I am passing fhandle to the function each time it's called and 
>> then reallocating a set of variables i.e.
>>
>> function sqrerror(fhandle::(Matrix{Float64},Vector{Int64},Float64,Vector{
>> Int64}),p::Vector{Float64})
>>
>>     (expdat,obsv,expdev,tsample) = fhandle
>>     (obs,error_flag) = odesolve(p,tsample,obsv)
>>
>>     if error_flag
>>         return(1e16)
>>     end
>>     error_val = sum((expdat.-obs).^2,1)
>>     error_val = sum(error_val./(expdev.^2))
>>     return(error_val)
>> end
>>
>>
>> Only 'p' is changed each time the function is called but fhandle is 
>> constant but needs to be defined in another file really.
>>
>> Can I speed this up? I was thinking about using a module with const 
>> global variables but the documentation suggested global variables are 
>> slower.
>>
> Did you profile your code? 
>
> From my experience (which you might not share), the most probable slow par 
> of the code would most certainly be "odesolve" in which case, fhandle is 
> not your problem. Please first profile your code and then let's see what we 
> can do for you.
>  
>
>>
>> Thankyou in advance for any help and advice
>>
>> Best,
>> Sam
>>
>>

Reply via email to