Skip to content

branliu0/transitive-trust-models

Repository files navigation

Testing Functions

I'm honestly being a bit lazy here, because it is a bit annoying to test nondeterministic/probabilistic functions. But running these routines will help increase confidence in the correctness of the code.

TrustGraph#initialize_agent_types

import matplotlib.pyplot as plt
from trust_graph import TrustGraph

# Print out histograms that should look like the underlying distribution
plt.hist(TrustGraph.initialize_agent_types(10000, 'uniform'), bins=20)
plt.hist(TrustGraph.initialize_agent_types(10000, 'normal'), bins=20)
plt.hist(TrustGraph.initialize_agent_types(10000, 'beta'), bins=20)

TrustGraph#initialize_edges

import matplotlib.pyplot as plt
import numpy as np
from trust_graph import TrustGraph

at = TrustGraph.initialize_agent_types(50, 'normal')

# Should print out a line graph that has a flat trendline
edges = TrustGraph.initialize_edges(at, 'uniform', 20)
plt.plot(np.mean(edges, 1))

# Should print out a line graph that has an increasing trendline
edges = TrustGraph.initialize_edges(at, 'cluster', 20)
plt.plot(np.mean(edges, 1))

TrustGraph#initialize_edge_weights

import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
from trust_graph import TrustGraph

at = TrustGraph.initialize_agent_types(50, 'normal')
edges = TrustGraph.initialize_edges(at, 'uniform', 20)
weights = TrustGraph.initialize_edge_weights(at, edges, 'sample', 'normal', 10)

# Verify that the right number of weights were set in the adjacency matrix
(np.array([len(filter(lambda x: x is not None, x)) for x in weights]) == 20).all()  # => True

# Verify that the sampled weights look close to the actual agent types
# The two lines should look pretty similar
plt.plot(stats.stats.nanmean(weights.astype(float), 0)); plt.plot(at);

# Verify that 'noisy' has a bias toward 0.5
weights = TrustGraph.initialize_edge_weights(at, edges, 'noisy', 'normal', 10)
plt.plot(stats.stats.nanmean(weights.astype(float), 0)); plt.plot(at);

# You can look at the other weights, but I'm not sure what kind of visual
# verification would be most effective, since they all have roughly similar
# expected values
weights = TrustGraph.initialize_edge_weights(at, edges, 'prior', 'uniform', 10)
plt.plot(stats.stats.nanmean(weights.astype(float), 0)); plt.plot(at);
weights = TrustGraph.initialize_edge_weights(at, edges, 'prior', 'normal', 10)
plt.plot(stats.stats.nanmean(weights.astype(float), 0)); plt.plot(at);
weights = TrustGraph.initialize_edge_weights(at, edges, 'prior', 'beta', 10)
plt.plot(stats.stats.nanmean(weights.astype(float), 0)); plt.plot(at);

utils.softmax_rv

import matplotlib.pyplot as plt
from trust_graph import TrustGraph
import utils

# Display the softmax probability distribution -- should be increasing
at = TrustGraph.initialize_agent_types(50, 'normal')
softmax = utils.softmax_rv(at)
plt.hist(softmax.rvs(size=10000))

About

Research in transitive trust models

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published