Skip to content

Instantly share code, notes, and snippets.

@MarHoff
Last active July 28, 2016 16:20
Show Gist options
  • Save MarHoff/169d4642fc4cdbe5874c4b8188fdc4db to your computer and use it in GitHub Desktop.
Save MarHoff/169d4642fc4cdbe5874c4b8188fdc4db to your computer and use it in GitHub Desktop.
A basic SQL function to return a score between 0 and 1 based on 2 parameters
CREATE OR REPLACE FUNCTION ia_sigmoid(
v_value numeric,
v_turn numeric,
v_slope numeric)
RETURNS numeric AS
'SELECT 1./(1.+ exp(((-v_slope*v_value)+v_slope*v_turn))); '
LANGUAGE sql ;
@MarHoff
Copy link
Author

MarHoff commented Jul 28, 2016

Parameters:

  • value = Value to score against
  • v_turn = Inflection point of the sigmoid (Where result is exactly 0.5)
  • v_slope = smoothness of the slope

Graphical example (where a= v_turn and b=v_slope ):

https://www.desmos.com/calculator/rna4aqta0c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment