{"id":16511368,"url":"https://github.com/pbenner/autodiff","last_synced_at":"2025-10-14T14:15:57.692Z","repository":{"id":37659876,"uuid":"56498421","full_name":"pbenner/autodiff","owner":"pbenner","description":"Autodiff is a numerical library for the Go programming language that supports automatic differentiation. It implements routines for linear algebra (vector/matrix operations), numerical optimization and statistics","archived":false,"fork":false,"pushed_at":"2021-12-08T10:11:08.000Z","size":8246,"stargazers_count":55,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-09-08T20:55:46.452Z","etag":null,"topics":["automatic-differentiation","bfgs","cholesky-decomposition","determinant","eigenvalues","gauss-jordan","go","golang","gram-schmidt","hessenberg-reduction","linear-algebra","linear-algebra-library","newton-raphson","numerical-optimization","qr-algorithm","rprop","singular-value-decomposition","special-functions","statistical-models","statistics"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pbenner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-18T10:22:35.000Z","updated_at":"2024-07-12T09:07:07.000Z","dependencies_parsed_at":"2022-08-18T02:06:19.362Z","dependency_job_id":null,"html_url":"https://github.com/pbenner/autodiff","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/pbenner/autodiff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbenner%2Fautodiff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbenner%2Fautodiff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbenner%2Fautodiff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbenner%2Fautodiff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pbenner","download_url":"https://codeload.github.com/pbenner/autodiff/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbenner%2Fautodiff/sbom","scorecard":{"id":724768,"data":{"date":"2025-08-11","repo":{"name":"github.com/pbenner/autodiff","commit":"41b4960641a8743453a1a7ed6440662d017d5882"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: GNU General Public License v3.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-22T12:27:09.611Z","repository_id":37659876,"created_at":"2025-08-22T12:27:09.611Z","updated_at":"2025-08-22T12:27:09.611Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019125,"owners_count":26086679,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automatic-differentiation","bfgs","cholesky-decomposition","determinant","eigenvalues","gauss-jordan","go","golang","gram-schmidt","hessenberg-reduction","linear-algebra","linear-algebra-library","newton-raphson","numerical-optimization","qr-algorithm","rprop","singular-value-decomposition","special-functions","statistical-models","statistics"],"created_at":"2024-10-11T15:59:55.601Z","updated_at":"2025-10-14T14:15:57.673Z","avatar_url":"https://github.com/pbenner.png","language":"Go","readme":"## Documentation\n\nAutodiff is a numerical optimization and linear algebra library for the Go / Golang programming language. It implements basic automatic differentation for many mathematical routines. The documentation of this package can be found [here](https://godoc.org/github.com/pbenner/autodiff).\n\n## Scalars\n\nAutodiff defines three different scalar types. A *Scalar* contains a single mutable value that can be the result of a mathematical operation, whereas the value of a *ConstScalar* is constant and fixed when the scalar is created. Automatic differentiation is implemented by *MagicScalar* types that allow to compute first and second order derivatives. Autodiff supports the following scalars types:\n\n| Scalar       | Implemented interfaces\n|--------------|------------------------------------------------------ |\n| ConstInt8    | ConstScalar                                           |\n| ConstInt16   | ConstScalar                                           |\n| ConstInt32   | ConstScalar                                           |\n| ConstInt64   | ConstScalar                                           |\n| ConstInt     | ConstScalar                                           |\n| ConstFloat32 | ConstScalar                                           |\n| ConstFloat64 | ConstScalar                                           |\n| Int8         | ConstScalar, Scalar                                   |\n| Int16        | ConstScalar, Scalar                                   |\n| Int32        | ConstScalar, Scalar                                   |\n| Int64        | ConstScalar, Scalar                                   |\n| Int          | ConstScalar, Scalar                                   |\n| Float32      | ConstScalar, Scalar                                   |\n| Float64      | ConstScalar, Scalar                                   |\n| Real32       | ConstScalar, Scalar, MagicScalar                      |\n| Real64       | ConstScalar, Scalar, MagicScalar                      |\n\nThe *ConstScalar*, *Scalar* and *MagicScalar* interfaces define the following operations:\n\n| Function     | Description                                           |\n|--------------|------------------------------------------------------ |\n| GetInt8      | Get value as int8                                     |\n| GetInt16     | Get value as int16                                    |\n| GetInt32     | Get value as int32                                    |\n| GetInt64     | Get value as int64                                    |\n| GetInt       | Get value as int                                      |\n| GetFloat32   | Get value as float32                                  |\n| GetFloat64   | Get value as float64                                  |\n| Equals       | Check if two constants are equal                      |\n| Greater      | True if first constant is greater                     |\n| Smaller      | True if first constant is smaller                     |\n| Sign         | Returns the sign of the scalar                        |\n\nThe *Scalar* and *MagicScalar* interfaces define the following operations:\n\n| Function     | Description                                           |\n|--------------|------------------------------------------------------ |\n| SetInt8      | Set value by passing an int8 variable                 |\n| SetInt16     | Set value by passing an int16 variable                |\n| SetInt32     | Set value by passing an int32 variable                |\n| SetInt64     | Set value by passing an int64 variable                |\n| SetInt       | Set value by passing an int variable                  |\n| SetFloat32   | Set value by passing an float32 variable              |\n| SetFloat64   | Set value by passing an float64 variable              |\n\nThe *Scalar* and *MagicScalar* interfaces define the following mathematical operations:\n\n| Function     | Description                                           |\n| ------------ | ----------------------------------------------------- |\n| Min          | Minimum                                               |\n| Max          | Maximum                                               |\n| Abs          | Absolute value                                        |\n| Sign         | Sign                                                  |\n| Neg          | Negation                                              |\n| Add          | Addition                                              |\n| Sub          | Substraction                                          |\n| Mul          | Multiplication                                        |\n| Div          | Division                                              |\n| Pow          | Power                                                 |\n| Sqrt         | Square root                                           |\n| Exp          | Exponential function                                  |\n| Log          | Logarithm                                             |\n| Log1p        | Logarithm of 1+x                                      |\n| Log1pExp     | Logarithm of 1+Exp(x)                                 |\n| Logistic     | Standard logistic function                            |\n| Erf          | Error function                                        |\n| Erfc         | Complementary error function                          |\n| LogErfc      | Log complementary error function                      |\n| Sigmoid      | Numerically stable sigmoid function                   |\n| Sin          | Sine                                                  |\n| Sinh         | Hyperbolic sine                                       |\n| Cos          | Cosine                                                |\n| Cosh         | Hyperbolic cosine                                     |\n| Tan          | Tangent                                               |\n| Tanh         | Hyperbolic tangent                                    |\n| LogAdd       | Addition on log scale                                 |\n| LogSub       | Substraction on log scale                             |\n| SmoothMax    | Differentiable maximum                                |\n| LogSmoothMax | Differentiable maximum on log scale                   |\n| Gamma        | Gamma function                                        |\n| Lgamma       | Log gamma function                                    |\n| Mlgamma      | Multivariate log gamma function                       |\n| GammaP       | Lower incomplete gamma function                       |\n| BesselI      | Modified Bessel function of the first kind            |\n| LogBesselI   | Log of the Modified Bessel function of the first kind |\n\n## Vectors and Matrices\n\nAutodiff implements dense and sparse vectors and matrices that support basic linear algebra operations. The following vector and matrix types are provided by autodiff:\n\n| Type                     | Scalar       | Description                            |\n|--------------------------|--------------|----------------------------------------|\n| DenseInt8Vector          | Int8         | Dense vector of Int8 scalars           |\n| DenseInt16Vector         | Int16        | Dense vector of Int16 scalars          |\n| DenseInt32Vector         | Int32        | Dense vector of Int32 scalars          |\n| DenseInt64Vector         | Int64        | Dense vector of Int64 scalars          |\n| DenseIntVector           | Int          | Dense vector of Int scalars            |\n| DenseFloat32Vector       | Float32      | Dense vector of Float32 scalars        |\n| DenseFloat64Vector       | Float64      | Dense vector of Float64 scalars        |\n| DenseReal32Vector        | Real32       | Dense vector of Real32 scalars         |\n| DenseReal64Vector        | Real64       | Dense vector of Real64 scalars         |\n| SparseInt8Vector         | Int8         | Sparse vector of Int8 scalars          |\n| SparseInt16Vector        | Int16        | Sparse vector of Int16 scalars         |\n| SparseInt32Vector        | Int32        | Sparse vector of Int32 scalars         |\n| SparseInt64Vector        | Int64        | Sparse vector of Int64 scalars         |\n| SparseIntVector          | Int          | Sparse vector of Int scalars           |\n| SparseFloat32Vector      | Float32      | Sparse vector of Float32 scalars       |\n| SparseFloat64Vector      | Float64      | Sparse vector of Float64 scalars       |\n| SparseReal32Vector       | Real32       | Sparse vector of Real32 scalars        |\n| SparseReal64Vector       | Real64       | Sparse vector of Real64 scalars        |\n| SparseConstInt8Vector    | ConstInt8    | Sparse vector of ConstInt8 scalars     |\n| SparseConstInt16Vector   | ConstInt16   | Sparse vector of ConstInt16 scalars    |\n| SparseConstInt32Vector   | ConstInt32   | Sparse vector of ConstInt32 scalars    |\n| SparseConstInt64Vector   | ConstInt64   | Sparse vector of ConstInt64 scalars    |\n| SparseConstIntVector     | ConstInt     | Sparse vector of ConstInt scalars      |\n| SparseConstFloat32Vector | ConstFloat32 | Sparse vector of ConstFloat32 scalars  |\n| SparseConstFloat64Vector | ConstFloat64 | Sparse vector of ConstFloat64 scalars  |\n| DenseInt8Matrix          | Int8         | Dense matrix of Int8 scalars           |\n| DenseInt16Matrix         | Int16        | Dense matrix of Int16 scalars          |\n| DenseInt32Matrix         | Int32        | Dense matrix of Int32 scalars          |\n| DenseInt64Matrix         | Int64        | Dense matrix of Int64 scalars          |\n| DenseIntMatrix           | Int          | Dense matrix of Int scalars            |\n| DenseFloat32Matrix       | Float32      | Dense matrix of Float32 scalars        |\n| DenseFloat64Matrix       | Float64      | Dense matrix of Float64 scalars        |\n| DenseReal32Matrix        | Real32       | Dense matrix of Real32 scalars         |\n| DenseReal64Matrix        | Real64       | Dense matrix of Real64 scalars         |\n| SparseInt8Matrix         | Int8         | Sparse matrix of Int8 scalars          |\n| SparseInt16Matrix        | Int16        | Sparse matrix of Int16 scalars         |\n| SparseInt32Matrix        | Int32        | Sparse matrix of Int32 scalars         |\n| SparseInt64Matrix        | Int64        | Sparse matrix of Int64 scalars         |\n| SparseIntMatrix          | Int          | Sparse matrix of Int scalars           |\n| SparseFloat32Matrix      | Float32      | Sparse matrix of Float32 scalars       |\n| SparseFloat64Matrix      | Float64      | Sparse matrix of Float64 scalars       |\n| SparseReal32Matrix       | Real32       | Sparse matrix of Real32 scalars        |\n| SparseReal64Matrix       | Real64       | Sparse matrix of Real64 scalars        |\n\nAutodiff defines three vector interfaces *ConstVector*, *Vector*, and *MagicVector*:\n\n| Interface                        | Function          | Description                                               |\n|----------------------------------|-------------------|-----------------------------------------------------------|\n| ConstVector                      | Dim               | Return the length of the vector                           |\n| ConstVector                      | Equals            | Returns true if the two vectors are equal                 |\n| ConstVector                      | Table             | Converts vector to a string                               |\n| ConstVector                      | Int8At            | Returns the scalar at the given position as int8          |\n| ConstVector                      | Int16At           | Returns the scalar at the given position as int16         |\n| ConstVector                      | Int32At           | Returns the scalar at the given position as int32         |\n| ConstVector                      | Int64At           | Returns the scalar at the given position as int64         |\n| ConstVector                      | IntAt             | Returns the scalar at the given position as int           |\n| ConstVector                      | Float32At         | Returns the scalar at the given position as Float32       |\n| ConstVector                      | Float64At         | Returns the scalar at the given position as Float64       |\n| ConstVector                      | ConstAt           | Returns the scalar at the given position as *ConstScalar* |\n| ConstVector                      | ConstSlice        | Returns a slice as a constant vector (*ConstVector*)      |\n| ConstVector                      | AsConstMatrix     | Convert vector to a matrix of type *ConstMatrix*          |\n| ConstVector                      | ConstIterator     | Returns a constant iterator                               |\n| ConstVector                      | CloneConstVector  | Return a deep copy of the vector as *ConstVector*         |\n| ConstVector, Vector              | At                | Return the scalar the given index                         |\n| ConstVector, Vector              | Reset             | Set all scalars to zero                                   |\n| ConstVector, Vector              | Set               | Set the value and derivatives of a scalar                 |\n| ConstVector, Vector              | Slice             | Return a slice of the vector                              |\n| ConstVector, Vector              | Export            | Export vector to file                                     |\n| ConstVector, Vector              | Permute           | Permute elements of the vector                            |\n| ConstVector, Vector              | ReverseOrder      | Reverse the order of vector elements                      |\n| ConstVector, Vector              | Sort              | Sort vector elements                                      |\n| ConstVector, Vector              | AppendScalar      | Append a single scalar to the vector                      |\n| ConstVector, Vector              | AppendVector      | Append another vector                                     |\n| ConstVector, Vector              | Swap              | Swap two elements of the vector                           |\n| ConstVector, Vector              | AsMatrix          | Convert vector to a matrix                                |\n| ConstVector, Vector              | Iterator          | Returns an iterator                                       |\n| ConstVector, Vector              | CloneVector       | Return a deep copy of the vector as *Vector*              |\n| ConstVector, Vector, MagicVector | MagicAt           | Returns the scalar at the given position as *MagicScalar* |\n| ConstVector, Vector, MagicVector | MagicSlice        | Resutns a slice as a magic vector (*MagicVector*)         |\n| ConstVector, Vector, MagicVector | AppendMagicScalar | Append a single magic scalar                              |\n| ConstVector, Vector, MagicVector | AppendMagicVector | Append a magic vector                                     |\n| ConstVector, Vector, MagicVector | AsMagicMatrix     | Convert vector to a matrix of type *MagicMatrix*          |\n| ConstVector, Vector, MagicVector | CloneMagicVector  | Return a deep copy of the vector as *MagicVector*         |\n\nVectors support the following mathematical operations:\n\n| Function | Description                      |\n| -------- | -------------------------------- |\n| VaddV    | Element-wise addition            |\n| VsubV    | Element-wise substraction        |\n| VmulV    | Element-wise multiplication      |\n| VdivV    | Element-wise division            |\n| VaddS    | Addition of a scalar             |\n| VsubS    | Substraction of a scalar         |\n| VmulS    | Multiplication with a scalar     |\n| VdivS    | Division by a scalar             |\n| VdotV    | Dot product                      |\n\nAutodiff defines three matrix interfaces *ConstMatrix*, *Matrix*, and *MagicMatrix*:\n\n| Interface                        | Function          | Description                                               |\n|----------------------------------|-------------------|-----------------------------------------------------------|\n| ConstMatrix                      | Dims              | Return the number of rows and columns of the matrix       |\n| ConstMatrix                      | Equals            | Returns true if the two matrixs are equal                 |\n| ConstMatrix                      | Table             | Converts matrix to a string                               |\n| ConstMatrix                      | Int8At            | Returns the scalar at the given position as int8          |\n| ConstMatrix                      | Int16At           | Returns the scalar at the given position as int16         |\n| ConstMatrix                      | Int32At           | Returns the scalar at the given position as int32         |\n| ConstMatrix                      | Int64At           | Returns the scalar at the given position as int64         |\n| ConstMatrix                      | IntAt             | Returns the scalar at the given position as int           |\n| ConstMatrix                      | Float32At         | Returns the scalar at the given position as Float32       |\n| ConstMatrix                      | Float64At         | Returns the scalar at the given position as Float64       |\n| ConstMatrix                      | ConstAt           | Returns the scalar at the given position as *ConstScalar* |\n| ConstMatrix                      | ConstSlice        | Returns a slice as a constant matrix (*ConstMatrix*)      |\n| ConstMatrix                      | ConstRow          | Returns the ith row as a *ConstVector*                    |\n| ConstMatrix                      | ConstCol          | Returns the jth column as a *ConstVector*                 |\n| ConstMatrix                      | ConstIterator     | Returns a constant iterator                               |\n| ConstMatrix                      | AsConstVector     | Convert matrix to a vector of type *ConstVector*          |\n| ConstMatrix                      | CloneConstMatrix  | Return a deep copy of the matrix as *ConstMatrix*         |\n| ConstMatrix, Matrix              | At                | Return the scalar the given index                         |\n| ConstMatrix, Matrix              | Reset             | Set all scalars to zero                                   |\n| ConstMatrix, Matrix              | Set               | Set the value and derivatives of a scalar                 |\n| ConstMatrix, Matrix              | Slice             | Return a slice of the matrix                              |\n| ConstMatrix, Matrix              | Export            | Export matrix to file                                     |\n| ConstMatrix, Matrix              | Permute           | Permute elements of the matrix                            |\n| ConstMatrix, Matrix              | ReverseOrder      | Reverse the order of matrix elements                      |\n| ConstMatrix, Matrix              | Sort              | Sort matrix elements                                      |\n| ConstMatrix, Matrix              | AppendScalar      | Append a single scalar to the matrix                      |\n| ConstMatrix, Matrix              | AppendMatrix      | Append another matrix                                     |\n| ConstMatrix, Matrix              | Swap              | Swap two elements of the matrix                           |\n| ConstMatrix, Matrix              | SwapRows          | Swap two rows                                             |\n| ConstMatrix, Matrix              | SwapCols          | Swap two columns                                          |\n| ConstMatrix, Matrix              | PermuteRows       | Permute rows                                              |\n| ConstMatrix, Matrix              | PermuteCols       | Permute columns                                           |\n| ConstMatrix, Matrix              | Row               | Returns a copy of the ith row as a *Vector*               |\n| ConstMatrix, Matrix              | Col               | Returns a copy of the jth column a *Vector*               |\n| ConstMatrix, Matrix              | T                 | Returns a transposed matrix                               |\n| ConstMatrix, Matrix              | Tip               | Transpose in-place                                        |\n| ConstMatrix, Matrix              | AsVector          | Convert matrix to a vector of type *Vector*               |\n| ConstMatrix, Matrix              | Iterator          | Returns an iterator                                       |\n| ConstMatrix, Matrix              | CloneMatrix       | Return a deep copy of the matrix as *Matrix*              |\n| ConstMatrix, Matrix, MagicMatrix | MagicAt           | Returns the scalar at the given position as *MagicScalar* |\n| ConstMatrix, Matrix, MagicMatrix | MagicSlice        | Resutns a slice as a magic matrix (*MagicMatrix*)         |\n| ConstMatrix, Matrix, MagicMatrix | MagicT            | Returns a transposed matrix of type *MagicMatrix*         |\n| ConstMatrix, Matrix, MagicMatrix | AppendMagicScalar | Append a single magic scalar                              |\n| ConstMatrix, Matrix, MagicMatrix | AppendMagicMatrix | Append a magic matrix                                     |\n| ConstMatrix, Matrix, MagicMatrix | CloneMagicMatrix  | Return a deep copy of the matrix as *MagicMatrix*         |\n\nMatrices support the following linear algebra operations:\n\n| Function | Description                      |\n| -------- | -------------------------------- |\n| MaddM    | Element-wise addition            |\n| MsubM    | Element-wise substraction        |\n| MmulM    | Element-wise multiplication      |\n| MdivM    | Element-wise division            |\n| MaddS    | Addition of a scalar             |\n| MsubS    | Substraction of a scalar         |\n| MmulS    | Multiplication with a scalar     |\n| MdivS    | Division by a scalar             |\n| MdotM    | Matrix product                   |\n| Outer    | Outer product                    |\n\nMethods, such as *VaddV* and *MaddM*, are generic and accept vector or matrix types that implement the respective *ConstVector* or *ConstMatrix* interface. However, opertions on interface types are much slower than on concrete types, which is why most vector and matrix types in *autodiff* also implement methods that operate on concrete types. For instance, *DenseFloat64Vector* implements a method called *VADDV* that takes as arguments two objects of type *DenseFloat64Vector*. Methods that operate on concrete types are always named in capital letters.\n\n## Algorithms\n\nThe algorithms package contains more complex linear algebra and optimization routines:\n\n| Package             | Description                                             |\n| ------------------- | ------------------------------------------------------- |\n| Adam                | Adam stochastic gradient method                         |\n| bfgs                | Broyden-Fletcher-Goldfarb-Shanno (BFGS) algorithm       |\n| blahut              | Blahut algorithm (channel capacity)                     |\n| cholesky            | Cholesky and LDL factorization                          |\n| determinant         | Matrix determinants                                     |\n| eigensystem         | Compute Eigenvalues and Eigenvectors                    |\n| gaussJordan         | Gauss-Jordan algorithm                                  |\n| gradientDescent     | Vanilla gradient desent algorithm                       |\n| gramSchmidt         | Gram-Schmidt algorithm                                  |\n| hessenbergReduction | Matrix Hessenberg reduction                             |\n| lineSearch          | Line-search (satisfying the Wolfe conditions)           |\n| matrixInverse       | Matrix inverse                                          |\n| msqrt               | Matrix square root                                      |\n| msqrtInv            | Inverse matrix square root                              |\n| newton              | Newton's method (root finding and optimization)         |\n| qrAlgorithm         | QR-Algorithm for computing Schur decompositions         |\n| rprop               | Resilient backpropagation                               |\n| svd                 | Singular Value Decomposition (SVD)                      |\n| saga                | SAGA stochastic average gradient descent method         |\n\n## Basic usage\n\nImport the autodiff library with\n```go\n  import . \"github.com/pbenner/autodiff\"\n```\nA scalar holding the value *1.0* can be defined in several ways, i.e.\n```go\n  a := NullScalar(Real64Type)\n  a.SetFloat64(1.0)\n  b := NewReal64(1.0)\n  c := NewFloat64(1.0)\n```\n*a* and *b* are both *MagicScalar*s, however *a* has type *Scalar* whereas *b* has type **Real64* which implements the *Scalar* interface. Variable *c* is of type *Float64* which cannot carry any derivatives. Basic operations such as additions are defined on all Scalars, i.e.\n```go\n  a.Add(a, b)\n```\nwhich stores the result of adding *a* and *b* in *a*. The *ConstFloat64* type allows to define float64 constants without allocation of additional memory. For instance\n```go\n  a.Add(a, ConstFloat64(1.0))\n```\nadds a constant value to *a* where a type cast is used to define the constant *1.0*.\n\nTo differentiate a function *f(x,y) = x y^3 + 4*, we define\n```go\n  f := func(x, y ConstScalar) MagicScalar {\n    // compute f(x,y) = x*y^3 + 4\n    z := NewReal64()\n    z.Pow(y, ConstFloat64(3.0))\n    z.Mul(z, x)\n    z.Add(z, ConstFloat64(4.0))\n    return z\n  }\n```\nthat accepts as arguments two *ConstScalar* variables and returns a *MagicScalar*. We first define two *MagicReal* variables\n```go\n  x := NewReal64(2)\n  y := NewReal64(4)\n```\nthat store the value at which the derivatives should be evaluated. Afterwards, *x* and *y* must be activated with\n```go\n  Variables(2, x, y)\n```\nwhere the first argument sets the order of the derivatives. *Variables()* should only be called once, as it allocates memory for the given magic variables. In this case, derivatives up to second order are computed. After evaluating *f*, i.e.\n```go\n  z := f(x, y)\n```\nthe function value at *(x,y) = (2, 4)* can be retrieved with *z.GetFloat64()*. The first and second partial derivatives can be accessed with *z.GetDerivative(i)* and *z.GetHessian(i, j)*, where the arguments specify the index of the variable. For instance, the derivative of *f* with respect to *x* is returned by *z.GetDerivative(0)*, whereas the derivative with respect to *y* by *z.GetDerivative(1)*.\n\n## Basic linear algebra\n\nVectors and matrices can be created with\n```go\n  v := NewDenseFloat64Vector([]float64{1,2})\n  m := NewDenseFloat64Matrix([]float64{1,2,3,4}, 2, 2)\n\n  v_ := NewDenseReal64Vector([]float64{1,2})\n  m_ := NewDenseReal64Matrix([]float64{1,2,3,4}, 2, 2)\n```\nwhere *v* has length 2 and *m* is a 2x2 matrix. With\n```go\n  v := NullDenseFloat64Vector(2)\n  m := NullDenseFloat64Matrix(2, 2)\n```\nall values are initially set to zero. Vector and matrix elements can be accessed with the *At*, *MagicAt* or *ConstAt* methods, which return a reference to the scalar implementing either a *Scalar*, *MagicScalar* or *ConstScalar*, i.e.\n```go\n  m.At(1,1).Add(v.ConstAt(0), v.ConstAt(1))\n```\nadds the first two values in *v* and stores the result in the lower right element of the matrix *m*. Autodiff supports basic linear algebra operations, for instance, the vector matrix product can be computed with\n```go\n  w := NullDenseFloat64Vector(2)\n  w.MdotV(m, v)\n```\nwhere the result is stored in w. Other operations, such as computing the eigenvalues and eigenvectors of a matrix, require importing the respective package from the algorithm library, i.e.\n```go\n  import \"github.com/pbenner/autodiff/algorithm/eigensystem\"\n\n  lambda, _, _ := eigensystem.Run(m)\n```\n\n## Examples\n\n### Gradient descent\n\nCompare vanilla gradient descent with resilient backpropagation\n```go\n  import . \"github.com/pbenner/autodiff\"\n  import   \"github.com/pbenner/autodiff/algorithm/gradientDescent\"\n  import   \"github.com/pbenner/autodiff/algorithm/rprop\"\n\n  f := func(x_ ConstVector) MagicScalar {\n    x := x_.ConstAt(0)\n    // x^4 - 3x^3 + 2\n    r := NewReal64()\n    s := NewReal64()\n    r.Pow(x.ConstAt(0), ConstFloat64(4.0)\n    s.Mul(ConstFloat64(3.0), s.Pow(x, ConstFloat64(3.0)))\n    r.Add(ConstFloat64(2.0), r.Add(r, s))\n    return r\n  }\n  x0 := NewDenseFloat64Vector([]float64{8})\n  // vanilla gradient descent\n  xn1, _ := gradientDescent.Run(f, x0, 0.0001, gradientDescent.Epsilon{1e-8})\n  // resilient backpropagation\n  xn2, _ := rprop.Run(f, x0, 0.0001, 0.4, rprop.Epsilon{1e-8})\n```\n![Gradient descent](demo/example1/example1.png)\n\n\n### Matrix inversion\n\nCompute the inverse *r* of a matrix *m* by minimizing the Frobenius norm *||mb - I||*\n```go\n  import . \"github.com/pbenner/autodiff\"\n  import   \"github.com/pbenner/autodiff/algorithm/rprop\"\n\n  // define matrix r\n  m := NewDenseFloat64Matrix([]float64{1,2,3,4}, 2, 2)\n  // create identity matrix I\n  I := NullDenseFloat64Matrix(2, 2)\n  I.SetIdentity()\n\n  // magic variables for computing the Frobenius norm and its derivative\n  t := NewDenseReal64Matrix(2, 2)\n  s := NewReal64()\n  // objective function\n  f := func(x ConstVector) MagicScalar {\n    t.Set(x)\n    s.Mnorm(t.MsubM(t.MmulM(m, t), I))\n    return s\n  }\n  r, _ := rprop.Run(f, r.GetValues(), 0.01, 0.1, rprop.Epsilon{1e-12})\n```\n\n### Newton's method\n\nFind the root of a function *f* with initial value *x0 = (1,1)*\n\n```go\n  import . \"github.com/pbenner/autodiff\"\n  import   \"github.com/pbenner/autodiff/algorithm/newton\"\n\n  t := NullReal64()\n\n  f := func(x ConstVector) MagicVector {\n    x1 := x.ConstAt(0)\n    x2 := x.ConstAt(1)\n    y  := NullDenseReal64Vector(2)\n    y1 := y.At(0)\n    y2 := y.At(1)\n    // y1 = x1^2 + x2^2 - 6\n    t .Pow(x1, ConstFloat64(2.0))\n    y1.Add(y1, t)\n    t .Pow(x2, ConstFloat64(2.0))\n    y1.Add(y1, t)\n    y1.Sub(y1, ConstFloat64(6.0))\n    // y2 = x1^3 - x2^2\n    t .Pow(x1, ConstFloat64(3.0))\n    y2.Add(y2, t)\n    t .Pow(x2, ConstFloat64(2.0))\n    y2.Sub(y2, t)\n\n    return y\n  }\n\n  x0    := NewDenseFloat64Vector([]float64{1,1})\n  xn, _ := newton.RunRoot(f, x0, newton.Epsilon{1e-8})\n```\n\n### Minimize Rosenbrock's function\nCompare Adam, Newton's method, BFGS and Rprop for minimizing Rosenbrock's function\n\n```go\n  import   \"fmt\"\n\n  import . \"github.com/pbenner/autodiff\"\n  import   \"github.com/pbenner/autodiff/algorithm/adam\"\n  import   \"github.com/pbenner/autodiff/algorithm/rprop\"\n  import   \"github.com/pbenner/autodiff/algorithm/bfgs\"\n  import   \"github.com/pbenner/autodiff/algorithm/newton\"\n\n  f := func(x ConstVector) (MagicScalar, error) {\n    // f(x1, x2) = (a - x1)^2 + b(x2 - x1^2)^2\n    // a = 1\n    // b = 100\n    // minimum: (x1,x2) = (a, a^2)\n    a := ConstFloat64(  1.0)\n    b := ConstFloat64(100.0)\n    c := ConstFloat64(  2.0)\n    s := NullReal64()\n    t := NullReal64()\n    s.Pow(s.Sub(a, x.ConstAt(0)), c)\n    t.Mul(b, t.Pow(t.Sub(x.ConstAt(1), t.Mul(x.ConstAt(0), x.ConstAt(0))), c))\n    s.Add(s, t)\n    return s, nil\n  }\n  hook_adam := func(x, gradient ConstVector, hessian ConstMatrix, y ConstScalar) bool {\n    fmt.Println(\"x       :\", x)\n    fmt.Println(\"gradient:\", gradient)\n    fmt.Println(\"y       :\", y)\n    fmt.Println()\n    return false\n  }\n  hook_rprop := func(gradient, step []float64, x ConstVector, y ConstScalar) bool {\n    fmt.Println(\"x       :\", x)\n    fmt.Println(\"gradient:\", gradient)\n    fmt.Println(\"y       :\", y)\n    fmt.Println()\n    return false\n  }\n  hook_bfgs := func(x, gradient ConstVector, y ConstScalar) bool {\n    fmt.Println(\"x       :\", x)\n    fmt.Println(\"gradient:\", gradient)\n    fmt.Println(\"y       :\", y)\n    fmt.Println()\n    return false\n  }\n  hook_newton := func(x, gradient ConstVector, hessian ConstMatrix, y ConstScalar) bool {\n    fmt.Println(\"x       :\", x)\n    fmt.Println(\"gradient:\", gradient)\n    fmt.Println(\"y       :\", y)\n    fmt.Println()\n    return false\n  }\n\n  x0 := NewDenseFloat64Vector([]float64{-0.5, 2})\n\n  adam.Run(f, x0,\n    adam.StepSize{0.1},\n    adam.Hook{hook_adam},\n    adam.Epsilon{1e-10})\n\n  rprop.Run(f, x0, 0.05, []float64{1.2, 0.8},\n    rprop.Hook{hook_rprop},\n    rprop.Epsilon{1e-10})\n\n  bfgs.Run(f, x0,\n    bfgs.Hook{hook_bfgs},\n    bfgs.Epsilon{1e-10})\n\n  newton.RunMin(f, x0,\n    newton.HookMin{hook_newton},\n    newton.Epsilon{1e-8},\n    newton.HessianModification{\"LDL\"})\n```\n![Gradient descent](demo/rosenbrock/rosenbrock.png)\n\n### Constrained optimization\n\nMaximize the function *f(x, y) = x + y* subject to *x^2 + y^2 = 1* by finding the critical point of the corresponding Lagrangian\n\n```go\n  import . \"github.com/pbenner/autodiff\"\n  import   \"github.com/pbenner/autodiff/algorithm/newton\"\n\n  z := NullReal64()\n  t := NullReal64()\n  // define the Lagrangian\n  f := func(x_ ConstVector) (MagicScalar, error) {\n    // z = x + y + lambda(x^2 + y^2 - 1)\n    x      := x_.ConstAt(0)\n    y      := x_.ConstAt(1)\n    lambda := x_.ConstAt(2)\n    z.Reset()\n    t.Pow(x, ConstFloat64(2.0))\n    z.Add(z, t)\n    t.Pow(y, ConstFloat64(2.0))\n    z.Add(z, t)\n    z.Sub(z, ConstFloat64(1.0))\n    z.Mul(z, lambda)\n    z.Add(z, y)\n    z.Add(z, x)\n\n    return z, nil\n  }\n  // initial value\n  x0    := NewDenseFloat64Vector([]float64{3,  5, 1})\n  // run Newton's method\n  xn, _ := newton.RunCrit(\n      f, x0,\n      newton.Epsilon{1e-8})\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpbenner%2Fautodiff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpbenner%2Fautodiff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpbenner%2Fautodiff/lists"}