在 Java 中实现稀疏向量的最佳方法是什么?

发布于 2024-08-14 23:17:47 字数 84 浏览 11 评论 0原文

在 Java 中实现稀疏向量的最佳方法是什么?

当然,好的事情是拥有一些可以很容易操纵的东西(标准化,标量积等)

提前致谢

Which is the best way to implement a sparse vector in Java?

Of course the good thing would be to have something that can be manipulated quite easily (normalization, scalar product and so on)

Thanks in advance

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

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

发布评论

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

评论(3

眸中客 2024-08-21 23:17:47

MTJ 有一个 稀疏向量 类。它具有范数函数(1-范数、2-范数和 ∞-范数)和点积函数。

MTJ has a Sparse Vector class. It has norm functions (1-norm 2-norm and ∞-norm) and dot product functions.

生生不灭 2024-08-21 23:17:47

JScience 有一个 SparseVector 实现是其线性的一部分代数包。

JScience has a SparseVector implementation that is part of its linear algebra package.

千柳 2024-08-21 23:17:47

您还可以尝试查看 la4jCompressedVector 实现。它使用一对数组:值数组和索引数组。再加上二分搜索,它就可以顺利进行。因此,此实现保证 get/set 操作的 O(log n) 运行时间。

只是一个简单的例子

Vector a = new CompressedVector(new double[]{ 1.0, 2.0, 3.0 }).

// calculates L_1 norm of the vector
double n = a.norm();

// calculates the sum of vectors elements
double s = a.fold(Vectors.asSumAccumulator(0.0));

You can also try to look at la4j's CompressedVector implementation. It uses pair of arrays: array of values and array of their indicies. And with binary search on top of that it just flies. So, this implementation guarantees O(log n) running time for get/set operations.

Just a brief example

Vector a = new CompressedVector(new double[]{ 1.0, 2.0, 3.0 }).

// calculates L_1 norm of the vector
double n = a.norm();

// calculates the sum of vectors elements
double s = a.fold(Vectors.asSumAccumulator(0.0));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文