Last active
July 13, 2021 12:29
-
-
Save kylebgorman/fff1adee2ed3d4fcf07336728235ffc0 to your computer and use it in GitHub Desktop.
Relative error reduction calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Computes relative error reduction given two percentages. | |
// | |
// This computes relative error reduction (RER) given two percentages, the | |
// "before" and "after" accuracy. | |
// | |
// This is given by: | |
// | |
// RER = 1 - (1 - new_accuracy) / (1 - old_accuracy) | |
// | |
// To compile: gcc -O3 -std=c99 -o rer rer.c | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) { | |
if (argc != 3) { | |
fprintf(stderr, "USAGE: %s old_accuracy new_accuracy\n", argv[0]); | |
return 1; | |
} | |
const double old_error = 1. - atof(argv[1]); | |
const double new_error = 1. - atof(argv[2]); | |
if (old_error < new_error) { | |
fprintf(stderr, "FATAL: Old accuracy > new_accuracy\n"); | |
return 1; | |
} | |
const double rel_error = 1. - new_error / old_error; | |
printf("%.4f\n", rel_error); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment