Skip to content
Snippets Groups Projects
Commit 8959d2cf authored by Hammouda Elbez's avatar Hammouda Elbez :computer:
Browse files

Log class updated

parent c48a84d5
Branches
No related tags found
No related merge requests found
...@@ -211,7 +211,8 @@ class NeuronsFireLog(name : String,mongoCollection: MongoCollection[Document], o ...@@ -211,7 +211,8 @@ class NeuronsFireLog(name : String,mongoCollection: MongoCollection[Document], o
} }
override def destroy(): Unit = { override def destroy(): Unit = {
mongoCollection.insertMany(documents).subscribe(observer) if (documents != List.empty){
mongoCollection.insertMany(documents).subscribe(observer)}
} }
} }
...@@ -249,7 +250,8 @@ class NeuronsPotentialLog(name : String,mongoCollection: MongoCollection[Documen ...@@ -249,7 +250,8 @@ class NeuronsPotentialLog(name : String,mongoCollection: MongoCollection[Documen
} }
override def destroy(): Unit = { override def destroy(): Unit = {
mongoCollection.insertMany(documents).subscribe(observer) if (documents != List.empty){
mongoCollection.insertMany(documents).subscribe(observer)}
} }
} }
...@@ -295,7 +297,8 @@ class LabelMonitoring(n2s3 : N2S3, outputNeuron : Seq[NeuronGroupRef],mongoColle ...@@ -295,7 +297,8 @@ class LabelMonitoring(n2s3 : N2S3, outputNeuron : Seq[NeuronGroupRef],mongoColle
} }
def destroy(): Unit = { def destroy(): Unit = {
mongoCollection.insertMany(documents).subscribe(observer) if (documents != List.empty){
mongoCollection.insertMany(documents).subscribe(observer)}
} }
} }
...@@ -402,7 +405,8 @@ class SynapticWeight(list : Seq[Seq[Seq[ConnectionPath]]], refreshRate : Int = 1 ...@@ -402,7 +405,8 @@ class SynapticWeight(list : Seq[Seq[Seq[ConnectionPath]]], refreshRate : Int = 1
} }
override def destroy(): Unit = { override def destroy(): Unit = {
mongoCollection.insertMany(documents).subscribe(observer) if (documents != List.empty){
mongoCollection.insertMany(documents).subscribe(observer)}
} }
override def process(message: Message, sender : ActorRef): Unit = { override def process(message: Message, sender : ActorRef): Unit = {
......
...@@ -59,8 +59,8 @@ object ExampleMnist2 extends App { ...@@ -59,8 +59,8 @@ object ExampleMnist2 extends App {
var logger: SimMongoLog = null var logger: SimMongoLog = null
var log = true var log = true
var prune = false var prune = false
var globalIteration = 6 var globalIteration = 1
var sizeChunk = 10000 var sizeChunk = 60000
for(x <- 1 to 1) { for(x <- 1 to 1) {
implicit val timeout = Config.longTimeout implicit val timeout = Config.longTimeout
...@@ -102,14 +102,20 @@ object ExampleMnist2 extends App { ...@@ -102,14 +102,20 @@ object ExampleMnist2 extends App {
var stream: MnistFileInputStreamP = null var stream: MnistFileInputStreamP = null
//inputStream.append(stream) //inputStream.append(stream)
val unsupervisedLayer = n2s3.createNeuronGroup() val unsupervisedLayer1 = n2s3.createNeuronGroup()
.setIdentifier("Layer1") .setIdentifier("Layer1")
.setNumberOfNeurons(20) .setNumberOfNeurons(20)
.setNeuronModel(LIF, Seq( .setNeuronModel(LIF, Seq(
(MembranePotentialThreshold, 35 millivolts))) (MembranePotentialThreshold, 35 millivolts)))
inputLayer.connectTo(unsupervisedLayer, new FullConnection(() => new SimplifiedSTDP())) val unsupervisedLayer2 = n2s3.createNeuronGroup()
unsupervisedLayer.connectTo(unsupervisedLayer, new FullConnection(() => new InhibitorySynapse())) .setIdentifier("Layer2")
.setNumberOfNeurons(10)
.setNeuronModel(LIF, Seq(
(MembranePotentialThreshold, 35 millivolts)))
inputLayer.connectTo(unsupervisedLayer1, new FullConnection(() => new SimplifiedSTDP()))
var Layer1WTAconnection = unsupervisedLayer1.connectTo(unsupervisedLayer1, new FullConnection(() => new InhibitorySynapse()))
n2s3.create() n2s3.create()
...@@ -117,34 +123,23 @@ object ExampleMnist2 extends App { ...@@ -117,34 +123,23 @@ object ExampleMnist2 extends App {
inputLayer.neurons.toList.foreach(n => { inputLayer.neurons.toList.foreach(n => {
CTotal += n.group.connections.length CTotal += n.group.connections.length
}) })
CTotal = CTotal * unsupervisedLayer.neurons.size CTotal = CTotal * unsupervisedLayer1.neurons.size
CRmaining = CTotal CRmaining = CTotal
//showHeatMap(inputLayer,unsupervisedLayer) //showHeatMap(inputLayer,unsupervisedLayer1)
SynapsesIndex(inputLayer, unsupervisedLayer) SynapsesIndexInput(inputLayer, unsupervisedLayer1)
SimTime = formatter.format(new Date()) SimTime = formatter.format(new Date())
folderName = SimName.split("-")(0) + " [" + x + "] " + SimTime folderName = SimName.split("-")(0) + " [" + x + "] " + SimTime
new File(folderName).mkdir() new File(folderName).mkdir()
//println("Start loading "+System.currentTimeMillis())
//NetworkLoading.from(n2s3,"1600N/1600N-1 Arch 6 cropped")
//println("Done loading "+System.currentTimeMillis())
//NetworkLoading.fromWithDefaultWeights(n2s3,"100N [1] 03-02-2020 23:50:43/100N-1 Archce
// 6 cropped","100N [1] 03-02-2020 23:50:43/100N-1 Arch 6 cropped",loadRandomWeights = false,binary = false)
saveCroppedSynapses(unsupervisedLayer, "Initial")
NetworkSaving.save(n2s3, croppedCnx, SynapseIndex, folderName + "/" + SimName + " Arch")
// ImageSynapsesWeight.save(unsupervisedLayer.neurons.map(n => (n.getNetworkAddress, 128, 128)), 4, 1, "freeway.layer1.png") var inputToClassifierIndex = new ConnectionIndex(inputLayer, unsupervisedLayer1)
var listOfConnexions = for (outputIndex <- 0 until unsupervisedLayer1.shape.getNumberOfPoints) yield {
//
val inputToClassifierIndex = new ConnectionIndex(inputLayer, unsupervisedLayer)
var listOfConnexions = for (outputIndex <- 0 until unsupervisedLayer.shape.getNumberOfPoints) yield {
for (inputX <- 0 until InputMnist.shape.dimensions(0)) yield { for (inputX <- 0 until InputMnist.shape.dimensions(0)) yield {
for { for {
inputY <- 0 until InputMnist.shape.dimensions(1) inputY <- 0 until InputMnist.shape.dimensions(1)
input = inputLayer.getNeuronPathAt(inputX, inputY) input = inputLayer.getNeuronPathAt(inputX, inputY)
output = unsupervisedLayer.getNeuronPathAt(outputIndex) output = unsupervisedLayer1.getNeuronPathAt(outputIndex)
if inputToClassifierIndex.getConnectionsBetween(input, output).nonEmpty if inputToClassifierIndex.getConnectionsBetween(input, output).nonEmpty
} yield inputToClassifierIndex.getConnectionsBetween(input, output).head } yield inputToClassifierIndex.getConnectionsBetween(input, output).head
} }
...@@ -154,58 +149,63 @@ object ExampleMnist2 extends App { ...@@ -154,58 +149,63 @@ object ExampleMnist2 extends App {
val labelTestFile = N2S3ResourceManager.getByName("mnist-test-labels").getAbsolutePath val labelTestFile = N2S3ResourceManager.getByName("mnist-test-labels").getAbsolutePath
while (iteration <= globalIteration) {
simTime = "" simTime = ""
unsupervisedLayer.unfixNeurons() // L1
n2s3.first = false unsupervisedLayer1.unfixNeurons()
stream = InputMnist.DataParts(dataFile, labelFile, sizeChunk*(iteration-1), sizeChunk) stream = InputMnist.DataParts(dataFile, labelFile, sizeChunk, sizeChunk)
inputStream.append(stream) inputStream.append(stream)
stream.goto()
println("Start Training ... " + "[" + iteration + "]")
if (iteration == 1 && log) { println("Start Training L1")
if (log) {
logger = new SimMongoLog(n2s3, listOfConnexions, SimName.split("-")(0), true, true, true, true, "MNIST", SimTime, SynapseIndex) logger = new SimMongoLog(n2s3, listOfConnexions, SimName.split("-")(0), true, true, true, true, "MNIST", SimTime, SynapseIndex)
} }
duration = System.currentTimeMillis() duration = System.currentTimeMillis()
simTime = "Train " + iteration simTime = "Train L1"
n2s3.runAndWait() n2s3.runAndWait()
println(System.currentTimeMillis() - duration) println(System.currentTimeMillis() - duration)
simTime = simTime + " | " + (System.currentTimeMillis() - duration) + "\n" simTime = simTime + " | " + (System.currentTimeMillis() - duration) + "\n"
if (iteration == globalIteration && log) { if (log) {
logger.storeSimInfoAndDestroy() logger.storeSimInfoAndDestroy()
} }
//println("saving : " + System.currentTimeMillis()) // L2
//NetworkSaving.save(n2s3, croppedCnx, SynapseIndex, folderName + "/" + SimName + " Arch " + iteration) unsupervisedLayer1.fixNeurons()
//println("end : " + System.currentTimeMillis()) Layer1WTAconnection.disconnect()
//println("saving cropped : " + System.currentTimeMillis())
//saveCroppedSynapses(unsupervisedLayer, "[" + iteration + "]")
//println("end : " + System.currentTimeMillis())
/*
inputStream.append(InputMnist.DataFrom(dataTestFile, labelTestFile))
println("Start Testing " + "[" + iteration + "]") unsupervisedLayer1.connectTo(unsupervisedLayer2, new FullConnection(() => new SimplifiedSTDP()))
var Layer2WTAconnection = unsupervisedLayer2.connectTo(unsupervisedLayer2, new FullConnection(() => new InhibitorySynapse()))
n2s3.first = false
stream = InputMnist.DataParts(dataFile, labelFile, sizeChunk, sizeChunk)
inputStream.append(stream)
unsupervisedLayer.fixNeurons() println("Start Training L2")
n2s3.first = false var layerTolayerIndex = new ConnectionIndex(unsupervisedLayer1, unsupervisedLayer2)
var listOfConnexions2 = for (outputIndex <- 0 until unsupervisedLayer2.shape.getNumberOfPoints) yield {
for (_ <- 0 until 1) yield {
for {
inputIndex <- 0 until unsupervisedLayer1.shape.getNumberOfPoints
input = unsupervisedLayer1.getNeuronPathAt(inputIndex)
output = unsupervisedLayer2.getNeuronPathAt(outputIndex)
if layerTolayerIndex.getConnectionsBetween(input, output).nonEmpty
} yield layerTolayerIndex.getConnectionsBetween(input, output).head
}}
benchmarkMonitor = n2s3.createBenchmarkMonitor(unsupervisedLayer) SynapsesIndex(unsupervisedLayer1, unsupervisedLayer2)
if (log) {
logger = new SimMongoLog(n2s3, listOfConnexions2, SimName.split("-")(0), true, true, true, true, "MNIST", SimTime, SynapseIndex)
}
duration = System.currentTimeMillis() duration = System.currentTimeMillis()
simTime = simTime + "Test " + iteration + "\n" + duration simTime = "Train L2"
n2s3.runAndWait() n2s3.runAndWait()
println(System.currentTimeMillis() - duration)
simTime = simTime + " | " + (System.currentTimeMillis() - duration) + "\n" simTime = simTime + " | " + (System.currentTimeMillis() - duration) + "\n"
benchmarkMonitor.exportToHtmlView(folderName + "/" + "test " + SimName + " [" + iteration + "]" + ".html")
benchmarkMonitor.saveCrops(folderName + "/" + "Sim " + SimName + " info a:" + alpha + " no b:" + beta, simTime, " Ratio " + Ratio)
*/
if (prune) { if (prune) {
Ratio = Ratio + (alpha * (CRmaining / CTotal)) Ratio = Ratio + (alpha * (CRmaining / CTotal))
println("Ratio " + Ratio) println("Ratio " + Ratio)
...@@ -215,12 +215,12 @@ object ExampleMnist2 extends App { ...@@ -215,12 +215,12 @@ object ExampleMnist2 extends App {
// cropInput(n2s3.inputLayerRef.get, Ratio) // cropInput(n2s3.inputLayerRef.get, Ratio)
} }
if (iteration == globalIteration) { // Testing
inputStream.append(InputMnist.DataFrom(dataTestFile, labelTestFile)) inputStream.append(InputMnist.DataFrom(dataTestFile, labelTestFile))
println("Start Testing cropped " + "[" + iteration + "]" + " with " + Ratio) println("Start Testing cropped " + "[" + iteration + "]" + " with " + Ratio)
benchmarkMonitor = n2s3.createBenchmarkMonitor(unsupervisedLayer) benchmarkMonitor = n2s3.createBenchmarkMonitor(unsupervisedLayer1)
duration = System.currentTimeMillis() duration = System.currentTimeMillis()
simTime = simTime + "Test cropped " + iteration simTime = simTime + "Test cropped " + iteration
...@@ -231,17 +231,16 @@ object ExampleMnist2 extends App { ...@@ -231,17 +231,16 @@ object ExampleMnist2 extends App {
simTime = simTime + " | " + (System.currentTimeMillis() - duration) + "\n" simTime = simTime + " | " + (System.currentTimeMillis() - duration) + "\n"
saveCroppedSynapses(unsupervisedLayer, "cropped " + "[" + iteration + "]" + " with " + Ratio) //saveCroppedSynapses(unsupervisedLayer1, "cropped " + "[" + iteration + "]" + " with " + Ratio)
NetworkSaving.save(n2s3, croppedCnx, SynapseIndex, folderName + "/" + SimName + " Arch " + iteration + " cropped") //NetworkSaving.save(n2s3, croppedCnx, SynapseIndex, folderName + "/" + SimName + " Arch " + iteration + " cropped")
benchmarkMonitor.exportToHtmlView(folderName + "/" + "test cropped " + SimName + " [" + iteration + "]" + ".html") benchmarkMonitor.exportToHtmlView(folderName + "/" + "test cropped " + SimName + " [" + iteration + "]" + ".html")
benchmarkMonitor.saveCrops(folderName + "/" + "Sim " + SimName + " info a:" + alpha + " b:" + beta, simTime, CropInfo + " Ratio " + Ratio) //benchmarkMonitor.saveCrops(folderName + "/" + "Sim " + SimName + " info a:" + alpha + " b:" + beta, simTime, CropInfo + " Ratio " + Ratio)
}
if (iteration == globalIteration && log) { if (log) {
logger.storeBenchmarkTestInfo(benchmarkMonitor) logger.storeBenchmarkTestInfo(benchmarkMonitor)
} logger.storeSimInfoAndDestroy()
iteration += 1
} }
} }
//logger.destroy() //logger.destroy()
...@@ -288,7 +287,7 @@ object ExampleMnist2 extends App { ...@@ -288,7 +287,7 @@ object ExampleMnist2 extends App {
}) })
} }
def SynapsesIndex(inputL: InputNeuronGroupRef,layer : NeuronGroupRef): Unit = { def SynapsesIndexInput(inputL: InputNeuronGroupRef,layer : NeuronGroupRef): Unit = {
val inputToClassifierIndex = new ConnectionIndex(inputL, layer) val inputToClassifierIndex = new ConnectionIndex(inputL, layer)
var listOfConnexions = for(outputIndex <- 0 until layer.shape.getNumberOfPoints) yield { var listOfConnexions = for(outputIndex <- 0 until layer.shape.getNumberOfPoints) yield {
...@@ -317,6 +316,38 @@ object ExampleMnist2 extends App { ...@@ -317,6 +316,38 @@ object ExampleMnist2 extends App {
SynapseIndex = SynapseIndex.reverse SynapseIndex = SynapseIndex.reverse
} }
def SynapsesIndex(layer1: NeuronGroupRef,layer2 : NeuronGroupRef): Unit = {
val layerTolayerIndex = new ConnectionIndex(layer1, layer2)
var listOfConnexions = for (outputIndex <- 0 until layer2.shape.getNumberOfPoints) yield {
for (_ <- 0 until 1) yield {
for {
inputIndex <- 0 until layer1.shape.getNumberOfPoints
input = layer1.getNeuronPathAt(inputIndex)
output = layer2.getNeuronPathAt(outputIndex)
if layerTolayerIndex.getConnectionsBetween(input, output).nonEmpty
} yield layerTolayerIndex.getConnectionsBetween(input, output).head
}}
var x = -1
var y = 0
SynapseIndex = List[(Integer,Integer,Integer)]()
listOfConnexions.head.foreach(
cnx => {
cnx.toList.foreach(c => {
x+=1
SynapseIndex = SynapseIndex.::(c.connectionID,x,y)
})
y+=1
x = -1
}
)
SynapseIndex = SynapseIndex.reverse
}
def saveCroppedSynapses(layer : NeuronGroupRef,name : String): Unit ={ def saveCroppedSynapses(layer : NeuronGroupRef,name : String): Unit ={
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment