diff --git a/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/logging/SimMongoLog.scala b/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/logging/SimMongoLog.scala index c6adb69841efc2ad35e5b4d92065acb17b516454..d1b577f5c641e7ab563e3b9b6905af7ce5b5c46c 100644 --- a/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/logging/SimMongoLog.scala +++ b/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/logging/SimMongoLog.scala @@ -18,7 +18,7 @@ import scala.collection.immutable /** * Hammouda Elbez * - * Fichier responsable sur la collection des informations sur la simulation et le stockage dans la base de données Mongo + * Class responsible for storing data in MongoDB * */ @@ -29,7 +29,7 @@ class SimMongoLog(n2s3 : N2S3,list : IndexedSeq[IndexedSeq[IndexedSeq[Connection * Setup DB connection & Collection * *****************************************************************************************************************/ - println("Connecting to database ") + println("Connecting to database") val USERNAME = "App" val PASSWORD = "timo" val HOST = "127.0.0.1:27017" @@ -109,14 +109,7 @@ class SimMongoLog(n2s3 : N2S3,list : IndexedSeq[IndexedSeq[IndexedSeq[Connection "QtInput" -> benchmark.getResult.quietInputCount, "NLabel" -> NeuronLabel)).subscribe(observer) - // adding Timestamps index to collections - - // PotentialCollection.createIndex(Indexes.ascending("T")) - // SpikesCollection.createIndex(Indexes.ascending("T")) - // SynapseWeightCollection.createIndex(Indexes.ascending("T")) - mongoClient.close() - // val restartMongo = "service mongod restart" ! } /** @@ -128,35 +121,19 @@ class SimMongoLog(n2s3 : N2S3,list : IndexedSeq[IndexedSeq[IndexedSeq[Connection InfoCollection = database.getCollection("info") InfoCollection.deleteMany(new BasicDBObject()) PotentialCollection = database.getCollection("potential") - //PotentialCollection.deleteMany(new BasicDBObject()) SpikesCollection = database.getCollection("spikes") - //SpikesCollection.deleteMany(new BasicDBObject()) LabelCollection = database.getCollection("labels") - //LabelCollection.deleteMany(new BasicDBObject()) SynapseWeightCollection = database.getCollection("synapseWeight") - //SynapseWeightCollection.deleteMany(new BasicDBObject()) var neuronsFireLogDocuments : List[Document] = List.empty var neuronsPotentialLogDocuments : List[Document] = List.empty var labelMonitoringDocuments : List[Document] = List.empty var synapticWeightMonitoringDocuments : List[Document] = List.empty - - - //*************************************** - - println("Starting Log") - //println("Layer name : " + n2s3.layers(0).identifier) - //println("Inputs : " + n2s3.layers(0).neurons.size) - /** ****************************************************************************************************************** * Architecture Save * *****************************************************************************************************************/ - // var Neuron_id: List[Int] = List[Int]() - - - //ArchiCollection.insertOne(Document("n" -> name,"i" -> n2s3.layers(0).neurons.size)).subscribe(observer) var layerNeron : Map[String,Int] = Map() n2s3.layers.foreach(layer => { layerNeron += (layer.identifier -> layer.neurons.size) @@ -257,7 +234,7 @@ class NeuronsFireLog(name : String,mongoCollection: MongoCollection[Document], o time = (System.currentTimeMillis() - globalTimestamps) * 1000 if(i < step){ documents = documents.::(Document("i" -> Document("L" -> path.actor.path.name.split(":")(0), - "N" -> BsonInt32.apply(Integer.valueOf(path.actor.path.name.split(":")(1)))),"T" -> time,"Input" -> GlobalLogVars.ActualInput)) + "N" -> BsonInt32.apply(Integer.valueOf(path.actor.path.name.split(":")(1)))),"T" -> BsonDouble.apply(BigDecimal(time/1000000).setScale(6, BigDecimal.RoundingMode.HALF_UP).toDouble),"Input" -> GlobalLogVars.ActualInput)) // ,"tt" -> BsonDouble(step*i) i = i + 1 }else{ @@ -292,11 +269,9 @@ class NeuronsPotentialLog(name : String,mongoCollection: MongoCollection[Documen override def process(message: Message, sender: ActorRef): Unit = message match { case NeuronPotentialResponse(timestamp, source, value) => if (((System.currentTimeMillis() - globalTimestamps) * 1000) - time > 250){ - time = (System.currentTimeMillis() - globalTimestamps) /1000 - documents = documents.::(Document("T" -> time,"L" -> source.actor.path.name.split(":")(0), - "N" -> BsonInt32(Integer.valueOf(source.actor.path.name.split(":")(1))), "V" -> + time = (System.currentTimeMillis() - globalTimestamps) * 1000 + documents = documents.::(Document("T" -> BsonDouble.apply(BigDecimal(time/1000000).setScale(6, BigDecimal.RoundingMode.HALF_UP).toDouble),"L" -> source.actor.path.name.split(":")(0), "N" -> BsonInt32(Integer.valueOf(source.actor.path.name.split(":")(1))), "V" -> BsonDouble.apply(BigDecimal(value).setScale(6, BigDecimal.RoundingMode.HALF_UP).toDouble))) - // "_id" -> id, i = i + 1 if(i > 10000){ @@ -316,7 +291,7 @@ class NeuronsPotentialLog(name : String,mongoCollection: MongoCollection[Documen } /** ****************************************************************************************************************** - * Label changement Logger for supervised learning + * Label changement Logger for labeled datasets * *****************************************************************************************************************/ class LabelMonitoring(n2s3 : N2S3, outputNeuron : Seq[NeuronGroupRef],mongoCollection: MongoCollection[Document],observer: Observer[Completed], globalTimestamps:Timestamp) extends Actor { @@ -340,7 +315,7 @@ class LabelMonitoring(n2s3 : N2S3, outputNeuron : Seq[NeuronGroupRef],mongoColle time = (System.currentTimeMillis() - globalTimestamps) /1000 GlobalLogVars.ActualInput = label GlobalLogVars.globalInput = GlobalLogVars.globalInput + 1 - documents = documents.::(Document("L" -> BsonInt32(Integer.valueOf(label)),"T" ->time,"G" -> GlobalLogVars.globalInput)) + documents = documents.::(Document("L" -> BsonInt32(Integer.valueOf(label)),"T" ->BsonDouble.apply(BigDecimal(time).setScale(6, BigDecimal.RoundingMode.HALF_UP).toDouble),"G" -> GlobalLogVars.globalInput)) i = i + 1 @@ -363,8 +338,6 @@ class SynapticWeightMonitoring(list : IndexedSeq[IndexedSeq[IndexedSeq[Connectio override def deploy(n2s3: N2S3): Unit = { this.actor = Some(n2s3.system.actorOf(Props(new SynapticWeight(list, refreshRate, name,mongoCollection,observer,step,globalTimestamps,SynapseIndex)), LocalActorDeploymentStrategy)) - // this.actor = Some(n2s3.system.actorOf(Props(new ActivityStoreActor(n2s3)), LocalActorDeploymentStrategy)) - } } @@ -385,9 +358,7 @@ class SynapticWeight(list : Seq[Seq[Seq[ConnectionPath]]], refreshRate : Int = 1 var filteredconnectionList : Seq[(Int,Int,ConnectionPath)] = Seq.empty def update(): Unit = { - // println(synapseList) values = synapseList.flatMap { case (neuron, connectionList) => - // println(neuron.actor.path.name) if (connectionList.size == 1) { Some((connectionList.head._1, connectionList.head._2, ExternalConnectionSender.askTo(connectionList.head._3, GetConnectionProperty(SynapticWeightFloat)) .asInstanceOf[PropertyValue[Float]].value,neuron)) @@ -407,8 +378,6 @@ class SynapticWeight(list : Seq[Seq[Seq[ConnectionPath]]], refreshRate : Int = 1 filteredconnectionList.map{ case (x, y, p) => (p.connectionID, p.outputNeuron.actor.path.name.split(":")(1).toInt, values(p.connectionID).head._3,p.outputNeuron)} } } - // values.foreach( x => println(s"From : ${x._1} , To : ${x._2} , Value : ",f"${x._3}%1.6f")) - // if (i < 5) { if(valuesTmp.isEmpty){ valuesTmp = values }else{ @@ -426,18 +395,14 @@ class SynapticWeight(list : Seq[Seq[Seq[ConnectionPath]]], refreshRate : Int = 1 } }) - documents = documents.::(Document("T" -> (System.currentTimeMillis() - globalTimestamps) / 1000 , "C" -> v._1,"L" -> v._4.actor.path.name.split(":")(0), "To" -> v._2, "V" -> BsonDouble.apply(BigDecimal(v._3).setScale(6, BigDecimal.RoundingMode.HALF_UP).toDouble),"index" -> Document("x" -> y, "y" -> x)))}) + documents = documents.::(Document("T" ->BsonDouble.apply(BigDecimal((System.currentTimeMillis() - globalTimestamps) / 1000).setScale(6, BigDecimal.RoundingMode.HALF_UP).toDouble) , "C" -> v._1,"L" -> v._4.actor.path.name.split(":")(0), "To" -> v._2, "V" -> BsonDouble.apply(BigDecimal(v._3).setScale(6, BigDecimal.RoundingMode.HALF_UP).toDouble),"index" -> Document("x" -> y, "y" -> x)))}) valuesTmp = values values = List.empty - // i = i + 1 - // } else { if(documents.nonEmpty){ mongoCollection.insertMany(documents).subscribe(observer) - // i = 0 documents = List.empty} - // } } } @@ -466,8 +431,6 @@ class ActivityStoreActor(n2s3 : N2S3) extends NetworkActor { var currentTimestamp : Timestamp = -1L var eventCount : Long = 0 - - override def initialize(): Unit = { askTo(n2s3.inputLayerRef.get.getContainer, SubscribeSynchronized(SynapseWeightChange, ExternalSender.getReference(self), n2s3.buildProperties.getSynchronizerPolicy.getInputSynchronizer))