Пример #1
0
func TestSinv() {
	dims := makeDims()
	s, _ := matrix.FloatParse(s_sinv)
	l, _ := matrix.FloatParse(lmbda_sinv)
	fmt.Printf("s=\n%s\n", s.ConvertToString())
	fmt.Printf("lambda=\n%s\n", l.ConvertToString())
	cvx.Sinv(s, l, dims, 0)
	fmt.Printf("s=\n%s\n", s.ConvertToString())
}
Пример #2
0
func TestComputeScaling() {
	dims := makeDims()
	sS :=
		"[ 3.57e+01]" +
			"[ 3.61e+01]" +
			"[ 2.29e+01]" +
			"[ 1.58e+01]" +
			"[-1.50e+01]" +
			"[ 1.22e+00]" +
			"[ 4.39e+01]" +
			"[ 2.99e-01]" +
			"[ 3.71e-01]" +
			"[-8.84e-01]" +
			"[ 1.07e+02]" +
			"[-2.80e+01]" +
			"[-2.24e+01]" +
			"[ 3.00e+01]" +
			"[ 1.22e+02]" +
			"[ 2.26e+01]" +
			"[ 1.90e+01]" +
			"[-2.30e+01]" +
			"[ 4.57e+01]"

	zS :=
		"[ 1.28e+00]" +
			"[ 1.21e+00]" +
			"[ 1.23e+00]" +
			"[ 1.00e-02]" +
			"[ 7.99e-03]" +
			"[ 9.00e-02]" +
			"[ 1.16e+00]" +
			"[-6.30e-03]" +
			"[-4.97e-04]" +
			"[-5.57e-03]" +
			"[ 1.26e+00]" +
			"[ 8.42e-03]" +
			"[-3.01e-02]" +
			"[ 0.00e+00]" +
			"[ 1.13e+00]" +
			"[-8.81e-02]" +
			"[ 0.00e+00]" +
			"[ 0.00e+00]" +
			"[ 1.06e+00]"

	s, _ := matrix.FloatParse(sS)
	z, _ := matrix.FloatParse(zS)
	lmbda := matrix.FloatZeros(14, 1)
	W, err := cvx.ComputeScaling(s, z, lmbda, dims, 0)
	fmt.Printf("lmbda=\n%v\n", lmbda)
	W.Print()
	if W == nil || err == nil {
	}
}
Пример #3
0
func TestSprod() {
	ws3_s := "{19 1 [-1.92202445509905195 -4.43413247878006267 -1.15775584063948567 0.54820887452676570 2.21649700627983037 -1.98162544855790612 -4.70041870169500520 -0.15660870756329515 0.08826681016515722 -0.07530910637617422 3.09357687112417423 -0.08892936366725440 -0.69040419578379308 228.60579362198546960 -1.79266278208156793 -0.15184232827552227 150.39533087821908452 -165.74065159010396542 -4.33886225701128136]}"

	dz_s := "{19 1 [-4.84625905630317177 -2.15952376487305475 -3.11487780722148111 -2.84890172439185640 -0.06018020686749934 1.66646286524597986 -2.43677726058904387 0.15165371621854387 -0.11690553045657326 0.16435133837885341 -16.31158280932658045 0.08892936366725440 0.69040419578379308 -228.60579362198546960 -8.40682303542823028 0.15184232827552227 -150.39533087821908452 165.74065159010396542 -1.90076109934411064]}"

	dims := makeDims()
	s, _ := matrix.FloatParse(ws3_s)
	l, _ := matrix.FloatParse(dz_s)
	fmt.Printf("s=\n%s\n", s.ConvertToString())
	fmt.Printf("l=\n%s\n", l.ConvertToString())
	cvx.Sprod(s, l, dims, 0)
	fmt.Printf("s=\n%s\n", s.ConvertToString())
}
Пример #4
0
func TestSgemv() {
	Gs := "{19 3 [16.0 7.0 24.0 -8.0 8.0 -1.0 0.0 -1.0 0.0 0.0 7.0 -5.0 1.0 -5.0 1.0 -7.0 1.0 -7.0 -4.0 -14.0 2.0 7.0 -13.0 -18.0 3.0 0.0 0.0 -1.0 0.0 3.0 13.0 -6.0 13.0 12.0 -10.0 -6.0 -10.0 -28.0 5.0 0.0 -15.0 12.0 -6.0 17.0 0.0 0.0 0.0 -1.0 9.0 6.0 -6.0 6.0 -7.0 -7.0 -6.0 -7.0 -11.0]}"
	xs := "{19 1 [1.28237163646993602 1.20577885626601700 1.23170989498268124 0.01004618744349980 0.00798511180410652 0.08995485424980643 1.16070198911381661 -0.00629749112134051 -0.00049721465140839 -0.00557415890687774 1.25644350107932512 0.00842128830287307 -0.03013075022837631 0.00000000000000000 1.13394694370391358 -0.08807369671161171 0.00000000000000000 0.00000000000000000 1.06027426641336442]}"
	ys := "{3 1 [0 0 0]}"

	res := "{3 1 [-65.19580144480464412 16.89263580404870524 17.05333779316251253]}"

	G, _ := matrix.FloatParse(Gs)
	x, _ := matrix.FloatParse(xs)
	y, _ := matrix.FloatParse(ys)
	r, _ := matrix.FloatParse(res)
	dims := makeDims()
	cvx.Sgemv(G, x, y, -1.0, 1.0, dims, linalg.OptTrans)
	fmt.Printf("y=\n%v\n", y.ConvertToString())
	if y.Equal(r) {
		fmt.Printf("OK\n")
	}
}
Пример #5
0
func TestPack() {
	s := "{19 1 [0.34685034769697742 0.39585039411618006 -17.26426975698158017 13.79271773799920275 -13.13205395184397339 0.84649931876339113 1.62479401776324162 0.03868823612413173 0.05311904070719403 -0.13134270109326304 10.23788144936299993 -0.21362220612188865 0.27062567408202032 -58.02205901917197650 6.16596220003297013 -0.23193020346970489 -41.37875150278244973 45.61335347561063713 0.40295716371409468]}"
	x, _ := matrix.FloatParse(s)
	y := matrix.FloatZeros(x.NumElements(), 1)
	dims := makeDims()
	fmt.Printf("x=\n%v\n", x.ConvertToString())
	cvx.Pack(x, y, dims, &linalg.IOpt{"mnl", 0}, &linalg.IOpt{"offsety", 3})
	fmt.Printf("y=\n%v\n", y.ConvertToString())
}
Пример #6
0
func makeW() (W *cvx.FloatMatrixSet, err error) {
	var m *matrix.FloatMatrix

	d0_s := "{2 1 [5.277942305425358 5.468379387636596]}"
	di0_s := "{2 1 [0.189467777806527 0.182869535764269]}"
	//dnl0_s  := "{0 1 []}"
	//dnli0_s := "{0 1 []}"
	r0_s := "{3 3 [-2.249267570008489 2.361205104290289 0.913567958765254 -1.925574750121168 -2.172410611043159 0.173946992908080 0.559540271653776 -0.139584324205900 2.348303661399984]}"
	rti0_s := "{3 3 [-0.214383299026403 0.195042904770822 0.062675463930892 -0.239513204273735 -0.244613737625478 0.042529866033816 0.101143782396739 -0.057758767117156 0.398306137924685]}"
	v0_s := "{4 1 [1.114132558182145 0.355030258425681 -0.339080260926309 0.016414915590130]}"
	v1_s := "{4 1 [1.000014508170784 0.003059892342288 0.002220573368109 -0.003837012486999]}"
	beta_s := "{2 1 [2.33309421747982 6.1486663985292]}"

	W = cvx.FloatSetNew("d", "di", "r", "rti", "beta", "v", "dnl", "dnli")
	m, err = matrix.FloatParse(d0_s)
	if err != nil {
		return
	}
	W.Append("d", m)

	m, err = matrix.FloatParse(di0_s)
	if err != nil {
		return
	}
	W.Append("di", m)

	m, err = matrix.FloatParse(r0_s)
	if err != nil {
		return
	}
	W.Append("r", m)

	m, err = matrix.FloatParse(rti0_s)
	if err != nil {
		return
	}
	W.Append("rti", m)

	m, err = matrix.FloatParse(beta_s)
	if err != nil {
		return
	}
	W.Append("beta", m)

	m, err = matrix.FloatParse(v0_s)
	if err != nil {
		return
	}
	W.Append("v", m)

	m, err = matrix.FloatParse(v1_s)
	if err != nil {
		return
	}
	W.Append("v", m)

	return
}
Пример #7
0
func TestUpdateScaling() {
	lmbda_s := "{14 1 [6.76828351140222306 6.59365624365311831 4.27263364786096478 2.30069284986509182 -2.15631679941233223 0.31516258331192648 7.13719596228404818 0.00495499134475126 0.02863872029141604 -0.08904223200267916 13.21800593820240444 10.19948581750979777 6.23962335635539134 1.00000000000000000]}"
	ds_s := "{19 1 [5.85597012340924117 4.24746698613998053 6.66652548029122194 0.58902278472678926 1.03308171512083025 -1.94414436400428547 4.60978114520661020 -0.08983717465618864 0.08317983679679065 -0.11015599534516843 -0.26824322970973236 -0.30242159737138297 -2.03756136168495861 -0.13360736529691733 -3.00562533088611916 0.28121160147417951 -3.90046688480349379 0.16852198213982270 0.22709525427810559]}"
	dz_s := "{19 1 [5.85597012340924117 4.24746698613998053 6.66652548029122194 0.58902278472678926 1.03308171512083025 -1.94414436400428547 4.60978114520661020 -0.08983717465618864 0.08317983679679065 -0.11015599534516843 -0.26824322970973236 -0.30242159737138297 -2.03756136168495861 -0.13360736529691733 -3.00562533088611916 0.28121160147417951 -3.90046688480349379 0.16852198213982270 0.22709525427810559]}"
	W, err := makeW()
	if err != nil {
	}

	ds, _ := matrix.FloatParse(ds_s)
	dz, _ := matrix.FloatParse(dz_s)
	lmbda, _ := matrix.FloatParse(lmbda_s)

	//fmt.Printf("s=\n%s\n", s.ConvertToString())
	fmt.Printf("dz=\n%s\n", dz.ConvertToString())
	fmt.Printf("** scaling **\n")
	cvx.UpdateScaling(W, lmbda, ds, dz)
	fmt.Printf("** done **\n")
	fmt.Printf("dz=\n%v\n", dz.ConvertToString())
	W.PrintMatrix()
}
Пример #8
0
func TestScale() {
	W, err := makeW()
	if err != nil {
		fmt.Printf("parse error: %s\n", err)
	}
	W.Print()
	ws3, _ := matrix.FloatParse(ws3_0s)
	fmt.Printf("ws=\n%v\n", ws3)
	cvx.Scale(ws3, W, true, false)
	fmt.Printf("ws=\n%s\n", ws3.ConvertToString())

}
Пример #9
0
func TestMaxStep() {
	mspecs := []string{
		"{19 1 [-0.71602483083619306, -0.32751537008799270, -0.90211796596401550, -0.35303654102293264, -0.62181576776956926, 0.66930098671978677, -0.34113990819044998, 0.02148714448960296, -0.01501162989804339, 0.01877131767501854, -1.23404262984806090, 0.00765901771826717, 0.07602234524271170, 0.00765901771826717, -0.82423988677899396, 0.01903375731520045, 0.07602234524271170, 0.01903375731520045, -0.30462753771957773]}",
		"{19 1 [-0.90418099173227473, -0.55446903694477567, -0.75852190575418754, -0.28521159129027612, -0.20324751939542904, 0.79072509490265286, -0.57257117058088591, 0.02809249154086312, -0.02019565501515897, 0.01983042575661653, -0.94662801660482254, 0.01692096411790065, 0.00189237051831477, 40.84289018309486607, -0.94203035351896691, 0.03530733835430711, 34.72882576816857636, -43.12536914015343825, -0.59269604329850678]}",
		"{19 1 [-0.63761557791730505, -0.49927109491614652, -2.88612127650269690, 1.02459187046607614, -1.08456607104760749, 2.02280079601045371, -0.55641455856187327, 0.02016189304049917, -0.01862912232512778, -0.02055526061347480, -1.15041626653479212, -0.10322882816344475, 0.01745666575882606, -0.10322882816344475, -0.79776805202587853, 0.15380596860249979, 0.01745666575882606, 0.15380596860249979, -1.09410501802037174]}",
		"{19 1 [-0.04445614722177669, -0.50472951271139443, 33.80457382481722561, 2.39409416284717746, 15.85293235027906533, -31.57416041647100258, -0.44030579629483829, 0.01108309271988339, -0.00050375838683239, -0.10680487835631132, -0.43517754110696782, -0.16566345671918681, -0.00835988722662511, 60.99826071780538683, -0.12936453144168999, 0.18454022191525460, 43.75065336359583057, -58.46469736057606070, -1.43237585470186524]}",
		"{19 1 [-0.52770801715780236, -0.34865075585151695, -0.06604795005220473, 0.00080608174920793, -0.57017026080125643, 0.80052702873932979, -0.57175900026306448, 0.00324120867723322, -0.03840371565131868, -0.04692128453549683, -1.13162513862336933, -0.02022797390433178, -0.08148180706695730, -0.02022797390433178, -0.41915784706047138, -0.18478231967325620, -0.08148180706695730, -0.18478231967325620, -1.21475736154926306]}",
		"{19 1 [-0.54427305833349060, -0.40577480999372106, 4.62287548428621076, 0.65685247317784301, -3.59483436984408211, 4.21033731752464035, -0.75849913685550663, -0.01241745345362589, -0.03919418072252966, -0.04462476088093722, -0.92949336514998260, -0.02063652716896694, -0.01272915453218180, 66.54656859704714122, -0.38962925938229281, -0.16399809144693109, 17.96615778060966306, -98.46837470885125754, -0.65178419983276770]}"}

	dims := makeDims()

	for k, s := range mspecs {
		m, _ := matrix.FloatParse(s)
		fmt.Printf("%d=\n%v\n", k, m.ConvertToString())
		t, _ := cvx.MaxStep(m, dims, 0, nil)
		fmt.Printf("== %d: t = %.17f\n", k, t)
	}

}
Пример #10
0
func TestJnrm2() {
	s, _ := matrix.FloatParse(sS)
	aa := cvx.Jnrm2(s, 4, 2)
	fmt.Printf("aa = %v\n", aa)
}
Пример #11
0
func TestSinv2() {
	dims := makeDims()
	sS2 :=
		"[ 4.58e+01]" +
			"[ 4.35e+01]" +
			"[ 2.83e+01]" +
			"[ 1.97e+01]" +
			"[-1.84e+01]" +
			"[ 2.69e+00]" +
			"[ 5.09e+01]" +
			"[ 7.07e-02]" +
			"[ 4.09e-01]" +
			"[-1.27e+00]" +
			"[ 1.75e+02]" +
			"[ 0.00e+00]" +
			"[ 0.00e+00]" +
			"[ 0.00e+00]" +
			"[ 1.04e+02]" +
			"[ 0.00e+00]" +
			"[ 0.00e+00]" +
			"[ 0.00e+00]" +
			"[ 3.89e+01]"
	lmbdaS2 :=
		"[ 6.77e+00]" +
			"[ 6.59e+00]" +
			"[ 4.27e+00]" +
			"[ 2.30e+00]" +
			"[-2.16e+00]" +
			"[ 3.15e-01]" +
			"[ 7.14e+00]" +
			"[ 4.95e-03]" +
			"[ 2.86e-02]" +
			"[-8.90e-02]" +
			"[ 1.32e+01]" +
			"[ 1.02e+01]" +
			"[ 6.24e+00]" +
			"[ 1.00e+00]"

	sinv_res :=
		"[-6.77e+00]" +
			"[-6.59e+00]" +
			"[-4.27e+00]" +
			"[-2.30e+00]" +
			"[ 2.16e+00]" +
			"[-3.15e-01]" +
			"[-7.14e+00]" +
			"[-4.95e-03]" +
			"[-2.86e-02]" +
			"[ 8.90e-02]" +
			"[-1.32e+01]" +
			"[-0.00e+00]" +
			"[-0.00e+00]" +
			"[-0.00e+00]" +
			"[-1.02e+01]" +
			"[-0.00e+00]" +
			"[-0.00e+00]" +
			"[-0.00e+00]" +
			"[-6.24e+00]"

	s, _ := matrix.FloatParse(sS2)
	lmbda, _ := matrix.FloatParse(lmbdaS2)
	cvx.Sinv(s, lmbda, dims, 0)
	blas.ScalFloat(s, -1.0)
	res_s, _ := matrix.FloatParse(sinv_res)
	fmt.Printf("res=\n%v\n", s)
	fmt.Printf("OK=%v\n", s.Equal(res_s))
}