Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<nav id="navbar">
    <header>N3Library</header>
    <ul>
      <li><a class="nav-link" href="#Introduction">Introduction</a></li>
      <li><a class="nav-link" href="#Documentation">Documentation</a></li>
      <li><a class="nav-link" href="#Get_and_Build_the_library">Get and Build the library</a></li>
      <li><a class="nav-link" href="#Use_the_library">Use the library</a></li>
      <li><a class="nav-link" href="#Save_and_load_results">Save and load results</a></li>
    </ul>
</nav>

<main id="main-doc">
  <section class="main-section" id="Introduction">
    <header>Introduction</header>
    <article>
      <p><a href="https://github.com/NeckersBOX/n3lib" title="Official GitHub Page">GitHub Project</a></p>

      <p>A C library for building neural network with the capability to define custom activation functions, learning rate, bias and others parameters.</p>

      <p>Both forward and backpropagation are built to parallelize through threads the operations.</p>

      <p>In forward propagation each layer execute the activation functions in concurrent threads, when one layer end its own job, the results to the each next layer's neuron are collected with others concurrent threads. The whole process is executed from each layer from the input one to the output one.</p>

      <p>In backward propagation first there is the delta evaluation from the output layer to the input layer, after that there is the weight updating process from the input to the output. Each return to the previous layer and delta evaluation on neurons in the same layer, is built, even in this case, with concurrent threads.</p>

      <p>Due to the list type structure of layers and neurons, N3 Library allow you to remove and add neurons or layers even while it's in running mode ( at the end of each iteration ).</p>
    </article>
  </section>
  
  
  <section class="main-section" id="Documentation">
    <header>Documentation</header>
    <article>
      <p><a href="https://neckersbox.github.io/n3lib/" title="Official Online Documentation">Official Online Docs</a></p>

      <p>The library is written to use Doxygen to generate up-to-date documentation and man pages. You can update the docs executing the following command:</p>

      <pre>doxygen n3lib.doxygen.conf</pre>
      
      <p>And install man pages by:</p>

      <pre># make install doc</pre>

      <p>Pre generated documentation is provided along with the library in the folder docs. More content, not strictly linked with the code, are included in the path <code>docs\extra</code>.</p>
    </article>
  </section>
  
  <section class="main-section" id="Get_and_Build_the_library">
    <header>Get and Build the library</header>
    <article>
      <pre>
$ git clone https://github.com/neckersbox/n3lib.git
$ cd n3lib
$ make
# make install
      </pre>
    </article>
  </section>
        
  <section class="main-section" id="Use_the_library">
    <header>Use the library</header>
    <article>
      <p>To use N3 Library in your project you need to follow the steps below:</p>

      <ol>
        <li>Include the n3l/n3lib.h header in your source.</li>
        <li>Build the network by <a href="https://neckersbox.github.io/n3lib/structN3LArgs.html">N3LArgs</a> and <a href="https://neckersbox.github.io/n3lib/n3__network_8c.html#a5f87e1efebd658dd55d7d2ca1768bdba">n3l_network_build()</a></li>
        <li>Forward your inputs through the network by <a href="https://neckersbox.github.io/n3lib/n3__forward_8c.html#abc37ac7f137db4d053e3b19ac8e6542a">n3l_forward_propagation()</a></li>
        <li>Improve network results providing targets and <a href="https://neckersbox.github.io/n3lib/n3__backward_8c.html#a871c936d33bfb280aa548e2dfd5ff32c">n3l_backward_propagation()</a></li>
        <li>Free the memory used by the network with <a href="https://neckersbox.github.io/n3lib/n3__network_8c.html#a327ffd586b67f586743d72a146c4ea95">n3l_network_free()</a></li>
        <li>Compile your project with the flag <code>-ln3l</code></li>
      </ol>
      

      <p><b>NOTE:</b> By defaults the numbers of cores in use are limited to one, this is ok if you work with small neural networks, but if you want to add more cores you only have to set the global variable <code>N3L_THREADS_CORES</code> with the value of cores to use.</p>

      <p>A small example implementing the XOR operation:</p>
      
      <pre>
#include &lt;stdlib.h&gt;
#include &lt;n3l/n3lib.h&gt;

int main(int argc, char *argv[])
{
  N3LArgs args;
  N3LNetwork *net;
  double inputs[4][2]  = { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 1, 0 } };
  double targets[4][2] = { { 0 }, { 1 }, { 0 }, { 1 } };
  double *outputs;
  uint64_t j;
  
  args = n3l_misc_init_arg();
  
  args.in_size = 2;
  
  args.h_layers = 1;
  args.h_size = (uint64_t *) malloc(args.h_layers * sizeof(uint64_t));
  args.h_size[0] = 2;
  args.act_h = (N3LActType *) malloc(args.h_layers * sizeof(N3LActType));
  args.act_h[0] = N3LSigmoid;
  
  args.out_size = 1;
  
  args.bias = 0.5;
  
  net = n3l_network_build(args, 0.5);
  
  for ( j = 0; j &lt; 10000; ++j ) {
    net-&gt;inputs = inputs[j % 4];
    outputs = n3l_forward_propagation(net);
    printf("Iter %ld/%d - Target: %.0lf - Output: %lf - Error: %lf\n",
      j + 1, 10000, targets[j % 4][0], outputs[0], targets[j % 4][0] - outputs[0]);
    free(outputs);
    
    net-&gt;targets = targets[j % 4];
    n3l_backward_propagation(net);
  }
  
  n3l_network_free(net);
  
  return 0;
}
      </pre>
      
      <p>Saved as <code>xor.c</code> can be compiled by <code>gcc xor.c -o xor -ln3l</code>, the results will be like this:</p>

      <pre>
Iter 1/10000 - Target: 0 - Output: 0.678551 - Error: -0.678551
Iter 2/10000 - Target: 1 - Output: 0.703232 - Error: 0.296768
Iter 3/10000 - Target: 0 - Output: 0.730443 - Error: -0.730443
Iter 4/10000 - Target: 1 - Output: 0.676008 - Error: 0.323992
...
Iter 9997/10000 - Target: 0 - Output: 0.091856 - Error: -0.091856
Iter 9998/10000 - Target: 1 - Output: 0.930525 - Error: 0.069475
Iter 9999/10000 - Target: 0 - Output: 0.080475 - Error: -0.080475
Iter 10000/10000 - Target: 1 - Output: 0.930533 - Error: 0.069467
      </pre>
    </article>
  </section>
        
  <section class="main-section" id="Save_and_load_results">
    <header>Save and load results</header>
    <article>
      <p>You can also save the results and load them in another project using <a href="https://neckersbox.github.io/n3lib/n3__file_8c.html#aea5e504fe0f565507b01729737f16341">n3l_file_export_network()</a> and <a href="https://neckersbox.github.io/n3lib/n3__file_8c.html#a4fef76548ed87845dceafaa9527a83d0">n3l_file_import_network()</a>. Using the same example used in the previous section, before calling n3l_network_free(net) we can add the following line:</p>

      <pre>
if ( n3l_file_export_network(net, "xor.n3l") == true ) {
  printf("Network state saved to xor.n3l.\n");
}
else {
  fprintf(stderr, "Error while exporting state to xor.n3l\n");
}
n3l_network_free(net);
      </pre>
      
      <p>Now, if you want to load a previous network state without do again the learning process, you can load the file <code>xor.n3l</code>. Example of another project which perform xor operation using the previous state saved:</p>

      <pre>
#include &lt;stdlib.h&gt;
#include &lt;n3l/n3lib.h&gt;

int main(int argc, char *argv[])
{
  N3LNetwork *net;
  double inputs[2][2] = { { 1, 0 }, { 1, 1 } };
  double *outputs;
  
  if ( !(net = n3l_file_import_network("xor.n3l")) ) {
    fprintf(stderr, "Error while loading xor.n3l\n");
    exit(1);
  }
  
  net-&gt;inputs = inputs[0];
  outputs = n3l_forward_propagation(net);
  printf("Case { 1, 0 } - Output: %lf\n", outputs[0]);
  free(outputs);
  
  net-&gt;inputs = inputs[1];
  outputs = n3l_forward_propagation(net);
  printf("Case { 1, 1 } - Output: %lf\n", outputs[0]);
  free(outputs);
  
  n3l_network_free(net);
  
  return 0;
}
      </pre>

      <p>And the results will be like these ones:</p>
      
      <pre>
Case { 1, 0 } - Output: 0.931341
Case { 1, 1 } - Output: 0.079728
      </pre>
    </article>
  </section>
</main>
              
            
!

CSS

              
                *
  font-family: 'Open Sans'

body
  margin: 0
  padding: 0
  
nav
  position: fixed
  left: 0
  top: 0
  height: 100%
  width: 240px
  background-color: white
  overflow: auto
  box-shadow: 2px 0 4px 0 rgba(0,0,0,0.17)
  
  header
    font-weight: bold
    margin: 16px
    text-align: center
    font-size: 28px
  
  ul
    border: 1px solid #e0e0e0
    border-bottom-width: 0
    margin: 0 4px
    list-style-type: none
    padding: 0
    
    li
      a
        display: block
        border-bottom: 1px solid #e0e0e0
        padding: 8px
        background-color: #f6f6f6
        text-decoration: none
        text-transform: uppercase
        font-size: 12px
        color: #01579B
        
        &:hover
          background-color: white
          color: #0277BD
          font-weight: bold
      
main
  background-color: #eee
  margin-left: 240px
  padding: 24px
  
  section
    header
      font-weight: bold
      font-size: 24px
      color: #01579B
      border-bottom: 1px solid #0277BD
    
    article
      background-color: white
      padding: 16px
      margin: 8px
      box-shadow: 0 0 4px 0 rgba(0,0,0,0.17)
      
      a
        text-decoration: none
        font-weight: bold
        color: #01579B
        font-size: 14px
      
      p
        font-size: 15px
        text-align: justify
        
      pre
        background-color: #f4f4f4
        padding: 8px
        box-shadow: 0 0 2px 0 rgba(0,0,0,0.17)
        overflow: auto
        font-family: 'Roboto Mono'
        font-size: 12px
        
      code
        font-size: 12px
        font-family: 'Roboto Mono'
  
        
@media screen and (max-width: 768px)
  nav
    position: relative
    min-height: 250px
    height: auto
    width: 100%
    
  main
    margin: 0
              
            
!

JS

              
                
              
            
!
999px

Console