Interactive code offline

Due to the discontinuation of www.scalafiddle.com, the code blocks on this website are currently not interactive. We regret the limitations this imposes and are working on a solution.

On this page you can find implementations of variants 1 and 2 of Party Subgrouping. Included are the formalizations themselves and the code to run a simulation for them. You need to press the run button to run the simulation. This then also allows you to change the input of the simulation to explore the behavior of the models. You are encouraged to explore the simulations to your heart’s content. Afterwards, you can compare the models through analysis here.

Party Subgrouping V1

Party Subgrouping (version 1)

Input: A set of guests and a function .

Output: A partition of into non-overlapping subsets that maximizes average ingroup similarity:

Where ingroup similarity for subset is defined as mean pair-wise similarity:

def ps1(G: Set[Person],
        sim: (Person, Person) => Double): Option[Set[Set[Person]]] = {
  def inGroupSim(subgroup: Set[Person]): Double =
    subgroup.uniquepairs.map(Function.tupled(sim)).sum / subgroup.size.toDouble

  G.allPartitionings
   .argMax(partitioning => {
     partitioning.map(Gi => inGroupSim(Gi) / partitioning.size).sum
   })
}

val a = Person("A")
val b = Person("B")
val c = Person("C")
val d = Person("D")
val e = Person("E")
val G = Set(a, b, c, d, e)
val similarities = Set(
  Similarity(a, b, 1.0),
  Similarity(a, c, 2.0),
  Similarity(a, d, -1.0),
  Similarity(a, e, 3.5),
  Similarity(b, c, -2.0),
  Similarity(b, d, 4.0),
  Similarity(c, d, -3.0)
)
def sim = similarities.deriveFun

val out = ps1(G, sim)

println(h2("Input:"))
VegaRenderer.render(similarities.deriveGraph(G))

println(h2("Output:"))
println(out)

Party Subgrouping V2

Party Subgrouping (version 2)

Input: A set of guests , a function , and threshold of satisfactory similarity .

Output: A partition of into non-overlapping subsets where each partition has satisfactory ingroup similarity:

Where ingroup similarity for subset is defined as mean pair-wise similarity:

def ps2(G: Set[Person],
        sim: (Person, Person) => Double,
        s: Double): Option[Set[Set[Person]]] = {
  def inGroupSim(subgroup: Set[Person]): Double =
    subgroup.uniquepairs.map(Function.tupled(sim)).sum / subgroup.size.toDouble

  G.allPartitionings
   .filter(_.forall(Gi => inGroupSim(Gi) >= s))
   .random
}

val a = Person("A")
val b = Person("B")
val c = Person("C")
val d = Person("D")
val e = Person("E")
val G = Set(a, b, c, d, e)
val similarities = Set(
  Similarity(a, b, 1.0),
  Similarity(a, c, 2.0),
  Similarity(a, d, -1.0),
  Similarity(a, e, 3.5),
  Similarity(b, c, -2.0),
  Similarity(b, d, 4.0),
  Similarity(c, d, -3.0)
)
def sim = similarities.deriveFun
val s = 2.5 // If you get no valid output, try lowering this value.

val out = ps2(G, sim, s)

println(h2("Input:"))
VegaRenderer.render(similarities.deriveGraph(G))
println(s"s=$s")

println(h2("Output:"))
println(out)