java 相当于 scipy.linalg.eigh 参数可选矩阵
java equivalent of scipy.linalg.eigh with parameter optional matrix
我需要计算 java 中的特征值。我需要相对矩阵,就像 scipy.linalg.eigh.
中的参数 b
def eigh(a, b=None, lower=True, eigvals_only=False, overwrite_a=False,
overwrite_b=False, turbo=True, eigvals=None, type=1,
check_finite=True, subset_by_index=None, subset_by_value=None,
driver=None):
Method description
Solve a standard or generalized eigenvalue problem for a complex
Hermitian or real symmetric matrix.
Find eigenvalues array ``w`` and optionally eigenvectors array ``v`` of
array ``a``, where ``b`` is positive definite such that for every
eigenvalue λ (i-th entry of w) and its eigenvector ``vi`` (i-th column of
``v``) satisfies::
a @ vi = λ * b @ vi
vi.conj().T @ a @ vi = λ
vi.conj().T @ b @ vi = 1
In the standard problem, ``b`` is assumed to be the identity matrix.
Parameters
----------
a : (M, M) array_like
A complex Hermitian or real symmetric matrix whose eigenvalues and
eigenvectors will be computed.
b : (M, M) array_like, optional
A complex Hermitian or real symmetric definite positive matrix in.
If omitted, identity matrix is assumed
我试过了apache.math。他们都只提供没有参数的类似 eig 方法。 java中是否有任何等价物?
看来 OjAlgo 图书馆很可能有你需要的东西。
这是一个具有特征值的 example。
var dim = 2;
Primitive64Store mtrxA = Primitive64Store.FACTORY.make(2, 2);
mtrxA.fillOne(0, 0, 4.0);
mtrxA.fillOne(0, 1, 0.0);
mtrxA.fillOne(1, 0, 0.0);
mtrxA.fillOne(1, 1, 1.0);
System.out.println(mtrxA);
Primitive64Store mtrxB = Primitive64Store.FACTORY.make(2, 2);
mtrxB.fillOne(0, 0, 0.6);
mtrxB.fillOne(0, 1, -0.5);
mtrxB.fillOne(1, 0, -0.5);
mtrxB.fillOne(1, 1, 0.7);
System.out.println(mtrxB);
/*
* There are several generalisations. 3 are supported by ojAlgo, specified by the enum:
* Eigenvalue.Generalisation This factory method returns the most common alternative.
*/
Eigenvalue.Generalised<Double> generalisedEvD = Eigenvalue.PRIMITIVE.makeGeneralised(mtrxA);
// Generalisation: [A][V] = [B][V][D]
// Use 2-args alternative
generalisedEvD.computeValuesOnly(mtrxA, mtrxB);
generalisedEvD.decompose(mtrxA, mtrxB);
// Eigenvectors in the columns
System.out.println("Eigenvectors are in the columns below");
System.out.println(generalisedEvD.getV());
// Eigenvalues on the diagonal
System.out.println("Eigenvalues are on the diagonal in the matrix below");
System.out.println(generalisedEvD.getD());
// You can also transpose the matrices with this lib
var transposed = mtrxB.transpose();
// Printing out the transposed matrix
System.out.println(transposed.toString());
编辑:这是一个working code example,它解决了您特定数据案例的问题。
EJML has flags to avoid computing eigenvalues and you can select different variants. JavaDoc for the factory.
我需要计算 java 中的特征值。我需要相对矩阵,就像 scipy.linalg.eigh.
中的参数 bdef eigh(a, b=None, lower=True, eigvals_only=False, overwrite_a=False,
overwrite_b=False, turbo=True, eigvals=None, type=1,
check_finite=True, subset_by_index=None, subset_by_value=None,
driver=None):
Method description
Solve a standard or generalized eigenvalue problem for a complex
Hermitian or real symmetric matrix.
Find eigenvalues array ``w`` and optionally eigenvectors array ``v`` of
array ``a``, where ``b`` is positive definite such that for every
eigenvalue λ (i-th entry of w) and its eigenvector ``vi`` (i-th column of
``v``) satisfies::
a @ vi = λ * b @ vi
vi.conj().T @ a @ vi = λ
vi.conj().T @ b @ vi = 1
In the standard problem, ``b`` is assumed to be the identity matrix.
Parameters
----------
a : (M, M) array_like
A complex Hermitian or real symmetric matrix whose eigenvalues and
eigenvectors will be computed.
b : (M, M) array_like, optional
A complex Hermitian or real symmetric definite positive matrix in.
If omitted, identity matrix is assumed
我试过了apache.math。他们都只提供没有参数的类似 eig 方法。 java中是否有任何等价物?
看来 OjAlgo 图书馆很可能有你需要的东西。
这是一个具有特征值的 example。
var dim = 2;
Primitive64Store mtrxA = Primitive64Store.FACTORY.make(2, 2);
mtrxA.fillOne(0, 0, 4.0);
mtrxA.fillOne(0, 1, 0.0);
mtrxA.fillOne(1, 0, 0.0);
mtrxA.fillOne(1, 1, 1.0);
System.out.println(mtrxA);
Primitive64Store mtrxB = Primitive64Store.FACTORY.make(2, 2);
mtrxB.fillOne(0, 0, 0.6);
mtrxB.fillOne(0, 1, -0.5);
mtrxB.fillOne(1, 0, -0.5);
mtrxB.fillOne(1, 1, 0.7);
System.out.println(mtrxB);
/*
* There are several generalisations. 3 are supported by ojAlgo, specified by the enum:
* Eigenvalue.Generalisation This factory method returns the most common alternative.
*/
Eigenvalue.Generalised<Double> generalisedEvD = Eigenvalue.PRIMITIVE.makeGeneralised(mtrxA);
// Generalisation: [A][V] = [B][V][D]
// Use 2-args alternative
generalisedEvD.computeValuesOnly(mtrxA, mtrxB);
generalisedEvD.decompose(mtrxA, mtrxB);
// Eigenvectors in the columns
System.out.println("Eigenvectors are in the columns below");
System.out.println(generalisedEvD.getV());
// Eigenvalues on the diagonal
System.out.println("Eigenvalues are on the diagonal in the matrix below");
System.out.println(generalisedEvD.getD());
// You can also transpose the matrices with this lib
var transposed = mtrxB.transpose();
// Printing out the transposed matrix
System.out.println(transposed.toString());
编辑:这是一个working code example,它解决了您特定数据案例的问题。
EJML has flags to avoid computing eigenvalues and you can select different variants. JavaDoc for the factory.