-
Notifications
You must be signed in to change notification settings - Fork 0
V4 #3
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
Merged
V4 #3
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3908fe3
• Add sparse dual caching, new helpers, and validation/doc improvements
tmonk 9c0e11c
docs: add author information and citation details to README.
tmonk c78c6d1
feat: Refactor model internals to use private methods for utility and…
tmonk 4d2f932
refactor: Remove redundant public compatibility wrappers for `transfo…
tmonk 84ef95a
emove legacy public wrappers and align callers
tmonk 9b27a2c
Merge branch 'master' into v4
tmonk 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
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,7 @@ def save_data_to_csv(X, y_single, y_dual, filepath_prefix="data"): | |||||||
| filepath_prefix: Prefix for output files | ||||||||
| """ | ||||||||
| N, K = X.shape | ||||||||
|
|
||||||||
| # Save covariates | ||||||||
| covariate_df = pd.DataFrame(X, columns=[f"x_{k}" for k in range(K)]) | ||||||||
| covariate_df.to_csv(f"{filepath_prefix}_covariates.csv", index=False) | ||||||||
|
|
@@ -145,11 +146,14 @@ def main(): | |||||||
| model = MultichoiceLogit(J, K) | ||||||||
| init_beta = np.zeros((J - 1) * K) | ||||||||
|
|
||||||||
| single_idx, dual_idx = model._validate_data( | ||||||||
| X_loaded, y_single_loaded, y_dual_loaded | ||||||||
| ) | ||||||||
|
|
||||||||
| result = minimize( | ||||||||
| fun=model.neg_log_likelihood, | ||||||||
| jac=model.gradient, | ||||||||
| fun=lambda b: model._neg_log_likelihood(b, X_loaded, single_idx, dual_idx), | ||||||||
| jac=lambda b: model._gradient(b, X_loaded, single_idx, dual_idx), | ||||||||
| x0=init_beta, | ||||||||
| args=(X_loaded, y_single_loaded, y_dual_loaded), | ||||||||
| method="BFGS", | ||||||||
| options={"disp": False, "gtol": 1e-5}, | ||||||||
| ) | ||||||||
|
|
@@ -179,7 +183,7 @@ def main(): | |||||||
| # Step 6: Compute standard errors | ||||||||
| print("\n6. Computing standard errors...") | ||||||||
| std_errs = model.compute_standard_errors( | ||||||||
| result.x, X_loaded, y_single_loaded, y_dual_loaded | ||||||||
| X_loaded, y_single_loaded, y_dual_loaded, result.x | ||||||||
| ) | ||||||||
| std_errs_reshaped = std_errs.reshape(J - 1, K) | ||||||||
|
|
||||||||
|
|
@@ -206,7 +210,7 @@ def main(): | |||||||
| os.remove("example_data_covariates.csv") | ||||||||
| os.remove("example_data_choices.csv") | ||||||||
| print("\nTemporary CSV files cleaned up.") | ||||||||
| except OSError: | ||||||||
| except FileNotFoundError: | ||||||||
|
||||||||
| except FileNotFoundError: | |
| except FileNotFoundError: | |
| # It's safe to ignore if the temporary files do not exist. |
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
Oops, something went wrong.
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.
The exception handling is now too narrow. While catching
FileNotFoundErroris more specific than a bareexcept:, the cleanup code could fail for other reasons (e.g.,PermissionError,OSError). Consider usingexcept OSError:instead, which coversFileNotFoundError,PermissionError, and other file operation errors.