{"id":25117833,"url":"https://github.com/deniztemur00/simplegrad","last_synced_at":"2025-04-22T16:49:15.856Z","repository":{"id":265687112,"uuid":"887893934","full_name":"deniztemur00/simplegrad","owner":"deniztemur00","description":"Simple auto gradient project that supports basic operations written in C++ from scratch.","archived":false,"fork":false,"pushed_at":"2024-12-17T13:29:14.000Z","size":89,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T12:46:12.551Z","etag":null,"topics":["cpp","deep-learning","micrograd","neural-network","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deniztemur00.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-11-13T13:19:50.000Z","updated_at":"2025-02-17T17:43:32.000Z","dependencies_parsed_at":"2024-12-17T14:21:54.764Z","dependency_job_id":"3a3f60f2-3210-4660-906a-30b112df9960","html_url":"https://github.com/deniztemur00/simplegrad","commit_stats":null,"previous_names":["deniztemur00/simplegrad"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniztemur00%2Fsimplegrad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniztemur00%2Fsimplegrad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniztemur00%2Fsimplegrad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deniztemur00%2Fsimplegrad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deniztemur00","download_url":"https://codeload.github.com/deniztemur00/simplegrad/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250282008,"owners_count":21404906,"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":["cpp","deep-learning","micrograd","neural-network","python"],"created_at":"2025-02-08T03:25:54.466Z","updated_at":"2025-04-22T16:49:15.833Z","avatar_url":"https://github.com/deniztemur00.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleGrad\n\nSimpleGrad is a lightweight automatic differentiation library written in C++ with Python bindings.\n\n\n## Prerequisites\n\n- Python \u003e= 3.6\n- g++/gcc\n- CMake\n\n## Build \u0026 Installation\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/deniztemur00/simplegrad.git\ncd simplegrad\n```\n2. Build with makefile:\n```bash\nmake build-python\n```\n## Features\n\n- Multi-layer perceptron (MLP) which can be used for regression and classification tasks\n- Supports basic arithmetic operations\n- Lightweight and easy to use\n- Gradient computation\n- Backpropagation\n- Numpy compatibility\n\n\n## Usage\n\nHere's a quick example of how to use MLP in SimpleGrad:\n\n```python\nfrom simplegrad import MLP, Node\nfrom sklearn import datasets\n\n# Define the model\nX, y = datasets.make_classification(\n        n_samples=1000,\n        n_features=10,\n        n_classes=2,\n        random_state=42,  # for reproducibility\n    )\n\n\nlr = 0.01\nbatch_size = 16\nepochs = 10\n\n# Define the model\nmodel = MLP(\n    10, [12, 1]\n)  # 2 input nodes, 2 hidden layers with arbitrary sizes, 1 output node\n\n# Training data\nn_batches = (len(X) + batch_size - 1) // batch_size  # Ceiling division\n\nfor epoch in range(epochs):\n    epoch_loss = 0.0\n    for i in range(0, len(X), batch_size):\n        batch_X = X[i : i + batch_size]\n        batch_y = y[i : i + batch_size]\n        current_batch_size = len(batch_X)  # Handle last batch\n\n        batch_loss = 0.0\n        #model.zero_grad()  # gradients are automatically reset after step function\n\n        # Accumulate gradients over batch\n        for x, y_true in zip(batch_X, batch_y):\n            y_hat = model(x)[0]\n            y_true = Node(y_true)\n            loss = (y_hat - y_true) ** 2\n            loss = loss * (1.0 / current_batch_size)  # Normalize loss\n            batch_loss += loss.data()\n            loss.backward()\n\n        model.step(lr)  # Update weights using accumulated gradients\n        epoch_loss += batch_loss\n\n    # Average loss over all batches\n    print(f\"Epoch {epoch+1}, Average Loss: {epoch_loss/n_batches:.3f}\")\n```\nYou can execute the above code by running the following command:\n```bash\nmake run\n```\n\n## Testing\nTests are written to ensure the correctness of the Node class. Thus making sure MLP works as expected. You can run tests with following command:\n```bash\nmake test\n```\n## License\n\nThis project is licensed under the MIT License.\n\n## Acknowledgements\n\nThis project was inspired by the [micrograd](https://github.com/karpathy/micrograd) project by Andrej Karpathy. \n\n## TODO\n\n - Compile and build for other platforms\n - Publish on pypi\n - Cyclic reference optimization\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeniztemur00%2Fsimplegrad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeniztemur00%2Fsimplegrad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeniztemur00%2Fsimplegrad/lists"}