{"id":13438375,"url":"https://github.com/harthur/brain","last_synced_at":"2025-09-28T19:32:02.819Z","repository":{"id":902336,"uuid":"658594","full_name":"harthur/brain","owner":"harthur","description":"Simple feed-forward neural network in JavaScript","archived":true,"fork":false,"pushed_at":"2020-09-03T20:20:29.000Z","size":393,"stargazers_count":8009,"open_issues_count":21,"forks_count":853,"subscribers_count":382,"default_branch":"master","last_synced_at":"2025-08-28T12:57:54.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harthur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-05-10T06:36:21.000Z","updated_at":"2025-08-11T02:12:56.000Z","dependencies_parsed_at":"2022-08-16T11:25:11.217Z","dependency_job_id":null,"html_url":"https://github.com/harthur/brain","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/harthur/brain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harthur%2Fbrain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harthur%2Fbrain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harthur%2Fbrain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harthur%2Fbrain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harthur","download_url":"https://codeload.github.com/harthur/brain/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harthur%2Fbrain/sbom","scorecard":{"id":456478,"data":{"date":"2025-08-11","repo":{"name":"github.com/harthur/brain","commit":"05bd28721c52b38562321fbc757eb93b9e114b5f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":1,"reason":"Found 5/28 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 7 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T09:49:41.262Z","repository_id":902336,"created_at":"2025-08-19T09:49:41.262Z","updated_at":"2025-08-19T09:49:41.262Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277347620,"owners_count":25803101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-28T02:00:08.834Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:04.972Z","updated_at":"2025-09-28T19:32:02.548Z","avatar_url":"https://github.com/harthur.png","language":"JavaScript","readme":"*This project has reached the end of its development as a simple neural network library. Feel free to browse the code, but please use other JavaScript neural network libraries in development like [brain.js](https://github.com/BrainJS/brain.js) and [convnetjs](https://github.com/karpathy/convnetjs).*\n\n# brain\n\n`brain` is a JavaScript [neural network](http://neuralnetworksanddeeplearning.com/) library. Here's an example of using it to approximate the XOR function:\n\n```javascript\nvar net = new brain.NeuralNetwork();\n\nnet.train([{input: [0, 0], output: [0]},\n           {input: [0, 1], output: [1]},\n           {input: [1, 0], output: [1]},\n           {input: [1, 1], output: [0]}]);\n\nvar output = net.run([1, 0]);  // [0.987]\n```\n\nThere's no reason to use a neural network to figure out XOR however (-: so here's a more involved, realistic example:\n[Demo: training a neural network to recognize color contrast](http://harthur.github.com/brain/)\n\n## Using in node\nIf you have [node](http://nodejs.org/) you can install with [npm](http://npmjs.org):\n\n```\nnpm install brain\n```\n\n## Using in the browser\nDownload the latest [brain.js](https://github.com/harthur/brain/tree/gh-pages). Training is computationally expensive, so you should try to train the network offline (or on a Worker) and use the `toFunction()` or `toJSON()` options to plug the pre-trained network in to your website.\n\n## Training\nUse `train()` to train the network with an array of training data. The network has to be trained with all the data in bulk in one call to `train()`. The more training patterns, the longer it will probably take to train, but the better the network will be at classifiying new patterns.\n\n#### Data format\nEach training pattern should have an `input` and an `output`, both of which can be either an array of numbers from `0` to `1` or a hash of numbers from `0` to `1`. For the [color constrast demo](http://harthur.github.com/brain/) it looks something like this:\n\n```javascript\nvar net = new brain.NeuralNetwork();\n\nnet.train([{input: { r: 0.03, g: 0.7, b: 0.5 }, output: { black: 1 }},\n           {input: { r: 0.16, g: 0.09, b: 0.2 }, output: { white: 1 }},\n           {input: { r: 0.5, g: 0.5, b: 1.0 }, output: { white: 1 }}]);\n\nvar output = net.run({ r: 1, g: 0.4, b: 0 });  // { white: 0.99, black: 0.002 }\n```\n\n#### Options\n`train()` takes a hash of options as its second argument:\n\n```javascript\nnet.train(data, {\n  errorThresh: 0.005,  // error threshold to reach\n  iterations: 20000,   // maximum training iterations\n  log: true,           // console.log() progress periodically\n  logPeriod: 10,       // number of iterations between logging\n  learningRate: 0.3    // learning rate\n})\n```\n\nThe network will train until the training error has gone below the threshold (default `0.005`) or the max number of iterations (default `20000`) has been reached, whichever comes first.\n\nBy default training won't let you know how its doing until the end, but set `log` to `true` to get periodic updates on the current training error of the network. The training error should decrease every time. The updates will be printed to console. If you set `log` to a function, this function will be called with the updates instead of printing to the console.\n\nThe learning rate is a parameter that influences how quickly the network trains. It's a number from `0` to `1`. If the learning rate is close to `0` it will take longer to train. If the learning rate is closer to `1` it will train faster but it's in danger of training to a local minimum and performing badly on new data. The default learning rate is `0.3`.\n\n#### Output\nThe output of `train()` is a hash of information about how the training went:\n\n```javascript\n{\n  error: 0.0039139985510105032,  // training error\n  iterations: 406                // training iterations\n}\n```\n\n#### Failing\nIf the network failed to train, the error will be above the error threshold. This could happen because the training data is too noisy (most likely), the network doesn't have enough hidden layers or nodes to handle the complexity of the data, or it hasn't trained for enough iterations.\n\nIf the training error is still something huge like `0.4` after 20000 iterations, it's a good sign that the network can't make sense of the data you're giving it.\n\n## JSON\nSerialize or load in the state of a trained network with JSON:\n\n```javascript\nvar json = net.toJSON();\n\nnet.fromJSON(json);\n```\n\nYou can also get a custom standalone function from a trained network that acts just like `run()`:\n\n```javascript\nvar run = net.toFunction();\n\nvar output = run({ r: 1, g: 0.4, b: 0 });\n\nconsole.log(run.toString()); // copy and paste! no need to import brain.js\n```\n\n## Options\n`NeuralNetwork()` takes a hash of options:\n\n```javascript\nvar net = new brain.NeuralNetwork({\n  hiddenLayers: [4],\n  learningRate: 0.6 // global learning rate, useful when training using streams\n});\n```\n\n#### hiddenLayers\nSpecify the number of hidden layers in the network and the size of each layer. For example, if you want two hidden layers - the first with 3 nodes and the second with 4 nodes, you'd give:\n\n```\nhiddenLayers: [3, 4]\n```\n\nBy default `brain` uses one hidden layer with size proportionate to the size of the input array.\n\n## Streams\nThe network now has a [WriteStream](http://nodejs.org/api/stream.html#stream_class_stream_writable). You can train the network by using `pipe()` to send the training data to the network.\n\n#### Example\nRefer to `stream-example.js` for an example on how to train the network with a stream.\n\n#### Initialization\nTo train the network using a stream you must first create the stream by calling `net.createTrainStream()` which takes the following options:\n\n* `floodCallback()` - the callback function to re-populate the stream. This gets called on every training iteration.\n* `doneTrainingCallback(info)` - the callback function to execute when the network is done training. The `info` param will contain a hash of information about how the training went:\n\n```javascript\n{\n  error: 0.0039139985510105032,  // training error\n  iterations: 406                // training iterations\n}\n```\n\n#### Transform\nUse a [Transform](http://nodejs.org/api/stream.html#stream_class_stream_transform) to coerce the data into the correct format. You might also use a Transform stream to normalize your data on the fly.\n","funding_links":[],"categories":["Machine_Learning","Researchers","JavaScript","Machine Learning","Javascript","Machine Learning [🔝](#readme)","Table of Contents","Uncategorized","Misc","[](https://github.com/josephmisiti/awesome-machine-learning/blob/master/README.md#javascript)Javascript","机器学习","Frameworks"],"sub_categories":["Frameworks","Runner","Uncategorized","Tools","Other ML frameworks","[Tools](#tools-1)","Speech Recognition","运行器","List of lists","运行器e2e测试"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharthur%2Fbrain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharthur%2Fbrain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharthur%2Fbrain/lists"}