<commit_before>package main

import (
	"os"
	"time"
	"fmt"
	"math/rand"
	"github.com/yaricom/goNEAT/experiments"
	"github.com/yaricom/goNEAT/neat"
	"github.com/yaricom/goNEAT/neat/genetics"
	"log"
	"flag"
)

// The XOR experiment runner
func main() {
	var out_dir_path = flag.String("out", "./out", "The output directory to store results")
	var context_path = flag.String("context", "./data/xor.neat", "The execution context configuration file")
	var genome_path = flag.String("genome", "./data/xorstartgenes", "The seed genome to start with")

	flag.Parse()

	// Seed the random-number generator with current time so that
	// the numbers will be different every time we run.
	rand.Seed(time.Now().Unix())

	// Load context configuration
	configFile, err := os.Open(*context_path)
	if err != nil {
		log.Fatal("Failed to open context configuration file: ", err)
	}
	context := neat.LoadContext(configFile)

	// Load Genome
	log.Println("Loading start genome for XOR experiment")
	genomeFile, err := os.Open(*genome_path)
	if err != nil {
		log.Fatal("Failed to open genome file: ", err)
	}
	start_genome, err := genetics.ReadGenome(genomeFile, 1)
	if err != nil {
		log.Fatal("Failed to read start genome: ", err)
	}
	fmt.Println(start_genome)

	// Check if output dir exists
	if _, err := os.Stat(*out_dir_path); err == nil {
		// clear it
		os.RemoveAll(*out_dir_path)
	}
	// create output dir
	err = os.MkdirAll(*out_dir_path, os.ModePerm)
	if err != nil {
		log.Fatal("Failed to create output directory: ", err)
	}

	// The 100 generation XOR experiment
	nodes, genes, evals, err := experiments.XOR(context, start_genome, *out_dir_path)
	if err != nil {
		log.Fatal("Failed to perform XOR experiment: ", err)
	}

	// Average and print stats
	fmt.Print("\nNodes: ")
	total_nodes := 0
	for exp_count := 0; exp_count < context.NumRuns; exp_count++ {
		fmt.Printf("\t%d", nodes[exp_count])
		total_nodes += nodes[exp_count]
	}

	fmt.Print("\nGenes: ")
	total_genes := 0
	for exp_count := 0; exp_count < context.NumRuns; exp_count++ {
		fmt.Printf("\t%d", genes[exp_count])
		total_genes += genes[exp_count]
	}

	fmt.Print("\nEvals: ")
	total_evals := 0
	for exp_count := 0; exp_count < context.NumRuns; exp_count++ {
		fmt.Printf("\t%d", evals[exp_count])
		total_evals += evals[exp_count]
	}

	fmt.Printf("\n>>>>>\nAverage Nodes:\t%d\nAverage Genes:\t%d\nAverage Evals:\t%d\n",
		total_nodes / context.NumRuns, total_genes / context.NumRuns, total_evals / context.NumRuns)

	fmt.Printf(">>> Start genome file:  %s\n", *genome_path)
	fmt.Printf(">>> Configuration file: %s\n", *context_path)
}<commit_msg>Applied advanced statistics holder to display experiment results<commit_after>package main

import (
	"os"
	"time"
	"fmt"
	"math/rand"
	"github.com/yaricom/goNEAT/experiments"
	"github.com/yaricom/goNEAT/neat"
	"github.com/yaricom/goNEAT/neat/genetics"
	"log"
	"flag"
	"github.com/yaricom/goNEAT/experiments/xor"
)

// The XOR experiment runner
func main() {
	var out_dir_path = flag.String("out", "./out", "The output directory to store results")
	var context_path = flag.String("context", "./data/xor.neat", "The execution context configuration file")
	var genome_path = flag.String("genome", "./data/xorstartgenes", "The seed genome to start with")

	flag.Parse()

	// Seed the random-number generator with current time so that
	// the numbers will be different every time we run.
	rand.Seed(time.Now().Unix())

	// Load context configuration
	configFile, err := os.Open(*context_path)
	if err != nil {
		log.Fatal("Failed to open context configuration file: ", err)
	}
	context := neat.LoadContext(configFile)

	// Load Genome
	log.Println("Loading start genome for XOR experiment")
	genomeFile, err := os.Open(*genome_path)
	if err != nil {
		log.Fatal("Failed to open genome file: ", err)
	}
	start_genome, err := genetics.ReadGenome(genomeFile, 1)
	if err != nil {
		log.Fatal("Failed to read start genome: ", err)
	}
	fmt.Println(start_genome)

	// Check if output dir exists
	if _, err := os.Stat(*out_dir_path); err == nil {
		// clear it
		os.RemoveAll(*out_dir_path)
	}
	// create output dir
	err = os.MkdirAll(*out_dir_path, os.ModePerm)
	if err != nil {
		log.Fatal("Failed to create output directory: ", err)
	}

	// The 100 generation XOR experiment
	experiment := experiments.Experiment {
		Id:0,
		Trials:make(experiments.Trials, context.NumRuns),
	}
	err = xor.XOR(context, start_genome, *out_dir_path, &experiment)
	if err != nil {
		log.Fatal("Failed to perform XOR experiment: ", err)
	}

	// Find winner statistics
	avg_nodes, avg_genes, avg_evals := experiment.AvgWinnerNGE()


	fmt.Printf("\nAverage\n\tWinner Nodes:\t%.1f\n\tWinner Genes:\t%.1f\n\tWinner Evals:\t%.1f\n",
		avg_nodes, avg_genes, avg_evals)
	mean_complexity, mean_diversity, mean_age := 0.0, 0.0, 0.0
	for _, t := range experiment.Trials {
		mean_complexity += t.Complexity().Mean()
		mean_diversity += t.Diversity().Mean()
		mean_age += t.Age().Mean()
	}
	count := float64(len(experiment.Trials))
	mean_complexity /= count
	mean_diversity /= count
	mean_age /= count
	fmt.Printf("Mean\n\tComplexity:\t%.1f\n\tDiversity:\t%.1f\n\tAge:\t\t%.1f\n", mean_complexity, mean_diversity, mean_age)

	fmt.Printf(">>> Start genome file:  %s\n", *genome_path)
	fmt.Printf(">>> Configuration file: %s\n", *context_path)
}
{'fraction_non_alphanumeric': 0.1515265736901621, 'fraction_numerical': 0.0054655107425555976, 'mean_word_length': 4.197845249755142, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 20, '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': '710427', 'n_tokens_mistral': 2046, 'n_tokens_neox': 1923, 'n_words': 464}