Skip to content

Commit

Permalink
Passing opts to TrieClassify.
Browse files Browse the repository at this point in the history
  • Loading branch information
antononcube committed Apr 7, 2018
1 parent 9c25cd2 commit 1bf1dcd
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions TriesWithFrequencies.m
Original file line number Diff line number Diff line change
Expand Up @@ -567,24 +567,30 @@ Mathematica is (C) Copyright 1988-2016 Wolfram Research, Inc.

Clear[TrieClassify]

TrieClassify[tr_, record_] := TrieClassify[tr, record, "Decision"];
Options[TrieClassify] := {"Default" -> None};

TrieClassify[tr_, record_, "Decision"] :=
First@Keys@TrieClassify[tr, record, "Probabilities"];
TrieClassify[tr_, record_, opts : OptionsPattern[]] :=
TrieClassify[tr, record, "Decision", opts];

TrieClassify[tr_, record_, "Decision", opts : OptionsPattern[]] :=
First@Keys@TrieClassify[tr, record, "Probabilities", opts];

TrieClassify[tr_, record_, "Probability" -> class_] :=
TrieClassify[tr, record, "Probabilities"][class];
Lookup[TrieClassify[tr, record, "Probabilities"], class, 0];

TrieClassify[tr_, record_, "TopProbabilities"] :=
Select[TrieClassify[tr, record, "Probabilities"], # > 0 &];
TrieClassify[tr_, record_, "TopProbabilities", opts : OptionsPattern[]] :=
Select[TrieClassify[tr, record, "Probabilities", opts], # > 0 &];

TrieClassify[tr_, record_, "TopProbabilities" -> n_Integer] :=
Take[TrieClassify[tr, record, "Probabilities"], UpTo[n]];
TrieClassify[tr_, record_, "TopProbabilities" -> n_Integer, opts : OptionsPattern[]] :=
Take[TrieClassify[tr, record, "Probabilities", opts], UpTo[n]];

TrieClassify[tr_, record_, "Probabilities"] :=
ReverseSort[
Association[
Rule @@@ TrieLeafProbabilities[TrieSubTrie[tr, record]]]];
TrieClassify[tr_, record_, "Probabilities", opts : OptionsPattern[]] :=
Block[{res, dval = OptionValue[TrieClassify, "Default"]},
res = TrieSubTrie[tr, record];
If[Length[res] == 0, <|dval -> 0|>,
ReverseSort[Association[Rule @@@ TrieLeafProbabilities[res]]]
]
];

End[]

Expand Down

0 comments on commit 1bf1dcd

Please sign in to comment.