"Matt J" wrote in message <j360ia$rd6$1@newscl01ah.mathworks.com>...
> A few miscellaneous remarks:
>
>
> > for k=1:8
> >
> > if (j >=0.98) & (j <=1.05)
> =================
>
> Are you sure it makes sense to apply this stopping criterion for every individual k? It's certainly not a good way in general to see if you've found a minimim. For example, if I apply your technique to the minimization of
>
> f(x)=x(1)^2 + x(2)^2 + x(3)^2
>
> starting at x=[0 0 1], then I will get j=1 right from loop iteration k=2 and the algorithm will stop without ever processing x(3).
>
>
>
>
> > arguments{k}=arguments_2{k};
> ================
>
> This command plays no role in your code and should probably be deleted.
> You immediately overwrite
> arguments{k} with arguments_2{k}(i) in later lines of code.
>
>
>
> > arguments{k}=grid1D(idx)
> ==============
>
> Shouldn't this be
>
> arguments{k}=grid1D(k,idx);
>
>
>
> >
> > for i=1:21
> >
> > arguments{k}=arguments_2{k}(i)
> >
> > h(i,:)=example1(arguments{:})
> >
> >
> > end
> >
> > [j1, idx]=min(h)
> ==========================
>
> It doesn't really make sense that you run this loop twice for every k in order to get both j1 and j2. When the forloop over k increments and k becomes k+1, your computation of j1 will be identical to your most recent computation of j2.
>
>
>
>
>
>
> > The function "example1" takes approximately 12 hours to run thats why I would like to use parfor.
> ===================
>
> As Steve said, nothing above looks parallelizable. However, 12 hours is a really long time for a function evaluation. Why don't you show us what's inside example1 and we can see if maybe PARFOR can be used to accelerate example1 itself?
Hi Matt and Steven
Apologies for the repetition it wont happen next time. Unfortunately the function example1 is really long and depends on other functions thats why I didnt paste it. To run the function takes up to 12 hours (generally between 5 and 12h max). Another bad news is that the function cannot be vectorized.
Here is what I am doing:
1) I am setting up a 9D grid: grid1D is a cell.
grid1D=[10:1:10; 10:1:10; 10:1:10; 10:1:10; 10:1:10; 10:1:10; 10:1:10; 10:1:10; 10:1:10]; %% this is just an example. In my study, I will just take 6 values per grid otherwise the number of evaluation will be very high.
2) the function "example1" is function of 9 parameters. So the aim of this exercise is to evaluate "example1" by changing the first parameter (iterating accross grid1D{1}) and keeping the other parameters fixed. Once this operation is done, take the parameter of grid1D{1} that gives the smallest value of "example1" and plug it into the function and move to other grid (grid1D{2}). Iterate accross all the values of this grid and keep the parameter that minimize the function "example1"....I keep doing this until "if" condition is fullfilled.
Now all I am doing is evaluating the same function by changing the parameters (in each grid1D). so In theory this is parallelizable no? Maybe the way I wrote the code above is confusing ? (sorry about that)
Matt, I am not sure but I think the reason why your function quickly fulfilled the "if" condition is because the function that you took as example is quite simple which is not the case for "example1". But I agree it is risky the iteration is risky it might not evaluate all the grids.
3) so basically in my code I am iterating accross the Grids and inside each grid I am iterating accross the values of the grid
As you mentioned PARFOR is not suitable when one iteration is dependent on the others but there is a still a room to use PARFOR in my case no? knowing that all I do is to evaluate the function at different values?
4) Worse case scenario, do you think I can do it manually? I can run the inner loop with PARFOR for grid1{1} ( I iterate accross grid1d{1} )
%%%%Inner loop%%%%
parfor i=1:21
arguments{k}=arguments_2{k}(i)
h(i,:)=example1(arguments{:})
end
[j1, idx]=min(h)
arguments{k}=grid1D(idx)
Store the best parameter and plug it in the function " example1" and then move to grid1D{2} run with parfor again and keep going until the function doesnt change (much)...it might be a silly way but at least it will enable me to use PARFOR to speed up the computation...What do you think?
Matt I also agree with you it might not be an intelligent way to minimize the function but Iam just replication a paper to retrieve the parameters.
Sorry for this long email and thanks a lot for any valuable advice you could give me.
Best Regards
S
