mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 07:37:03 +08:00
stat/spatial: use mat.RowNonZeroDoer
This commit is contained in:
@@ -38,6 +38,35 @@ func ExampleGlobalMoransI_linear() {
|
||||
// Moran's I=0.1111 z-score=0.6335
|
||||
}
|
||||
|
||||
func ExampleGlobalMoransI_banded() {
|
||||
data := []float64{0, 0, 0, 1, 1, 1, 0, 1, 0, 0}
|
||||
|
||||
// The locality here describes spatial neighbor
|
||||
// relationships.
|
||||
// This example uses the band matrix representation
|
||||
// to improve time and space efficiency.
|
||||
locality := mat.NewBandDense(10, 10, 1, 1, []float64{
|
||||
0, 0, 1,
|
||||
1, 0, 1,
|
||||
1, 0, 1,
|
||||
1, 0, 1,
|
||||
1, 0, 1,
|
||||
1, 0, 1,
|
||||
1, 0, 1,
|
||||
1, 0, 1,
|
||||
1, 0, 1,
|
||||
1, 0, 0,
|
||||
})
|
||||
|
||||
i, _, z := spatial.GlobalMoransI(data, nil, locality)
|
||||
|
||||
fmt.Printf("Moran's I=%.4v z-score=%.4v\n", i, z)
|
||||
|
||||
// Output:
|
||||
//
|
||||
// Moran's I=0.1111 z-score=0.6335
|
||||
}
|
||||
|
||||
func ExampleGetisOrdGStar() {
|
||||
data := []float64{0, 0, 0, 1, 1, 1, 0, 1, 0, 0}
|
||||
|
||||
@@ -73,3 +102,41 @@ func ExampleGetisOrdGStar() {
|
||||
// v=0 G*i=-0.2673
|
||||
// v=0 G*i=-1.225
|
||||
}
|
||||
|
||||
func ExampleGetisOrd_band() {
|
||||
data := []float64{0, 0, 0, 1, 1, 1, 0, 1, 0, 0}
|
||||
|
||||
// The locality here describes spatial neighbor
|
||||
// relationships including self.
|
||||
// This example uses the band matrix representation
|
||||
// to improve time and space efficiency.
|
||||
locality := mat.NewBandDense(10, 10, 1, 1, []float64{
|
||||
0, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
1, 1, 0,
|
||||
})
|
||||
|
||||
for i, v := range data {
|
||||
fmt.Printf("v=%v G*i=% .4v\n", v, spatial.GetisOrdGStar(i, data, nil, locality))
|
||||
}
|
||||
|
||||
// Output:
|
||||
//
|
||||
// v=0 G*i=-1.225
|
||||
// v=0 G*i=-1.604
|
||||
// v=0 G*i=-0.2673
|
||||
// v=1 G*i= 1.069
|
||||
// v=1 G*i= 2.405
|
||||
// v=1 G*i= 1.069
|
||||
// v=0 G*i= 1.069
|
||||
// v=1 G*i=-0.2673
|
||||
// v=0 G*i=-0.2673
|
||||
// v=0 G*i=-1.225
|
||||
}
|
||||
|
Reference in New Issue
Block a user