equalityojalgo

How do I test the equality of two MatrixStore in ojalgo up until a certain degree?


Does ojalgo provide an efficient way to test whether two matrix are equal ?

For instance, I would like to know if MatrixStore A is equal to MatrixStore B up until a certain tolerance level.

I could implement a naive test using a nested for loop however I would like to know if there is a more computationally efficient way to do so on larger matrices.

What I am trying to achieve is something similar to Python numpy's allclose method, where the user can specify two input numpy arrays and a tolerance value to check if the two arrays are equal to that extent.

Suppose I have 2 MatrixStores filled randomly

storeA = storeFactory.makeFilled(5,5,new Weibull(5.0,2.0));
storeB = storeFactory.makeFilled(5,1,new Weibull(5.0,2.0));

And I solve the equation Ax=B

SolverTask linsolv = SolverTask.PRIMITIVE.make(storeA, storeB);
storeX = linsolv.solve(storeA,storeB);

I know that storeX should be equal to storeB up until a certain degree, but how do I verify it ?

I expect the following, or some functions that allows the comparison of 2 matrices

storeB.equals( storeA.multiply(storeX) );

to return True.


Solution

  • NumberContext accuracy = ...
    storeB.equals(storeA.multiply(storeX), accuracy);