Skip to content

The implementation of the Morris function is wrong #112

Description

@mbaudin47

The implementation of the Morris function at _MorrisSensitivity.py is wrong:

  • b2 is wrongly initialized because of a shallow copy,
  • b2 is wrongly initialized because k is not updated,
  • b3 is wrongly initialized because of a shallow copy,
  • b4 is wrongly initialized because of a shallow copy,
  • y is overwritten by a dot product, instead of being updated.

Let us detail these problems.

The index k is not updated to initialize b2 from gamma

At:

self.b2[i][j] = gamma[k]

the index k is used, but never updated.

The code should write:

k = 0
for i in range(6, 20):
    for j in range(20):
        self.b2[i][j] = gamma[k]
        k = k + 1

The value y is overwritten by a dot product instead of being updated

At:

the value of y is overwritten, instead of being updated.

The correct code is:

y += w.dot(b1)

The variable b2 is initialized from a shallow copy

At:

self.b2 = [[0.0] * 20] * 20

the value of b2 is wrongly defined because it is a shallow copy: many entries share the same memory!
The correct code is:

b2 = [[0.0 for _ in range(20)] for _ in range(20)]

The variable b3 is initialized from a shallow copy

At:

self.b3 = [[[0.0] * 20] * 20] * 20

the same happens for b3. The correct code is:

self.b3 = [[[0.0 for _ in range(20)] for _ in range(20)] for _ in range(20)]

The variable b4 is initialized from a shallow copy

And so for b4 at:

self.b4 = [[[[0.0] * 20] * 20] * 20] * 20

where the correct code is:

self.b4 = [
    [[[0.0 for _ in range(20)] for _ in range(20)] for _ in range(20)]
        for _ in range(20)
    ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions