Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please update your use of github.com/gonum/matrix to github.com/gonum/gonum #2

Open
nim-nim opened this issue Mar 19, 2018 · 2 comments

Comments

@nim-nim
Copy link

nim-nim commented Mar 19, 2018

github.com/gonum/matrix is deprecated

@nim-nim
Copy link
Author

nim-nim commented Mar 20, 2018

diff -uNr go-moremath-033754ab1fee508c9f98f2785eec2365964e0b05.orig/fit/lsquares.go go-moremath-033754ab1fee508c9f98f2785eec2365964e0b05/fit/lsquares.go
--- go-moremath-033754ab1fee508c9f98f2785eec2365964e0b05.orig/fit/lsquares.go   2017-02-10 20:34:28.000000000 +0100
+++ go-moremath-033754ab1fee508c9f98f2785eec2365964e0b05/fit/lsquares.go        2018-03-20 13:07:28.200088026 +0100
@@ -9,7 +9,7 @@
        "math"
        "strings"

-       "github.com/gonum/matrix/mat64"
+       "gonum.org/v1/gonum/mat"
 )

 // LinearLeastSquares computes the least squares fit for the function
@@ -60,36 +60,36 @@
        for i, term := range terms {
                term(xs, xTVals[i*len(xs):i*len(xs)+len(xs)])
        }
-       XT := mat64.NewDense(len(terms), len(xs), xTVals)
+       XT := mat.NewDense(len(terms), len(xs), xTVals)
        X := XT.T()

        // Construct 𝐗ᵀ𝐖.
-       var XTW *mat64.Dense
+       var XTW *mat.Dense
        if weights == nil {
                // 𝐖 is the identity matrix.
                XTW = XT
        } else {
                // Since 𝐖 is a diagonal matrix, we do this directly.
-               XTW = mat64.DenseCopyOf(XT)
-               WDiag := mat64.NewVector(len(weights), weights)
+               XTW = mat.DenseCopyOf(XT)
+               WDiag := mat.NewVecDense(len(weights), weights)
                for row := 0; row < len(terms); row++ {
-                       rowView := XTW.RowView(row)
+                       rowView := XTW.RowView(row).(*mat.VecDense)
                        rowView.MulElemVec(rowView, WDiag)
                }
        }

        // Construct 𝐲.
-       y := mat64.NewVector(len(ys), ys)
+       y := mat.NewVecDense(len(ys), ys)

        // Compute Β̂.
-       lhs := mat64.NewDense(len(terms), len(terms), nil)
+       lhs := mat.NewDense(len(terms), len(terms), nil)
        lhs.Mul(XTW, X)

-       rhs := mat64.NewVector(len(terms), nil)
+       rhs := mat.NewVecDense(len(terms), nil)
        rhs.MulVec(XTW, y)

        BVals := make([]float64, len(terms))
-       B := mat64.NewVector(len(terms), BVals)
+       B := mat.NewVecDense(len(terms), BVals)
        B.SolveVec(lhs, rhs)
        return BVals
 }

@dgryski
Copy link

dgryski commented Mar 27, 2018

ping @aclements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants