Neural Network-based inverse matrix algorithm 1

Source: Internet
Author: User

 

Is the result of finding the inverse using the Matlab function INV and the MATLAB version of the neural network algorithm described in this article

Implemented in C/C ++

From the comparison of the results, the algorithm is good.

 

MATLAB source code

Function C = inverse_1 (a) <br/> learning_rate = 0.065; <br/> epoch = 2500; <br/> C = zeros (SIZE ()); <br/> I = eye (SIZE (a); <br/> for I = 1: epoch <br/> C = C + learning_rate * transpose () * (I-A * C); <br/> end <br/>

C source code

The source code is dependent on several other files related to matrix operations. Then I will post the complete program.

# Include <vector> <br/> # include <assert. h> <br/> # include "matrix. H "</P> <p> using namespace STD; </P> <p> // C is the inverse of, the original matrix <br/> static void _ initialize_c (Matrix & C) <br/>{< br/> assert (C. size ()! = 0); </P> <p> vect V (C. size (); <br/> for (unsigned int I = 0; I <v. size (); I ++) {<br/> C [I] = V; <br/>}< br/> // identity matrix <br/> static void _ initialize_ I (Matrix & I) <br/> {<br/> for (INT I = 0; I <I. size (); I ++) {<br/> I [I] [I] = 1; <br/>}< br/> matrix matrix_inverse_1 (const Matrix & mat) <br/>{< br/> assert (mat. size () = mat [0]. size (); </P> <p> int mat_size = mat. size (); </P> <p> Matrix Weight = matrix_mul (matrix_transpose (MAT), mat); <br/> matrix C (mat_size ); <br/> _ initialize_c (c); <br/> Matrix I = C; <br/> _ initialize_ I (I ); </P> <p> double learning_rate = 0.065; // learning rate <br/> int epoch = 2500; // training generation <br/> while (EPOCH --> 0) {<br/> C = C + learning_rate * matrix_transpose (MAT) * (I-mat * C); <br/>}< br/> return C; <br/>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.