Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by f_rodrigues · May 11, 2015 at 06:30 AM · functionmathmatrix

Matrix Multiplication, Standard Deviant and More usefull methods

I'm trying to create a Artificial Neural Network to make a evolving AI for a simple game.

But I'm struggling with the math required by it.

I made a neural net in Python, in around 100 lines, but when I tried to port it to c# I'm already at 200 lines of code, and I haven't even begin the back propagation algorithm (the bulk of the code in python).

For instance a simple input normalization in python takes 1 line:

 self.input_values = (inputs - np.mean(inputs , axis=0)) / np.std(inputs , axis=0)

While in C# I've to do it step by step:

 float[] normalize_input(float[] inputs){
     float sum = 0.0f;
     for (int i = 0; i < inputs.Length; i++) {
         sum += inputs[i] ;
     }
     float average = sum / inputs.Length;
 
     float[] deviations = new float[inputs.Length];
 
     for (int i = 0; i < inputs.Length; i++) {
         deviations[i] = Mathf.Pow(inputs[i] - average,2);
     }
 
     float sum_deviation = 0;
 
     for (int i = 0; i < deviations.Length; i++) {
         sum_deviation += deviations[i];
     }
 
     float variance = sum_deviation / deviations.Length;
 
     float std = Mathf.Sqrt (variance);
 
     for (int i = 0; i < inputs.Length; i++) {
         inputs[i] = (inputs[i] - average)/std;
     }
 
     return inputs;
 }

Is there any way to have access to this sort of math functions and matrix computation?

I know I can do it step by step like I'm doing, but it will take a lot longer, and further more, it's very hard to debug once something is off.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Baste · May 11, 2015 at 08:20 AM

You have the Mathf library which have some formulas. There's also the default C# Math library.

Other than that, you should just define all of the helpers you need. It's not very hard to define arbitrary-length mean methods, or matrix multiplication methods.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · May 11, 2015 at 01:20 PM 1
Share

For example, writing just float arraySum(float[] A) { ... } would eli$$anonymous$$ate two of your loops (I think C# has some sort of extension that does that, but not worth learning just for this.)

avatar image
1

Answer by tanoshimi · May 11, 2015 at 08:21 AM

I'm not that experienced with Python, but if you want to write C# code that handles vectors and matrices in a similar way to, say, MATLAB or Octave, you can try http://numerics.mathdotnet.com/ - I believe the Normalize() method will then provide the single-line method you're looking for.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Camera public functions 0 Answers

How to calculate a vertex position of SkinnedMesh? 1 Answer

Is this a valid projection matrix and why? 1 Answer

Spectrum of a mathematical function? 2 Answers

Large matrix formation and multiplication 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges