Add merge/1 and merge/2 to Markov.Chain
merge/1 takes a nonempty list of markov chains to merge merge/2 takes two markov chains of the same order and sums their weights Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -67,4 +67,19 @@ defmodule MarkovChainTest do
|
||||
["foo", "bar"] => %{"baz" => 3, "qux" => 1},
|
||||
}
|
||||
end
|
||||
|
||||
test "chain merge works correctly" do
|
||||
chain1 = %Chain {order: 2}
|
||||
|> Chain.add_weight(["foo", "bar"], "baz")
|
||||
|
||||
chain2 = %Chain {order: 2}
|
||||
|> Chain.add_weight(["foo", "bar"], "baz")
|
||||
|> Chain.add_weight(["bar", "baz"], "qux")
|
||||
|
||||
merged = Chain.merge(chain1, chain2)
|
||||
assert merged.chain == %{
|
||||
["foo", "bar"] => %{"baz" => 2},
|
||||
["bar", "baz"] => %{"qux" => 1},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user