计算Java中大数据集的主要轴/特征值和 - 向量

发布于 2025-01-19 02:44:13 字数 791 浏览 1 评论 0 原文

我有一个大型数据集(> 500.000 个元素),其中包含有限元元素的应力值(σ_xx、σ_yy、σ_zz、τ_xy、τ_yz、τ_xz)。这些应力值在模型的全局 xyz 坐标空间中给出。我想计算主轴应力值和方向。如果您不太熟悉其背后的物理原理,这意味着采用对称矩阵

| σ_xx τ_xy τ_xz |
| τ_xy σ_yy τ_yz |
| τ_xz τ_yz σ_zz |

并计算其特征值和特征向量。单独计算每组特征值和向量太慢。我正在寻找一个库、一个算法或 Java 中的其他东西,可以让我以数组计算的方式进行此操作。举个例子,在 python/numpy 中,我可以将所有 3x3 矩阵,沿着第三个维度堆叠它们以获得 nx3x3 数组,并将其传递给 np.linalg.eig(arr),它会自动给我一个三个特征值的 nx3 数组和三个特征向量的 nx3x3 数组。

我尝试过的事情:

  • nd4j 有一个用于计算特征值和向量的特征模块,但一次只支持一个方阵。
  • 计算特征多项式并使用卡尔达诺公式来获取根/特征值 - 可以一次对整个数组执行此操作,但我现在陷入如何获取相应特征向量的困境。是否有一个通用的简单算法可以从这些到特征向量?
  • 寻找可以直接计算的特征值和向量的分析形式:它确实存在,但只是 不。

I have a large dataset (>500.000 elements) that contains the stress values (σ_xx, σ_yy, σ_zz, τ_xy, τ_yz, τ_xz) of FEM-Elements. These stress values are given in the global xyz-coordinate space of the model. I want to calculate the main axis stress values and directions from those. If you're not that familiar with the physics behind it, this means taking the symmetric matrix

| σ_xx τ_xy τ_xz |
| τ_xy σ_yy τ_yz |
| τ_xz τ_yz σ_zz |

and calculating its eigenvalues and eigenvectors. Calculating each set of eigenvalues and -vectors on its own is too slow. I'm looking for a library, an algorithm or something in Java that would allow me to do this as array calculations. As an example, in python/numpy I could just take all my 3x3-matrices, stack them along a third dimension to get a nx3x3-array, and pass that to np.linalg.eig(arr), and it automatically gives me an nx3-array for the three eigenvalues and an nx3x3-array for the three eigenvectors.

Things I tried:

  • nd4j has an Eigen-module for calculating eigenvalues and -vectors, but only supports a single square array at a time.
  • Calculate the characteristic polynomial and use cardanos formula to get the roots/eigenvalues - possible to do for the whole array at once, but I'm stuck now on how to get the corresponding eigenvectors. Is there maybe a general simple algorithm to get from those to the eigenvectors?
  • Looking for an analytical form of the eigenvalues and -vectors that can be calculated directly: It does exist, but just no.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜心 2025-01-26 02:44:13

您需要编写一些代码。

我将创建或使用 Matrix 类作为依赖项,并找到为您提供特征值和特征向量的方法。您在 nd4j 中找到的那些听起来像是很好的候选者。您还可以考虑 Java 线性代数 (LA4J) 依赖项。

将数据集加载到 List 中。

使用函数式 Java 方法应用映射,为您提供一个特征值列表(作为每个应力矩阵的向量)和一个特征向量列表(作为每个应力矩阵的矩阵)。

您可以通过将映射函数应用于流来最大程度地优化此计算。 Java 将在后台并行计算,以最大程度地利用可用的内核。

You'll need to write a little code.

I'd create or use a Matrix class as a dependency and find methods to give you eigenvalues and eigenvectors. The ones you found in nd4j sound like great candidates. You might also consider the Linear Algebra For Java (LA4J) dependency.

Load the dataset into a List<Matrix>.

Use functional Java methods to apply a map to give you a List of eigenvalues as a vector per stress matrix and a List of eigenvectors as a matrix per stress matrix.

You can optimize this calculation to the greatest extent possible by applying the map function to a stream. Java will parallelize the calculation under the covers to leverage available cores to the greatest extent possible.

赢得她心 2025-01-26 02:44:13

后续:这是对我最有效的方式,因为我可以在不迭代每个元素的情况下进行所有操作。如上所述,我正在使用ND4J,与Numpy相比,它的可能性似乎有限(或者也许我只是没有足够彻底阅读文档)。以下方法仅使用基本数组操作:

  1. 从给定的应力值中,使用Cardano的公式计算特征值。仅需要元素明智的说明来做到这一点(添加,子,mul,div,pow)。结果应为三个尺寸n的向量,每个向量均包含所有元素的一个特征值。

  2. 使用给定的公式计算每个特征值的矩阵s。像步骤1一样,这显然也可以仅使用带有应力值和特征值向量的元素操作来完成,以避免指定一些复杂的指令,根据哪个轴在哪个轴上保留其他任何轴,同时乘以哪个数组来乘以。<<<<<<<<<<。 /p>

  3. 从s中获取一列并将其标准化以获得给定特征值的归一化特征向量。

请注意,此方法仅在您具有真实的对称矩阵时才起作用。您还应确保正确处理多次出现相同特征值的情况。

Follow-up: This is the way that worked best for me, as I can do all operations without iterating over every element. As stated above, I'm using Nd4j, which seems to be limited in its possibilities compared to numpy (or maybe I just didn't read the documentation thoroughly enough). The following method uses only basic array operations:

  1. From the given stress values, calculate the eigenvalues using Cardano's formula. Only element wise instructions are needed to do that (add, sub, mul, div, pow). The result should be three vectors of size n, each containing one eigenvalue for all elements.

  2. Use the formula given here to calculate the matrix S for each eigenvalue. Like step 1, this can obviously also be done using only element-wise operations with the stress value- and eigenvalue-vectors, in order to avoid specifiying some complicated instructions on which array to multiply according to which axis while keeping whatever other axis.

  3. Take one column from S and normalize it to get a normalized eigenvector for the given eigenvalue.

Note that this method only works if you have a real symmetric matrix. You also should make sure to properly deal with cases where the same eigenvalue appears multiple times.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文