math.extras: adding the Herfindahl measure.

db4
John Benediktsson 2012-09-26 15:25:45 -07:00
parent 35677bc5fa
commit 905e26e9e0
2 changed files with 10 additions and 0 deletions

View File

@ -65,3 +65,6 @@ IN: math.extras.test
{ 0 } [ { 1 1 1 1 1 1 } concentration-coefficient ] unit-test
{ 0 } [ { 10 10 10 10 } concentration-coefficient ] unit-test
{ 0 } [ { } concentration-coefficient ] unit-test
{ 57/200 } [ { 80 60 10 20 30 } herfindahl ] unit-test
{ 17/160 } [ { 80 60 10 20 30 } normalized-herfindahl ] unit-test

View File

@ -178,3 +178,10 @@ PRIVATE>
] [
[ gini ] [ length [ ] [ 1 - ] bi / ] bi *
] if ;
: herfindahl ( seq -- x )
dup sum sq '[ sq _ / ] map-sum ;
: normalized-herfindahl ( seq -- x )
[ herfindahl ] [ length recip ] bi
[ - ] [ 1 swap - / ] bi ;