def test_stochastic_training_regression_ensemble_model(self):
        """
        regression model is deterministic (default) but the forecasting models are
        probabilistic and they can be sampled to train the regression model.
        """
        quantiles = [0.25, 0.5, 0.75]

        # cannot sample deterministic forecasting models
        with pytest.raises(ValueError):
            RegressionEnsembleModel(
                forecasting_models=[
                    self.get_deterministic_global_model(lags=[-1, -3]),
                    self.get_deterministic_global_model(lags=[-2, -4]),
                ],
                regression_train_n_points=50,
                regression_train_num_samples=500,
            )

        # must use appropriate reduction method
        with pytest.raises(ValueError):
            RegressionEnsembleModel(
                forecasting_models=[
                    self.get_probabilistic_global_model(
                        lags=[-1, -3], quantiles=quantiles
                    ),
                    self.get_probabilistic_global_model(
                        lags=[-2, -4], quantiles=quantiles
                    ),
                ],
                regression_train_n_points=50,
                regression_train_num_samples=500,
                regression_train_samples_reduction="wrong",
            )

        # by default, does not reduce samples and convert them to components
        ensemble_model_mean = RegressionEnsembleModel(
            forecasting_models=[
                self.get_probabilistic_global_model(lags=[-1, -3], quantiles=quantiles),
                self.get_probabilistic_global_model(lags=[-2, -4], quantiles=quantiles),
            ],
            regression_train_n_points=50,
            regression_train_num_samples=500,
            regression_train_samples_reduction="mean",
        )

        ensemble_model_median = RegressionEnsembleModel(
            forecasting_models=[
                self.get_probabilistic_global_model(lags=[-1, -3], quantiles=quantiles),
                self.get_probabilistic_global_model(lags=[-2, -4], quantiles=quantiles),
            ],
            regression_train_n_points=50,
            regression_train_num_samples=500,
        )
        assert ensemble_model_median.train_samples_reduction == "median"

        ensemble_model_0_5_quantile = RegressionEnsembleModel(
            forecasting_models=[
                self.get_probabilistic_global_model(lags=[-1, -3], quantiles=quantiles),
                self.get_probabilistic_global_model(lags=[-2, -4], quantiles=quantiles),
            ],
            regression_train_n_points=50,
            regression_train_num_samples=500,
            regression_train_samples_reduction=0.5,
        )

        train, val = self.ts_sum1.split_after(0.9)
        ensemble_model_mean.fit(train)
        ensemble_model_median.fit(train)
        ensemble_model_0_5_quantile.fit(train)

        pred_mean_training = ensemble_model_mean.predict(len(val))
        pred_median_training = ensemble_model_median.predict(len(val))
        pred_0_5_qt_training = ensemble_model_0_5_quantile.predict(len(val))

        assert pred_median_training == pred_0_5_qt_training
        assert (
            pred_mean_training.all_values().shape
            == pred_median_training.all_values().shape
        )

        # deterministic regression model -> deterministic ensemble
        with pytest.raises(ValueError):
            ensemble_model_mean.predict(len(val), num_samples=100)
        with pytest.raises(ValueError):
            ensemble_model_median.predict(len(val), num_samples=100)
        with pytest.raises(ValueError):
            ensemble_model_0_5_quantile.predict(len(val), num_samples=100)

        # possible to use very small regression_train_num_samples
        ensemble_model_mean_1_sample = RegressionEnsembleModel(
            forecasting_models=[
                self.get_probabilistic_global_model(lags=[-1, -3], quantiles=quantiles),
                self.get_probabilistic_global_model(lags=[-2, -4], quantiles=quantiles),
            ],
            regression_train_n_points=50,
            regression_train_num_samples=1,
        )
        ensemble_model_mean_1_sample.fit(train)
        ensemble_model_mean_1_sample.predict(len(val))

        # multi-series support
        ensemble_model_median.fit([train, train + 100])
        ensemble_model_mean.predict(len(val), series=train)

        regression model is deterministic (default) but the forecasting models are
        probabilistic and they can be sampled to train the regression model.
        
darts/tests/models/forecasting/test_regression_ensemble_model.py