Skip to content

Commit

Permalink
Merge pull request #169 from hmcalister/Fix-copying-of-energy-history
Browse files Browse the repository at this point in the history
Fix bug where energy profile was not correctly copied to history array
  • Loading branch information
hmcalister authored May 3, 2023
2 parents 521ddf3 + ce09c03 commit 808d750
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hopfieldnetwork/HopfieldNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (network *HopfieldNetwork) RelaxState(state *mat.VecDense) *RelaxationResul
// Only collect data on histories if allowed, as otherwise very intensive
if network.allowIntensiveDataCollection {
stateHistory[0] = mat.VecDenseCopyOf(state)
copy(energyHistory[0], network.AllUnitEnergies(state))
energyHistory[0] = network.AllUnitEnergies(state)
}

// We will loop up to the maximum number of iterations, only returning early if the state is stable
Expand All @@ -326,7 +326,7 @@ func (network *HopfieldNetwork) RelaxState(state *mat.VecDense) *RelaxationResul
// Collect the current history item if requested
if network.allowIntensiveDataCollection || network.StateIsStable(state) {
stateHistory[stepIndex] = mat.VecDenseCopyOf(state)
copy(energyHistory[stepIndex], network.AllUnitEnergies(state))
energyHistory[stepIndex] = network.AllUnitEnergies(state)
}

// Here we check the unit energies, counting how many unstable units there are (E>0)
Expand Down Expand Up @@ -387,7 +387,7 @@ StateRecvLoop:
// Only collect data on histories if allowed, as otherwise very intensive
if network.allowIntensiveDataCollection {
stateHistory[0] = mat.VecDenseCopyOf(state)
copy(energyHistory[0], network.AllUnitEnergies(state))
energyHistory[0] = network.AllUnitEnergies(state)
}

for stepIndex := 1; stepIndex <= network.maximumRelaxationIterations; stepIndex++ {
Expand Down

0 comments on commit 808d750

Please sign in to comment.