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
Conversation
Fixed a bug in the implementation. Very tricksy. |
stat/distmv/normal.go
Outdated
@@ -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 |
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.
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?
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.
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.
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.
Done.
stat/distmv/normal.go
Outdated
// 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 { |
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.
I would call the first parameter score
.
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.
Done.
stat/distmv/normal.go
Outdated
// 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. |
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.
deriv
does not exist. Do you mean score
?
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.
Yes, sorry, missed that one.
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.
Done. (sorry for squashing, made some silly git decisions)
This has gone semantically stale. It uses the solve method on |
stat/distmv/normal.go
Outdated
|
||
dv := mat.NewVector(len(score), score) | ||
dt := mat.NewVector(len(tmp), tmp) | ||
dv.SolveCholeskyVec(&n.chol, dt) |
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.
n.chol.SolveVec(mat.NewVector(len(score), score), mat.NewVector(len(tmp), tmp))
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.
Thanks
Rebased. |
No description provided.