{"id":13398577,"url":"https://github.com/miha-stopar/nnets","last_synced_at":"2026-03-02T22:46:49.886Z","repository":{"id":18175058,"uuid":"21287071","full_name":"miha-stopar/nnets","owner":"miha-stopar","description":"Python neural network library","archived":false,"fork":false,"pushed_at":"2014-07-10T15:38:45.000Z","size":21976,"stargazers_count":38,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-28T21:51:02.568Z","etag":null,"topics":[],"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/miha-stopar.png","metadata":{"files":{"readme":"README.rst","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}},"created_at":"2014-06-27T19:37:45.000Z","updated_at":"2024-01-03T20:56:57.000Z","dependencies_parsed_at":"2022-07-26T21:16:56.727Z","dependency_job_id":null,"html_url":"https://github.com/miha-stopar/nnets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/miha-stopar/nnets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miha-stopar%2Fnnets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miha-stopar%2Fnnets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miha-stopar%2Fnnets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miha-stopar%2Fnnets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miha-stopar","download_url":"https://codeload.github.com/miha-stopar/nnets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miha-stopar%2Fnnets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30022999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T22:30:10.381Z","status":"ssl_error","status_checked_at":"2026-03-02T22:23:34.650Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-30T19:00:28.816Z","updated_at":"2026-03-02T22:46:49.859Z","avatar_url":"https://github.com/miha-stopar.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"About\n=====\n\nPython neural network library that provides the following network types:\n \n * feed-forward neural network\n * recurrent (Elman) neural network \n\nIt supports the following activations functions:\n \n * linear\n * sigmoid\n * tanh\n * softmax\n \nIt supports the following cost functions:\n\n * sum of squared errors (SSE)\n * cross entropy (CE)\n \nAnd it supports an arbitrary number of hidden layers and arbitrary batch size for gradient descent algorithm.\n\nHow to use\n=====\n\nTo learn XOR function (see code for this and other examples in *test* folder):\n\n::\n\n    from neuron.neuralnet import NN\n\t\n    inputs = [[0,0], [0,1], [1,0], [1,1]]\n    targets = [[0], [1], [1], [0]]\n    nn = NN([2, 2, 1], [\"sigmoid\", \"sigmoid\"], cost_function=\"ce\")\n    nn.train(inputs, targets, batch_size=4, alpha=1, lamda=0.0, iterations=3000)\n    preds = []\n    for index, inp in enumerate(inputs):\n        pred = nn.predict(inp)\n        preds.append(pred)\n        print \"%s -\u003e %s\" % (inp, pred)\n    \nThe output looks like:\n\n::\n\n\t[0, 0] -\u003e [ 0.00903832]\n\t[0, 1] -\u003e [ 0.99312]\n\t[1, 0] -\u003e [ 0.99327432]\n\t[1, 1] -\u003e [ 0.00975482]\n\nTo learn (some nonsense) function using softmax output layer and two hidden layers:\n\n::\n\n    inputs = [[0, 0, 1], [1, 0, 0], [0, 1, 0]]\n    targets = [[1, 0, 0], [0, 0, 1], [0, 1, 0]]\n    nn = NN([3, 3, 5, 3], [\"sigmoid\", \"tanh\", \"softmax\"], cost_function=\"softmax_ce\")\n    nn.train(inputs, targets, batch_size=4, alpha=1, lamda=0.0, iterations=1000)\n    preds = []\n    for index, inp in enumerate(inputs):\n        pred = nn.predict(inp)\n        preds.append(pred)\n        print \"%s -\u003e %s\" % (inp, pred)\n        \nThe output looks like:\n\n::\n\n\t[0, 0, 1] -\u003e [  9.99473157e-01   2.26014879e-04   3.00828353e-04]\n\t[1, 0, 0] -\u003e [  2.29435307e-04   2.89636262e-04   9.99480928e-01]\n\t[0, 1, 0] -\u003e [  1.68368019e-04   9.99476531e-01   3.55100544e-04]\n\t\nApproximating the sine function using Recurrent network:\n\n::\n\n    from neuron.recurrent import Recurrent\n    import pylab as pl\n    import numpy as np\n    \n    size = 100\n    np.random.seed(0)\n    inputs = np.linspace(-7, 7, 20)\n    targets = np.sin(inputs) * 0.5\n    inputs.resize((size, 1))\n    targets.resize((size, 1))\n\n    nn = Recurrent([1, 10, 1], [\"tanh\", \"linear\"], cost_function=\"sse\")\n    epoch_errors = nn.train(inputs, targets, batch_size=1, alpha=0.1, lamda=0.0, iterations=500, calculate_errors=True)\n    \n    pl.subplot(211)\n    pl.plot(epoch_errors)\n    pl.xlabel('Epoch number')\n    pl.ylabel('error (default SSE)')\n    \n    output = []\n    for index, inp in enumerate(inputs):\n        pred = nn.predict(inp)\n        output.append(pred)\n        \n    x2 = np.linspace(-6.0,6.0,150)\n    x2.resize((size, 1))\n    output1 = []\n    for index, inp in enumerate(x2):\n        pred = nn.predict(inp)\n        output1.append(pred)\n    \n    pl.subplot(212)\n    pl.plot(inputs , targets, '.', inputs, output, 'p')\n    pl.show()\n\n\n.. image:: https://raw.github.com/miha-stopar/nnets/master/test/sine.png\n\n\nHow to find hyperparameters\n=====\n\nYou can use *findparameters.find* function to try to find the optimal hyperparameters. For example for recognition of\nhandwritten digits (see *digits.py* and *digits_findparameters.py* in *test* folder):\n\n::\n\n    import scipy.io\n    from neuron import findparameters\n\n    training_data = scipy.io.loadmat('../data/digits/ex4data1.mat')\n    X = training_data.get(\"X\")\n    y = training_data.get(\"y\")\n    targets = []\n    for j in y:\n        t = [0] * 10\n        t[j-1] = 1\n        targets.append(t)\n        \n    def evaluate(nn, inputs, targets):\n        wrong = 0\n        right = 0\n        for jindex, x in enumerate(inputs):\n            p = nn.predict(x)\n            maxind = p.argmax() + 1\n            if maxind == y[jindex]:\n                right += 1\n            else:\n                wrong += 1\n        #print \"right: %s, wrong: %s\" % (right, wrong)\n        acc = right / float(len(y))\n        return acc\n        \n    findparameters.find(evaluate, X, targets, net_type=\"feedforward\", input_size=400, output_size=10, \n                        output_activation=\"sigmoid\", cost_function=\"ce\")\n \n\nYou should get accuracy for a bunch of different hyperparameters configurations, some of them:\n \n::\n \n\thidden_size: 250, activation: tanh, alpha: 0.1, lambda: 0, iter: 1, batch_size: 5 ---- 0.9104\n\thidden_size: 250, activation: tanh, alpha: 0.1, lambda: 0, iter: 1, batch_size: 50 ---- 0.9292\n\thidden_size: 250, activation: tanh, alpha: 0.1, lambda: 0, iter: 5, batch_size: 5 ---- 0.9784\n\thidden_size: 250, activation: tanh, alpha: 0.1, lambda: 0, iter: 5, batch_size: 50 ---- 0.9878\n\thidden_size: 250, activation: tanh, alpha: 0.1, lambda: 0, iter: 10, batch_size: 5 ---- 0.9994\n\t\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiha-stopar%2Fnnets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiha-stopar%2Fnnets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiha-stopar%2Fnnets/lists"}