Skip to content

A basic automatic differentiation library built with C++ expression template pattern. The main focus of the project is not reinventing the wheel but push the limit of meta-programming in modern C++.

Notifications You must be signed in to change notification settings

f4ded4k/ET-Autodiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ET-Autodiff

A basic automatic differentiation library built with C++ expression templates.

Et::ConstantExpr C1{ 4 }, C2{ 2 };
Et::VariableExpr X1{ 5.53 }, X2{ -3.12 };
Et::PlaceholderExpr P;

Declaration of Constants,Variables & Placeholder objects.

auto Y = X1 * X1 + X2 * X2 + C1 * X1 + C2 * X2 + P;

Define the Cost function to minimize with respect to the Variables.

y = f(x1,x2) = x12 + x22 + 4x1 + 2x2 - 6.3

Et::GradientDescentOptimizer Optimizer{ Y };

Create an Optimizer object which simplifies the training steps.

int Iterations = 1000;
for (int i = 0; i < Iterations; i++)
{
   std::cout << "Value at #" << i + 1 << " : " <<

   Optimizer
      .ForwardPass(Et::H(P, -6.3))
      .Minimize(0.01)
      .GetPreResult()

   << std::endl;
}

Apply Backpropagation 1,000 times.

std::cout << "Final Value : " << Optimizer.GetPostResult() << std::endl;

Print the final value of the Cost function.

About

A basic automatic differentiation library built with C++ expression template pattern. The main focus of the project is not reinventing the wheel but push the limit of meta-programming in modern C++.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages