Reputation: 12336
In matlab, I have a program that this implementation of linear support vector machines to do machine learning.
The library outputs a structure during the training phase that represents the model. This structure is to be used in the testing phase.
I would like to save this structure to a file so I don't have to go through the training phase every time.
I have tried psychtoolbox's WriteStructsToText()
and ReadStructsFromText()
, but they fail due to a buffer overflow while reading the struct into memory.
The outputted structure is a very large amount of data (tens of megabytes), so this could be the issue.
The structure:
-Parameters: Parameters
-nr_class: number of classes; = 2 for regression
-nr_feature: number of features in training data (without including the bias term)
-bias: If >= 0, we assume one additional feature is added to the end
of each data instance.
-Label: label of each class; empty for regression
-w: a nr_w-by-n matrix for the weights, where n is nr_feature
or nr_feature+1 depending on the existence of the bias term.
nr_w is 1 if nr_class=2 and -s is not 4 (i.e., not
multi-class svm by Crammer and Singer). It is
nr_class otherwise.
edit:
Anyone know how to fix this error?
>> save('mode.txt','-struct','model');
>> model = load('mode.txt');
??? Error using ==> load
Number of columns on line 1 of ASCII file C:\Users\jason\Dropbox\Homework\cs280\FINAL PROJECTO\mode.txt
must be the same as previous lines.
Upvotes: 0
Views: 759
Reputation: 74940
The easiest is to save the structure to a .mat-file:
outputStructure = yourTrainingFunction;
save('someFileName.mat','-struct','outputStructure');
And to load
outputStructure = load('someFileName.mat')
Be aware that if your files are very large, you may have to set the proper compatibility in the general settings of Matlab (save-file versions earlier than 7.3 cannot handle files >2GB, if I recall correctly).
Upvotes: 2