Skip to content

Commit

Permalink
Moved Maslowian param distribution specs to config utils
Browse files Browse the repository at this point in the history
  • Loading branch information
IDoCodingStuffs committed Jul 7, 2019
1 parent 5a0a4bd commit a40341a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 65 deletions.
5 changes: 4 additions & 1 deletion conf/application.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
numberGroupsSimulated = 10000
preferenceGenerators = "Uniform;Uniform;Uniform;Uniform"
weightsGenerators = "Uniform;Uniform;Uniform;Uniform"
decisionModels = "WeightedRoundup(0.5,0.5);WeightedRoundup(0.5,0.5);WeightedRoundup(0.5,0.5);WeightedRoundup(0.5,0.5)"
decisionModels = "WeightedRoundup(0.5,0.5);WeightedRoundup(0.5,0.5);WeightedRoundup(0.5,0.5);WeightedRoundup(0.5,0.5)"

maslowian.means = "0.3, 0.4, 0.2, 0.2, 0.2, 0.2"
maslowian.sd = "0.2, 0.3, 0.1, 0.1, 0.1, 0.1"

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package net.codingstuffs.abilene.intake.parse

import com.typesafe.config.{Config, ConfigFactory}
import net.codingstuffs.abilene.simulation.decision_making.generators.random.{Beta, Discrete, FoldedGaussian, Uniform}
import net.codingstuffs.abilene.simulation.decision_making.models.DecisionMakingModel
import net.codingstuffs.abilene.simulation.decision_making.models.simplified.ArithmeticRoundup.{EgalitarianRoundup, SelfishRoundup, WeightedRoundup}

import scala.util.Random

object ConfigUtil {
val config: Config = ConfigFactory.load()

final val DECISION_MODELS: Seq[DecisionMakingModel] = {
config.getString("decisionModels").split(";")
.map({
case "SelfishRoundup" => SelfishRoundup
case "EgalitarianRoundup" => EgalitarianRoundup
case "WeightedRoundup" => SelfishRoundup
case sasScale: String if sasScale.startsWith("WeightedRoundup(") =>
WeightedRoundup(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(sasScale).get.split(",")(0).toDouble,
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(sasScale).get.split(",")(1).toDouble
)
})
}
final val PREFERENCE_GENERATORS: Seq[Random] = {
config.getString("preferenceGenerators").split(";")
.map({
case "Uniform" => Uniform.GENERATOR
case discrete: String if discrete.startsWith("Discrete") =>
Discrete.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(discrete).get.split(",").map
(_.toDouble).toSeq)
case beta: String if beta.startsWith("Beta") =>
Beta.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(0).toDouble,
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(1).toDouble)
case gaussian: String if gaussian.startsWith("FoldedGaussian") =>
FoldedGaussian.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(gaussian).get.toDouble)
}).toSeq
}
final val WEIGHTS_GENERATORS: Seq[Random] = {
config.getString("preferenceGenerators").split(";")
.map({
case "Uniform" => Uniform.GENERATOR
case discrete: String if discrete.startsWith("Discrete") =>
Discrete.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(discrete).get.split(",").map
(_.toDouble).toSeq)
case beta: String if beta.startsWith("Beta") =>
Beta.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(0).toDouble,
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(0).toDouble)
case gaussian: String if gaussian.startsWith("FoldedGaussian") =>
FoldedGaussian.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(gaussian).get.toDouble)
}).toSeq
}

final val MASLOWIAN_MEAN_SD: Map[String, (Double, Double)] = {
val means = config.getString("maslowian.means").split(",").map(i => i.toDouble).toSeq
val sd = config.getString("maslowian.sd").split(",").map(i => i.toDouble).toSeq

val labels = Seq("physio", "safety", "affiliation", "mate_acquisition", "mate_retention", "parenting")

labels.zipWithIndex.map(label => label._1 -> (means(label._2), sd(label._2))).toMap
}
}
55 changes: 6 additions & 49 deletions src/main/scala/net/codingstuffs/abilene/simulation/Abilene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.typesafe.config.ConfigFactory
import net.codingstuffs.abilene.simulation.decision_making.generators.random.{Beta, Discrete, FoldedGaussian, Uniform}
import net.codingstuffs.abilene.simulation.decision_making.models.{DecisionMakingModel, MaslowianAgent, SimpleAgent}
import net.codingstuffs.abilene.simulation.decision_making.models.simplified.ArithmeticRoundup.{EgalitarianRoundup, SelfishRoundup, WeightedRoundup}
import net.codingstuffs.abilene.intake.parse.ConfigUtil._

import scala.concurrent.duration.FiniteDuration

Expand All @@ -20,55 +21,11 @@ object Abilene extends App {
import Member._

val config = ConfigFactory.load()

val extraIterations: Int = config.getInt("numberGroupsSimulated")
System.setProperty("hadoop.home.dir", "C:\\hadoop-2.8.0")
//!TODO: Refactor this plz future me thx


val studyModel = MaslowianAgent
val decisionModels: Seq[DecisionMakingModel] = {
config.getString("decisionModels").split(";")
.map({
case "SelfishRoundup" => SelfishRoundup
case "EgalitarianRoundup" => EgalitarianRoundup
case "WeightedRoundup" => SelfishRoundup
case sasScale: String if sasScale.startsWith("WeightedRoundup(") =>
WeightedRoundup(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(sasScale).get.split(",")(0).toDouble,
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(sasScale).get.split(",")(1).toDouble
)
})
}
val preferenceGenerators: Seq[Random] = {
config.getString("preferenceGenerators").split(";")
.map({
case "Uniform" => Uniform.GENERATOR
case discrete: String if discrete.startsWith("Discrete") =>
Discrete.GENERATOR("""(?<=\()(.*?)(?=\))""".r.findFirstIn(discrete).get.split(",").map(_.toDouble).toSeq)
case beta: String if beta.startsWith("Beta") =>
Beta.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(0).toDouble,
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(1).toDouble)
case gaussian: String if gaussian.startsWith("FoldedGaussian") =>
FoldedGaussian.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(gaussian).get.toDouble)
}).toSeq
}
val weightsGenerators: Seq[Random] = {
config.getString("preferenceGenerators").split(";")
.map({
case "Uniform" => Uniform.GENERATOR
case discrete: String if discrete.startsWith("Discrete") =>
Discrete.GENERATOR("""(?<=\()(.*?)(?=\))""".r.findFirstIn(discrete).get.split(",").map(_.toDouble).toSeq)
case beta: String if beta.startsWith("Beta") =>
Beta.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(0).toDouble,
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(beta).get.split(",")(0).toDouble)
case gaussian: String if gaussian.startsWith("FoldedGaussian") =>
FoldedGaussian.GENERATOR(
"""(?<=\()(.*?)(?=\))""".r.findFirstIn(gaussian).get.toDouble)
}).toSeq
}

val system: ActorSystem = ActorSystem("Abilene0")
val dataDumpGenerator = system.actorOf(DataAggregatorActor.props, "dataDumper")
Expand All @@ -85,16 +42,16 @@ object Abilene extends App {
group = system.actorOf(Group.props(groupMembers, dataDumpGenerator), s"$groupId---group")

father = system.actorOf(
Member.props(group, studyModel, decisionModels.head, (preferenceGenerators.head, weightsGenerators.head)),
Member.props(group, studyModel, DECISION_MODELS.head, (PREFERENCE_GENERATORS.head, WEIGHTS_GENERATORS.head)),
s"$groupId@@@father")
mother = system.actorOf(
Member.props(group, studyModel, decisionModels(1), (preferenceGenerators(1), weightsGenerators(1))),
Member.props(group, studyModel, DECISION_MODELS(1), (PREFERENCE_GENERATORS(1), WEIGHTS_GENERATORS(1))),
s"$groupId@@@mother")
wife = system.actorOf(
Member.props(group, studyModel, decisionModels(2), (preferenceGenerators(2), weightsGenerators(2))),
Member.props(group, studyModel, DECISION_MODELS(2), (PREFERENCE_GENERATORS(2), WEIGHTS_GENERATORS(2))),
s"$groupId@@@wife")
husband = system.actorOf(
Member.props(group, studyModel, decisionModels(3), (preferenceGenerators(3), weightsGenerators(3))),
Member.props(group, studyModel, DECISION_MODELS(3), (PREFERENCE_GENERATORS(3), WEIGHTS_GENERATORS(3))),
s"$groupId@@@husband")

father ? Declare
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.codingstuffs.abilene.simulation

import akka.actor.{Actor, ActorLogging, ActorRef, Props}
import net.codingstuffs.abilene.intake.mock.SocialBehavior
import net.codingstuffs.abilene.intake.parse.ConfigUtil._
import net.codingstuffs.abilene.simulation.Group.DataPoint
import net.codingstuffs.abilene.simulation.decision_making.calculators.DecisionCalculator
import net.codingstuffs.abilene.simulation.decision_making.generators.GroupParamGenerator
Expand Down Expand Up @@ -43,14 +43,15 @@ class Member(group: ActorRef,
agentParamGenerator.self = name
agentParamGenerator.memberNames = GroupParamGenerator.AbileneMembers

val initialParams = agentParamGenerator.get
val initialParams: DecisionParams = agentParamGenerator.get

implicit var params: DecisionParams = behaviorModel match {

case SimpleAgent => initialParams

case MaslowianAgent =>
val maslowianParams = new MaslowianParamGenerator(SocialBehavior.index_means_sd.map(
//!TODO : Move this to member param generation
val maslowianParams = new MaslowianParamGenerator(MASLOWIAN_MEAN_SD.map(
mapping => FoldedGaussian.GENERATOR(mapping._2._1, mapping._2._2).nextDouble
).toList)

Expand Down

0 comments on commit a40341a

Please sign in to comment.