code: def in_sample_ts_forecast(
      pipeline,
      input_data: Union[InputData, MultiModalData],
      horizon: int = None,
  ) -> np.array:
      """
      Method allows to make in-sample forecasting. The actual values of the time
      series, rather than the previously predicted parts of the time series,
      are used for forecasting next parts. Sources indices in input_data parameter
      will be ignored
      time series ----------------|---|---|---|
      forecast                    |---|---|---|
  
      :param pipeline: Pipeline for making time series forecasting
      :param input_data: data for prediction
      :param horizon: forecasting horizon
      :return final_forecast: array with forecast
      """
      # Divide data on samples into pre-history and validation part
      task = input_data.task
      exception_if_not_ts_task(task)
      # How many elements to the future pipeline can produce
      scope_len = task.task_params.forecast_length
      number_of_iterations = _calculate_number_of_steps(
          scope_len, horizon
      )
  
      if isinstance(input_data, InputData):
          time_series = np.array(input_data.features)
          pre_history_ts = time_series[:-horizon]
          source_len = len(pre_history_ts)
          last_index_pre_history = source_len - 1
  
          data = _update_input(
              pre_history_ts, scope_len, task, input_data.data_type
          )
      else:
          # TODO simplify
  
          data = MultiModalData()
          for data_id in input_data.keys():
              features = input_data[data_id].features
              time_series = np.array(features)
              pre_history_ts = time_series[:-horizon]
              source_len = len(pre_history_ts)
              last_index_pre_history = source_len - 1
  
              local_data = _update_input(
                  pre_history_ts,
                  scope_len,
                  task,
                  input_data[data_id].data_type,
              )
              data[data_id] = local_data
  
      # Calculate intervals
      intervals = _calculate_intervals(
          last_index_pre_history, number_of_iterations, scope_len
      )
  
      # Make forecast iteratively moving throw the horizon
      final_forecast = []
      for _, border in zip(range(0, number_of_iterations), intervals):
          iter_predict = pipeline.predict(input_data=data)
          iter_predict = np.ravel(np.array(iter_predict.predict))
          final_forecast.append(iter_predict)
  
          if isinstance(input_data, InputData):
              # Add actual values to the historical data - update it
              pre_history_ts = time_series[: border + 1]
              # Prepare InputData for next iteration
              data = _update_input(
                  pre_history_ts, scope_len, task, input_data.data_type
              )
          else:
              # TODO simplify
              data = MultiModalData()
              for data_id in input_data.keys():
                  features = input_data[data_id].features
                  time_series = np.array(features)
                  pre_history_ts = time_series[: border + 1]
                  local_data = _update_input(
                      pre_history_ts,
                      scope_len,
                      task,
                      input_data[data_id].data_type,
                  )
                  data[data_id] = local_data
  
      # Create output data
      final_forecast = np.ravel(np.array(final_forecast))
      # Clip the forecast if it is necessary
      final_forecast = final_forecast[:horizon]
      return final_forecast
  
file_path: FEDOT/fedot/core/pipelines/ts_wrappers.py
imports: import math
  from copy import copy
  from typing import Union, Optional
  import numpy
  from fedot.core.data.data import InputData, OutputData
  from fedot.core.data.multi_modal import MultiModalData
  from fedot.core.operations.evaluation.operation_implementations.data_operations.ts_transformations import ts_to_table
  from fedot.core.pipelines.pipeline import Pipeline
  from fedot.core.repository.dataset_types import DataTypesEnum
  from fedot.core.repository.tasks import TaskTypesEnum
label_desc: Use image node_id 2 for calling a global function with example usage: in_sample_ts_forecast(pipeline, input_data, horizon) and returns: final_forecast