Skip to content

Instantly share code, notes, and snippets.

@kylebgorman
Last active July 13, 2021 12:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylebgorman/fff1adee2ed3d4fcf07336728235ffc0 to your computer and use it in GitHub Desktop.
Save kylebgorman/fff1adee2ed3d4fcf07336728235ffc0 to your computer and use it in GitHub Desktop.
Relative error reduction calculation
// 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