source: prextra/gendatw.m @ 72

Last change on this file since 72 was 5, checked in by bduin, 14 years ago
File size: 808 bytes
RevLine 
[5]1%GENDATW Sample dataset by given weigths
2%
3%   B = GENDATW(A,V,N)
4%
5% INPUT
6%   A    Dataset
7%   V    Vector with weigths for each object in A
8%   N    Number of objects to be generated (default size A);
9%
10% OUTPUT
11%   B    Dataset
12%
13% DESCRIPTION
14% The dataset A is sampled using the weigths in V as a prior distribution.
15
16function b = gendatw(a,v,n)
17
18isdataset(a);
19if nargin < 3, n  = size(a,1); end
20
21v = v./sum(v);
22if any(v<0)
23    error('Weights should be positive');
24end
25
26mins = 0;
27nn = 0;
28while(mins < 2)
29        N = genclass(n,v);
30        L = [];
31        while any(N > 0)
32            L = [L find(N > 0)];
33            N = N-1;
34        end
35        b = a(L,:);
36        mins = min(classsizes(b));
37        nn = nn + 1;
38        if nn > 100
39                error('Problems with weighted subsampling. Please enlarge training set.')
40        end
41end
42
43return
44
Note: See TracBrowser for help on using the repository browser.