【问题标题】:Create N-Dimensional normal distribution from single ones (in python)从单个创建 N 维正态分布(在 python 中)
【发布时间】:2016-11-06 06:34:13
【问题描述】:

有没有通用的解决方案?您必须将它们相乘,但很难实现。

对于二维情况,您可以使用表示单个正态分布的两个向量的outer product

【问题讨论】:

    标签: python multidimensional-array distribution normal-distribution gauss


    【解决方案1】:

    一般解决方案涉及Cholesky decomposition of the variance/covariance matrix。 Cholesky 分解可通过numpy 在 Python 中使用。

    【讨论】:

      【解决方案2】:

      我找到了一个可能的解决方案并在 2d 案例中进行了测试。看起来不错,但我会在更多情况下进行测试:

      def normal_nd(*priors):
          # Trivial case
          if len(priors) == 1:
              return priors
      
          # General case
          shape = []
          for item in priors:
              shape.append(len(item))
          n = np.ones(shape)
      
          for idx, _ in np.ndenumerate(n):
              for ax, element in enumerate(idx):
                  n[idx] *= priors[ax][element]
      
          return n
      

      编辑: 我也在一般情况下对其进行了测试,看来这是一个正确的解决方案! :)

      【讨论】:

        猜你喜欢
        • 2020-06-25
        • 2022-01-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-12
        • 2018-12-10
        相关资源
        最近更新 更多