gama-platform/gama.old

Lack of a check for data coherence in Moran()

Closed this issue · 1 comments

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

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.