-
Notifications
You must be signed in to change notification settings - Fork 1
/
similarity.sql.in
66 lines (59 loc) · 2.59 KB
/
similarity.sql.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- Similarity functions
Create or Replace FUNCTION _OCSCHEMA_.tanimoto(bit, bit)
Returns real AS '
Select _OCSCHEMA_.nbits_set($1 & $2)::real /
(_OCSCHEMA_.nbits_set($1 & ~$2) + _OCSCHEMA_.nbits_set($2 & ~$1) +
_OCSCHEMA_.nbits_set($1 & $2))::real;
' LANGUAGE sql IMMUTABLE;
Comment On FUNCTION _OCSCHEMA_.tanimoto(bit, bit)
Is 'standard tanimoto similarity of fingerprints';
/*
Create or Replace FUNCTION _OCSCHEMA_.tani2(bit, bit)
Returns real AS '
Select _OCSCHEMA_.nbits_set($1 & $2)::real /
(_OCSCHEMA_.nbits_set($1) + _OCSCHEMA_.nbits_set($2) - _OCSCHEMA_.nbits_set($1 & $2))::real;
' LANGUAGE sql IMMUTABLE;
Comment On FUNCTION _OCSCHEMA_.tani2(bit, bit)
Is 'According to the Daylight Theory Manual.';
Create or Replace FUNCTION _OCSCHEMA_.tani3(bit, bit)
Returns real AS '
Select _OCSCHEMA_.nbits_set($1 & $2)::real /
_OCSCHEMA_.nbits_set($1 | $2)::real;
' LANGUAGE sql IMMUTABLE;
Comment On FUNCTION _OCSCHEMA_.tani3(bit, bit)
Is 'According to Sayle';
*/
Create or Replace FUNCTION _OCSCHEMA_.euclid(bit, bit)
Returns real AS '
Select sqrt((_OCSCHEMA_.nbits_set($1 & $2) + _OCSCHEMA_.nbits_set(~$1 & ~$2))::real /
length($1))::real;
' LANGUAGE sql IMMUTABLE;
Comment On FUNCTION _OCSCHEMA_.euclid(bit, bit)
Is 'standard euclid similarity of fingerprints';
Create or Replace FUNCTION _OCSCHEMA_.hamming(bit, bit)
Returns real AS '
Select ((_OCSCHEMA_.nbits_set($1 & ~$2) + _OCSCHEMA_.nbits_set(~$1 & $2))::real /
length($1))::real;
' LANGUAGE sql IMMUTABLE;
Comment On FUNCTION _OCSCHEMA_.hamming(bit, bit)
Is 'standard hamming similarity of fingerprints';
Create or Replace FUNCTION _OCSCHEMA_.tversky(bit, bit, real, real)
Returns real AS '
Select _OCSCHEMA_.nbits_set($1 & $2)::real /
($3*_OCSCHEMA_.nbits_set($1 & ~$2) + $4*_OCSCHEMA_.nbits_set($2 & ~$1) +
_OCSCHEMA_.nbits_set($1 & $2))::real;
' LANGUAGE sql IMMUTABLE;
Comment On FUNCTION _OCSCHEMA_.tversky(bit, bit, real, real)
Is 'standard tversky similarity of fingerprints';
Create or Replace FUNCTION _OCSCHEMA_.similarity(bit, bit)
Returns real AS '
Select _OCSCHEMA_.tversky($1, $2, 0.5, 0.5);
' LANGUAGE sql IMMUTABLE;
Comment On FUNCTION _OCSCHEMA_.similarity(bit, bit)
Is 'standard dice similarity of fingerprints';
Create or Replace FUNCTION _OCSCHEMA_.similarity(Text, Text)
Returns real AS '
Select _OCSCHEMA_.tversky(_OCSCHEMA_.public166keys($1), _OCSCHEMA_.public166keys($2), 0.5, 0.5);
' LANGUAGE sql IMMUTABLE;
Comment On FUNCTION _OCSCHEMA_.similarity(Text, Text)
Is 'standard dice similarity of smiles using public166key';