4*4*5
This commit is contained in:
@@ -58,6 +58,7 @@ func solveCoefficients(f, latVec, lonVec, heightVec *mat.VecDense, method SolveM
|
||||
var MtF mat.VecDense
|
||||
MtF.MulVec(M.T(), f)
|
||||
x0.MulVec(invMtM, &MtF)
|
||||
// return mat.Col(nil, 0, &x0), nil
|
||||
|
||||
if method == SolveMethodNelderMead {
|
||||
numerator := mat.NewVecDense(20, nil)
|
||||
@@ -83,12 +84,10 @@ func solveCoefficients(f, latVec, lonVec, heightVec *mat.VecDense, method SolveM
|
||||
}
|
||||
|
||||
// 迭代
|
||||
var wm mat.Dense
|
||||
var wmx, wf mat.VecDense
|
||||
|
||||
var x1 mat.VecDense
|
||||
|
||||
var vx []*VX
|
||||
v0 := 0.0
|
||||
iterations := 0
|
||||
maxIterations := 10
|
||||
denominator := mat.NewVecDense(20, nil)
|
||||
@@ -113,22 +112,36 @@ func solveCoefficients(f, latVec, lonVec, heightVec *mat.VecDense, method SolveM
|
||||
MtW2F.MulVec(&MtW2, f)
|
||||
x1.MulVec(invMtW2M, &MtW2F)
|
||||
|
||||
wm.Mul(weights, M)
|
||||
wmx.MulVec(&wm, &x1)
|
||||
wf.MulVec(weights, f)
|
||||
wmx.SubVec(&wmx, &wf)
|
||||
wmx.MulElemVec(&wmx, &wmx)
|
||||
v := math.Sqrt(mat.Max(&wmx))
|
||||
log.Println("iteration:", iterations, "v-err:", v)
|
||||
numerator1 := mat.NewVecDense(20, nil)
|
||||
denominator1 := mat.NewVecDense(20, nil)
|
||||
denominator1.SetVec(0, 1.0)
|
||||
numerator1.SetVec(0, x0.AtVec(0))
|
||||
for i := 1; i < 20; i++ {
|
||||
numerator1.SetVec(i, x1.AtVec(i))
|
||||
denominator1.SetVec(i, x1.AtVec(i+19))
|
||||
}
|
||||
|
||||
vx = append(vx, &VX{v: v, x: x1})
|
||||
if math.Abs(v-v0) < epsilon {
|
||||
break
|
||||
errorSquared := 0.0
|
||||
lambda := 1e-4
|
||||
for i := 0; i < n; i++ {
|
||||
predictedV := project(numerator1, denominator1, latVec.AtVec(i), lonVec.AtVec(i), heightVec.AtVec(i))
|
||||
errorV := predictedV - f.AtVec(i)
|
||||
errorSquared += errorV * errorV
|
||||
}
|
||||
fmt.Printf("squared error: %.8f\n", errorSquared)
|
||||
var coeffsSquared float64
|
||||
for i := 0; i < 20; i++ {
|
||||
coeffsSquared += lambda * (numerator1.AtVec(i)*numerator1.AtVec(i) + denominator1.AtVec(i)*denominator1.AtVec(i))
|
||||
}
|
||||
|
||||
x0 = x1
|
||||
v0 = v
|
||||
iterations++
|
||||
|
||||
fmt.Printf("squared error+lambda*coeffs: %.8f\n", coeffsSquared)
|
||||
vx = append(vx, &VX{v: errorSquared, x: x1})
|
||||
if errorSquared < 0.001 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
log.Println("iterations:", iterations)
|
||||
|
||||
Reference in New Issue
Block a user