本文整理匯總了Golang中github.com/hrautila/go/opt/matrix.FloatMatrix.Mul方法的典型用法代碼示例。如果您正苦於以下問題:Golang FloatMatrix.Mul方法的具體用法?Golang FloatMatrix.Mul怎麽用?Golang FloatMatrix.Mul使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hrautila/go/opt/matrix.FloatMatrix
的用法示例。
在下文中一共展示了FloatMatrix.Mul方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: F2
func (p *FloorPlan) F2(x, z *matrix.FloatMatrix) (f, Df, H *matrix.FloatMatrix, err error) {
f, Df, err = p.F1(x)
x17 := matrix.FloatVector(x.FloatArray()[17:])
tmp := p.Amin.Div(x17.Pow(3.0))
tmp = z.Mul(tmp).Scale(2.0)
diag := matrix.FloatDiagonal(5, tmp.FloatArray()...)
H = matrix.FloatZeros(22, 22)
H.SetSubMatrix(17, 17, diag)
return
}
示例2: computeScaling
/*
Returns the Nesterov-Todd scaling W at points s and z, and stores the
scaled variable in lmbda.
W * z = W^{-T} * s = lmbda.
W is a MatrixSet with entries:
- W['dnl']: positive vector
- W['dnli']: componentwise inverse of W['dnl']
- W['d']: positive vector
- W['di']: componentwise inverse of W['d']
- W['v']: lists of 2nd order cone vectors with unit hyperbolic norms
- W['beta']: list of positive numbers
- W['r']: list of square matrices
- W['rti']: list of square matrices. rti[k] is the inverse transpose
of r[k].
*/
func computeScaling(s, z, lmbda *matrix.FloatMatrix, dims *DimensionSet, mnl int) (W *FloatMatrixSet, err error) {
/*DEBUGGED*/
err = nil
W = FloatSetNew("dnl", "dnli", "d", "di", "v", "beta", "r", "rti")
// For the nonlinear block:
//
// W['dnl'] = sqrt( s[:mnl] ./ z[:mnl] )
// W['dnli'] = sqrt( z[:mnl] ./ s[:mnl] )
// lambda[:mnl] = sqrt( s[:mnl] .* z[:mnl] )
var stmp, ztmp, lmd *matrix.FloatMatrix
if mnl > 0 {
stmp = matrix.FloatVector(s.FloatArray()[:mnl])
ztmp = matrix.FloatVector(z.FloatArray()[:mnl])
dnl := stmp.Div(ztmp)
dnl.Apply(dnl, math.Sqrt)
dnli := dnl.Copy()
dnli.Apply(dnli, func(a float64) float64 { return 1.0 / a })
W.Set("dnl", dnl)
W.Set("dnli", dnli)
lmd = stmp.Mul(ztmp)
lmd.Apply(lmd, math.Sqrt)
lmbda.SetIndexes(matrix.MakeIndexSet(0, mnl, 1), lmd.FloatArray())
} else {
mnl = 0
}
// For the 'l' block:
//
// W['d'] = sqrt( sk ./ zk )
// W['di'] = sqrt( zk ./ sk )
// lambdak = sqrt( sk .* zk )
//
// where sk and zk are the first dims['l'] entries of s and z.
// lambda_k is stored in the first dims['l'] positions of lmbda.
m := dims.At("l")[0]
td := s.FloatArray()
stmp = matrix.FloatVector(td[mnl : mnl+m])
zd := z.FloatArray()
//fmt.Printf("zdata=%v\n", zd[mnl:mnl+m])
ztmp = matrix.FloatVector(zd[mnl : mnl+m])
d := stmp.Div(ztmp)
d.Apply(d, math.Sqrt)
di := d.Copy()
di.Apply(di, func(a float64) float64 { return 1.0 / a })
//fmt.Printf("d:\n%v\n", d)
//fmt.Printf("di:\n%v\n", di)
W.Set("d", d)
W.Set("di", di)
lmd = stmp.Mul(ztmp)
lmd.Apply(lmd, math.Sqrt)
// lmd has indexes mnl:mnl+m and length of m
lmbda.SetIndexes(matrix.MakeIndexSet(mnl, mnl+m, 1), lmd.FloatArray())
//fmt.Printf("after l:\n%v\n", lmbda)
/*
For the 'q' blocks, compute lists 'v', 'beta'.
The vector v[k] has unit hyperbolic norm:
(sqrt( v[k]' * J * v[k] ) = 1 with J = [1, 0; 0, -I]).
beta[k] is a positive scalar.
The hyperbolic Householder matrix H = 2*v[k]*v[k]' - J
defined by v[k] satisfies
(beta[k] * H) * zk = (beta[k] * H) \ sk = lambda_k
where sk = s[indq[k]:indq[k+1]], zk = z[indq[k]:indq[k+1]].
lambda_k is stored in lmbda[indq[k]:indq[k+1]].
*/
ind := mnl + dims.At("l")[0]
var beta *matrix.FloatMatrix
for _, k := range dims.At("q") {
W.Append("v", matrix.FloatZeros(k, 1))
}
//.........這裏部分代碼省略.........