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

Fix issue 395 - pspm_con1 #398

Merged
merged 11 commits into from
Jul 11, 2022
Merged

Fix issue 395 - pspm_con1 #398

merged 11 commits into from
Jul 11, 2022

Conversation

teddychao
Copy link
Contributor

@teddychao teddychao commented Jun 14, 2022

Fixes #395.

Changes proposed in this pull request:

  • pspm_con1
    • Update the method of calculating conval.

Explanation

Definitions

  • A1. Define Line N does not have issue if data.stats(N,:) does not have NaN.
  • A2. Define Line N has a valid issue if data.stats(N,:) does have NaN and conmat(N)==0.
  • A3. Define Line N has an invalid issue if data.stats(N,:) does have NaN and conmat(N)~=0.

Therefore, there are 3 situations when there are issue(s)

  • B1. There are issue(s), all issues are valid.
  • B2. There are issue(s), all issues are invalid.
  • B3. There are issues, issues are valid and invalid.

Among the three situations, B2 and B3 will lead to the same results of conval as NaN, thus the processing for B2 and B3 is the same.
For B1, the valid parts are converted to be 0 for calculating conval.
The logic is therefore as

Check if data.stats has NaN

If there are NaNs, there are issues, and the issue(s) could be B1, B2 or B3. B2 and B3 lead to the same processing.

For B1, convert the NaN rows to be 0 in data.stats, then calculate conval. Give a warning "Calculated data.stats contain NaN caused by 0 in conmat, which are ignored when calculating conval".
For B2 and B3, calculate conval as NaN. Give a warning "Calculated data.stats contain NaNs, caused by unknown reason, which is invalid."

@teddychao teddychao self-assigned this Jun 14, 2022
@teddychao teddychao added this to the v6.0 milestone Jun 14, 2022
@teddychao teddychao changed the title Fix issue 395 pspm_con1 Fix issue 395 - pspm_con1 Jun 14, 2022
@teddychao teddychao added the Completed & Waiting for Review Completed and waiting for review label Jun 14, 2022
@teddychao teddychao marked this pull request as draft June 14, 2022 16:24
Copy link

@jbrochar jbrochar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same point than in the other review, I prefer actual errors to warnings (but it's not my call in the end :) )

Dominik said to avoid throwing errors, so don't mind my comments :)

src/pspm_con1.m Show resolved Hide resolved
src/pspm_con1.m Show resolved Hide resolved
src/pspm_con1.m Outdated Show resolved Hide resolved
@teddychao teddychao requested a review from jbrochar June 21, 2022 16:56
@teddychao teddychao marked this pull request as ready for review June 21, 2022 17:32
Copy link

@jbrochar jbrochar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code won't handle multiple contrasts.

src/pspm_con1.m Outdated

% there are issues if data.stats has NaN and the corresponding conmat
% also contains 0
idx_issue = isnan(prod(data.stats,2));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? I am not sure to understand why you would need prod here.

Would any(isnan(data.stats),2) does the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you solution has a higher readability. I have updated the code in this line 🙂

conmat = zeros(numel(connames), paramno);
for c = 1:numel(convec)
conmat(c,1:numel(convec{c})) = convec{c};
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: If all cells of convec are row-vector, I think conmat = cat(1,convec{:}); is similar to your for loop

Copy link
Contributor Author

@teddychao teddychao Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not written by me. I just checked and I do not think they do have similar features. In the old code convec could be a 2D matrix thus we may need to do for each row..

src/pspm_con1.m Outdated
idx_issue = isnan(prod(data.stats,2));
idx_valid_issue = transpose(conmat==0) .* idx_issue;
idx_invalid_issue = transpose(conmat~=0) .* idx_issue;
if sum(idx_issue) > 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion : if any(idx_issue(:))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I have changed both of this line and the following line to replace sum by any now.

src/pspm_con1.m Outdated
idx_valid_issue = transpose(conmat==0) .* idx_issue;
idx_invalid_issue = transpose(conmat~=0) .* idx_issue;
if sum(idx_issue) > 0
if sum(idx_valid_issue) > 0 && sum(idx_invalid_issue) == 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the sum are run on matrices, right?
If so, then it is a bit confusing if you run an if on the resulting boolean vector

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sum here is just used to detect if there are positive values. I have changed it to any as they are really Boolean vectors. In the new version, these operations are done in every line thus idx_valid_issue and idx_invalid_issue are both vectors.

@teddychao
Copy link
Contributor Author

teddychao commented Jun 28, 2022

Hi @jbrochar Thanks for discussing with me about this issue today. Could you please try this data (just load it in matlab) and then run the code in this script (maybe just run them in terminal)? I think it can run and it contains two rows of NaNs? thanks.

Screenshot 2022-06-28 at 17 25 39

Archive.zip

@teddychao
Copy link
Contributor Author

@jbrochar Hi Jules, I have updated pspm_con1 to make it compatible if conmat is a 2D matrix. Could you please have a look and let me know if you are happy with this solution? Thanks.

@teddychao teddychao requested a review from jbrochar July 5, 2022 17:05
@teddychao teddychao merged commit 196ef15 into develop Jul 11, 2022
@teddychao teddychao deleted the 395-incorrect-assigned-nan branch July 11, 2022 17:58
@teddychao teddychao mentioned this pull request Jul 12, 2022
@teddychao teddychao restored the 395-incorrect-assigned-nan branch July 12, 2022 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Completed & Waiting for Review Completed and waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect assigned NaN
2 participants