added new peak finder, optimized code - #84
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new two-power-law peak finder implementation and optimizes existing code, particularly in the statistics computation and random forest classifier modules.
- Added
PeakFinderTwoPowerLawclass with fitting logic for spectra analysis - Optimized
compute_statsfunction by removing redundant type conversions and reorganizing calculations - Refactored
predict_probamethod to extract tree probability computation into a separate function
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 20 comments.
Show a summary per file
| File | Description |
|---|---|
| py/squeze/utils.py | Added serialization support for np.int16 type |
| py/squeze/stats_utils.py | Optimized compute_stats with dtype changes, added global probability constants, and removed conditional printing logic |
| py/squeze/random_forest_classifier.py | Extracted predict_proba_tree function and updated dtype for indexs parameter; contains unreachable code after early returns |
| py/squeze/peak_finder_two_power_law.py | New file implementing two-power-law peak finder with convergent fitting algorithm; contains spelling errors and incorrect NaN comparison |
| py/squeze/peak_finder_power_law.py | Added optional return_bestfit parameter; contains spelling error in variable name |
| py/squeze/model.py | Simplified probability calculation by removing NaN checks; old logic retained as comments |
Comments suppressed due to low confidence (4)
py/squeze/random_forest_classifier.py:384
- Unreachable code after return statement. Lines 366-384 will never execute and should be removed.
output = np.zeros((len(X), self.num_categories))
for tree_index in np.arange(self.num_trees):
proba = np.zeros((len(X), self.num_categories))
children_left = self.trees[tree_index]["children_left"]
children_right = self.trees[tree_index]["children_right"]
features = self.trees[tree_index]["feature"]
thresholds = self.trees[tree_index]["threshold"]
tree_proba = self.trees[tree_index]["proba"]
indexs = np.arange(X.shape[0], dtype=int)
if len(children_left) > sys.getrecursionlimit():
sys.setrecursionlimit(int(len(children_left) * 1.2))
search_nodes(X, children_left, children_right, features, thresholds,
tree_proba, proba, indexs, 0)
output += proba
output /= self.num_trees
return output
py/squeze/model.py:47
- This comment appears to contain commented-out code.
#if np.isnan(row["PROB_CLASS3"]):
# prob = np.nan
#else:
# prob = row["PROB_CLASS3"] + row["PROB_CLASS30"]
py/squeze/model.py:53
- This comment appears to contain commented-out code.
#if np.isnan(row["PROB_CLASS30"]):
# prob = np.nan
#else:
# prob = row["PROB_CLASS30"]
py/squeze/random_forest_classifier.py:362
- This statement is unreachable.
output = np.array([
predict_proba_tree(
X,
self.trees[tree_index]["children_left"],
self.trees[tree_index]["children_right"],
self.trees[tree_index]["feature"],
self.trees[tree_index]["threshold"],
self.trees[tree_index]["proba"],
self.num_categories,
)
for tree_index in np.arange(self.num_trees)
]).sum() / self.num_trees
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 35 changed files in this pull request and generated 14 comments.
Comments suppressed due to low confidence (1)
py/squeze/tests/test_peakfinder.py:1
- Missing space after '#' in comment. Should be '# find peak indices' for consistency with Python style guidelines.
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 26 out of 36 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 26 out of 36 changed files in this pull request and generated 16 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 26 out of 36 changed files in this pull request and generated 9 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 26 out of 36 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.