{"id":15049278,"url":"https://github.com/100/cranium","last_synced_at":"2025-04-04T21:10:22.294Z","repository":{"id":50656890,"uuid":"77307441","full_name":"100/Cranium","owner":"100","description":"🤖   A portable, header-only, artificial neural network library written in C99","archived":false,"fork":false,"pushed_at":"2023-10-29T19:34:30.000Z","size":102,"stargazers_count":597,"open_issues_count":10,"forks_count":55,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-03-28T20:10:04.650Z","etag":null,"topics":["artificial-neural-networks","blas","c","c99","cblas","classification","continuous-integration","efficient","embedded","feedforward-neural-network","header-only","machine-learning","matrix","neural-network","portable","regression","travis-ci","vectorization"],"latest_commit_sha":null,"homepage":"https://100.github.io/Cranium/","language":"C","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/100.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-25T02:33:42.000Z","updated_at":"2025-03-19T22:59:28.000Z","dependencies_parsed_at":"2024-09-29T01:20:54.591Z","dependency_job_id":"90c55042-3ac0-4d9d-8f56-8aea04360470","html_url":"https://github.com/100/Cranium","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/100%2FCranium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/100%2FCranium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/100%2FCranium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/100%2FCranium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/100","download_url":"https://codeload.github.com/100/Cranium/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249532,"owners_count":20908212,"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","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":["artificial-neural-networks","blas","c","c99","cblas","classification","continuous-integration","efficient","embedded","feedforward-neural-network","header-only","machine-learning","matrix","neural-network","portable","regression","travis-ci","vectorization"],"created_at":"2024-09-24T21:19:26.239Z","updated_at":"2025-04-04T21:10:22.275Z","avatar_url":"https://github.com/100.png","language":"C","readme":"\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"docs/image.png\"\u003e\u003c/img\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n[![Build Status](https://travis-ci.org/100/Cranium.svg?branch=master)](https://travis-ci.org/100/Cranium)\n[![MIT License](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/100/Cranium/blob/master/LICENSE)\n\n## *Cranium* is a portable, header-only, feedforward artificial neural network library written in vanilla C99. \n\n#### It supports fully-connected networks of arbitrary depth and structure, and should be reasonably fast as it uses a matrix-based approach to calculations. It is particularly suitable for low-resource machines or environments in which additional dependencies cannot be installed.\n\n#### Cranium supports CBLAS integration. Simply uncomment line 7 in ```matrix.h``` to enable the BLAS ```sgemm``` function for fast matrix multiplication.\n\n#### Check out the detailed documentation [here](https://100.github.io/Cranium/) for information on individual structures and functions.\n\n\u003chr\u003e\n\n## Features\n* **Activation functions**\n    * sigmoid\n    * ReLU\n    * tanh\n    * softmax (*classification*)\n    * linear (*regression*)\n* **Loss functions**\n    * Cross-entropy loss (*classification*)\n    * Mean squared error (*regression*)\n* **Optimization algorithms** \n    * Batch Gradient Descent\n    * Stochastic Gradient Descent\n    * Mini-Batch Stochastic Gradient Descent\n* **L2 Regularization**\n* **Learning rate annealing**\n* **Simple momentum**\n* **Fan-in weight initialization**\n* **CBLAS support for fast matrix multiplication**\n* **Serializable networks**\n\n\u003chr\u003e\n\n## Usage\nSince Cranium is header-only, simply copy the ```src``` directory into your project, and ```#include \"src/cranium.h\"``` to begin using it. \n\nIts only required compiler dependency is from the ```\u003cmath.h\u003e``` header, so compile with ```-lm```.\n\nIf you are using CBLAS, you will also need to compile with ```-lcblas``` and include, via ```-I```, the path to wherever your particular machine's BLAS implementation is. Common ones include [OpenBLAS](http://www.openblas.net/) and [ATLAS](http://math-atlas.sourceforge.net/).\n\nIt has been tested to work perfectly fine with any level of gcc optimization, so feel free to use them. \n\n\u003chr\u003e\n\n## Example\n\n```c\n#include \"cranium.h\"\n\n/*\nThis basic example program is the skeleton of a classification problem.\nThe training data should be in matrix form, where each row is a data point, and\n    each column is a feature. \nThe training classes should be in matrix form, where the ith row corresponds to\n    the ith training example, and each column is a 1 if it is of that class, and\n    0 otherwise. Each example may only be of 1 class.\n*/\n\n// create training data and target values (data collection not shown)\nint rows, features, classes;\nfloat** training;\nfloat** classes;\n\n// create datasets to hold the data\nDataSet* trainingData = createDataSet(rows, features, training);\nDataSet* trainingClasses = createDataSet(rows, classes, classes);\n\n// create network with 2 input neurons, 1 hidden layer with sigmoid\n// activation function and 5 neurons, and 2 output neurons with softmax \n// activation function\nsrand(time(NULL));\nsize_t hiddenSize[] = {5};\nActivation hiddenActivation[] = {sigmoid};\nNetwork* net = createNetwork(2, 1, hiddenSize, hiddenActivation, 2, softmax);\n\n// train network with cross-entropy loss using Mini-Batch SGD\nParameterSet params;\nparams.network = net;\nparams.data = trainingData;\nparams.classes = trainingClasses;\nparams.lossFunction = CROSS_ENTROPY_LOSS;\nparams.batchSize = 20;\nparams.learningRate = .01;\nparams.searchTime = 5000;\nparams.regularizationStrength = .001;\nparams.momentumFactor = .9;\nparams.maxIters = 10000;\nparams.shuffle = 1;\nparams.verbose = 1;\noptimize(params);\n\n// test accuracy of network after training\nprintf(\"Accuracy is %f\\n\", accuracy(net, trainingData, trainingClasses));\n\n// get network's predictions on input data after training\nforwardPass(net, trainingData);\nint* predictions = predict(net);\nfree(predictions);\n\n// save network to a file\nsaveNetwork(net, \"network\");\n\n// free network and data\ndestroyNetwork(net);\ndestroyDataSet(trainingData);\ndestroyDataSet(trainingClasses);\n\n// load previous network from file\nNetwork* previousNet = readNetwork(\"network\");\ndestroyNetwork(previousNet);\n```\n\n\u003chr\u003e\n\n## Building and Testing\n\nTo run tests, look in the ```tests``` folder. \n\nThe ```Makefile``` has commands to run each batch of unit tests, or all of them at once.\n\n\u003chr\u003e\n\n## Contributing\n\nFeel free to send a pull request if you want to add any features or if you find a bug.\n\nCheck the issues tab for some potential things to do.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F100%2Fcranium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F100%2Fcranium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F100%2Fcranium/lists"}