math.extras: adding the Herfindahl measure.
parent
35677bc5fa
commit
905e26e9e0
|
@ -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
|
||||
|
|
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue