Similarity v0.1.0 Similarity.Cosine View Source
A struct that can be used to accumulate ids & attributes and calcuate similarity between them.
Link to this section Summary
Functions
Puts a new id with attributes into %Cosine{}.map
and returns %Cosine{}
struct.
Returns Similarity.cosine_srol/2
similarity between two pairs of ids (id_a, id_b) in %Cosine{}
Returns a stream of all unique pairs of similarities in %Cosine{}.map
Link to this section Functions
Link to this function
add(struct, id, attributes) View Source
Puts a new id with attributes into %Cosine{}.map
and returns %Cosine{}
struct.
Example:
s = Similarity.Cosine.new
s = s |> Similarity.Cosine.add("barna", [{"n_of_bacons", 3}, {"hair_color_r", 124}, {"hair_color_g", 188}, {"hair_color_b", 11}])
Link to this function
between(cosine, id_a, id_b) View Source
Returns Similarity.cosine_srol/2
similarity between two pairs of ids (id_a, id_b) in %Cosine{}
Example:
s = Similarity.Cosine.new
s = s |> Similarity.Cosine.add("barna", [{"n_of_bacons", 3}, {"hair_color_r", 124}, {"hair_color_g", 188}, {"hair_color_b", 11}])
s = s |> Similarity.Cosine.add("somebody", [{"n_of_bacons", 0}, {"hair_color_r", 222}, {"hair_color_g", 62}, {"hair_color_b", 11}])
s |> Similarity.Cosine.between("barna", "somebody")
Returns a new %Cosine{}
struct to be first used with add/3
function
Link to this function
stream(cosine) View Source
Returns a stream of all unique pairs of similarities in %Cosine{}.map
Example:
s = Similarity.Cosine.new
s = s |> Similarity.Cosine.add("barna", [{"n_of_bacons", 3}, {"hair_color_r", 124}, {"hair_color_g", 188}, {"hair_color_b", 11}])
s = s |> Similarity.Cosine.add("somebody", [{"n_of_bacons", 0}, {"hair_color_r", 222}, {"hair_color_g", 62}, {"hair_color_b", 11}])
Similarity.Cosine.stream(s)