From a40341a295942a518627c167ce46df3ae7669080 Mon Sep 17 00:00:00 2001 From: IDoCodingStuffs Date: Sun, 7 Jul 2019 17:57:32 -0400 Subject: [PATCH] Moved Maslowian param distribution specs to config utils --- conf/application.conf | 5 +- .../abilene/intake/mock/SocialBehavior.scala | 12 ---- .../abilene/intake/parse/ConfigUtil.scala | 69 +++++++++++++++++++ .../abilene/simulation/Abilene.scala | 55 ++------------- .../abilene/simulation/Member.scala | 7 +- 5 files changed, 83 insertions(+), 65 deletions(-) delete mode 100644 src/main/scala/net/codingstuffs/abilene/intake/mock/SocialBehavior.scala create mode 100644 src/main/scala/net/codingstuffs/abilene/intake/parse/ConfigUtil.scala diff --git a/conf/application.conf b/conf/application.conf index 07d1c2d..ae5ba0b 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -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)" \ No newline at end of file +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" \ No newline at end of file diff --git a/src/main/scala/net/codingstuffs/abilene/intake/mock/SocialBehavior.scala b/src/main/scala/net/codingstuffs/abilene/intake/mock/SocialBehavior.scala deleted file mode 100644 index aa76a3a..0000000 --- a/src/main/scala/net/codingstuffs/abilene/intake/mock/SocialBehavior.scala +++ /dev/null @@ -1,12 +0,0 @@ -package net.codingstuffs.abilene.intake.mock - -object SocialBehavior { - val index_means_sd: Map[String, (Double, Double)] = Map( - "physio" -> (0, 0.2), - "safety" -> (0, 0.2), - "affiliation" -> (0, 0.2), - "mate_acquisition" -> (0, 0.2), - "mate_retention" -> (0, 0.2), - "parenting" -> (0, 0.2) - ) -} diff --git a/src/main/scala/net/codingstuffs/abilene/intake/parse/ConfigUtil.scala b/src/main/scala/net/codingstuffs/abilene/intake/parse/ConfigUtil.scala new file mode 100644 index 0000000..709e81e --- /dev/null +++ b/src/main/scala/net/codingstuffs/abilene/intake/parse/ConfigUtil.scala @@ -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 + } +} diff --git a/src/main/scala/net/codingstuffs/abilene/simulation/Abilene.scala b/src/main/scala/net/codingstuffs/abilene/simulation/Abilene.scala index 30c4a60..f79dc3d 100644 --- a/src/main/scala/net/codingstuffs/abilene/simulation/Abilene.scala +++ b/src/main/scala/net/codingstuffs/abilene/simulation/Abilene.scala @@ -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 @@ -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") @@ -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 diff --git a/src/main/scala/net/codingstuffs/abilene/simulation/Member.scala b/src/main/scala/net/codingstuffs/abilene/simulation/Member.scala index dbf8e6d..7be7cbf 100644 --- a/src/main/scala/net/codingstuffs/abilene/simulation/Member.scala +++ b/src/main/scala/net/codingstuffs/abilene/simulation/Member.scala @@ -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 @@ -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)