help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Optimisation / parallelisation Problems


From: somealias
Subject: Optimisation / parallelisation Problems
Date: Thu, 19 Apr 2012 22:43:09 -0700 (PDT)

Hi all,

I'm running some machine learning experiments with Octave. I have optimised
(e.g. used sparse matrices, pre-allocated etc.) and vectorised most of my
code but want to improve the performance of some loops. I have tried
vectorising and parallelising (pararrayfun) these loops but without success.
I need some help!

Here's an example of what I'm trying to do.

---
X = rand(10,20); % examples
y = rand(10,1); % labels
[m, n] = size(X); % # examples and dimensions
increment = 1; % # of examples incremented per iteration 
iterations = 5; % # of times we randomly pick the examples

% Train the model incrementally
% e.g. increment = 1, train on 1 example, then 2, then 3 etc...
for i = increment:increment:m
        % Initialise running totals for the current # of examples  
        errorTrainTotal = 0;
        errorValTotal = 0;
        
        % randomly select the examples used for training
        % e.g. iterations = 5, then we do this 5 times
        for j = 1:iterations
                % Create matrices of randomly selected examples from the 
training set 
            shuffle = randperm(m);

                % Initialise the new random training matrices
                X_random = X(shuffle(1:i),:);
                y_random = y(shuffle(1:i));

                % Learn the model parameters
                theta = trainLogisticReg(X_random, y_random, lambda);

                % Predict the class of the training examples based on the theta 
                predictions = predict(theta, X_random);
                % Predict the class of the validation examples based on the 
theta 
                predictionsval = predict(theta, Xval);

        % Compute training and validation f-score errors
            errorTrainTotal = errorTrainTotal + (1 - fscore(predictions,
y_random));
            errorValTotal = errorValTotal + (1 - fscore(predictionsval, yval));
        end

        % Calculate the training and validation errors for the current # of
examples
        errorTrain(i/increment) = errorTrainTotal / iterations;
        errorVal(i/increment) = errorValTotal / iterations;
end
---

The above code becomes slow for the large number of examples (m) in my real
dataset. I thought the best way to improve performance would be to
parallelise these loops because my other CPU cores are idle while each loop
being processed in a serial manner.

Any suggestions and comments would be greatly appreciated!

Kev

--
View this message in context: 
http://octave.1599824.n4.nabble.com/Optimisation-parallelisation-Problems-tp4572922p4572922.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]