ml-trust-model

git clone git://git.codymlewis.com/ml-trust-model.git
Log | Files | Refs | README

commit 7fe2c03a14e1f3bc7744fcbe02ea18984ecf4228
Author: Cody Lewis <codymlewis@protonmail.com>
Date:   Tue, 12 Mar 2019 22:48:06 +1100

Reports and most of the nodes are implemented

Diffstat:
A.gitattributes | 2++
A.gitignore | 392+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A.gitlab-ci.yml | 7+++++++
AREADME.md | 13+++++++++++++
ATrustModel.py | 47+++++++++++++++++++++++++++++++++++++++++++++++
Arequirements.txt | 1+
Atest.py | 39+++++++++++++++++++++++++++++++++++++++
7 files changed, 501 insertions(+), 0 deletions(-)

diff --git a/.gitattributes b/.gitattributes @@ -0,0 +1,2 @@ +*.pdf binary +*.png binary diff --git a/.gitignore b/.gitignore @@ -0,0 +1,392 @@ + +# Created by https://www.gitignore.io/api/tex,python +# Edit at https://www.gitignore.io/?templates=tex,python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +### Python Patch ### +.venv/ + +### TeX ### +## Core latex/pdflatex auxiliary files: +*.aux +*.lof +*.lot +*.fls +*.out +*.toc +*.fmt +*.fot +*.cb +*.cb2 +.*.lb + +## Intermediate documents: +*.dvi +*.xdv +*-converted-to.* +# these rules might exclude image files for figures etc. +# *.ps +# *.eps +# *.pdf + +## Generated if empty string is given at "Please type another file name for output:" +.pdf + +## Bibliography auxiliary files (bibtex/biblatex/biber): +*.bbl +*.bcf +*.blg +*-blx.aux +*-blx.bib +*.run.xml + +## Build tool auxiliary files: +*.fdb_latexmk +*.synctex +*.synctex(busy) +*.synctex.gz +*.synctex.gz(busy) +*.pdfsync + +## Build tool directories for auxiliary files +# latexrun +latex.out/ + +## Auxiliary and intermediate files from other packages: +# algorithms +*.alg +*.loa + +# achemso +acs-*.bib + +# amsthm +*.thm + +# beamer +*.nav +*.pre +*.snm +*.vrb + +# changes +*.soc + +# comment +*.cut + +# cprotect +*.cpt + +# elsarticle (documentclass of Elsevier journals) +*.spl + +# endnotes +*.ent + +# fixme +*.lox + +# feynmf/feynmp +*.mf +*.mp +*.t[1-9] +*.t[1-9][0-9] +*.tfm + +#(r)(e)ledmac/(r)(e)ledpar +*.end +*.?end +*.[1-9] +*.[1-9][0-9] +*.[1-9][0-9][0-9] +*.[1-9]R +*.[1-9][0-9]R +*.[1-9][0-9][0-9]R +*.eledsec[1-9] +*.eledsec[1-9]R +*.eledsec[1-9][0-9] +*.eledsec[1-9][0-9]R +*.eledsec[1-9][0-9][0-9] +*.eledsec[1-9][0-9][0-9]R + +# glossaries +*.acn +*.acr +*.glg +*.glo +*.gls +*.glsdefs + +# gnuplottex +*-gnuplottex-* + +# gregoriotex +*.gaux +*.gtex + +# htlatex +*.4ct +*.4tc +*.idv +*.lg +*.trc +*.xref + +# hyperref +*.brf + +# knitr +*-concordance.tex +# TODO Comment the next line if you want to keep your tikz graphics files +*.tikz +*-tikzDictionary + +# listings +*.lol + +# makeidx +*.idx +*.ilg +*.ind +*.ist + +# minitoc +*.maf +*.mlf +*.mlt +*.mtc[0-9]* +*.slf[0-9]* +*.slt[0-9]* +*.stc[0-9]* + +# minted +_minted* +*.pyg + +# morewrites +*.mw + +# nomencl +*.nlg +*.nlo +*.nls + +# pax +*.pax + +# pdfpcnotes +*.pdfpc + +# sagetex +*.sagetex.sage +*.sagetex.py +*.sagetex.scmd + +# scrwfile +*.wrt + +# sympy +*.sout +*.sympy +sympy-plots-for-*.tex/ + +# pdfcomment +*.upa +*.upb + +# pythontex +*.pytxcode +pythontex-files-*/ + +# tcolorbox +*.listing + +# thmtools +*.loe + +# TikZ & PGF +*.dpth +*.md5 +*.auxlock + +# todonotes +*.tdo + +# vhistory +*.hst +*.ver + +# easy-todo +*.lod + +# xcolor +*.xcp + +# xmpincl +*.xmpi + +# xindy +*.xdy + +# xypic precompiled matrices +*.xyc + +# endfloat +*.ttt +*.fff + +# Latexian +TSWLatexianTemp* + +## Editors: +# WinEdt +*.bak +*.sav + +# Texpad +.texpadtmp + +# LyX +*.lyx~ + +# Kile +*.backup + +# KBibTeX +*~[0-9]* + +# auto folder when using emacs and auctex +./auto/* +*.el + +# expex forward references with \gathertags +*-tags.tex + +# standalone packages +*.sta + +### TeX Patch ### +# glossaries +*.glstex + +# End of https://www.gitignore.io/api/tex,python +tags +tags.lock diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml @@ -0,0 +1,7 @@ +before_script: + - apt-get install python3 python3-pip -y + - pip3 install -r requirements.txt + +run-test: + script: + - python3 test.py diff --git a/README.md b/README.md @@ -0,0 +1,13 @@ +# ML Trust Model +A centralised trust model that uses either a neural network or kernel machine +to figure out the trust of the nodes. + +## Installation +``` +pip3 install -r requirements.txt +``` + +## Running +``` +python3 TrustModel.py +``` diff --git a/TrustModel.py b/TrustModel.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import numpy as np + +class Report: + def __init__(self, service=0, capability=0, note=0): + self.service = service + self.capability = capability + self.note = note + + +class Node: + def __init__(self, service=100, capability=100, note_acc=1.0): + self.service = service + self.capability = capability + self.note_taking_acc = note_acc + + def send_report(self, proxy_service, proxy_capability, + service_target, capability_target): + note = self.take_note(proxy_service, proxy_capability, + service_target, capability_target) + + return Report(service_target, capability_target, note) + + def take_note(self, proxy_service, proxy_capability, + service_target, capability_target): + if proxy_service >= service_target and \ + proxy_capability >= capability_target: + note = 1 + elif proxy_service >= service_target or \ + proxy_service >= capability_target: + note = 0 + else: + note = -1 + + return note if np.random.rand() < self.note_taking_acc \ + else wrong_note(note) + + +def wrong_note(note): + wrong_notes = {-1, 0, 1} - {note} + return list(wrong_notes)[int(np.round(np.random.rand()))] + + +if __name__ == '__main__': + REPORT = Report(50, 50, -1) + print(f"{REPORT.service}, {REPORT.capability}, {REPORT.note}") diff --git a/requirements.txt b/requirements.txt @@ -0,0 +1 @@ +numpy diff --git a/test.py b/test.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +import unittest + +import TrustModel + +''' +Perform unit tests on the program. + +Author: Cody Lewis +Date: 2019-03-12 +''' + + +class TestTrustModel(unittest.TestCase): + def test_report(self): + ''' + Test report creation for all possible values + ''' + for service in range(101): + for capability in range(101): + for note in [-1, 0, 1]: + self.report_create(service, capability, note) + + def report_create(self, service, capability, note): + ''' + Test the creation of reports. + ''' + report = TrustModel.Report(service, capability, note) + self.assertEqual(report.service, service) + self.assertEqual(report.capability, capability) + self.assertEqual(report.note, note) + + def test_wrong_note(self): + for note in [-1, 0, 1]: + self.assertNotEqual(TrustModel.wrong_note(note), note) + + +if __name__ == '__main__': + unittest.main()