Skip to content

Commit

Permalink
Improved Choquet integral calculation so level sets are constructed a…
Browse files Browse the repository at this point in the history
…t the same time that the values are ordered.
  • Loading branch information
mcmtroffaes committed Jun 7, 2011
1 parent d17790b commit 5e94f1c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -29,6 +29,9 @@ Version 0.1.1 (in development)
over undefined singletons uniformly (addresses in part issue #4,
reported by Erik Quaeghebeur).

* Improved Choquet integral calculation so level sets are constructed
at the same time that the values are ordered.

Version 0.1.0 (24 August 2010)
------------------------------

Expand Down
23 changes: 19 additions & 4 deletions improb/setfunction.py
Expand Up @@ -19,6 +19,7 @@

from __future__ import division, absolute_import, print_function

import bisect
import cdd
import collections
import itertools
Expand Down Expand Up @@ -251,13 +252,27 @@ def get_choquet(self, gamble):
KeyError: Event(pspace=PSpace(['a', 'b', 'c']), elements=set(['c']))
"""
gamble = self.pspace.make_gamble(gamble)
values = sorted(set(gamble.itervalues())) # set to get unique values
# construct list of values and level sets
# we use the bisect algorithm to sort the values
# this allows us to construct level sets at the same time
values = []
events = []
for key, value in gamble.iteritems():
# find index i such that values[j] <= value for j < i
# and values[j] > value for i >= j
i = bisect.bisect_right(values, value)
if i == 0 or values[i - 1] != value:
# value does not yet exist, so update values
values.insert(i, value)
events.insert(i, set()) # set, not Event (must be mutable)
i += 1
# update level sets
for j in xrange(0, i):
events[j].add(key)
# calculate the sum
coeffs = (current - previous # v0, v1-v0, ...
for current, previous
in itertools.izip(values, [0] + values))
level = lambda t: (key for key, value in gamble.iteritems()
if value >= t)
events = (Event(gamble.pspace, level(value)) for value in values)
return sum(coeff * self[event]
for coeff, event in itertools.izip(coeffs, events))

Expand Down

0 comments on commit 5e94f1c

Please sign in to comment.