Algorithmadvanced
TruthFinder
Also called TruthFinder algorithm.
Iterate between the trust of sources and the confidence of the facts they claim, with similar facts supporting each other and conflicting facts counting against each other.
- Solves
- Truth discovery
- Time
- O(k n d) worst · averageO(n d) best
- Space
- O(n) extra
- Where
- d = the largest number of different facts on one object; k = the number of iterations; n = the number of claims
- Model
- Real RAM
- Properties
- deterministicnot exactnot externalnot in placeofflineiterative
- Evidence
- Full proofCode in 1 languages
- Origin
- Xiaoxin Yin, Jiawei Han, Philip S. Yu, 2007
TruthFinder is an algorithm for truth discovery: many sources make claims about the same objects, the claims conflict, and the task is to pick the true value of each object without labels. TruthFinder gives each source a trust and each fact a confidence. The confidence of a fact grows with the trust of the sources that claim it, and the trust of a source is the mean confidence of its facts. It runs the two steps in turn until the trust values stop changing in direction. It also lets a fact gain support from similar facts on the same object and lose support to conflicting ones. The page truth discovery states the problem and compares the other methods; this page gives TruthFinder in full. Its equations are heuristics with a probabilistic reading. There is no proof that the iteration converges or that it finds the truth.
In plain words
Many web sites list the authors of the same books, and they do not agree. You do not know which sites to believe. TruthFinder starts by trusting every site the same. A fact that many trusted sites give gets a high score. A site whose facts have high scores becomes more trusted. Then the scores are computed again with the new trust, and so on, until the trust values settle. Facts that are close to each other, such as two spellings of one author list, help each other. Two different answers to the same question count against each other. At the end, for each book, you take the answer with the highest score.
The problem
The input is a set of claims : source says that object has value . A fact is a pair . is the set of sources that claim , and is the set of facts of . An optional implication , for two facts on the same object, says how much supports : positive for similar values, negative for values that exclude each other. The paper uses , with on its book data. The output is a confidence for each fact, a trust for each source, and for each object the fact with the largest confidence.
The algorithm
TruthFinder(claims, imp, t0, ρ, γ, δ, T)- 1
for each source w do t(w) ← t0 ▷ t0 = 0.9 in the paper - 2
repeat - 3
for each source w do τ(w) ← -ln(1 - t(w)) - 4
for each fact f do σ(f) ← Σ over w in W(f) of τ(w) - 5
for each fact f do σ*(f) ← σ(f) + ρ · Σ over f' ≠ f on the same object of σ(f') · imp(f' → f) - 6
for each fact f do s(f) ← 1 / (1 + e^(-γ · σ*(f))) - 7
t_old ← t; for each source w do t(w) ← the mean of s(f) over f in F(w) - 8
until 1 - cos(t_old, t) < δ or T iterations are done - 9
return s, t, and for each object the fact with the largest s
Lines L3 and L4 are the basic model. If each source is right with probability , independently, then is the probability that at least one source of is right (Lemma 1 of the paper). Working with turns the product into a sum. Line L5 adds the support of the other facts on the same object, weighted by . Line L6 uses the logistic function instead of , for two reasons: can be negative, and sources copy each other, so the dampening factor makes the evidence count less than independence would say. Line L8 compares the direction of the trust vectors with cosine similarity. The paper uses , and . The cap is not in the paper; the implementation adds it so that the loop always stops.
Example
Three sources and three books. The implication is between two different values of the same book, and the parameters are those of the paper.
| source | b1 | b2 | b3 |
|---|---|---|---|
| A | x | x | x |
| B | y | y | |
| C | x | x |
For b1 the vote is a tie between x and y.
Iteration 1. All trusts are 0.9, so for every source. For b1, , and each loses to the other, so and for both. For b2, and , so and , which give and . For b3, . The new trusts are the means: A = 0.732, B = 0.606, C = 0.785.
Iteration 2. A is now trusted more than B, so for b1 the confidence of x is 0.581 and that of y is 0.545. The tie is broken in favour of A.
The loop stops after 5 iterations, with trusts A = 0.611, B = 0.529 and C = 0.638 and the answer x for all three books. The trusts fall below 0.9 in every iteration, because the logistic function with keeps the confidences between 0.5 and 0.8 here.
A larger run. On generated data with 200 objects, 4 sources that are right 90% of the time and claim half of the objects, and 20 sources that are right 30% of the time, claim 15% of the objects and usually agree on one wrong value (Python seed 42, 1025 claims), the vote is right on 63% of the objects. TruthFinder is right on 72% without implications and 73% with the implication above, after 3 and 5 iterations. These numbers are measurements on that data only.
Correctness
TruthFinder is a heuristic, so the claims that can be proved are about what it computes. All trust values stay strictly between 0 and 1, so every logarithm in line L3 is defined and every confidence is strictly between 0 and 1. When all trusts are equal and the implication is 0 or a fixed negative constant, the first iteration ranks the facts of each object by their number of sources, as a vote does; later iterations change the answers only through the trusts. The loop stops after at most iterations. There is no proof that the trusts converge, that the limit is unique, or that the facts with the highest confidence are true. The full statements are in the proof page.
Proof: TruthFinder computes well-defined trust and confidence values, stops, and starts as a votefull
We use the pseudocode of the page. is the set of sources, each fact is a pair (object, value), is the set of sources that claim , and is the set of facts that claims, which is not empty. The implication is a number in , and , , , , and the cap .
TruthFinder is a heuristic: nothing here says that the facts with the highest confidence are true, and nothing says that the iteration converges. The claims below are about what the method computes.
Lemma 1 (the values are defined). At the start of each iteration, for every source. In each iteration every , , is a finite real number, and .
Proof. By induction on the iterations. Line L1 sets . If , then , so in line L3 is a finite positive number. Line L4 sums finitely many of them, and line L5 adds a finite sum of finite terms. Line L6 applies the logistic function , whose values lie strictly between 0 and 1 for every real . Line L7 sets to a mean of values in over the non-empty set , which again lies in .
In floating point, can round to 1 when is very large; the implementation keeps away from 0 before it takes the logarithm.
Lemma 2 (the meaning of ). For each fact, .
Proof. .
So, if each source is right with probability , independently of the others, is the probability that at least one source of is right. This is the basic model of Yin, Han and Yu; lines L5 and L6 then change it, and the independence is an assumption, not a fact about the data. The logistic function with is their correction for sources that copy each other, and it is a heuristic.
Lemma 3 (the first iteration is a vote). Suppose , or with a constant for any two different facts on one object. Then after the first iteration, for any two facts on the same object, if and only if .
Proof. In the first iteration every source has , so and with . Let be the sum of over the facts on the object of . Then
which grows strictly with , since is the same for and . The logistic function is strictly increasing.
So the answers after one iteration are those of a vote, up to ties, and the later iterations change the answers only through the trust values. The tests check this on generated data.
Termination. Each pass of lines L3 to L8 counts one iteration, and line L8 stops the loop when the iteration count reaches , whatever the values. So the loop stops after at most iterations. It can stop earlier, when . With only one source, both vectors have one positive entry, so the cosine is 1 and the loop stops after the first iteration.
Cost of one iteration. Let be the number of claims and the number of different facts on object . Lines L3 and L7 take , line L4 takes , line L5 takes calls of imp, and line L6 takes one step per fact. With imp in constant time an iteration takes , and the whole run at most times that. Line L9 takes one pass over the facts.
What is not proved. The map from the trust vector to the next trust vector is continuous and maps into itself, but the method has no proof that the iteration converges, that its limit is unique, or that it ranks true facts first. Yin, Han and Yu report that the trust values settle after a few iterations on their data; that is a measurement.
Complexity
- One iteration. Lines L3, L4 and L7 take for claims. Line L5 takes calls of imp, where is the number of different facts on object . Without implications, line L5 is free and an iteration takes .
- The run. iterations take . On the book data of the paper the trusts settled after a few iterations; this is a measurement, not a bound, so caps .
- Space. for the claims, trusts and confidences.
Properties
- Heuristic. The trust and confidence equations, , and are choices of the authors, set on their data.
- Mutual reinforcement. Like HITS and PageRank, it computes two scores from each other, but its update is not linear and has no eigenvector form.
- Fixed point method. The update maps trust vectors in to trust vectors, so a limit, if there is one, is a fixed point of that map, as in fixed-point iteration.
- Deterministic. Ties are broken by a fixed order of the values.
- Independence assumption. Line L4 treats sources as independent. only weakens all evidence by the same factor; it does not find which sources copy.
Variants and improvements
- Without implications. Set . Then each fact depends only on its own sources, which is a vote weighted by .
- Similarity of values. For lists of authors the paper defines the similarity from the number of shared authors; numbers and strings need their own similarity.
- Probabilistic models. Later methods put the sources and the truths in one probabilistic model and fit it with expectation maximization or sampling. They can model a false positive rate and a false negative rate for each source.
- Copy detection. Dong, Berti-Equille and Srivastava model which sources copy from which, instead of one global .
- Optimization methods. Methods such as CRH write truth discovery as the minimization of a weighted loss over sources and truths, with an alternating solver.
When to use it
Use it when many sources claim values for many objects, you have no labels, and you believe that sources that are often right on the objects where others agree with them are also right elsewhere. It helps most when a few sources cover many objects and many weak sources each cover a few. With few sources, or when every source covers only a few objects, the trusts carry little information and a vote does about as well.
Pitfalls
- The cosine stop sees only the direction. If all trusts change by the same factor, the cosine is 1 and the loop stops; with one source it always stops after one iteration. A cap and a check of the absolute change are safer.
- Narrow trust range. With the confidences of facts with positive stay above 0.5, so the trusts of good and bad sources can be close, and a large group of weak sources can still outvote one good source.
- Copying. Sources that copy one source count as many. The global does not fix this for one group of copiers.
- Single truth. It picks one value for each object. Objects with several true values, such as a list of authors read as separate facts, need a different model.
- Implication on the wrong scale. multiplies sums of that grow with the number of sources, so a strong negative implication on a popular object can drive all its confidences below 0.5.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/truthfinder/. The authors are listed in prov/HNKC9H.jsonl.
"""TruthFinder (Yin, Han and Yu): iterate between source trust and fact confidence.
A claim is a triple (source, object, value). A fact is a pair (object, value).
imp(obj, v1, v2) is the implication from the fact (obj, v1) to the fact
(obj, v2), a number in [-1, 1]; the default is 0 for every pair, which gives
the plain version without similar facts. The defaults rho = 0.5, gamma = 0.3,
t0 = 0.9 and delta = 1e-5 (0.001%) are the values that the paper uses.
"""
import math
def facts_of(claims):
"""Return (sources, facts, providers of each fact, facts of each source)."""
providers = {}
by_source = {}
for w, o, v in claims:
f = (o, v)
providers.setdefault(f, set()).add(w)
by_source.setdefault(w, set()).add(f)
sources = sorted(by_source, key=repr)
facts = sorted(providers, key=repr)
return sources, facts, providers, by_source
def cosine(a, b):
na = math.sqrt(sum(x * x for x in a))
nb = math.sqrt(sum(x * x for x in b))
if na == 0 or nb == 0:
return 1.0
return sum(x * y for x, y in zip(a, b)) / (na * nb)
def no_implication(obj, v1, v2):
return 0.0
def exclusive_implication(base_sim=0.5):
"""imp = sim - base_sim with sim = 0 for two different values: each value counts against the others."""
def imp(obj, v1, v2):
return (1.0 if v1 == v2 else 0.0) - base_sim
return imp
def truthfinder(claims, imp=no_implication, t0=0.9, rho=0.5, gamma=0.3, delta=1e-5, max_iter=100):
"""Return (confidence of each fact, trust of each source, number of iterations)."""
sources, facts, providers, by_source = facts_of(claims)
same_object = {}
for o, v in facts:
same_object.setdefault(o, []).append(v)
t = {w: t0 for w in sources} # @line L1
s = {}
it = 0
while True: # @line L2
it += 1
tau = {w: -math.log(max(1e-300, 1.0 - t[w])) for w in sources} # @line L3
sigma = {f: sum(tau[w] for w in providers[f]) for f in facts} # @line L4
sigma_star = {}
for o, v in facts: # @line L5
adj = sum(sigma[(o, u)] * imp(o, u, v) for u in same_object[o] if u != v) # @line L5
sigma_star[(o, v)] = sigma[(o, v)] + rho * adj # @line L5
s = {f: 1.0 / (1.0 + math.exp(-gamma * sigma_star[f])) for f in facts} # @line L6
old = [t[w] for w in sources] # @line L7
t = {w: sum(s[f] for f in by_source[w]) / len(by_source[w]) for w in sources} # @line L7
new = [t[w] for w in sources]
if 1.0 - cosine(old, new) < delta or it >= max_iter: # @line L8
break
return s, t, it
def answers(confidence):
"""For each object, the value with the largest confidence (ties go to the smallest repr)."""
best = {}
for (o, v), c in sorted(confidence.items(), key=lambda kv: repr(kv[0])): # @line L9
if o not in best or c > best[o][1]: # @line L9
best[o] = (v, c) # @line L9
return {o: v for o, (v, c) in best.items()}
def voting(claims):
"""The baseline: for each object, the value that most sources claim."""
count = {}
for w, o, v in set(claims):
count[(o, v)] = count.get((o, v), 0) + 1
return answers({f: float(c) for f, c in count.items()})
test_truthfinder.py 156 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/truthfinder/. The authors are listed in prov/HNKC9H.jsonl.
import math
import random
import unittest
from truthfinder import answers, exclusive_implication, truthfinder, voting
def synthetic(seed, objects=200, good=4, bad=20, good_acc=0.9, bad_acc=0.3):
"""Few accurate sources with large coverage, many poor sources that share a popular wrong value."""
rng = random.Random(seed)
truth, popular = {}, {}
for o in range(objects):
a, b = rng.sample(range(6), 2)
truth[o] = "v%d_%d" % (o, a)
popular[o] = "v%d_%d" % (o, b)
specs = [("good%d" % i, good_acc, 0.5) for i in range(good)]
specs += [("bad%d" % i, bad_acc, 0.15) for i in range(bad)]
claims = []
for name, acc, cover in specs:
for o in range(objects):
if rng.random() < cover:
if rng.random() < acc:
v = truth[o]
elif rng.random() < 0.7:
v = popular[o]
else:
v = truth[o]
while v in (truth[o], popular[o]):
v = "v%d_%d" % (o, rng.randint(0, 5))
claims.append((name, o, v))
return truth, claims
def accuracy(ans, truth):
return sum(ans[o] == truth[o] for o in ans) / len(ans)
class TestTruthFinder(unittest.TestCase):
def test_one_iteration_by_hand(self):
claims = [("w1", "o", "a"), ("w2", "o", "a"), ("w2", "o", "b")]
s, t, it = truthfinder(claims, imp=exclusive_implication(), max_iter=1)
self.assertEqual(it, 1)
tau = -math.log(1 - 0.9)
sa, sb = 2 * tau, tau
star_a = sa + 0.5 * sb * (-0.5)
star_b = sb + 0.5 * sa * (-0.5)
conf_a = 1 / (1 + math.exp(-0.3 * star_a))
conf_b = 1 / (1 + math.exp(-0.3 * star_b))
self.assertAlmostEqual(s[("o", "a")], conf_a, places=12)
self.assertAlmostEqual(s[("o", "b")], conf_b, places=12)
self.assertAlmostEqual(t["w1"], conf_a, places=12)
self.assertAlmostEqual(t["w2"], (conf_a + conf_b) / 2, places=12)
self.assertEqual(answers(s), {"o": "a"})
def test_cosine_stop_with_one_source(self):
# One trust value: the cosine of two one-element vectors is 1, so the loop stops at once.
s, t, it = truthfinder([("w", "o", "a")])
self.assertEqual(it, 1)
self.assertAlmostEqual(s[("o", "a")], 1 / (1 + 0.1 ** 0.3), places=12)
def test_iteration_cap(self):
truth, claims = synthetic(3)
for cap in (1, 2, 5):
_, _, it = truthfinder(claims, max_iter=cap, delta=0.0)
self.assertEqual(it, cap)
def test_ranges_and_renaming(self):
rng = random.Random(8)
truth, claims = synthetic(8, objects=60)
s, t, it = truthfinder(claims, imp=exclusive_implication())
self.assertTrue(all(0 < c < 1 for c in s.values()))
self.assertTrue(all(0 < x < 1 for x in t.values()))
names = sorted({w for w, _, _ in claims})
shuffled = names[:]
rng.shuffle(shuffled)
rename = dict(zip(names, ["src%03d" % i for i in range(len(names))]))
renamed = [(rename[w], o, v) for w, o, v in reversed(claims)]
s2, t2, it2 = truthfinder(renamed, imp=exclusive_implication())
self.assertEqual(it, it2)
for f in s:
self.assertAlmostEqual(s[f], s2[f], places=9)
for w in t:
self.assertAlmostEqual(t[w], t2[rename[w]], places=9)
def test_similar_facts_support_each_other(self):
claims = [("w1", "x", 100), ("w2", "x", 101), ("w3", "x", 50)]
def imp(o, v1, v2):
return math.exp(-abs(v1 - v2)) - 0.5
s0, _, _ = truthfinder(claims)
self.assertAlmostEqual(s0[("x", 100)], s0[("x", 50)], places=12)
s, _, _ = truthfinder(claims, imp=imp)
self.assertGreater(s[("x", 100)], s[("x", 50)])
self.assertGreater(s[("x", 101)], s[("x", 50)])
self.assertIn(answers(s)["x"], (100, 101))
def test_against_voting_synthetic(self):
truth, claims = synthetic(42)
vote = accuracy(voting(claims), truth)
s, t, it = truthfinder(claims)
plain = accuracy(answers(s), truth)
s2, t2, it2 = truthfinder(claims, imp=exclusive_implication())
excl = accuracy(answers(s2), truth)
# The numbers on the page (seed 42): 1025 claims on 200 objects.
self.assertEqual(len(claims), 1025)
self.assertEqual((round(vote, 3), round(plain, 3), round(excl, 3)), (0.63, 0.72, 0.73))
self.assertEqual((it, it2), (3, 5))
good = sum(t2["good%d" % i] for i in range(4)) / 4
bad = sum(t2["bad%d" % i] for i in range(20)) / 20
self.assertGreater(good, bad)
def test_first_iteration_is_a_vote(self):
truth, claims = synthetic(42)
count = {}
for w, o, v in claims:
count[(o, v)] = count.get((o, v), 0) + 1
for imp in (None, exclusive_implication()):
if imp is None:
s, _, _ = truthfinder(claims, max_iter=1)
else:
s, _, _ = truthfinder(claims, imp=imp, max_iter=1)
for f in s:
for g in s:
if f[0] == g[0] and count[f] > count[g]:
self.assertGreater(s[f], s[g])
def test_page_example(self):
claims = [
("A", "b1", "x"), ("A", "b2", "x"), ("A", "b3", "x"),
("B", "b1", "y"), ("B", "b2", "y"),
("C", "b2", "x"), ("C", "b3", "x"),
]
imp = exclusive_implication()
s, t, it = truthfinder(claims, imp=imp, max_iter=1)
r = {f: round(c, 3) for f, c in s.items()}
self.assertEqual(r, {("b1", "x"): 0.627, ("b1", "y"): 0.627, ("b2", "x"): 0.77, ("b2", "y"): 0.585, ("b3", "x"): 0.799})
self.assertEqual({w: round(x, 3) for w, x in t.items()}, {"A": 0.732, "B": 0.606, "C": 0.785})
s, t, it = truthfinder(claims, imp=imp, max_iter=2, delta=0.0)
self.assertEqual((round(s[("b1", "x")], 3), round(s[("b1", "y")], 3)), (0.581, 0.545))
s, t, it = truthfinder(claims, imp=imp)
self.assertEqual(it, 5)
self.assertEqual(answers(s), {"b1": "x", "b2": "x", "b3": "x"})
self.assertEqual({w: round(x, 3) for w, x in t.items()}, {"A": 0.611, "B": 0.529, "C": 0.638})
def test_several_seeds_beat_voting(self):
for seed in (1, 2, 3, 4, 5):
truth, claims = synthetic(seed)
s, _, _ = truthfinder(claims, imp=exclusive_implication())
self.assertGreater(accuracy(answers(s), truth), accuracy(voting(claims), truth))
if __name__ == "__main__":
unittest.main()
History
Yin, Han and Yu introduced TruthFinder at KDD 2007 and gave the full version in IEEE TKDE in 2008. They studied the authors of computer science books listed by online bookstores: 1265 books, 894 bookstores and 34031 listings. With and they measured an accuracy of about 95% on that data after three iterations. Later work on truth discovery added copy detection, probabilistic models and optimization models.
References
- Xiaoxin Yin, Jiawei Han and Philip S. Yu, Truth discovery with multiple conflicting information providers on the web, Proceedings of the 13th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 2007, pages 1048 to 1052, Section 3.1.1 (Equations 1 to 4 and Lemma 1), Section 3.1.2 (the implication between facts, Equation 6), Section 3.1.3 (the dampening factor and the logistic function, Equation 8), Section 3.2 (the iteration and the cosine stop), Section 4 (the parameters and the book data)
- Xiaoxin Yin, Jiawei Han and Philip S. Yu, Truth discovery with multiple conflicting information providers on the web, IEEE Transactions on Knowledge and Data Engineering 20(6), 2008, pages 796 to 808, the journal version
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H2 full proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag HNKC9H Edit this page History Report an error Markdown