class_docstr: Represent relation-weights as a linear combination of base transformation matrices.
  
  The basis decomposition represents the relation-specific transformation matrices
  as a weighted combination of base matrices, $\{\mathbf{B}_i^l\}_{i=1}^{B}$, i.e.,
  
  .. math::
      \mathbf{W}_r^l = \sum \limits_{b=1}^B \alpha_{rb} \mathbf{B}^l_i
  
  The implementation uses a reshaping of the adjacency tensor into a sparse matrix to support message passing by a
  single sparse matrix multiplication, cf. [thanapalasingam2021]_.
  
  .. seealso ::
      https://github.com/thiviyanT/torch-rgcn/blob/267faffd09a441d902c483a8c130410c72910e90/torch_rgcn/layers.py#L450-L565
class_docstr_tok: ["Represent","relation-weights","as","a","linear","combination","of","base","transformation","matrices",".","The","basis","decomposition","represents","the","relation-specific","transformation","matrices","as","a","weighted","combination","of","base","matrices",",","$","\\","{","\\mathbf","{","B","}","_i^l\\","}","_","{","i=1","}","^","{","B","}","$",",","i.e.",",","..","math",":",":","\\mathbf","{","W","}","_r^l","=","\\sum","\\limits_","{","b=1","}","^B","\\alpha_","{","rb","}","\\mathbf","{","B","}","^l_i","The","implementation","uses","a","reshaping","of","the","adjacency","tensor","into","a","sparse","matrix","to","support","message","passing","by","a","single","sparse","matrix","multiplication",",","cf",".","[","thanapalasingam2021","]","_",".","..","seealso",":",":","https",":","\/\/github.com\/thiviyanT\/torch-rgcn\/blob\/267faffd09a441d902c483a8c130410c72910e90\/torch_rgcn\/layers.py","#","L450-L565"]
docstr: Initialize the bases decomposition.
  
  :param num_bases:
      the number of bases
  :param kwargs:
      additional keyword-based parameters passed to :meth:`Decomposition.__init__`
code: def __init__(self, num_bases: Optional[int] = None, **kwargs):
      """
      Initialize the bases decomposition.
  
      :param num_bases:
          the number of bases
      :param kwargs:
          additional keyword-based parameters passed to :meth:`Decomposition.__init__`
      """
      super().__init__(**kwargs)
  
      # Heuristic for default value
      if num_bases is None:
          num_bases = math.ceil(math.sqrt(self.num_relations))
          logger.info(
              f"No num_bases was provided. Using sqrt(num_relations)={num_bases}."
          )
  
      if num_bases > self.num_relations:
          logger.warning(
              f"The number of bases ({num_bases}) exceeds the number of relations ({self.num_relations})."
          )
  
      self.relation_representations = LowRankRepresentation(
          max_id=self.num_relations,
          shape=(self.input_dim, self.output_dim),
          num_bases=num_bases,
          weight_initializer=uniform_norm_p1_,
          initializer=nn.init.xavier_normal_,
      )
  
imports: import logging
  import math
  from abc import ABC, abstractmethod
  from typing import Any, Iterable, Mapping, Optional, Sequence
  import torch
  from class_resolver import ClassResolver, Hint, HintOrType, OptionalKwargs
  from class_resolver.contrib.torch import activation_resolver
  from docdata import parse_docdata
  from torch import nn
  from .init import uniform_norm_p1_, xavier_normal_
  from .representation import LowRankRepresentation, Representation
  from .utils import ShapeError, adjacency_tensor_to_stacked_matrix, use_horizontal_stacking
  from .weighting import EdgeWeighting, edge_weight_resolver
  from ..triples import CoreTriplesFactory
  from ..utils import ExtraReprMixin, einsum
label_desc: Use image node_id 1 to create a new BasesDecomposition object from inherited base classes: Decomposition with example: obj = BasesDecomposition(num_bases)