🍠Python和R及Julia妊娠相关疾病生物剖析算法

1. 算法使用了矢量投影、现代优化线性代数、空间分区技术和大数据编程 2. 利用相应向量空间中标量积和欧几里得距离的紧密关系来计算 3. 使用妊娠相关疾病(先兆子痫)、健康妊娠和癌症测试算法模型 4. 使用相关性投影利用相关性和欧几里得距离之间的关系

🍪语言内容分比

🍇Python线性组合可视化

考虑 R ^2 中的两个向量 u 和 v,它们彼此独立,即不指向相同或相反的方向。因此,R ^2 中的任何向量都可以用 u 和 v 的线性组合来表示。例如,这是一个线性组合,本质上是一个线性系统。

 import matplotlib.pyplot as plt
 import numpy as np
 import sympy as sy
 ​
 sy.init_printing()
 A = sy.Matrix([[4, -2, 2], [2, 2, 10]])
 A.rref()

基础可以构建为:

其中a和b将被设置为具有规则间隔的常数,例如(2.5,5,7.5,10)。

基础的坐标以粉色网状网格表示,其中每个线段都是“新”坐标中的一个单位(如笛卡尔坐标系中的 1 )。

 fig, ax = plt.subplots(figsize=(8, 8))
 vectors = np.array(
     [[[0, 0, 4, 2]], [[0, 0, -2, 2]], [[0, 0, 2, 10]], [[0, 0, 8, 4]], [[0, 0, -6, 6]]]
 )
 colors = ["b", "b", "r", "b", "b"]
 ​
 for i in range(vectors.shape[0]):
     X, Y, U, V = zip(*vectors[i, :, :])
     ax.quiver(
         X, Y, U, V, angles="xy", scale_units="xy", color=colors[i], scale=1, alpha=0.6
     )
     ax.text(
         x=vectors[i, 0, 2],
         y=vectors[i, 0, 3],
         s="$(%.0d, %.0d)$" % (vectors[i, 0, 2], vectors[i, 0, 3]),
         fontsize=16,
     )
 ​
 points12 = np.array([[8, 4], [2, 10]])
 ax.plot(points12[:, 0], points12[:, 1], color="b", lw=3.5, alpha=0.5, ls="--")
 ​
 points34 = np.array([[-6, 6], [2, 10]])
 ax.plot(points34[:, 0], points34[:, 1], color="b", lw=3.5, alpha=0.5, ls="--")
 ​
 ax.set_xlim([-10, 10])
 ax.set_ylim([0, 10.5])
 ax.set_xlabel("x-axis", fontsize=16)
 ax.set_ylabel("y-axis", fontsize=16)
 ax.grid()
 ​
 a = np.arange(-11, 20, 1)
 x = np.arange(-11, 20, 1)
 ​
 for i in a:
     y1 = i + 0.5 * x
     ax.plot(x, y1, ls="--", color="pink", lw=2)
     y2 = i - x
     ax.plot(x, y2, ls="--", color="pink", lw=2)
 ​
 ax.set_title(
     r"Linear Combination of Two Vectors in $\mathbf{R}^2$", size=22, x=0.5, y=1.01
 )
 ​
 plt.show()

我们还可以证明,R ^3 中的任何向量都可以是笛卡尔坐标系中标准基的线性组合。这是从标准基础绘制 3D 线性组合的函数,我们只需输入标量乘数。

 def linearCombo(a, b, c):
     fig = plt.figure(figsize=(10, 10))
     ax = fig.add_subplot(111, projection="3d")
 ​
     vec = np.array(
         [
             [[0, 0, 0, 1, 0, 0]],  
             [[0, 0, 0, 0, 1, 0]],  
             [[0, 0, 0, 0, 0, 1]],  
             [[0, 0, 0, a, 0, 0]],  
             [[0, 0, 0, 0, b, 0]], 
             [[0, 0, 0, 0, 0, c]],  
             [[0, 0, 0, a, b, c]],
         ]
     )  
     colors = ["b", "b", "b", "r", "r", "r", "g"]
     for i in range(vec.shape[0]):
         X, Y, Z, U, V, W = zip(*vec[i, :, :])
         ax.quiver(
             X,
             Y,
             Z,
             U,
             V,
             W,
             length=1,
             normalize=False,
             color=colors[i],
             arrow_length_ratio=0.08,
             pivot="tail",
             linestyles="solid",
             linewidths=3,
             alpha=0.6,
         )
 ​
     dlines = np.array(
         [
             [[a, 0, 0], [a, b, 0]],
             [[0, b, 0], [a, b, 0]],
             [[0, 0, c], [a, b, c]],
             [[0, 0, c], [a, 0, c]],
             [[a, 0, c], [a, b, c]],
             [[0, 0, c], [0, b, c]],
             [[0, b, c], [a, b, c]],
             [[a, 0, 0], [a, 0, c]],
             [[0, b, 0], [0, b, c]],
             [[a, b, 0], [a, b, c]],
         ]
     )
     colors = ["k", "k", "g", "k", "k", "k", "k", "k", "k"]
     for i in range(dlines.shape[0]):
         ax.plot(
             dlines[i, :, 0],
             dlines[i, :, 1],
             dlines[i, :, 2],
             lw=3,
             ls="--",
             color="black",
             alpha=0.5,
         )
 ​
     ax.text(x=a, y=b, z=c, s=" $(%0.d, %0.d, %.0d)$" % (a, b, c), size=18)
     ax.text(x=a, y=0, z=0, s=" $%0.d e_1 = (%0.d, 0, 0)$" % (a, a), size=15)
     ax.text(x=0, y=b, z=0, s=" $%0.d e_2 = (0, %0.d, 0)$" % (b, b), size=15)
     ax.text(x=0, y=0, z=c, s=" $%0.d e_3 = (0, 0, %0.d)$" % (c, c), size=15)
 ​
     ax.grid()
     ax.set_xlim([0, a + 1])
     ax.set_ylim([0, b + 1])
     ax.set_zlim([0, c + 1])
 ​
     ax.set_xlabel("x-axis", size=18)
     ax.set_ylabel("y-axis", size=18)
     ax.set_zlabel("z-axis", size=18)
 ​
     ax.set_title("Vector $(%0.d, %0.d, %.0d)$ Visualization" % (a, b, c), size=20)
 ​
     ax.view_init(elev=20.0, azim=15)
 ​
 ​
 if __name__ == "__main__":
     a = 7
     b = 4
     c = 9
     linearCombo(a, b, c)

不一致系统意味着不存在唯一解。将不一致系统的解视为线性组合似乎很奇怪,但它本质上代表了一条线的轨迹。我们将从线性组合的角度探讨解的含义。

考虑此系统:

Python解

 A = sy.Matrix([[1, 1, 2, 1], [-2, 0, 1, -3], [1, 1, 2, 1]])
 A.rref()

由于自由变量的存在,该解不是唯一的:

 fig = plt.figure(figsize=(8, 8))
 ax = fig.add_subplot(projection="3d")
 ​
 t = np.linspace(-1, 1, 10)
 c1 = 3 / 2 + t / 2
 c2 = -1 / 2 - 5 / 2 * t
 ​
 ax.plot(c1, c2, t, lw=5)
 ​
 ax.set_xlabel("x-axis", size=18)
 ax.set_ylabel("y-axis", size=18)
 ax.set_zlabel("z-axis", size=18)
 ​
 ax.set_title("Solution of A Linear System with One Free Variable", size=18)
 plt.show()

Last updated