Installation and Use

Installation

pip install openrank-sdk

from openrank_sdk import EigenTrust

Here's the Github repo.

Parameters

Local Trust

i

From Peer ID: Address of the user initiating the interaction

*(Required)

j

To Peer ID: Address of the user receiving the interaction

*(Required)

v

Value of Interaction: Score/Weight/Value of the interaction

*(Required)

Seed Peers (PreTrust)

I

Seed Peers: Address of the Peer

Defaults to using all i in the Local Trust as Seed Peers

V

Trust Score: Initial trust score for the peer

Defaults to giving all the Preturst members the a common trust score

Parameters

Alpha

Pre-trust Strength: Weighting factor for initial trust scores

0.5 (50%) as the strength

Input:

In order to use the OpenRank SDK, you will need to provide information regarding local trust and optionally pre-trust values.

Local trust: represents the trust relationships between peers within the network Pre-trust: indicates the initial level of trust assigned to each peer by default.

Both local trust and pre-trust values can be specified either using a CSV file or an array of dictionaries with the following format:

v value cannot be negative or 0.

Sample local trust data:

localtrust = [
    {"i": "alice", "j": "bob", "v": 100},
    {"i": "charlie", "j": "bob", "v": 100},
    {"i": "alice", "j": "charlie", "v": 75}
]

Sample Local Trust CSV:

from,to,value
alice,bob,100
charlie,bob,100
alice,charlie,75

In this example, there are three peers: Alice, Charlie, and Bob. Both Alice and Charlie trust Bob by 100, and Alice also trusts Charlie by 75, which is 3/4 of the trust he places in Bob.

Sample Pre-Trust Data:

pre = [
    {"i": "Alice", "v": 50},
    {"i": "Charlie", "v": 100}
]

Here, both Alice and Charlie are pre-trusted by the network, with Charlie being trusted twice as much as Alice.

Running:

To execute the EigenTrust algorithm using the provided input, you can follow these steps:

from openrank_sdk import EigenTrust

api_key = 'your_api_key'
a = EigenTrust(api_key=api_key)

# Option A - Use local variable
a.run_eigentrust(localtrust)
## run with pretrust you've defined rather than the one distributed equally
a.run_eigentrust(localtrust, pretrust)

# Option B - Use CSV
a.run_eigentrust_from_csv("./lt.csv")
## run with pretrust you've defined rather than the one distributed equally
a.run_eigentrust_from_csv("./lt.csv", "./pt.csv")

Output:

Upon execution, the OpenRank SDK will generate rankings based on the provided input. An example of the output is as follows:

[
  {'i': 'Charlie', 'v': 0.485969387755102},
  {'i': 'Bob', 'v': 0.2933673469387755},
  {'i': 'Alice', 'v': 0.22066326530612243}
]

Here, the EigenTrust algorithm has distributed the network's trust among the three peers as follows:

  • Alice receives 22.1% of the total trust.

  • Bob receives 29.3% of the total trust.

  • Charlie receives 48.6% of the total trust.

This output provides a clear understanding of how trust is distributed within the network based on the EigenTrust algorithm.

Appendix

Tweaking Alpha: Adjusting Seed trust strength in EigenTrust

The pre-trust input defines the relative ratio by which the network distributes its a priori trust onto trustworthy peers.

You can also tweak the overall absolute strength of the pre-trust. This parameter, named alpha, represents the portion of the EigenTrust output taken from the pre-trust. For example, with alpha of 0.2, the EigenTrust output is a blend of 20% pre-trust and 80% peer-to-peer trust.

The default for alpha is 0.5 (50%). If you re-run EigenTrust using a lower alpha of only 0.01 (1%):

from openrank_sdk import EigenTrust

api_key = 'your_api_key'
a = EigenTrust(api_key=api_key, alpha=0.01)

a.run_eigentrust(localtrust, pretrust)

Output Rankings changed due to this

[
  {'address': 'Charlie', 'score': 0.39451931175281096},
  {'address': 'Bob', 'score': 0.4401132971693594},
  {'address': 'Alice', 'score': 0.16536739107782936}
]

Tips for developers

  1. Choose a data set that could represent peer to peer interactions. For example, onchain attestations, github stars, social network engagement among users, token transfers among EOAs.

  2. Identify a trust heuristic value between peers. For example, value of tokens sent from Alice to Bob (value=$sent), giving an attestation or a github star (value=1).

  3. Create a Local trust matrix from the above two steps. The v1 SDK can support a few million non-zero entries in this matrix.

  4. Choose a few seed peers based on the context of the data set or use case. This would be any known trustworthy users or peers in the graph. Optionally, you can also choose the intenstity of the seed trust in the compute. The v1 defaults to 50% amplification of the seed trust peers in the output score calculation.

  5. Run the compute and view the resulting scores. You can fine tune and iterate the local trust and seed peers based on eyeballing the compute results.

  6. Reach out to us for any help.

Last updated

Logo

Copyright 2024