merged mutating_versions into master #29
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replaces #17
The version allocates memory for prediction already during training. In addition it provides a svmpredict! version by writing the output into a preallocated svmtmp type.
The gain in performance of the new svmpredict! can best be seen, when using large matrices, e.g. computing the kernel matrix for the svm model explicitly in julia:
Example
using LIBSVM
using Distances
train = randn(3,5000);
D = pairwise(Euclidean(), train);
K = exp(-0.5.*D); #transform to simple kernel matrix
test = randn(3, 300);
Dtest = pairwise(Euclidean(), train, test);
Ktest = exp(-0.5.*Dtest);
@time model = svmtrain(K, svmtype = OneClassSVM, nu = 0.1, kernel = Kernel.Precomputed);
0.5s 440 mb new; 0.4 s, 400 Mb old version
gc()
@time (class, decvalues) = svmpredict(model, Ktest)
22 mb 0.01 s new; 0.04 s, 61 mb old version
@time svmtmp = LIBSVM.init_svmpredict(Ktest, model) # 22mb, 0.005s
@time LIBSVM.svmpredict!(svmtmp, model, Ktest) # 20kb, 0.004 s --> about 10 time speedup