Пример #1
0
func check(x, s, z *matrix.FloatMatrix) {
	var xref, sref, zref *matrix.FloatMatrix = nil, nil, nil

	if len(xVal) > 0 {
		xref, _ = matrix.FloatParse(xVal)
		nrm, diff := error(xref, x)
		fmt.Printf("x: nrm=%.17f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.17f"))
		}
	}

	if len(sVal) > 0 {
		sref, _ = matrix.FloatParse(sVal)
		nrm, diff := error(sref, s)
		fmt.Printf("s: nrm=%.17f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.17f"))
		}
	}

	if len(zVal) > 0 {
		zref, _ = matrix.FloatParse(zVal)
		nrm, diff := error(zref, z)
		fmt.Printf("z: nrm=%.17f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.17f"))
		}
	}
}
Пример #2
0
func check(x, s, z *matrix.FloatMatrix) {
	if len(xVal) > 0 {
		ref, _ := matrix.FloatParse(xVal)
		nrm, diff := error(ref, x)
		fmt.Printf("x: nrm=%.9f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.12f"))
		}
	}
	if len(sVal) > 0 {
		ref, _ := matrix.FloatParse(sVal)
		nrm, diff := error(ref, s)
		fmt.Printf("s: nrm=%.9f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.12f"))
		}
	}
	if len(zVal) > 0 {
		ref, _ := matrix.FloatParse(zVal)
		nrm, diff := error(ref, z)
		fmt.Printf("z: nrm=%.9f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.12f"))
		}
	}
}
Пример #3
0
func main() {
	blas.PanicOnError(true)
	matrix.PanicOnError(true)

	var data *matrix.FloatMatrix = nil
	flag.Parse()
	if len(dataVal) > 0 {
		data, _ = matrix.FloatParse(dataVal)
		if data == nil {
			fmt.Printf("could not parse:\n%s\n", dataVal)
			return
		}
	} else {
		data = matrix.FloatNormal(20, 20)
	}

	if len(spPath) > 0 {
		checkpnt.Reset(spPath)
		checkpnt.Activate()
		checkpnt.Verbose(spVerbose)
		checkpnt.Format("%.7f")
	}

	sol, err := mcsdp(data)
	if sol != nil && sol.Status == cvx.Optimal {
		x := sol.Result.At("x")[0]
		z := sol.Result.At("z")[0]
		matrix.Reshape(z, data.Rows(), data.Rows())
		fmt.Printf("x=\n%v\n", x.ToString("%.9f"))
		//fmt.Printf("z=\n%v\n", z.ToString("%.9f"))
		check(x, z)
	} else {
		fmt.Printf("status: %v\n", err)
	}
}
Пример #4
0
func main() {

	var A, b *matrix.FloatMatrix = nil, nil
	m, n := 20, 20

	blas.PanicOnError(true)
	matrix.PanicOnError(true)

	flag.Parse()
	if len(spPath) > 0 {
		checkpnt.Reset(spPath)
		checkpnt.Activate()
		checkpnt.Verbose(spVerbose)
		checkpnt.Format("%.17f")
	}
	if len(AVal) > 0 {
		A, _ = matrix.FloatParse(AVal)
		if A == nil {
			fmt.Printf("could not parse:\n%s\n", AVal)
			return
		}
	} else {
		A = matrix.FloatNormal(m, n)
	}
	if len(bVal) > 0 {
		b, _ = matrix.FloatParse(bVal)
		if b == nil {
			fmt.Printf("could not parse:\n%s\n", bVal)
			return
		}
	} else {
		b = matrix.FloatNormal(m, 1)
	}

	sol, err := qcl1(A, b)
	if sol != nil {
		r := sol.Result.At("x")[0]
		x := matrix.FloatVector(r.FloatArray()[:A.Cols()])
		r = sol.Result.At("z")[0]
		z := matrix.FloatVector(r.FloatArray()[r.NumElements()-A.Rows():])
		fmt.Printf("x=\n%v\n", x.ToString("%.9f"))
		fmt.Printf("z=\n%v\n", z.ToString("%.9f"))
		check(x, z)
	} else {
		fmt.Printf("status: %v\n", err)
	}
}
Пример #5
0
func (m *mVariable) Verify(dataline string) float64 {
	refdata, err := matrix.FloatParse(dataline)
	if err != nil {
		fmt.Printf("parse error: %s", err)
		return 0.0
	}
	return blas.Nrm2Float(matrix.Minus(m.mtx, refdata))
}
Пример #6
0
func (m *mVariable) ShowError(dataline string) {
	refdata, err := matrix.FloatParse(dataline)
	if err != nil {
		fmt.Printf("parse error: %s", err)
		return
	}
	df := matrix.Minus(m.mtx, refdata)
	emtx, _ := matrix.FloatMatrixStacked(matrix.StackRight, m.mtx, refdata, df)
	fmt.Printf("my data | ref.data | diff \n%v\n", emtx.ToString(spformat))
}
Пример #7
0
func check(x *matrix.FloatMatrix) {
	if len(xVal) > 0 {
		ref, _ := matrix.FloatParse(xVal)
		nrm, diff := errorToRef(ref, x)
		fmt.Printf("x: nrm=%.9f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.12f"))
		}
	}
}
Пример #8
0
func check(x, ss0, ss1, zs0, zs1 *matrix.FloatMatrix) {
	if len(xVal) > 0 {
		ref, _ := matrix.FloatParse(xVal)
		nrm, diff := error(ref, x)
		fmt.Printf("x: nrm=%.9f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.12f"))
		}
	}
	if len(ss0Val) > 0 {
		ref, _ := matrix.FloatParse(ss0Val)
		nrm, diff := error(ref, ss0)
		fmt.Printf("ss0: nrm=%.9f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.12f"))
		}
	}
	if len(ss1Val) > 0 {
		ref, _ := matrix.FloatParse(ss1Val)
		nrm, diff := error(ref, ss1)
		fmt.Printf("ss1: nrm=%.9f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.12f"))
		}
	}
	if len(zs0Val) > 0 {
		ref, _ := matrix.FloatParse(zs0Val)
		nrm, diff := error(ref, zs0)
		fmt.Printf("zs0: nrm=%.9f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.12f"))
		}
	}
	if len(zs1Val) > 0 {
		ref, _ := matrix.FloatParse(zs1Val)
		nrm, diff := error(ref, zs1)
		fmt.Printf("zs1: nrm=%.9f\n", nrm)
		if nrm > 10e-7 {
			fmt.Printf("diff=\n%v\n", diff.ToString("%.12f"))
		}
	}
}
Пример #9
0
func fromFile(name string, t *testing.T) *matrix.FloatMatrix {
	fd, ferr := os.Open(name)
	if ferr != nil {
		return nil
	}
	fi, _ := fd.Stat()
	buf := make([]byte, fi.Size(), fi.Size())
	n, _ := fd.Read(buf)
	t.Logf("read %d bytes ...%v\n", n, buf[0:20])
	data := string(buf)
	Ac, _ := matrix.FloatParse(data)
	return Ac
}