diff --git a/p3/go.mod b/p3/go.mod index 7b732b1..6c46fd3 100644 --- a/p3/go.mod +++ b/p3/go.mod @@ -4,4 +4,4 @@ go 1.19 require git.dotya.ml/wanderer/ak9im/p2 v0.0.0-20230227032746-9910d7702660 -require gonum.org/v1/gonum v0.12.0 // indirect +require gonum.org/v1/gonum v0.12.0 diff --git a/p3/lrls/helper.go b/p3/lrls/helper.go new file mode 100644 index 0000000..3b67025 --- /dev/null +++ b/p3/lrls/helper.go @@ -0,0 +1,58 @@ +package lrls + +import ( + "errors" + "log" + + "gonum.org/v1/gonum/mat" +) + +// diagMat returns a Diagonal Matrix initialised with *data* across the main +// diagonal. +// nolint: unused +func diagMat(data []float64) *mat.DiagDense { + n := len(data) + + dm := mat.NewDiagDense(n, data) + + return dm +} + +// nolint: unused +func diagVals(n int) []float64 { + d := make([]float64, n) + + for i := 0; i < n; i++ { + d[i] = 1000000 + } + + return d +} + +// nolint: unused +func covMatrices(size, params int) ([]*mat.Dense, error) { + switch { + case size < 1: + return nil, errors.New("ErrCovMatricesSize") + + case params < 4 || params > 5: + log.Printf("error: params needs to be from the set {4 ,5}, got: %d", params) + return nil, errors.New("ErrBadParams") + } + + // slice of covariance matrices. + cms := make([]*mat.Dense, 0, size) + + for i := range cms { + cms[i] = mat.NewDense(params, params, nil) + } + + // create a matrix of the same shape as the cov matrix, with *diagVals* + // along the main diagonal. + dm := diagMat(diagVals(params)) + + // replace the second covariance matrix with the diagonal matrix. + cms[1].CloneFrom(dm) + + return cms, nil +}