Skip to content

Commit

Permalink
stat/distuv: move destination to first position
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Jun 21, 2017
1 parent 11453e6 commit f42bbc8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions stat/distuv/exponential.go
Expand Up @@ -72,7 +72,7 @@ func (Exponential) ExKurtosis() float64 {
// If weights is not nil, then the len(weights) must equal len(samples).
func (e *Exponential) Fit(samples, weights []float64) {
suffStat := make([]float64, e.NumSuffStat())
nSamples := e.SuffStat(samples, weights, suffStat)
nSamples := e.SuffStat(suffStat, samples, weights)
e.ConjugateUpdate(suffStat, nSamples, make([]float64, e.NumSuffStat()))
}

Expand Down Expand Up @@ -201,7 +201,7 @@ func (e Exponential) StdDev() float64 {
//
// If weights is nil, the weights are assumed to be 1, otherwise panics if
// len(samples) != len(weights). Panics if len(suffStat) != NumSuffStat().
func (Exponential) SuffStat(samples, weights, suffStat []float64) (nSamples float64) {
func (Exponential) SuffStat(suffStat, samples, weights []float64) (nSamples float64) {
if len(weights) != 0 && len(samples) != len(weights) {
panic(badLength)
}
Expand Down
6 changes: 3 additions & 3 deletions stat/distuv/general_test.go
Expand Up @@ -101,19 +101,19 @@ func testConjugateUpdate(t *testing.T, newFittable func() ConjugateUpdater) {
incWeights = test.weights[j : j+1]
allWeights = test.weights[0 : j+1]
}
nsInc := incDist.SuffStat(test.samps[j:j+1], incWeights, stats)
nsInc := incDist.SuffStat(stats, test.samps[j:j+1], incWeights)
incDist.ConjugateUpdate(stats, nsInc, prior)

allDist := newFittable()
nsAll := allDist.SuffStat(test.samps[0:j+1], allWeights, stats)
nsAll := allDist.SuffStat(stats, test.samps[0:j+1], allWeights)
allDist.ConjugateUpdate(stats, nsAll, make([]float64, allDist.NumParameters()))
if !parametersEqual(incDist.parameters(nil), allDist.parameters(nil), 1e-12) {
t.Errorf("prior doesn't match after incremental update for (%d, %d). Incremental is %v, all at once is %v", i, j, incDist, allDist)
}

if test.weights == nil {
onesDist := newFittable()
nsOnes := onesDist.SuffStat(test.samps[0:j+1], ones(j+1), stats)
nsOnes := onesDist.SuffStat(stats, test.samps[0:j+1], ones(j+1))
onesDist.ConjugateUpdate(stats, nsOnes, make([]float64, onesDist.NumParameters()))
if !parametersEqual(onesDist.parameters(nil), incDist.parameters(nil), 1e-14) {
t.Errorf("nil and uniform weighted prior doesn't match for incremental update for (%d, %d). Uniform weighted is %v, nil is %v", i, j, onesDist, incDist)
Expand Down
4 changes: 2 additions & 2 deletions stat/distuv/norm.go
Expand Up @@ -81,7 +81,7 @@ func (Normal) ExKurtosis() float64 {
// are 1. If weights is not nil, then the len(weights) must equal len(samples).
func (n *Normal) Fit(samples, weights []float64) {
suffStat := make([]float64, n.NumSuffStat())
nSamples := n.SuffStat(samples, weights, suffStat)
nSamples := n.SuffStat(suffStat, samples, weights)
n.ConjugateUpdate(suffStat, nSamples, make([]float64, n.NumSuffStat()))
}

Expand Down Expand Up @@ -189,7 +189,7 @@ func (n Normal) StdDev() float64 {
//
// If weights is nil, the weights are assumed to be 1, otherwise panics if
// len(samples) != len(weights). Panics if len(suffStat) != NumSuffStat().
func (Normal) SuffStat(samples, weights, suffStat []float64) (nSamples float64) {
func (Normal) SuffStat(suffStat, samples, weights []float64) (nSamples float64) {
lenSamp := len(samples)
if len(weights) != 0 && len(samples) != len(weights) {
panic(badLength)
Expand Down

0 comments on commit f42bbc8

Please sign in to comment.