How to save workspace in a for loop?

2 views (last 30 days)
ibra
ibra on 17 Nov 2014
Commented: Greg Heath on 18 Nov 2014
Hello,
I want to save the workspace at each iteration (in a vector maybe). By doing this, I will be able to reach any workspace generated at any iteration.
Thank you.
  3 Comments
ibra
ibra on 18 Nov 2014
Hello Geoff,
To be more specific, I'm training a Neural Network. I want to train it for several times within a for loop and find out which network structure gives the lowest error. Therefore, I can say that I want to save the whole variables in the workspace at each iteration.
Thank you.
Image Analyst
Image Analyst on 18 Nov 2014
Just have the variables be arrays. Assign the value to an array with the same index as the loop index (if it's sequential integers).

Sign in to comment.

Accepted Answer

Greg Heath
Greg Heath on 18 Nov 2014
Typically I design 100 nets at a time using a double loop: 10 values of hidden nodes: h = Hmin:dH:Hmax and 10 random initial weight assignments ntrial = 1:Ntrials for each value of h.
Instead of saving all of the nets, just save h, the state of the random number generator s(rng) and the corresponding performance measure (NMSE or Rsquared = 1-NMSE) for each design. Afterwards the values of h and s for the smallest NMSE are retrieved and the best net can be retrained.
Better yet, alternatively start with the first net as the best net. Then each time a new design is better, that becomes the best net. Consequently, only one net needs to be saved at any time.
If you wish, you could modify the last approach to save the best 10 (or whatever) nets.
I have posted many, many designs using the first approach. Unfortunately, I have posted at most, a few designs using the best saved net.
I will search for the latter and post the URLs.
The first approach designs are reasdily found by searching
greg i=1:Ntrials h=Hmin:dH:Hmax (or h = 0:dH:Hmax)
Hope this helps.
Thank you for formally accepting my answer
Greg
  1 Comment
Greg Heath
Greg Heath on 18 Nov 2014
NN accuracy on test set low Asked by Anitha on 12 Mar 2014 http://www.mathworks.com/matlabcentral/answers/121234-nn-accuracy-on-test-set-low =============================================================================
Subject: DUPLICATING THE BEST NEURAL NET DESIGN From: Greg Heath Date: 18 Mar, 2014 http://www.mathworks.com/matlabcentral/newsreader/view_thread/334932#919949

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!