49 std::vector<BaseFloat> *nontarget_scores,
51 KALDI_ASSERT(!target_scores->empty() && !nontarget_scores->empty());
52 std::sort(target_scores->begin(), target_scores->end());
53 std::sort(nontarget_scores->begin(), nontarget_scores->end());
55 size_t target_position = 0,
56 target_size = target_scores->size();
57 for (; target_position + 1 < target_size; target_position++) {
58 ssize_t nontarget_size = nontarget_scores->size(),
59 nontarget_n = nontarget_size * target_position * 1.0 / target_size,
60 nontarget_position = nontarget_size - 1 - nontarget_n;
61 if (nontarget_position < 0)
62 nontarget_position = 0;
63 if ((*nontarget_scores)[nontarget_position] <
64 (*target_scores)[target_position])
67 *threshold = (*target_scores)[target_position];
68 BaseFloat eer = target_position * 1.0 / target_size;
77 int main(
int argc,
char *argv[]) {
78 using namespace kaldi;
82 "Computes Equal Error Rate\n" 83 "Input is a series of lines, each with two fields.\n" 84 "The first field must be a numeric score, and the second\n" 85 "either the string 'target' or 'nontarget'. \n" 86 "The EER will be printed to the standard output.\n" 88 "Usage: compute-eer <scores-in>\n" 89 "e.g.: compute-eer -\n";
99 std::string scores_rxfilename = po.
GetArg(1);
101 std::vector<BaseFloat> target_scores, nontarget_scores;
102 Input ki(scores_rxfilename);
105 while (std::getline(ki.
Stream(), line)) {
106 std::vector<std::string> split_line;
109 if (split_line.size() != 2) {
110 KALDI_ERR <<
"Invalid input line (must have two fields): " 114 KALDI_ERR <<
"Invalid input line (first field must be float): " 117 if (split_line[1] ==
"target")
118 target_scores.push_back(score);
119 else if (split_line[1] ==
"nontarget")
120 nontarget_scores.push_back(score);
122 KALDI_ERR <<
"Invalid input line (second field must be " 123 <<
"'target' or 'nontarget')";
126 if (target_scores.empty() && nontarget_scores.empty())
128 if (target_scores.empty())
130 if (nontarget_scores.empty())
131 KALDI_ERR <<
"No non-target scores seen.";
136 KALDI_LOG <<
"Equal error rate is " << (100.0 * eer)
137 <<
"%, at threshold " << threshold;
139 std::cout.precision(4);
140 std::cout << (100.0 * eer);
143 }
catch(
const std::exception &e) {
144 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int main(int argc, char *argv[])
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters.
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
bool ConvertStringToReal(const std::string &str, T *out)
ConvertStringToReal converts a string into either float or double and returns false if there was any ...
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
BaseFloat ComputeEer(std::vector< BaseFloat > *target_scores, std::vector< BaseFloat > *nontarget_scores, BaseFloat *threshold)
ComputeEer computes the Equal Error Rate (EER) for the given scores and returns it as a proportion be...
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_ASSERT(cond)