Line | |
---|
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 |
|
---|
16 | function b = gendatw(a,v,n)
|
---|
17 |
|
---|
18 | isdataset(a);
|
---|
19 | if nargin < 3, n = size(a,1); end
|
---|
20 |
|
---|
21 | v = v./sum(v);
|
---|
22 | if any(v<0)
|
---|
23 | error('Weights should be positive');
|
---|
24 | end
|
---|
25 |
|
---|
26 | mins = 0;
|
---|
27 | nn = 0;
|
---|
28 | while(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
|
---|
41 | end
|
---|
42 |
|
---|
43 | return
|
---|
44 |
|
---|
Note: See
TracBrowser
for help on using the repository browser.