Skip to content

Compute your R 'neuralnet' neural network using cpp code

License

Notifications You must be signed in to change notification settings

perdumonocle/neuralnet2cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

neuralnet2cpp

Compute your R 'neuralnet' neural network using cpp code.

You can train you neural network with R:

> library( 'neuralnet' )
> data <- data.frame( i1 = c(1, 2, 4), i2 = c(5, 5, 6), o = c(1, 1, 0) )
> net <- neuralnet( o~i1+i2, hidden = c( 5, 2 ) )

Then test your net:

> test <- data.frame( i1 = 5, i2 = 1 )
> res <- compute( net, test )
> res$net.result
               [,1]
[1,] -0.08056605515

And convert that network into cpp:

> compute.gen.cpp( net, "~/myprojects/subfolder/compute.cpp" )

Test your network using compute.cpp:

int main(int argc, char *argv[])
{
    const double covariates[2] = { 5, 1 };
    double results[1] = { 0 };
    neuralnet::compute( &covariates[0], &results[0] );
    printf( "%f\n", results[0] ); // -0.080566
    return 0;
}