Giter Site home page Giter Site logo

nnplusplus's People

Contributors

stagadish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nnplusplus's Issues

Some issues regarding your library

Hey,

Today I have got to know about your library thru your post in G+. I am also trying to write a similar library/toolbox to be used in optimization.

At first look at your library, I can say that it looks neat. However, it would be great if you considered using templates in your data structures. Or, if you would like to go for inheritance for some reason, then you can abstract some functionality in your base classes.

What I mean by the above comment is that, for example, you could use an activation function abstraction and keep a pointer inside your NeuralNet class to support different activation functions, such as:

#include <iostream>
#include <vector>

template <typename T>
class IFunction {
public:
  virtual T operator()(T variable) const = 0;
  virtual ~IFunction() = default;
};

template <typename T>
class PReLU : public IFunction<T> {
private:
  T alpha_;
public:
  PReLU(T alpha = T { 0 }) : alpha_ {alpha} { }
  T operator()(T variable) const override {
    T zero { 0 };
    return variable < zero ? alpha_*variable : variable;
  }
};

template <typename T>
class Identity : public IFunction<T> {
public:
  T operator()(T variable) const override {
    return variable;
  }
};

int main (int argc, char* argv[]) {
  Identity    <double>  identity_function {         };
  PReLU       <double>  relu_function     {         };
  PReLU       <double>  absolute_value    { -1.     };

  IFunction   <double>  *generic_func_ptr { nullptr };

  size_t numelems { 100ul };
  double xmin { -5. }, xmax { 5. }, dx {(xmax - xmin)/(numelems-1)};
  std::vector <double>  xvalues ( numelems );
  for (size_t idx = 0; idx < xvalues.size(); idx++)
    xvalues[idx] = xmin + idx*dx;

  // either directly call as if your instances were functions (actually, they
  // are functors right now, with their operator()'s overloaded)
  for (auto x : xvalues)
    std::cout << "x: " << x
              << ", identity_function(x): " << identity_function(x)
              << ", relu_function(x): " << relu_function(x)
              << std::endl;

  // or, use polymorphism
  generic_func_ptr = &identity_function;
  for (auto x : xvalues)
    std::cout << "x: " << x
              << ", generic_func_ptr->operator()(x): "
              << generic_func_ptr->operator()(x)
              << std::endl;

  // or, both
  generic_func_ptr = &relu_function;
  for (auto x : xvalues)
    std::cout << "x: " << x
              << ", (*generic_func_ptr)(x): " << (*generic_func_ptr)(x)
              << std::endl;

  // absolute value function
  for (auto x : xvalues)
    std::cout << "x: " << x
              << ", absolute_value(x): " << absolute_value(x)
              << std::endl;

  return 0;
}

I hope this helps :) Good luck with your code!...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.