parent
23e4694db7
commit
f8672c00fd
67
pam.go
67
pam.go
|
|
@ -3,6 +3,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -15,6 +16,11 @@ const (
|
|||
clusterN = 3
|
||||
)
|
||||
|
||||
type Ctx struct {
|
||||
data [][]float64
|
||||
SetS map[int]interface{}
|
||||
}
|
||||
|
||||
func initData() [][]float64 { //初始数据集
|
||||
src := rand.NewSource(time.Now().UnixNano())
|
||||
rnd := rand.New(src)
|
||||
|
|
@ -29,7 +35,66 @@ func initData() [][]float64 { //初始数据集
|
|||
return r
|
||||
}
|
||||
|
||||
func copyIntMap(src map[int]interface{}, dst map[int]interface{}) {
|
||||
for k, v := range src {
|
||||
dst[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
func minDistance(vec []float64, mat [][]float64) float64 {
|
||||
var r float64
|
||||
r = 1e20
|
||||
var t float64
|
||||
for m := 0; m < len(mat); m++ {
|
||||
t = 0
|
||||
for v := 0; v < len(vec); v++ {
|
||||
t += math.Pow(vec[v]-mat[m][v], 2)
|
||||
}
|
||||
t = math.Sqrt(t)
|
||||
if t < r {
|
||||
r = t
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func subData(set map[int]interface{}, ctx *Ctx) [][]float64 {
|
||||
r := make([][]float64, len(set))
|
||||
ind := 0
|
||||
for k, _ := range set {
|
||||
r[ind] = ctx.data[k]
|
||||
ind++
|
||||
}
|
||||
}
|
||||
|
||||
func selectInitCluster(ctx *Ctx) {
|
||||
for clusterI := 0; clusterI < clusterN-1; clusterI++ {
|
||||
for cluster := 0; cluster < dataN; cluster++ {
|
||||
if _, has := ctx.SetS[cluster]; has {
|
||||
continue
|
||||
}
|
||||
//选一个候选数据
|
||||
cddtI := cluster
|
||||
cadSetS := make(map[int]interface{})
|
||||
copyIntMap(cadSetS, ctx.SetS)
|
||||
cadSetS[cddtI] = nil
|
||||
Cij := 0.0
|
||||
for J := 0; J < dataN; J++ {
|
||||
if _, has := cadSetS[J]; has {
|
||||
continue
|
||||
}
|
||||
d := ctx.data[J]
|
||||
//寻找最短距离
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
initData()
|
||||
ctx := Ctx{}
|
||||
ctx.data = initData()
|
||||
ctx.SetS = make(map[int]interface{})
|
||||
ctx.SetS[1] = nil
|
||||
fmt.Println("Hello World!")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue