code: def mixture_of_experts(networks, gating_layer=None):
      """
      Generates mixture of experts architecture from the set of
      networks that has the same input and output shapes.
  
      Mixture of experts learns to how to mix results from different
      networks in order to get better performances. It adds gating layer
      that using input data tries to figure out which of the networks
      will make better contribution to the final result. The final result
      mixes from all networks using different weights. The higher the weight
      the larger contribution from the individual layer.
  
      Parameters
      ----------
      networks : list of networks/layers
  
      gating_layer : None or layer
          In case if value equal to `None` that the following layer
          will be created.
  
          .. code-block:: python
  
              gating_layer = layers.Softmax(len(networks))
  
          Output from the gating layer should be 1D and equal to
          the number of networks.
  
      Raises
      ------
      ValueError
          In case if there is some problem with input networks
          or custom gating layer.
  
      Returns
      -------
      network
          Mixture of experts network that combine all networks into
          single one and adds gating layer to it.
  
      Examples
      --------
      >>> from neupy import algorithms, architectures
      >>> from neupy.layers import *
      >>>
      >>> network = architectures.mixture_of_experts([
      ...     join(
      ...         Input(10),
      ...         Relu(5),
      ...     ),
      ...     join(
      ...         Input(10),
      ...         Relu(33),
      ...         Relu(5),
      ...     ),
      ...     join(
      ...         Input(10),
      ...         Relu(12),
      ...         Relu(25),
      ...         Relu(5),
      ...     ),
      ... ])
      >>> network
      (?, 10) -> [... 12 layers ...] -> (?, 5)
      >>>
      >>> optimizer = algorithms.Momentum(network, step=0.1)
      """
      if not isinstance(networks, (list, tuple)):
          raise ValueError("Networks should be specified as a list")
  
      for index, network in enumerate(networks):
          check_if_network_is_valid(network, index)
  
      check_if_networks_compatible(networks)
      input_shape = tf.TensorShape(None)
  
      for network in networks:
          input_shape = input_shape.merge_with(network.input_shape)
  
      n_layers_to_combine = len(networks)
      n_features = input_shape[1].value
  
      if n_features is None:
          raise ValueError(
              "Cannot create mixture of experts model, because "
              "number of input features is unknown"
          )
  
      if gating_layer is None:
          gating_layer = layers.Softmax(n_layers_to_combine)
  
      if not isinstance(gating_layer, layers.BaseLayer):
          raise ValueError(
              "Invalid type for gating layer. Type: {}"
              "".format(type(gating_layer))
          )
  
      return layers.join(
          layers.Input(n_features),
          # Note: Gating network should be specified
          # as a first parameter.
          layers.parallel(*as_tuple(gating_layer, networks)),
          layers.GatedAverage(),
      )
  
imports: import tensorflow
  from neupy import layers
  from neupy.utils import tf_utils, as_tuple
  from neupy.layers.base import BaseGraph
label_desc: Use image node_id 3 for calling a global function with example usage: mixture_of_experts(networks, gating_layer) and returns: layers