From ac60a6c815e4e011fdba0b0aaefbb9af21ec6b0a Mon Sep 17 00:00:00 2001 From: Iaroslav Omelianenko Date: Thu, 23 Jun 2022 18:09:10 +0300 Subject: [PATCH] Fixed bug when `FastModularNetworkSolver` returned outputs as slice of internal signals array. Thus, it made it possible to change solver state by modifying values in the returned slice. --- neat/network/fast_network.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/neat/network/fast_network.go b/neat/network/fast_network.go index 0bebe1c..ed809c5 100644 --- a/neat/network/fast_network.go +++ b/neat/network/fast_network.go @@ -331,7 +331,10 @@ func (s *FastModularNetworkSolver) LoadSensors(inputs []float64) error { // ReadOutputs Read output values from the output nodes of the network func (s *FastModularNetworkSolver) ReadOutputs() []float64 { - return s.neuronSignals[s.sensorNeuronCount : s.sensorNeuronCount+s.outputNeuronCount] + // decouple and return + outs := make([]float64, s.outputNeuronCount) + copy(outs, s.neuronSignals[s.sensorNeuronCount:s.sensorNeuronCount+s.outputNeuronCount]) + return outs } // NodeCount Returns the total number of neural units in the network