NeuraLegion / shainet

SHAInet - a pure Crystal machine learning library
MIT License
183 stars 19 forks source link

Object Oriented - move to leverage inheritance #68

Closed drujensen closed 5 years ago

drujensen commented 6 years ago

Looking through the code, I have a couple suggested changes to make it more OO:

NEURON_TYPES should be inherited. The base class would be Neuron and then MemoryNeuron would be inherited from it.

Learn or Training functions sgd, rprop, adam should be extracted out of the Network class. These should become their own class with base class Learn or something. Adam, SGD, ...

Cost functions should also be extracted out of the Network class. Base class would be Cost with each inherited class implementing the evaluate(input, expected)

Activation functions should be its own class. ...

WDYT?

ArtLinkov commented 6 years ago

@drujensen that's a great idea! Feel free to give it a go in a PR :) If you don't have time for this, we will add it to our task list and do our best to get to it.

drujensen commented 6 years ago

Ok, I will take a stab when I get a chance. In theory, someone could easily extend SHAInet by creating their own classes that inherit from the base to implement their own Learn/Cost/Activation functions.

bararchy commented 6 years ago

@drujensen Lately @ArtLinkov has been working on cost function as Proc, do you feel this is enough in regard to dynamic needs?

drujensen commented 6 years ago

@bararchy right, I saw that and its a huge improvement. 💯

The thing is that procs is more a functional approach instead of an object oriented one. I took a couple attempts to refactor some of this to try and make it more OO but it is difficult to do it in smaller chunks and will require more changes than I think you would want.

I think procs works just fine so not sure this is worth the effort. If I have the time, I might make another attempt at it but its not on my priority list at the moment.

You can close this if you don't want the ticket hanging around.