def _apply_default_pipeline_settings(pipeline):
        from autoPyTorch.pipeline.nodes.network_selector import NetworkSelector
        from autoPyTorch.pipeline.nodes.loss_module_selector import LossModuleSelector
        from autoPyTorch.pipeline.nodes.metric_selector import MetricSelector
        from autoPyTorch.pipeline.nodes.train_node import TrainNode
        from autoPyTorch.pipeline.nodes.resampling_strategy_selector import ResamplingStrategySelector
        from autoPyTorch.pipeline.nodes.cross_validation import CrossValidation
        from autoPyTorch.pipeline.nodes.one_hot_encoding import OneHotEncoding
        from autoPyTorch.pipeline.nodes.resampling_strategy_selector import ResamplingStrategySelector
        from autoPyTorch.components.preprocessing.resampling import RandomOverSamplingWithReplacement, RandomUnderSamplingWithReplacement, SMOTE, \
            TargetSizeStrategyAverageSample, TargetSizeStrategyDownsample, TargetSizeStrategyMedianSample, TargetSizeStrategyUpsample

        import torch.nn as nn
        from autoPyTorch.components.metrics.standard_metrics import accuracy
        from autoPyTorch.components.preprocessing.loss_weight_strategies import LossWeightStrategyWeighted

        AutoNetFeatureData._apply_default_pipeline_settings(pipeline)

        net_selector = pipeline[NetworkSelector.get_name()]
        net_selector.add_final_activation('softmax', nn.Softmax(1))

        loss_selector = pipeline[LossModuleSelector.get_name()]
        loss_selector.add_loss_module('cross_entropy', nn.CrossEntropyLoss,
                                      None, True)
        loss_selector.add_loss_module('cross_entropy_weighted',
                                      nn.CrossEntropyLoss,
                                      LossWeightStrategyWeighted(), True)

        metric_selector = pipeline[MetricSelector.get_name()]
        metric_selector.add_metric('accuracy', accuracy)

        resample_selector = pipeline[ResamplingStrategySelector.get_name()]
        resample_selector.add_over_sampling_method(
            'random', RandomOverSamplingWithReplacement)
        resample_selector.add_over_sampling_method('smote', SMOTE)
        resample_selector.add_under_sampling_method(
            'random', RandomUnderSamplingWithReplacement)
        resample_selector.add_target_size_strategy('upsample',
                                                   TargetSizeStrategyUpsample)
        resample_selector.add_target_size_strategy(
            'downsample', TargetSizeStrategyDownsample)
        resample_selector.add_target_size_strategy(
            'average', TargetSizeStrategyAverageSample)
        resample_selector.add_target_size_strategy(
            'median', TargetSizeStrategyMedianSample)

        train_node = pipeline[TrainNode.get_name()]
        train_node.default_minimize_value = False

        cv = pipeline[CrossValidation.get_name()]
        cv.use_stratified_cv_split_default = True

        one_hot_encoding_node = pipeline[OneHotEncoding.get_name()]
        one_hot_encoding_node.encode_Y = True

        return pipeline
    def get_default_pipeline(cls):
        from autoPyTorch.pipeline.base.pipeline import Pipeline
        from autoPyTorch.pipeline.nodes.autonet_settings import AutoNetSettings
        from autoPyTorch.pipeline.nodes.optimization_algorithm import OptimizationAlgorithm
        from autoPyTorch.pipeline.nodes.cross_validation import CrossValidation
        from autoPyTorch.pipeline.nodes.imputation import Imputation
        from autoPyTorch.pipeline.nodes.normalization_strategy_selector import NormalizationStrategySelector
        from autoPyTorch.pipeline.nodes.one_hot_encoding import OneHotEncoding
        from autoPyTorch.pipeline.nodes.preprocessor_selector import PreprocessorSelector
        from autoPyTorch.pipeline.nodes.resampling_strategy_selector import ResamplingStrategySelector
        from autoPyTorch.pipeline.nodes.embedding_selector import EmbeddingSelector
        from autoPyTorch.pipeline.nodes.network_selector import NetworkSelector
        from autoPyTorch.pipeline.nodes.optimizer_selector import OptimizerSelector
        from autoPyTorch.pipeline.nodes.lr_scheduler_selector import LearningrateSchedulerSelector
        from autoPyTorch.pipeline.nodes.log_functions_selector import LogFunctionsSelector
        from autoPyTorch.pipeline.nodes.metric_selector import MetricSelector
        from autoPyTorch.pipeline.nodes.loss_module_selector import LossModuleSelector
        from autoPyTorch.pipeline.nodes.train_node import TrainNode

        # build the pipeline
        pipeline = Pipeline([
            AutoNetSettings(),
            OptimizationAlgorithm([
                CrossValidation([
                    Imputation(),
                    NormalizationStrategySelector(),
                    OneHotEncoding(),
                    PreprocessorSelector(),
                    ResamplingStrategySelector(),
                    EmbeddingSelector(),
                    NetworkSelector(),
                    OptimizerSelector(),
                    LearningrateSchedulerSelector(),
                    LogFunctionsSelector(),
                    MetricSelector(),
                    LossModuleSelector(),
                    TrainNode()
                ])
            ])
        ])

        cls._apply_default_pipeline_settings(pipeline)
        return pipeline
    def test_resampling_strategy_selector_with_valid(self):
        X = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 2, 3], [4, 5, 6],
                      [7, 8, 9]])
        Y = np.array([[0, 1], [1, 0], [1, 0], [0, 1], [1, 0], [1, 0]])
        train_indices = np.array([0, 1, 2])
        valid_indices = np.array([3, 4, 5])
        hyperparameter_config = {
            ResamplingStrategySelector.get_name() + ConfigWrapper.delimiter + "over_sampling_method":
            "random_over_sampling",
            ResamplingStrategySelector.get_name() + ConfigWrapper.delimiter + "under_sampling_method":
            "random_under_sampling",
            ResamplingStrategySelector.get_name() + ConfigWrapper.delimiter + "target_size_strategy":
            "up",
        }

        resampler_node = ResamplingStrategySelector()
        resampler_node.add_over_sampling_method(
            "random_over_sampling", RandomOverSamplingWithReplacement)
        resampler_node.add_under_sampling_method(
            "random_under_sampling", RandomUnderSamplingWithReplacement)
        resampler_node.add_target_size_strategy("up",
                                                TargetSizeStrategyUpsample)

        pipeline_config = {"random_seed": 42, "shuffle": True}
        fit_result = resampler_node.fit(
            pipeline_config=pipeline_config,
            hyperparameter_config=hyperparameter_config,
            X=X,
            Y=Y,
            train_indices=train_indices,
            valid_indices=valid_indices)

        assert_array_almost_equal(sorted(fit_result['train_indices']),
                                  np.array([0, 1, 2, 3]))
        assert_array_almost_equal(sorted(fit_result['valid_indices']),
                                  np.array([4, 5, 6]))
        assert_array_almost_equal(fit_result['X'][fit_result['valid_indices']],
                                  X[valid_indices])
        assert_array_almost_equal(fit_result['Y'][fit_result['valid_indices']],
                                  Y[valid_indices])
        self.assertEqual(fit_result['X'].shape, (7, 3))
        num_0 = 0
        num_1 = 0
        for i in range(fit_result['X'][fit_result['train_indices']].shape[0]):
            x = fit_result['X'][fit_result['train_indices']][i, :]
            y = fit_result['Y'][fit_result['train_indices']][i, :]

            if np.all(y == np.array([0, 1])):
                assert_array_almost_equal(x, np.array([1, 2, 3]))
                num_0 += 1
            else:
                self.assertTrue(
                    np.all(x == np.array([4, 5, 6]))
                    or np.all(x == np.array([7, 8, 9])))
                num_1 += 1
        self.assertEqual(num_0, 2)
        self.assertEqual(num_1, 2)