Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of a check for data coherence in Moran() #3848

Closed
ScriBanana opened this issue Aug 17, 2023 · 1 comment
Closed

Lack of a check for data coherence in Moran() #3848

ScriBanana opened this issue Aug 17, 2023 · 1 comment

Comments

@ScriBanana
Copy link
Contributor

Hi,

Describe the bug
If a value list longer than the weight matrix dimensions is given to the moran function, it skews the result, as no check for that exists.

To Reproduce

  • Load Moran Index.gaml from the library.
  • Optional : run the model and change the parameter to checkerboard pattern to check that the value of Moran I is indeed -1.
  • Add one or more values to the vals list, e.g. by adding something like vals <+ 100.0; before line 49.
  • Run the model with checkerboard. No error is thrown, yet an I value different of -1 is given (about -0.008 in the example above).

Expected behavior
An error to be returned whenever the sizes of the inputs of the function are the same (length of the list and width and height of the weight matrix).

Proposed fix
Add a check in the moranIndex function that vals.size() must be equal to weightMatrix.numCols * weightMatrix.numRows.

Desktop (please complete the following information):

  • OS: Linux (any)
  • GAMA version: bfa98eb
@ScriBanana
Copy link
Contributor Author

ScriBanana commented Aug 17, 2023

So here is a fix that I am not authorised to push (ERROR: Permission to gama-platform/gama.git denied to ScriBanana. (git); Can't connect to any repository: git@github.com:gama-platform/gama.git (git@github.com:gama-platform/gama.git: push not permitted) (Eclipse)).

Add following lines to msi.gama.core/src/msi/gaml/operators/Spatial.java (right after 7263):

7264	if (N != weightMatrix.numRows * weightMatrix.numCols) throw GamaRuntimeException
7265		.error("The lengths of the value list and of the weight matrix do not match", scope);

It is tested and working (1.9.2).

Edit : So, I sent a pull request with the fix. It is my first time doing such a thing on a big project on Github. Please point to (and forgive 🙂 ) any mistake I may have made in this process.

@ScriBanana ScriBanana reopened this Aug 17, 2023
lesquoyb added a commit that referenced this issue Aug 18, 2023
Fix to #3848 : Added a check on Moran inputs consistency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants