Skip to content

Commit

Permalink
0.1.0 GST
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Feb 27, 2022
1 parent d76f508 commit e146531
Show file tree
Hide file tree
Showing 13 changed files with 626 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libraries/GST/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560
13 changes: 13 additions & 0 deletions libraries/GST/.github/workflows/arduino-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

name: Arduino-lint

on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict
17 changes: 17 additions & 0 deletions libraries/GST/.github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Arduino CI

on: [push, pull_request]

jobs:
runTest:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb
18 changes: 18 additions & 0 deletions libraries/GST/.github/workflows/jsoncheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: JSON check

on:
push:
paths:
- '**.json'
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

112 changes: 112 additions & 0 deletions libraries/GST/GST.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#pragma once
//
// FILE: GST.h
// VERSION: 0.1.0
// PURPOSE: Arduino library for Gold Standard Test metrics
// URL: https://github.com/RobTillaart/GST
// https://en.wikipedia.org/wiki/Sensitivity_and_specificity
// https://en.wikipedia.org/wiki/Confusion_matrix
//
// formula's based upon wikipedia.


#define GST_LIB_VERSION (F("0.1.0"))


class GST
{
public:
GST() {};

// These 4 need to be filled in.
void setTruePositive(float v) { TP = v; P = TP + FN; };
void setTrueNegative(float v) { TN = v; N = TN + FP; };
void setFalsePositive(float v) { FP = v; N = TN + FP; };
void setFalseNegative(float v) { FN = v; P = TP + FN; };

float getTruePositive() { return TP; };
float getTrueNegative() { return TN; };
float getFalsePositive() { return FP; };
float getFalseNegative() { return FN; };

float getTotal() { return P + N; };
float getActualPositive() { return P; };
float getActualNegative() { return N; };
float getTestedPositive() { return TP + FP; };
float getTestedNegative() { return TN + FN; };

float sensitivity() { return TPR(); };
float specificity() { return TNR(); };



// true positive rate
float TPR() { return TP / P; };
// true negative rate
float TNR() { return TN / N; };

// false negative rate
float FNR() { return FN / (FN + TP); };
// false positive rate
float FPR() { return FP / (FP + TN); };



// positive predictive value
float PPV() { return TP / (TP + FP); };
// negative predictive value
float NPV() { return TN / (TN + FN); };

// false discovery rate
float FDR() { return FP / (FP + TP); };
// false omission rate
float FOR() { return FN / (FN + TN); };



// positive likelihood ratio
float LRplus() { return TPR() / FPR(); };
// negative likelihood ratio
float LRminus() { return FNR() / TNR(); };



float prevalenceThreshold() { return sqrt(FPR()) / (sqrt(TPR()) + sqrt(FPR())); };
float threatScore() { return TP / (TP + FN + FP); };
float criticalSuccessIndex() { return threatScore(); };



float prevalence() { return P / (P + N); };
float accuracy() { return (TP + TN) / (P + N); };
float balancedAccuracy() { return (TPR() + TNR()) / 2; };
float F1Score() { return (2 * TP)/(2 * TP + FP + FN); };



// Matthews correlation coefficient
float MCC() { return (TP*TN-FP*FN)/sqrt((TP+FP)*(TP+FN)*(TN+FP)*(TN+FN)); };
float phi() { return MCC(); };
// Fowlkes–Mallows index
float FM() { return sqrt(PPV()*TPR()); };
// Bookmaker informedness
float BM() { return TPR() + TNR() - 1; };
// markedness
float MK() { return PPV() + NPV() - 1; };
float deltaP() { return MK(); };
// diagnostic odds ratio
float DOR() { return LRplus() / LRminus(); };


private:
float P = 0;
float N = 0;
float TP = 0;
float TN = 0;
float FP = 0;
float FN = 0;
};


// -- END OF FILE --

21 changes: 21 additions & 0 deletions libraries/GST/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022-2022 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 42 additions & 0 deletions libraries/GST/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

[![Arduino CI](https://github.com/RobTillaart/GST/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/GST/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/GST/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/GST/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/GST/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/GST/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/GST.svg?maxAge=3600)](https://github.com/RobTillaart/GST/releases)


# GST

Arduino library for Gold Standard Test metrics.


## Description

The GST library is **experimental**.


#### Links

- https://en.wikipedia.org/wiki/Sensitivity_and_specificity
- https://en.wikipedia.org/wiki/Confusion_matrix


## Interface

See .h file


## Future

- documentation
- improve
- more links?
- test
- complete the CI test coverage.
- examples
- add real life examples.
- combination with a sensor? batch testing?
- code
- full name functions instead of acronyms. (wrap?)
- is GST a good class name?
9 changes: 9 additions & 0 deletions libraries/GST/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# GST Changelog


## 0.1.0 2022-02-25
- initial version
-


Loading

0 comments on commit e146531

Please sign in to comment.