用python 将公式\left\langle\boldsymbol{\varphi}{k}\right\rangle=\left(\left\langle\alpha{k}\right\rangle \mathbf{I}+\sum_{n=1}^{N}\left\langle z_{n k}\right\rangle\left\langle\lambda_{k}\right\rangle \tilde{\boldsymbol{x}}{n} \tilde{\boldsymbol{x}}{n}^{\mathrm{T}}\right)^{-1}\left(\sum_{n=1}^{N}\left\langle z_{n k}\right\rangle\left\langle\lambda_{k}\right\rangle y_{n} \tilde{\boldsymbol{x}}_{n}\right) ,转换成代码
时间: 2023-02-28 10:24:53 浏览: 79
主要总结了Markdown常用语法,包括文字、公式、符号、矩阵等
下面是用Python实现该公式的代码:
```
import numpy as np
def formula(alpha, z, lambd, x, y, N):
I = np.identity(len(x[0]))
sum_z_lambda_x = np.zeros((len(x[0]), len(x[0])))
sum_z_lambda_y = np.zeros(len(x[0]))
for n in range(N):
sum_z_lambda_x += z[n] * lambd * np.dot(np.array([x[n]]).T, np.array([x[n]]))
sum_z_lambda_y += z[n] * lambd * y[n] * np.array([x[n]])
phi = np.dot(np.linalg.inv(alpha * I + sum_z_lambda_x), sum_z_lambda_y)
return phi
```
阅读全文