def test_create_line_hyp_space(): n_features = 2 line_hyp_space_one = create_line_hyp_space(n_features) true_hyp_space_one = np.array([[1, 0], [0, 1], [1, 1]]) assert np.array_equal(line_hyp_space_one, true_hyp_space_one) n_features = 4 line_hyp_space_two = create_line_hyp_space(n_features) true_hyp_space_two = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1], [1, 1, 1, 0], [0, 1, 1, 1], [1, 1, 1, 1]]) assert np.array_equal(line_hyp_space_two, true_hyp_space_two)
def __init__(self, n_features=3, hyp_space_type="boundary", sampling="max", true_hyp=None): assert(n_features > 0) self.d = [] # observed data points self.n_obs = 0 # number of observed data points self.n_labels = 2 # number of possible y values self.n_features = n_features if hyp_space_type == "boundary": self.hyp_space = utils.create_boundary_hyp_space(self.n_features) elif hyp_space_type == "line": self.hyp_space = utils.create_line_hyp_space(self.n_features) self.n_hyp = len(self.hyp_space) self.prior = np.array([1 / self.n_hyp for _ in range(self.n_hyp)]) self.posterior = self.prior if true_hyp is not None: self.true_hyp = true_hyp self.true_hyp_idx = \ np.where([np.all(true_hyp == hyp) for hyp in self.hyp_space])[0] else: self.true_hyp_idx = np.random.randint(self.n_hyp) self.true_hyp = self.hyp_space[self.true_hyp_idx] self.posterior_true_hyp = np.ones(self.n_features + 1) self.posterior_true_hyp[0] = 1 / self.n_hyp self.first_feature_prob = np.zeros(n_features) self.sampling = sampling
def __init__(self, n_features=3, hyp_space_type="boundary", sampling="max", true_hyp=None): self.n_features = n_features self.n_labels = 2 self.observed_features = np.array([]) self.observed_labels = np.array([]) self.n_obs = 0 self.features = np.arange(self.n_features) self.labels = np.arange(self.n_labels) if hyp_space_type == "boundary": self.hyp_space = utils.create_boundary_hyp_space(self.n_features) elif hyp_space_type == "line": self.hyp_space = utils.create_line_hyp_space(self.n_features) self.n_hyp = len(self.hyp_space) self.learner_prior = (1 / self.n_hyp) * \ np.ones((self.n_hyp, self.n_features, self.n_labels)) self.self_teaching_posterior = np.zeros( (self.n_hyp, self.n_features, self.n_labels)) self.learner_posterior = self.learner_prior self.sampling = sampling if true_hyp is not None: self.true_hyp = true_hyp self.true_hyp_idx = \ np.where([np.all(true_hyp == hyp) for hyp in self.hyp_space])[0] else: self.true_hyp_idx = np.random.randint(self.n_hyp) self.true_hyp = self.hyp_space[self.true_hyp_idx] self.posterior_true_hyp = np.ones(self.n_features + 1) self.posterior_true_hyp[0] = 1 / self.n_hyp self.first_feature_prob = np.zeros(self.n_features)
def __init__(self, n_features=3, hyp_space_type="boundary"): assert(n_features > 0) self.n_features = n_features self.n_labels = 2 # number of possible y values if hyp_space_type == "boundary": self.hyp_space = utils.create_boundary_hyp_space(self.n_features) elif hyp_space_type == "line": self.hyp_space = utils.create_line_hyp_space(self.n_features) self.n_hyp = len(self.hyp_space) self.prior = 1 / self.n_hyp * \ np.ones((self.n_hyp, self.n_features, self.n_labels))
def __init__(self, n_features=3, hyp_space_type="boundary"): if hyp_space_type == "boundary": self.hyp_space = utils.create_boundary_hyp_space(n_features) elif hyp_space_type == "line": self.hyp_space = utils.create_line_hyp_space(n_features) self.n_features = n_features self.n_labels = 2 self.features = np.arange(self.n_features) self.labels = np.arange(self.n_labels) self.n_hyp = len(self.hyp_space) self.learner_prior = (1 / self.n_hyp) * \ np.ones((self.n_hyp, self.n_features, self.n_labels)) self.self_teaching_posterior = np.zeros( (self.n_hyp, self.n_features, self.n_labels)) self.learner_posterior = self.learner_prior