forked from qpsy/nonnest2
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(glm): preserve binomial normalization without ifelse #87
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
Draft
seonghobae
wants to merge
6
commits into
master
Choose a base branch
from
bolt-optimize-ifelse-llcont-11787999515468212853
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+39
−2
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d7cbd39
Optimize ifelse calls in llcont.glm binomial family
seonghobae 7f99055
Merge branch 'master' into bolt-optimize-ifelse-llcont-11787999515468…
opencode-agent[bot] fc3b679
Optimize ifelse calls in llcont.glm binomial family
seonghobae 29d12bc
chore(perf): keep llcont optimization local to measured code
seonghobae 272c061
chore(ci): keep llcont optimization scoped to product code
seonghobae a3b350d
test(llcont): preserve binomial zero-weight semantics
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| context("llcont binomial normalization contract") | ||
|
|
||
| test_that("matrix-response zero totals preserve glm log-likelihood", { | ||
| successes <- c(0, 1, 2, 3, 1) | ||
| failures <- c(0, 2, 1, 0, 3) | ||
| predictor <- seq_along(successes) | ||
| response <- cbind(successes, failures) | ||
|
|
||
| fit <- glm(response ~ predictor, family = binomial()) | ||
| fit$y <- response | ||
|
|
||
| contributions <- llcont(fit) | ||
|
|
||
| expect_false(any(is.nan(contributions))) | ||
| expect_equal(sum(contributions), as.numeric(logLik(fit))) | ||
| }) | ||
|
|
||
| test_that("zero prior weights remain zero-contribution observations", { | ||
| response <- c(0, 1, 0, 1, 1, 0) | ||
| predictor <- seq_along(response) | ||
| prior_weight <- c(0, 1, 1, 1, 1, 1) | ||
|
|
||
| fit <- glm( | ||
| response ~ predictor, | ||
| family = binomial(), | ||
| weights = prior_weight | ||
| ) | ||
|
|
||
| contributions <- llcont(fit) | ||
|
|
||
| expect_identical(unname(contributions[1]), 0) | ||
| expect_equal(sum(contributions), as.numeric(logLik(fit))) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge ContextualWisdomLab/nonnest2 /tmp/coderabbit-repo-knowledge/contextualwisdomlab-nonnest2-6d5bc311/conventionsLength of output: 5712
🏁 Script executed:
Repository: ContextualWisdomLab/nonnest2
Length of output: 13840
🏁 Script executed:
Repository: ContextualWisdomLab/nonnest2
Length of output: 24018
NA총합 경로에 대한 회귀 테스트를 추가하십시오.현재 테스트는
NA가 없는 matrix response만 사용합니다. 따라서rowSums(y)가NA를 반환하는 경우의!is.na(n)보정과 후속m분기를 실행하지 않습니다.NA총합을 포함한 response를 추가하고, contribution의 기대 결과를 명시하십시오. 해당 입력이 지원 범위가 아니면 테스트와 목표에서 제외한다고 명시하십시오.🤖 Prompt for AI Agents