FastMatrix

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

FastMatrix

29 Jul 2018, 07:29

Link to GitHub repository
Link to Wiki

Hello everyone.
For a few Months I have been working on making Neural Networks more useable in AHK.
AHK is a bit too slow for this kind of calculations. Normally C/C++ or something similar is used. (Good libraries make use of the GPU)
The first requirement for that is being able to calculate faster when it comes to Matrices. (Neural Networks are mainly that type of calculations).

So I decided to write a few C functions and use them in AHK - but how would I use them in AHK?
Normally you would use a dll here - however that is kind of unwieldy. So I decided to go with MCode.
As it turns out the current MCode functions and compilers were not capable of correctly compiling a MCode function that I could use for this purpose.

So I had to write a new MCode compiler and a new MCode function: https://github.com/nnnik/MCode-Ex
This took a really long time and Im still not finished.
One of the biggest things that is still missing is the ability to compile for 64 bit and it will take a while before that is implemented correctly.
However I have already successfully created this FastMatrix library using it.

Any kind of documntation can be found on github.
I look forward to your questions and comments.
Update 3
Update 2
Update 1
Recommends AHK Studio
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: FastMatrix

29 Jul 2018, 11:21

I like your exercises, although I can not handle classes. You do so much work for this useful and underrated scripting language.
Without your work and that of others, I would not be able to program nearly as deeply and so quickly.

Thank you.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: FastMatrix

29 Jul 2018, 15:49

Frosti wrote:I like your exercises, although I can not handle classes. You do so much work for this useful and underrated scripting language.
Without your work and that of others, I would not be able to program nearly as deeply and so quickly.

Thank you.
Thank you for your kind response :)
I think that using this class is in fact very easy and possible with little to no knowledge about objects - would it help you if I add a few examles to show what it can do?
Recommends AHK Studio
SpecialGuest
Posts: 26
Joined: 15 May 2016, 07:49

Re: FastMatrix

29 Jul 2018, 17:57

Please do. Very interested in this as well.
AI, machine learning, neural networks and the likes are all topics one can not have enough knowledge about.
I'm not there yet but I'm learning. (Udacity atm - if you know good places do tell)
Thanks for sharing ! :)
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: FastMatrix

30 Jul 2018, 02:31

hmm yeah then I might add a simple tutorial about Linear algebra and how the Matrix relates to it all as well as how I implemented them in AHK.

BTW I learned a lot about AI from this video:
https://www.youtube.com/watch?v=IN69suHxS8w
also I can reccomend Googles course into AI.

I took the hard path and learned all the parts that make up AI step by step.
Recommends AHK Studio
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: FastMatrix

30 Jul 2018, 02:40

I only glanced on it for now, it seems intutive and easy to use :bravo: :superhappy:. I'll follow the continuation of this (infinite) project with interest :ugeek: .

Cheers and thank you very much for sharing.
example
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: FastMatrix

30 Jul 2018, 02:45

Glad you like it :)
Recommends AHK Studio
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: FastMatrix

04 Aug 2018, 10:00

Hello I kept on enhancing the class little by little and its slowly taking shape.
I also added a lot more documentation and resources that you can use and added a few examples.
Everything can be found in the
> Wiki <
Recommends AHK Studio
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: FastMatrix

05 Aug 2018, 13:08

:clap: A great piece of work! Enabling fast matrix calculations will not only make neural networks more usable with AHK, it generally adds a lot of power to the language! Possibilities! :D
:thumbup:
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: FastMatrix

06 Aug 2018, 06:17

Thanks for your kind words.
I feel the same way - Matrices are a simple yet powerful way of modifying a lot of vector data types.
And vector data types are almost everywhere.
Recommends AHK Studio
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: FastMatrix

11 Aug 2018, 05:32

I have added a few new features and updated the wiki a lot and added many new examples.
I look forward to any comments on how you like my explination or the general style of describing the class.
Recently the class was put into a practical test and that resulted in finding many bugs.
I decided to add many examples and check if these examples still work after I updated the class to test it.
update class wrote:
  • Added 2 new methods: magnitude and multiplyTransposed2
  • Added new features to the .values property
  • Made it possible to output to input for every action
  • Changed the sigmoid method to use C's exp functions
  • Changed the toString method to allow for function names too
  • Many bug fixes
update examples wrote:
  • Added 6 new examples: Values, LengthOfVector, Transpose, Sigmoid, Multiplies, OutputMatrix
  • Ordered examples by complexity
  • Gave them an introduction
  • Overhauled the examples using the new features
  • Fixing minor mistakes
update wiki wrote:
  • Added most pages in the wiki - some of them are empty though
  • Changed the index page to give an overview over the wiki
  • Completed the pages: quickstart and transition
  • Added new text to the linear algebraics page
  • Updated the examples page
  • Made a proper sidebar
Recommends AHK Studio
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: FastMatrix

20 Aug 2018, 05:26

Once again I have worked on the class.
The wiki is what i focused the most on this time around - sadly it doesn't seem like a lot has changed from a glance but the wiki is almost complete now.
I hope you give it a read and point out my mistakes.
update class wrote:
  • Added 2 new methods: getSize and getVersion
  • 1 bug fix
update examples and benchmarks wrote:
  • Added 1 new Example: multiplyByIdentity
  • Added benchmakrs in general and added the first benchmark: Comparison, added results for that benchmark
update wiki wrote:
  • Added the entire documentation pages for all methods
  • Completed the pages: How to achieve speed, Architecture, Future plans and How to contribute
  • The wiki is mostly complete - only a part of the linear algebraics and the entire update page is missing
Recommends AHK Studio
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: FastMatrix

20 Aug 2018, 11:12

Really good work. I'd recommend just copying numpy as much as possible, decrease time spent on laying groundwork, and building a practical AHK demo.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: FastMatrix

21 Aug 2018, 08:15

I have taken my time to reply since I had to get a look at NumPy first.
iseahound wrote:Really good work.
Thank you
iseahound wrote:I'd recommend just copying numpy as much as possible
I just had a look at NumPy - but Im not completely finished yet so I will have to do the same.
I can see the similarities to numpy. And I see a lot of things that could be made similar.
However I see a lot of things that need to be made different since AHK is a different language.
iseahound wrote:decrease time spent on laying groundwork
Sadly that won't be possible. There is no ground I could built this library upon so I have to make my own.
I do not feel like shipping a dll with my projects so I wouldnt want to use a library including a .dll.
No other MCode function is capable of compiling the code that I used in this project - so I had to make my own.
And thats a lot of work since I have to enable relocations and
iseahound wrote:and building a practical AHK demo.
Yeah that was planned next - I wanted to write a Neural Network library with it and then make the neural network library recognize handwritten letters.
Sadly to do that it's still missing minor data import(2 hours)/ and export features (30 minutes work).
The neural network library is mostly done too - just some minor changes.

What I also planned was to listen to peoples suggestions regarding what kind of examle they want to see.
What do you want to see as practical example for a matrix library?
I could recolour images or make them distorted.
I could calculate 3D graphics in AHK with this.
I could make more examples for neural networks.
I'll try to implement whatever you guys suggest.
Recommends AHK Studio
User avatar
Gio
Posts: 1247
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: FastMatrix

21 Aug 2018, 08:32

This is great! :shock:

Can't believe i missed this topic. Thank you very much for sharing this Nnnik, i will certainly make use of it when i get back to studying Neural Networks :D
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: FastMatrix

21 Aug 2018, 12:54

Gio wrote:This is great! :shock:

Can't believe i missed this topic. Thank you very much for sharing this Nnnik, i will certainly make use of it when i get back to studying Neural Networks :D
Thanks a lot.
The initial inspiration for this library stems from the conversation in the tutorials forums.
I still plan to write a basic implementation for neural nets - but I really want to make it possible to save.
Recommends AHK Studio
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: FastMatrix

21 Jun 2020, 17:22

nnnik wrote:
21 Aug 2018, 08:15
I could recolour images or make them distorted.
I could calculate 3D graphics in AHK with this.
I could make more examples for neural networks.
I'll try to implement whatever you guys suggest.
3D graphics or recoloring images would be really interesting, if you are still developing this library.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
User avatar
Chunjee
Posts: 1400
Joined: 18 Apr 2014, 19:05
Contact:

Re: FastMatrix

01 Jul 2020, 11:35

I wasn't aware of this work. Hope I can find a good project to play with it. Thanks!

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 159 guests