Skip to content

Conversation

@zsk2002
Copy link

@zsk2002 zsk2002 commented Sep 29, 2025

In this pull request, I added the Hyvarinen Score Matching Score based on the paper http://jmlr.org/papers/v6/hyvarinen05a.html. The performance in terms of point estimation and negative log likelihood is very close to the logScore presented in the paper.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the Hyvarinen Score Matching Score for the normal distribution in NGBoost, based on the referenced JMLR paper. The implementation provides an alternative scoring method that reportedly achieves similar performance to the existing log score.

Key changes:

  • Added a generic ScoreMatchingScore base class in the scores module
  • Implemented NormalScoreMatchingScore with score computation, derivatives, and Fisher information matrix
  • Integrated the new scoring method into the Normal distribution's available scores

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
ngboost/scores.py Adds generic ScoreMatchingScore base class with reference documentation
ngboost/distns/normal.py Implements NormalScoreMatchingScore and adds it to Normal distribution's score options

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

def score(self, Y):
loc = self.loc
var = self.var
var = var
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

This line is redundant - var is assigned to itself without any transformation. This should be removed.

Suggested change
var = var

Copilot uses AI. Check for mistakes.
n = len(Y)
D = np.zeros((len(Y), 2))
D[:, 0] = (self.loc -Y)/(self.var **2)
D[:, 1] = 2/self.var - (2*(Y - self.loc)**2)/(self.var**2)
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

[nitpick] The expression (2*(Y - self.loc)**2)/(self.var**2) can be simplified to 2*(Y - self.loc)**2/self.var**2 for better readability.

Suggested change
D[:, 1] = 2/self.var - (2*(Y - self.loc)**2)/(self.var**2)
D[:, 1] = 2/self.var - 2*(Y - self.loc)**2/self.var**2

Copilot uses AI. Check for mistakes.
loc = self.loc
var = self.var
var = var
return ((Y - loc)**2 / (2* var**2)) - 1/var
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

[nitpick] Inconsistent spacing around the multiplication operator. Should be 2 * var**2 instead of 2* var**2.

Suggested change
return ((Y - loc)**2 / (2* var**2)) - 1/var
return ((Y - loc)**2 / (2 * var**2)) - 1/var

Copilot uses AI. Check for mistakes.
def d_score(self, Y):
n = len(Y)
D = np.zeros((len(Y), 2))
D[:, 0] = (self.loc -Y)/(self.var **2)
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

[nitpick] Inconsistent spacing: extra space after = and missing space before -Y. Should be D[:, 0] = (self.loc - Y)/(self.var**2).

Suggested change
D[:, 0] = (self.loc -Y)/(self.var **2)
D[:, 0] = (self.loc - Y) / (self.var**2)

Copilot uses AI. Check for mistakes.
return ((Y - loc)**2 / (2* var**2)) - 1/var

def d_score(self, Y):
n = len(Y)
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

The variable n is defined but never used in the function. This line should be removed.

Suggested change
n = len(Y)

Copilot uses AI. Check for mistakes.
@ryan-wolbeck
Copy link
Collaborator

Please run make lint and make test in your environment to fix the linting issues causing the build to fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants