本文整理汇总了Golang中github.com/gonum/matrix/mat64.Dense.RawMatrix方法的典型用法代码示例。如果您正苦于以下问题:Golang Dense.RawMatrix方法的具体用法?Golang Dense.RawMatrix怎么用?Golang Dense.RawMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/gonum/matrix/mat64.Dense
的用法示例。
在下文中一共展示了Dense.RawMatrix方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Predict
// double predict(const struct model *model_, const struct feature_node *x);
func Predict(model *Model, X *mat64.Dense) *mat64.Dense {
nRows, nCols := X.Dims()
cX := mapCDouble(X.RawMatrix().Data)
y := mat64.NewDense(nRows, 1, nil)
result := doubleToFloats(C.call_predict(
model.cModel, &cX[0], C.int(nRows), C.int(nCols)), nRows)
y.SetCol(0, result)
return y
}
示例2: predictFeaturized
// predictFeaturized multiplies the featureWeights by the featurized input and stores the value. It assumes
// that inMat and outMat already have the correct shape, but will replace the data in them
func predictFeaturized(featurizedInput []float64, output []float64, featureWeights *mat64.Dense, inMat *mat64.Dense, outMat *mat64.Dense) {
rm := inMat.RawMatrix()
rmin.Data = featurizedInput
inMat.LoadRawMatrix(rmin)
rm = outMat.RawMatrix()
rm.Data = outMat
outMat.LoadRawMatrix(rmin)
// Multiply the feature weights by the featurized input ond store
outMat.Mul(inMat, featureWeights)
}
示例3: PredictProba
// double predict_probability(const struct model *model_, const struct feature_node *x, double* prob_estimates);
func PredictProba(model *Model, X *mat64.Dense) *mat64.Dense {
nRows, nCols := X.Dims()
nrClasses := int(C.get_nr_class(model.cModel))
cX := mapCDouble(X.RawMatrix().Data)
y := mat64.NewDense(nRows, nrClasses, nil)
result := doubleToFloats(C.call_predict_proba(
model.cModel, &cX[0], C.int(nRows), C.int(nCols), C.int(nrClasses)),
nRows*nrClasses)
for i := 0; i < nRows; i++ {
y.SetRow(i, result[i*nrClasses:(i+1)*nrClasses])
}
return y
}
示例4: Train
// Wrapper for the `train` function in liblinear.
//
// `model* train(const struct problem *prob, const struct parameter *param);`
//
// The explanation of parameters are:
//
// solverType:
//
// for multi-class classification
// 0 -- L2-regularized logistic regression (primal)
// 1 -- L2-regularized L2-loss support vector classification (dual)
// 2 -- L2-regularized L2-loss support vector classification (primal)
// 3 -- L2-regularized L1-loss support vector classification (dual)
// 4 -- support vector classification by Crammer and Singer
// 5 -- L1-regularized L2-loss support vector classification
// 6 -- L1-regularized logistic regression
// 7 -- L2-regularized logistic regression (dual)
// for regression
// 11 -- L2-regularized L2-loss support vector regression (primal)
// 12 -- L2-regularized L2-loss support vector regression (dual)
// 13 -- L2-regularized L1-loss support vector regression (dual)
//
// eps is the stopping criterion.
//
// C_ is the cost of constraints violation.
//
// p is the sensitiveness of loss of support vector regression.
//
// classWeights is a map from int to float64, with the key be the class and the
// value be the weight. For example, {1: 10, -1: 0.5} means giving weight=10 for
// class=1 while weight=0.5 for class=-1
//
// If you do not want to change penalty for any of the classes, just set
// classWeights to nil.
func Train(X, y *mat64.Dense, bias float64, solverType int, c_, p, eps float64, classWeights map[int]float64) *Model {
var weightLabelPtr *C.int
var weightPtr *C.double
nRows, nCols := X.Dims()
cX := mapCDouble(X.RawMatrix().Data)
cY := mapCDouble(y.ColView(0).RawVector().Data)
nrWeight := len(classWeights)
weightLabel := []C.int{}
weight := []C.double{}
for key, val := range classWeights {
weightLabel = append(weightLabel, (C.int)(key))
weight = append(weight, (C.double)(val))
}
if nrWeight > 0 {
weightLabelPtr = &weightLabel[0]
weightPtr = &weight[0]
} else {
weightLabelPtr = nil
weightPtr = nil
}
model := C.call_train(
&cX[0], &cY[0],
C.int(nRows), C.int(nCols), C.double(bias),
C.int(solverType), C.double(c_), C.double(p), C.double(eps),
C.int(nrWeight), weightLabelPtr, weightPtr)
return &Model{
cModel: model,
}
}