2
$\begingroup$

I want to use Mathematica to show which subsets of a power set are required to calculate the plausibility for a given set in a power set. This has lead me to compute a summation with a Do and an If function in Mathematica. I would like to know if there is a neater way.

The plausibility $pl(A)$ is the sum of all the masses of the sets B that intersect the set of interest A:

$pl(A) = \sum_{B|B \cap A \ne \emptyset}^{ } {m(B)}$

This is based on the Wikipedia example https://en.wikipedia.org/wiki/Dempster%E2%80%93Shafer_theory.

To calculate summation I used the following Mathematica code:

Do[If[Intersection[{r},i]!={},Print[i]],{i,powerset}]
powerset = Subsets[{r,y,g}]

This returns:

{{},{r},{y},{g},{r,y},{r,g},{y,g},{r,y,g}}

If I want to calculate the plausibility of 'Red' then I need to sum the masses of the following sets:

Do[If[Intersection[{r},i]!={},Print[i]],{i,powerset}]

This returns:

{r}
{r,y}
{r,g}
{r,y,g}

Is there a better way I can get Mathematica to return this list of sets?

$\endgroup$
2
$\begingroup$

From your code, you appear to be looking for subsets in the power set that contain a certain symbol. That's a job for Selector Cases:

Select[Subsets[{r, y, g}], MemberQ[r]]
Cases[Subsets[{r, y, g}], {___, r, ___}]

Both return the same:

{{r}, {r, y}, {r, g}, {r, y, g}}
$\endgroup$
  • $\begingroup$ Maybe a silly question, but wouldn't all sets of Subsets[{r,y,g}] that have r in it be just the same as Subsets[{y,g}] with r appended to each subset? $\endgroup$ – Sjoerd Smit Apr 18 at 14:35
  • $\begingroup$ @SjoerdSmit Yes I think so. However, I am not sure that I understand the theory behind what OP was doing, so I simply translated the "algorithm" that he was using to more idiomatic MMA code. $\endgroup$ – MarcoB Apr 18 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.