{"id":13454928,"url":"https://github.com/welschma/NNFlow","last_synced_at":"2025-03-24T07:32:15.030Z","repository":{"id":215186187,"uuid":"79344148","full_name":"welschma/NNFlow","owner":"welschma","description":null,"archived":false,"fork":false,"pushed_at":"2021-03-24T08:14:42.000Z","size":34,"stargazers_count":7,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-28T22:34:40.928Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/welschma.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}},"created_at":"2017-01-18T13:48:29.000Z","updated_at":"2021-03-24T08:14:44.000Z","dependencies_parsed_at":"2024-01-07T10:57:27.309Z","dependency_job_id":null,"html_url":"https://github.com/welschma/NNFlow","commit_stats":null,"previous_names":["welschma/nnflow"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welschma%2FNNFlow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welschma%2FNNFlow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welschma%2FNNFlow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welschma%2FNNFlow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/welschma","download_url":"https://codeload.github.com/welschma/NNFlow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245227547,"owners_count":20580897,"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":[],"created_at":"2024-07-31T08:00:59.489Z","updated_at":"2025-03-24T07:32:14.719Z","avatar_url":"https://github.com/welschma.png","language":"Python","funding_links":[],"categories":["Libraries","库"],"sub_categories":["微信群"],"readme":"# Disclaimer:\nThis project was started during my bachelor's thesis at a time where TensorFlow was still just released and libraries like Keras weren't included into the TensorFlow framework. Today, probbably all of this code is obsolete and shouldn't be used any more.\n\n# NNFlow (Archived)\nA simple interface for Google's TensorFlow \n\n## Basic Workflow\n### Converting Root nTuples into numpy arrays\nNNFlow provides a function, based on root-numpy, for converting Root nTuples into numpy arrays.\n\nExample:\n```\nfrom NNFlow.preprocessing import conv_root_to_np\n\nntuples = ['path/to/ntuple_1', 'path/to/ntuple_2', ...]\nsave_to = 'path/to/storage/directory'\nname = 'array.npy'\nmy_tree = 'tree'\nmy_branches = ['branch_1', 'branch_2']\n\nconv_root_to_np(save_to, name, ntuples, treename=my_tree, branches=my_branches)\n```\nIf there is only one TTree in the nTuple you do not have to provide the name of the tree which should be converted.\nIf you want to convert all branches of a tree, do not provide a branchlist.\n\nNOTE: The array the data is saved to is of type np.structure_array (https://docs.scipy.org/doc/numpy/user/basics.rec.html).\n\n### Preprocess numpy arrays\nOnce you've converted the nTuples to numpy arrays, you have do some other preprocessing steps, like getting some specific branches from the array if you've converted everything in the nTuple.\n\nExample:\n```\nfrom NNFlow.preprocessing import GetVariables\n\nsig_1 = 'path/to/signal_1.npy'\nsig_2 = 'path/to/signal_2.npy'\n...\n\nbkg_1 = 'path/to/background_1.npy'\nbkg_2 = 'path/to/background_2.npy'\n...\n\nvariables = ['var_1', 'var_2', 'var_3', ...]\nweights = ['weight_1', 'weight_2', 'weight_3', ...]\ncategory = '63'\n\ngv = GetVariables(variables, weights, category, 'my_variables')\ngv.run([sig_1, sig_2, ...], [bkg_1, bkg_2, ...])\n```\nThis script gets the variables defined in the ```variables``` list from the structured array and saves them into a normal 2D np.ndarray.\nIf a variable is vector like then you should check if the branch is included in the list in line 106 in file [NNFlow/preprocessing](NNFlow/preprocessing.py) (checking for vector like data is not automated yet).\n\nThe signal (ttH) and background (ttbarSL) are combined into one array.\nLabels for signal (1) and background (0) are added in the first column, the event weights are added in the last column.\nThe data is split into a split into 3 datasets. 50% of the data is used for training, 10% for validation and 40% for testing.\nThe event weights are normed to sum 1 respectively for signal and background in each dataset.\nThe arrays will be saved in the directory 'my_variables/category' as ```train.npy```, ```val.npy``` and ```test.npy```.\n\n### Train a neural network\nHere is a simple example script if you want to train a neural network.\nPlease have a look at [NNFlow/binary_mlp](NNFlow/binary_mlp.py) and [NNFlow/data_frame](NNFlow/data_frame.py) files for more information about the options.\n```\nimport numpy as np\nfrom NNFlow.binary_mlp import BinaryMLP\nfrom NNFlow.data_frame import Dataframe\n\n# load numpy arrays\ntrain = np.load('my_variables/category/train.npy')\nval = np.load('my_variables/category/val.npy')\ntest = np.load('my_variables/category/test.npy')\n\n# use DataFrame\ntrain = DataFrame(train)\nval = DataFrame(val)\ntest = DataFrame(test)\n\nsave_model_to = 'my_variables/category/models/2x100'\nhidden_layers = [100, 100] \n\n# create neural net\nmlp = BinaryMLP(train.nvariables, [100, 100], save_model_to)\n\n# train \nmlp.train(train, val, epochs=250, lr=1e-3)\n\n# classify new events\ny_test = mlp.classify(test.x)\n```\nThis script will train a neural network with two hidden layers with 100 neurons.\nThe network is saved to the directory 'save_model_to'. \nAlso some controll plots of the training process will be saved there.\nTo reuse a model in a different script, you can use the same script without the training step.\n\n## ToDo\n* root-numpy now supports python3 -\u003e check if NNFlow supports Python3\n* get rid of scikit-learn dependency -\u003e write own implementation for calculating ROC-Curves and ROC-AUC score\n\n## Dependencies\nTested with\n* tensorflow (0.12.0rc1)\n* numpy (1.11.2)\n* matplotlib (1.5.3)\n* scikit-learn (0.18.1)\n* root-numpy (4.5.2)\n* graphviz (0.5.1)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwelschma%2FNNFlow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwelschma%2FNNFlow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwelschma%2FNNFlow/lists"}