def __init__(self, configs=MethodConfigs()): super(StackingTransfer, self).__init__(configs) #from far_transfer_methods import GraphTransferNW self.base_learner = method.SKLRidgeRegression(deepcopy(configs)) self.source_learner = method.NadarayaWatsonMethod(deepcopy(configs)) self.target_learner = method.NadarayaWatsonMethod(deepcopy(configs)) self.joint_cv = getattr(configs, 'joint_cv', False) self.only_use_source_prediction = False self.use_all_source = True self.source_only = False self.target_only = False self.just_bias = False self.linear_source = False if self.target_only or self.source_only or self.linear_source: self.joint_cv = False if self.just_bias: self.base_learner.cv_params = {'alpha': [1e16]} self.joint_cv = False if self.linear_source: self.target_learner.cv_params = {'sigma': [1]} if self.joint_cv: self.cv_params = self.base_learner.cv_params.copy() self.cv_params.update(self.target_learner.cv_params) self.base_learner.cv_params = None self.target_learner.cv_params = None sub_configs = deepcopy(configs) #self.source_learner = method.NadarayaWatsonKNNMethod(deepcopy(sub_configs)) #self.target_learner = method.NadarayaWatsonKNNMethod(deepcopy(sub_configs)) self.use_validation = configs.use_validation
def __init__(self, configs=None): super(GraphTransferNW, self).__init__(configs) self.cv_params = dict() step = 2 self.use_rbf = True if self.use_rbf: self.cv_params['C'] = self.create_cv_params(-4, 5, step, append_zero=True) self.cv_params['sigma_nw'] = self.create_cv_params(-5, 6, 1) self.cv_params['sigma_tr'] = self.create_cv_params(-5, 6, 1) else: self.cv_params['C'] = self.create_cv_params(-5, 10, step, append_zero=True) self.cv_params['sigma_nw'] = np.asarray( [1, .5, .25, .1, .05, .025, .01]) self.cv_params['sigma_tr'] = np.asarray( [1, .5, .25, .1, .05, .025]) self.use_prediction_graph_sparsification = False self.k_sparsification = 25 self.use_prediction_graph_radius = True self.radius = .1 if self.use_prediction_graph_radius: self.cv_params['radius'] = np.asarray([1, .3, .1, .05]) self.use_oracle_graph = False self.oracle_guidance = getattr(configs, 'oracle_guidance', None) self.oracle_guidance_binary = getattr(configs, 'oracle_guidance_binary', True) self.nystrom_percentage = getattr(configs, 'nystrom_percentage') self.sigma_nw = None self.C = None self.sigma_tr = None self.just_nw = getattr(configs, 'just_nw', False) if self.just_nw: del self.cv_params['sigma_tr'] del self.cv_params['C'] self.C = 0 self.sigma_tr = 0 configs = deepcopy(configs) self.source_learner = method.NadarayaWatsonMethod(deepcopy(configs)) self.source_learner.configs.source_labels = None self.source_learner.configs.target_labels = None self.transform = StandardScaler() self.predict_sample = None self.use_validation = getattr(configs, 'use_validation', False) self.nw_learner = method.NadarayaWatsonMethod(deepcopy(configs)) self.nw_learner.configs.source_labels = None self.nw_learner.configs.target_labels = None self.source_learner.configs.use_validation = False self.nw_learner.configs.use_validation = False self.sampled_inds = None self.predict_time = None
def __init__(self, configs=MethodConfigs()): super(ReweightedTransfer, self).__init__(configs) self.target_kde = None self.source_kde = None self.kde_bandwidths = 10**np.asarray(range(-6, 6), dtype='float64') c = deepcopy(configs) c.temp_dir = None self.base_learner = method.NadarayaWatsonMethod(configs) self.cv_params = {'B': np.asarray([2, 4, 8, 16, 32])} self.base_learner_cv_keys = []
def __init__(self, configs=None): super(GraphTransfer, self).__init__(configs) self.cv_params = dict() self.alpha = 0 self.just_transfer = getattr(configs, 'just_transfer', False) self.just_target = getattr(configs, 'just_target', False) self.cv_params['alpha'] = [0, .2, .4, .6, .8, 1] configs = deepcopy(configs) self.source_learner = method.NadarayaWatsonMethod(deepcopy(configs)) self.nw_transfer = method.NadarayaWatsonMethod(deepcopy(configs)) self.nw_target = method.NadarayaWatsonMethod(deepcopy(configs)) self.nw_target.quiet = True assert not (self.just_transfer and self.just_target) if self.just_transfer: del self.cv_params['alpha'] self.alpha = 0 if self.just_target: del self.cv_params['alpha'] self.alpha = 1
def __init__(self, configs=MethodConfigs()): super(ModelSelectionTransfer, self).__init__(configs) self.methods.append(TargetTranfer(configs)) self.methods.append(FuseTransfer(configs)) for m in self.methods: m.base_learner = method.NadarayaWatsonMethod(configs)
def __init__(self, configs=MethodConfigs()): super(MixedFeatureGuidanceMethod, self).__init__(configs) #self.cv_params['C'] = self.create_cv_params(-5, 5, append_zero=True) self.cv_params['C'] = self.create_cv_params(-5, 5, append_zero=False) #self.cv_params['C2'] = self.create_cv_params(-8, 8, append_zero=True, prepend_inf=True) self.cv_params['C2'] = self.create_cv_params(-8, 8, append_zero=True, prepend_inf=False) #self.cv_params['C2'] = np.asarray([np.inf]) self.cv_params['C3'] = self.create_cv_params(-5, 5, append_zero=True) self.transform = StandardScaler() #self.preprocessor = preprocessing.BasisQuadraticFewPreprocessor() if hasattr(configs, 'method'): self.method = configs.method else: self.method = MixedFeatureGuidanceMethod.METHOD_RELATIVE #self.method = MixedFeatureGuidanceMethod.METHOD_RIDGE #self.method = MixedFeatureGuidanceMethod.METHOD_ORACLE #self.method = MixedFeatureGuidanceMethod.METHOD_ORACLE_SPARSITY self.use_sign = getattr(configs, 'use_sign', True) self.use_corr = getattr(configs, 'use_corr', False) self.use_training_corr = getattr(configs, 'use_training_corr', False) self.use_oracle = getattr(configs, 'use_oracle', False) self.use_nonneg = getattr(configs, 'use_nonneg', False) self.use_stacking = getattr(configs, 'use_stacking', False) self.can_use_test_error_for_model_selection = True self.use_test_error_for_model_selection = configs.use_test_error_for_model_selection self.use_validation = configs.use_validation self.num_random_pairs = getattr(configs, 'num_random_pairs', 0) self.num_random_signs = getattr(configs, 'num_random_signs', 0) self.disable_relaxed_guidance = getattr(configs, 'disable_relaxed_guidance', False) self.disable_tikhonov = getattr(configs, 'disable_tikhonov', False) self.random_guidance = getattr(configs, 'random_guidance', False) self.use_transfer = getattr(configs, 'use_transfer', False) self.w = None self.b = None self.stacking_method = method.NadarayaWatsonMethod(configs) self.trained_stacked_methods = list() self.cvx_method = getattr(configs, 'cvx_method', 'SCS') self.num_features = getattr(configs, 'num_features', -1) self.use_l1 = getattr(configs, 'use_l1', False) self.solve_dual = getattr(configs, 'solve_dual', False) self.mean_b = getattr(configs, 'mean_b', False) self.solve_scipy = getattr(configs, 'solve_scipy', False) self.use_pairwise_same_signs = getattr(configs, 'use_pairwise_same_signs', False) self.use_hinge_primal = getattr(configs, 'use_hinge_primal', False) self.fix_C2 = getattr(configs, 'fix_C2', False) self.fix_C3 = getattr(configs, 'fix_C3', False) if self.method == MixedFeatureGuidanceMethod.METHOD_HARD_CONSTRAINT: self.configs.scipy_opt_method = 'SLSQP' if self.method in MixedFeatureGuidanceMethod.METHODS_UNIFORM_C: self.C = 1 del self.cv_params['C'] if (self.method in MixedFeatureGuidanceMethod.METHODS_NO_C3 and not self.use_hinge_primal) or self.fix_C3: self.C3 = 1 del self.cv_params['C3'] if self.method in MixedFeatureGuidanceMethod.METHODS_NO_C2 or self.fix_C2: self.C2 = 1 del self.cv_params['C2'] if self.disable_relaxed_guidance: self.C2 = np.inf if 'C2' in self.cv_params: del self.cv_params['C2'] if self.disable_tikhonov: self.C = 0 if 'C' in self.cv_params: del self.cv_params['C'] self.quiet = False self.pairs = None self.feats_to_constrain = None self.learner_lasso = Lasso()