JDACS4C-IMPROVE / IMPROVE

Libraries and scripts for basic IMPROVE functionalities
0 stars 3 forks source link

Assert arrays debug #10

Closed RylieWeaver closed 2 months ago

RylieWeaver commented 3 months ago

Help users debug why the arrays are not equal. Printing the placements should help to determine whether there was an undesirable shuffle vs a shift

RylieWeaver commented 3 months ago

If this is better to put in feedback in the google doc, let me know.

adpartin commented 3 months ago

@RylieWeaver That's a good effort! A few things:

  1. It's weird to see assert() inside try. What do you think?
  2. Why does v2 start from the 2nd item? assert np.array_equal(v1, v2[2:])
  3. Have you tested this assertion? Does it throw appropriate messages when vectors are shuffled?
RylieWeaver commented 3 months ago

Thanks for the encouragement! As you know I'm still learning, hopefully I continue to get better with your feedback.

  1. This could be, I'm not sure of the normal programming manners with this. I could do this structure below
  2. This was for testing to get output even when the arrays were equal and should be fixed now
  3. Yes, tested to the best of my abilities. Output looks like this and will be up to the model curator to interpret:

Other Implementation:

if not np.array_equal(v1, v2):
    print("Loaded y data vector is not equal to the true vector")
    # Print positions of the first 10 values of v1 in v2 to help with debugging
    for i, value in enumerate(v1[:10]):
        if value in v2:
            positions = np.where(v2 == value)[0]
            print(f"Value {value} from v1 (index {i}) is found at positions {positions} in v2")
        else:
            print(f"Value {value} from v1 (index {i}) is not found in v2")
    raise ValueError("v1 is not equal to v2")

Output:

Loaded y data vector is not equal to the true vector
Value 0.4724000096321106 from v1 (index 0) is found at positions [337] in v2
Value 0.7627999782562256 from v1 (index 1) is found at positions [3] in v2
Value 0.8429999947547913 from v1 (index 2) is found at positions [53] in v2
Value 0.7447999715805054 from v1 (index 3) is found at positions [161] in v2
Value 0.6991000175476074 from v1 (index 4) is found at positions [77] in v2
Value 0.802299976348877 from v1 (index 5) is found at positions [421] in v2
Value 0.6606000065803528 from v1 (index 6) is found at positions [332] in v2
Value 0.6740999817848206 from v1 (index 7) is found at positions [32] in v2
Value 0.5396999716758728 from v1 (index 8) is found at positions [120] in v2
Value 0.5291000008583069 from v1 (index 9) is found at positions [136] in v2
Exiting due to assertion failure.

As always don't feel forced to respond during my unconventional student working hours haha

adpartin commented 2 months ago

@RylieWeaver I just pushed an alternative version for the assertion script. Let me know if it's more clear now.

RylieWeaver commented 2 months ago

Yes, I think that's clear and a very efficient way to do it, thanks.