def predict(self, data): o = self.target_learner.predict(data) is_target = data.is_target o_source = self.source_learner.predict(data.get_subset(is_target)) if not data.is_regression: assert o.fu.ndim == 2 else: assert o.fu.ndim == 1 assert o_source.fu.ndim == 1 o.fu = o.fu.reshape((o.fu.size,1)) o_source.fu = o_source.fu.reshape((o_source.fu.size,1)) fu_orig = o.fu for i in range(o.fu.shape[1]): fu_t = o.fu[is_target,i] fu_s = o_source.fu[:,i] o.fu[is_target,i] = self.a*fu_s + (1-self.a)*fu_t #o.fu[is_target] = np.multiply(o.fu[is_target],(1-self.g)) + np.multiply(self.g,o_source.fu) if data.is_regression: o.y = o.fu else: fu = array_functions.replace_invalid(o.fu,0,1) fu = array_functions.normalize_rows(fu) o.fu = fu o.y = fu.argmax(1) assert not (np.isnan(o.y)).any() assert not (np.isnan(o.fu)).any() return o
def predict(self, data): o = self.target_learner.predict(data) is_target = data.is_target o_source = self.source_learner.predict(data.get_subset(is_target)) if not data.is_regression: assert o.fu.ndim == 2 else: assert np.squeeze(o.fu).ndim == 1 assert np.squeeze(o_source.fu).ndim == 1 o.fu = o.fu.reshape((o.fu.size,1)) o_source.fu = o_source.fu.reshape((o_source.fu.size,1)) for i in range(o.fu.shape[1]): fu_t = o.fu[is_target,i] fu_s = o_source.fu[:,i] if self.g_learner is not None: pred = self.g_learner.combine_predictions(data.x[is_target,:],fu_s,fu_t) if data.x.shape[1] == 1: x = scipy.linspace(data.x.min(),data.x.max(),100) x = array_functions.vec_to_2d(x) g = self.g_learner.predict_g(x) o.x = x o.g = g else: pred = np.multiply(fu_t,1-self.g) + np.multiply(fu_s,self.g) o.fu[is_target,i] = pred #o.fu[is_target] = np.multiply(o.fu[is_target],(1-self.g)) + np.multiply(self.g,o_source.fu) if data.is_regression: o.y = o.fu else: fu = array_functions.replace_invalid(o.fu,0,1) fu = array_functions.normalize_rows(fu) o.fu = fu o.y = fu.argmax(1) if data.x.shape[1] == 1: x = array_functions.vec_to_2d(scipy.linspace(data.x.min(),data.x.max(),100)) o.linspace_x = x o.linspace_g = self.g_learner.predict_g(x) assert not (np.isnan(o.y)).any() assert not (np.isnan(o.fu)).any() return o