<commit_before>package neurgo

import (
	"math"
	"math/rand"
)

type StochasticHillClimber struct {
	currentCandidate *NeuralNetwork
	currentOptimal   *NeuralNetwork
}

func (shc *StochasticHillClimber) Train(neuralNet *NeuralNetwork, examples []*TrainingSample) *NeuralNetwork {

	fittestNeuralNet := neuralNet

	// Apply NN to problem and save fitness
	fitness := fittestNeuralNet.Fitness(examples)

	if fitness > FITNESS_THRESHOLD {
		return fittestNeuralNet
	}

	for {

		// Save the genotype
		candidateNeuralNet := fittestNeuralNet.Copy()
		candidateNeuralNet.Run()

		// Perturb synaptic weights and biases
		shc.perturbParameters(candidateNeuralNet)

		// Re-Apply NN to problem
		candidateFitness := candidateNeuralNet.Fitness(examples)

		// If the fitness of the perturbed NN is higher, discard original NN and keep
		// the new.  If the fitness of original is higher, discard perturbed and keep
		// the old.
		if candidateFitness > fitness {
			fittestNeuralNet = candidateNeuralNet
			fitness = candidateFitness
		}

		if candidateFitness > FITNESS_THRESHOLD {
			break
		}
<commit_msg>in stochastic hill climber, shutdown networks after done with them<commit_after>package neurgo

import (
	"math"
	"math/rand"
)

type StochasticHillClimber struct {
	currentCandidate *NeuralNetwork
	currentOptimal   *NeuralNetwork
}

func (shc *StochasticHillClimber) Train(neuralNet *NeuralNetwork, examples []*TrainingSample) *NeuralNetwork {

	fittestNeuralNet := neuralNet

	// Apply NN to problem and save fitness
	fitness := fittestNeuralNet.Fitness(examples)

	if fitness > FITNESS_THRESHOLD {
		return fittestNeuralNet
	}

	for {

		// Save the genotype
		candidateNeuralNet := fittestNeuralNet.Copy()
		candidateNeuralNet.Run()

		// Perturb synaptic weights and biases
		shc.perturbParameters(candidateNeuralNet)

		// Re-Apply NN to problem
		candidateFitness := candidateNeuralNet.Fitness(examples)

		// If the fitness of the perturbed NN is higher, discard original NN and keep
		// the new.  If the fitness of original is higher, discard perturbed and keep
		// the old.
		if candidateFitness > fitness {
			fittestNeuralNet.Shutdown()
			fittestNeuralNet = candidateNeuralNet
			fitness = candidateFitness
		} else {
			candidateNeuralNet.Shutdown()
		}

		if candidateFitness > FITNESS_THRESHOLD {
			break
		}

{'fraction_non_alphanumeric': 0.07259450171821306, 'fraction_numerical': 0.0, 'mean_word_length': 4.233707865168539, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4410205', 'n_tokens_mistral': 823, 'n_tokens_neox': 714, 'n_words': 202}