ml-trust-model

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

commit 3dfe3457399c872a1145c929758cd6d71b40dc48
parent 08c54d6582a75e5fd9058c784b5b9728c78bfe31
Author: Cody Lewis <codymlewis@protonmail.com>
Date:   Wed, 13 Mar 2019 15:41:18 +1100

Added test case for bootstrapping phase

Diffstat:
MTest.py | 14++++++++++++++
MTrustModel.py | 11+++++++----
2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/Test.py b/Test.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import unittest +import numpy as np import TrustModel @@ -100,6 +101,19 @@ class TestTrustModel(unittest.TestCase): self.assertEqual(report.capability, capability) self.assertEqual(report.note, note) + def test_bootstrap(self): + trust_manager = TrustModel.TrustManager() + no_of_transactions = 5 + + trust_manager.bootstrap(no_of_transactions) + self.assertEqual(np.shape(trust_manager.reports), (200, 200)) + for i in range(200): + for j in range(200): + if i != j: + self.assertEqual( + len(trust_manager.reports[i][j]), no_of_transactions + ) + if __name__ == '__main__': unittest.main() diff --git a/TrustModel.py b/TrustModel.py @@ -22,7 +22,7 @@ class Report: class Node: ''' - A node in the trust managed network + A node in the trust managed network. ''' def __init__(self, service=100, capability=100, note_acc=1.0): self.service = service @@ -97,12 +97,12 @@ class TrustManager: [[] for _ in range(no_of_nodes)] for _ in range(no_of_nodes) ] - def bootstrap(self, epochs=1_000): + def bootstrap(self, epochs=100): ''' Go through the network and perform artificial transactions to develop reports. ''' - for _ in range(epochs): + for i in range(epochs): self._artificial_transactions() def _artificial_transactions(self): @@ -131,4 +131,7 @@ def wrong_note(note): if __name__ == '__main__': - pass + TRUST_MANAGER = TrustManager() + TRUST_MANAGER.bootstrap(5) + print(f"Shape of the reports: {np.shape(TRUST_MANAGER.reports)}") + print(TRUST_MANAGER.reports[0][1])