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

stat/distmv: Add ScoreInput function for the Normal distribution #103

Merged
merged 1 commit into from Jul 10, 2017

Conversation

btracey
Copy link
Member

@btracey btracey commented Jun 23, 2017

No description provided.

@btracey
Copy link
Member Author

btracey commented Jun 30, 2017

Fixed a bug in the implementation. Very tricksy.

@@ -277,6 +277,38 @@ func (n *Normal) Rand(x []float64) []float64 {
return x
}

// ScoreInput returns the score function with respect to the input of the
Copy link
Member

Choose a reason for hiding this comment

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

I would rewrite these two sentences as: ScoreInput returns the value at x of the score function s which is defined as the gradient of the log-probability: s(x) = \nabla log(p(x)).
If gradient is not used in statistics, then keep derivative.
Also, why not call the method just Score?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the score function https://en.wikipedia.org/wiki/Score_(statistics) is the derivative with respect to the parameters, and this is with respect to the inputs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

// If deriv is nil, a new slice will be allocated and returned. If deriv is of
// length the dimension of Normal, then the result will be put in-place into deriv.
// If neither of these is true, ScoreInput will panic.
func (n *Normal) ScoreInput(deriv, x []float64) []float64 {
Copy link
Member

Choose a reason for hiding this comment

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

I would call the first parameter score.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

// input x. That is, ScoreInput computes
// ∇_x log(p(x))
// If score is nil, a new slice will be allocated and returned. If score is of
// length the dimension of Normal, then the result will be put in-place into deriv.
Copy link
Member

Choose a reason for hiding this comment

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

deriv does not exist. Do you mean score?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, sorry, missed that one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. (sorry for squashing, made some silly git decisions)

@kortschak
Copy link
Member

This has gone semantically stale. It uses the solve method on mat.Vector which no longer exists. You should probably rebase onto master and fix that.


dv := mat.NewVector(len(score), score)
dt := mat.NewVector(len(tmp), tmp)
dv.SolveCholeskyVec(&n.chol, dt)
Copy link
Member

Choose a reason for hiding this comment

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

n.chol.SolveVec(mat.NewVector(len(score), score), mat.NewVector(len(tmp), tmp))

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks

@btracey
Copy link
Member Author

btracey commented Jul 9, 2017

Rebased.

@btracey btracey merged commit 5419911 into master Jul 10, 2017
@btracey btracey deleted the normscoreinput branch March 20, 2018 15:36
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.

None yet

3 participants