-
Notifications
You must be signed in to change notification settings - Fork 2
/
StructSampler.m
54 lines (49 loc) · 1.63 KB
/
StructSampler.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
classdef StructSampler < Sampler & handle
%StructSampler sample (x,y) values from the struct given by the mat arg
% Required Arguments:
% - mat - struct with fields xPos, xUnlabeled
% xPos : n x d matrix of features for each positive instance
% xUnlabeled : m x d matrix of features for each unlabeled
% instance
%
% Optional Arguments:
% - nBootstraps : number of bootstrapped samples to return from mat
% default : 0 (just return original data)
properties
mat
n
d
m
nBootstraps
end
methods
function obj = StructSampler(mat,varargin)
%StructSampler Construct an instance of this class
obj.mat = mat;
[obj.n, obj.d] = size(mat.xPos);
[obj.m,~] = size(mat.xUnlabeled);
p= inputParser;
addOptional(p,'nBootstraps', 0);
parse(p,varargin{:});
obj.nBootstraps = p.Results.nBootstraps;
end
function [xP,xU,alpha] = getSample(obj,~)
% Return dummy for compatability
alpha = -1;
if obj.nBootstraps > 0
xP = datasample(obj.mat.xPos,obj.n);
xU = datasample(obj.mat.xUnlabeled, obj.m);
else
xP = obj.mat.xPos;
xU = obj.mat.xUnlabeled;
end
end
function [len] = getLength(obj)
if obj.nBootstraps == 0
len = 1;
else
len = obj.nBootstraps;
end
end
end
end