Code coverage report for node-fann-lite/example.js

Statements: 61.36% (27 / 44)      Branches: 28% (7 / 25)      Functions: 66.67% (6 / 9)      Lines: 61.36% (27 / 44)      Ignored: none     

All files » node-fann-lite/ » example.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261                                                                                                                                            1     1   1 1 1 1   1                                                                                                                                                                                                       1 1 1 1   1                               1 1                                       1         1   1 1 1 1                     1       1     1 1   1       1   1  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/*
example.js
 
this node script will serve a web-page with an interactive neural net
 
instruction
    1. save this script as example.js
    2. run the shell command:
          $ npm install fann-lite && node example.js
    3. open a browser to http://localhost:1337
    4. edit or paste script in browser to interact with the neural net
*/
 
/*jslint
    browser: true,
    maxerr: 8,
    maxlen: 96,
    node: true,
    nomen: true,
    stupid: true
*/
 
(function (local) {
    'use strict';
    // run node js-env code
    (function () {
        // require modules
        local.fs = require('fs');
        local.http = require('http');
        local.path = require('path');
        local.url = require('url');
        // init assets
        local['/'] = (String() +
 
 
 
/* jslint-ignore-begin */
'<!DOCTYPE html>\n' +
'<html>\n' +
'<head>\n' +
    '<meta charset="UTF-8">\n' +
    '<title>\n' +
    'fann-lite [2015.6.1-a]\n' +
    '</title>\n' +
    '<link rel="stylesheet" href="/assets/utility2.css">\n' +
    '<style>\n' +
    '* {\n' +
        'box-sizing: border-box;\n' +
    '}\n' +
    'body {\n' +
        'background-color: #fff;\n' +
        'font-family: Helvetical Neue, Helvetica, Arial, sans-serif;\n' +
    '}\n' +
    'body > div {\n' +
        'margin-top: 20px;\n' +
    '}\n' +
    'textarea {\n' +
        'font-family: monospace;\n' +
        'height: 32em;\n' +
        'width: 100%;\n' +
    '}\n' +
    '.csslintOutputPre {\n' +
        'color: #f00;\n' +
    '}\n' +
    '.fannOutputPre {\n' +
        'color: #f00;\n' +
    '}\n' +
    '.testReportDiv {\n' +
        'display: none;\n' +
    '}\n' +
    '</style>\n' +
 
'</head>\n' +
'<body>\n' +
    '<div class="ajaxProgressDiv" style="display: none;">\n' +
    '<div class="ajaxProgressBarDiv ajaxProgressBarDivLoading" >loading</div>\n' +
    '</div>\n' +
    '<h1 >fann-lite [2015.6.1-a]</h1>\n' +
    '<h3>pure javascript version of fann (fast artificial neural net library) with zero npm-dependencies (compiled from emscripten)</h3>\n' +
    '<div>edit or paste script below to\n' +
    '<a href="http://leenissen.dk/fann/html/files2/gettingstarted-txt.html" target="_blank">\n' +
    'eval</a>\n' +
    '</div>\n' +
'<textarea class="fannInputTextarea">\n' +
'// test\n' +
'local.ann = local.fann.create_standard(3, 2, 3, 1);\n' +
'local.data = local.fann\n' +
    '.create_train_from_array(4, 2, 1, [-1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, -1]);\n' +
'local.fann\n' +
    '.set_activation_function_hidden(local.ann, local.fann.ACTIVATION_SIGMOID_SYMMETRIC);\n' +
'local.fann.set_activation_function_output(local.ann, 5);\n' +
'local.fann.train_on_data(local.ann, local.data, 5000, 1000, 0.001);\n' +
'console.log("1 xor 1 -> " + local.fann.run(local.ann, [1, 1]));\n' +
'console.log("1 xor 0 -> " + local.fann.run(local.ann, [1, -1]));\n' +
'console.log("0 xor 1 -> " + local.fann.run(local.ann, [-1, 1]));\n' +
'</textarea>\n' +
    '<pre class="fannOutputPre"></pre>\n' +
    '<div class="testReportDiv"></div>\n' +
    '<script src="/assets/fann.js"></script>\n' +
    '<script src="/assets/utility2.js"></script>\n' +
    '<script>\n' +
    'window.utility2 = window.utility2 || {};\n' +
    'window.utility2.envDict = {\n' +
        'npm_package_description: "pure javascript version of fann (fast artificial neural net library) with zero npm-dependencies (compiled from emscripten)",\n' +
        'npm_package_name: "fann-lite",\n' +
        'npm_package_version: "2015.6.1-a"\n' +
    '};\n' +
    'document.querySelector(\n' +
        '".fannInputTextarea"\n' +
    ').addEventListener("keyup", window.fann.fannInputTextarea);\n' +
    'window.fann.fannInputTextarea();\n' +
    '</script>\n' +
    '<script src="/test/test.js"></script>\n' +
 
'</body>\n' +
'</html>\n' +
/* jslint-ignore-end */
 
 
 
        String()).replace((/\{\{envDict\.\w+?\}\}/g), function (match0) {
            switch (match0) {
            case '{{envDict.npm_package_description}}':
                return 'this is an example module';
            case '{{envDict.npm_package_name}}':
                return 'example-module';
            case '{{envDict.npm_package_version}}':
                return '0.0.1';
            default:
                return '';
            }
        });
        local['/assets/fann.js'] = local.fann['/assets/fann.js'];
        local['/assets/utility2.css'] = '';
        local['/assets/utility2.js'] = '';
        local['/test/test.js'] = '';
        // create server
        local.server = local.http.createServer(function (request, response) {
            switch (local.url.parse(request.url).pathname) {
            // serve assets
            case '/':
            case '/assets/fann.js':
            case '/assets/utility2.css':
            case '/assets/utility2.js':
            case '/test/test.js':
                response.end(local[local.url.parse(request.url).pathname]);
                break;
            // default to 404 Not Found
            default:
                response.statusCode = 404;
                response.end('404 Not Found');
            }
        });
        Eif (process.env.npm_config_server_port) {
            return;
        }
        // start server
        local.serverPort = 1337;
        console.log('server starting on port ' + local.serverPort);
        local.server.listen(local.serverPort, function () {
            // this internal build-code will screen-capture the server
            // and then exit
            if (process.env.MODE_BUILD === 'testExampleJs') {
                console.log('server stopping on port ' + local.serverPort);
                require(
                    process.env.npm_config_dir_utility2 + '/index.js'
                ).phantomScreenCapture({
                    url: 'http://localhost:' + local.serverPort
                }, process.exit);
            }
        });
    }());
}((function () {
    'use strict';
    var local;
 
 
 
    // run shared js-env code
    (function () {
        // init local
        local = {};
        local.modeJs = (function () {
            try {
                return module.exports &&
                    typeof process.versions.node === 'string' &&
                    typeof require('http').createServer === 'function' &&
                    'node';
            } catch (errorCaughtNode) {
                return typeof navigator.userAgent === 'string' &&
                    typeof document.querySelector('body') === 'object' &&
                    'browser';
            }
        }());
        // init global
        local.global = local.modeJs === 'browser'
            ? window
            : global;
        // init fann-lite
        local.fann = local.modeJs === 'browser'
            ? window.fann
            : (function () {
                try {
                    return require('fann-lite');
                } catch (errorCaught) {
                    return require('./fann.js');
                }
            }());
        // export local
        module.exports = local;
    }());
    return local;
}())));