diff core/tools/machine_learning/mlr_repeat_YX_by_rating.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/tools/machine_learning/mlr_repeat_YX_by_rating.m	Tue Feb 10 15:05:51 2015 +0000
@@ -0,0 +1,32 @@
+function [Yout, Xout] = mlr_repeat_YX_by_rating(Y, X, weights)
+% [Yout, Xout] = mlr_repeat_YX_by_rating(Y, X, weights)
+% 
+% repeats the data in X and Y according to the weights specified
+% in weights or Y(:,3)
+
+cprint(2, 'Repeating data for weighted learning');
+if nargin == 2
+    weights = cell2mat(Y(:,3));
+end
+
+Yout = Y(:,1:2);
+
+valid = ~(cellfun(@isempty, Y(:,1)) | cellfun(@isempty, Y(:,2)));
+
+for i = 1:size(Y, 1)
+    if valid(i)
+        for j = 2:weights(i)
+            Yout(end + 1, :) = Y(i, 1:2);
+        end
+    end
+end
+
+Xout = zeros(size(X,1), size(Y,1));
+Xout(:,1:size(X,2)) = X;
+for i = 1:size(Y, 1)
+    if valid(i)
+        for j = 2:weights(i)
+            Xout(:,end+1) = X(:,i);
+        end
+    end
+end
\ No newline at end of file