<commit_before>var g_myMatrix;
var g_width = 40;
var g_height = 40;

var g_interval;
var g_running = 0;
var g_tick = 0;

var g_initScenario = "random";

var g_lambda = 0.5; // how likely the agent is to change its behaviour; 0.2: slow change, 0.8: fast change, 0.5: default
var g_memoryLimit = 20; //10: very fast change, 100: very slow change
var g_alphaBias = 1; // fitness of alpha, bias towards alpha (if given a choice between alpha and beta)
var g_errorRate = 0;
var g_neighborRange = 1;

var g_logValues = new Array();

// matrix function from stackoverflow
function matrix(rows, cols, defaultValue) {
	var arr = [];

	for (var i = 0; i < rows; i++){
		arr.push([]);
		arr[i].push(new Array(cols));
		for(var j=0; j < cols; j++){
			arr[i][j] = defaultValue;
		}
	}
	return arr;
}


function setGridSize(i) {
	
	stopSim();
	g_tick = 0;
	document.getElementById('ticks').innerHTML = g_tick;
	document.getElementById("stepButton").disabled = true;
	document.getElementById("runStopButton").disabled = true;

	g_width = i;
	g_height = i;
	g_myMatrix = 0;
	
	document.getElementById("simCanvas").width = i * 4;
	document.getElementById("simCanvas").height = i * 4;

}


function chooseInitScenario(s) {
	
	//~ console.log("s=" + s);
	g_initScenario = s;
	
}

function setMemory(i) {
	g_memoryLimit = i;
}

function setLambda(i) {
	g_lambda = i;
}

function setAlphaBias(i) {
	g_alphaBias = i;
}

function setMemory(i) {
	g_memoryLimit = i;
}

function setLambda(i) {
	g_lambda = i;
}

function setAlphaBias(i) {
	g_alphaBias = i;
}

function setNeighborRange(i) {
	g_neighborRange = i;
}


function setWeighting(s) {
	var myClassName = "";
	var myDisabled = true;
	if (s === "none") {
		g_alphaBias = 1;
		myClassName = "grayed";
		myDisabled = true;
	} else if (s === "weighted") {
		myClassName = "";
		myDisabled = false;
	}
	document.getElementById("alphaBiasSpan").className = myClassName;
	document.getElementById("alphaBiasSlider").disabled = myDisabled;
}

function setErrorRate(i) {
	g_errorRate = i;
}
function initSim() {
	var myCanvas = document.getElementById("simCanvas");
	var myContext = myCanvas.getContext("2d");
	
	// clear canvases
	var plotCanvas = document.getElementById("plotCanvas");
	var plotContext = plotCanvas.getContext("2d");
	myCanvas.width = myCanvas.width;
	plotCanvas.width = plotCanvas.width;

	// draw lines on plot canvas
	plotContext.fillStyle = "#ccc";
	plotContext.font = 'bold 8pt Arial'
	for (var i = 0; i < 5; i++) {
		plotContext.fillRect(0, i*25, 800, 1);
		plotContext.fillText((100-(i*25)).toString(), 10, 10+i*25);
	}

	
	g_tick = 0;
	g_logValues = new Array();
	document.getElementById("stepButton").disabled = false;
	document.getElementById("runStopButton").disabled = false;

	g_myMatrix = matrix(g_height, g_width, 0);// initial probability, initial memory
	
	// purely random
	if (g_initScenario === "random") {
		for (var x = 0; x < g_width; x++) {
			for (var y = 0; y < g_height; y++) {
				g_myMatrix[x][y] = [0.5 + (Math.random() - 0.5)/2, ""]; // probability of saying α
			}
		}
	}

	//island
	if (g_initScenario === "island") {
		for (var x = 0; x < g_width; x++) {
			for (var y = 0; y < g_height; y++) {
				g_myMatrix[x][y] = [0, ""]; // probability of saying α
				var blockwidth = 4;
				if (x > (g_width / 2) - (blockwidth / 2) && x < (g_width / 2) + (blockwidth / 2) && y > (g_height / 2) - (blockwidth / 2) && y < (g_height / 2) + (blockwidth / 2) ) {
					g_myMatrix[x][y] = [1, ""];
				}
				
			}
		}
	}

	//two fields
	if (g_initScenario === "two fields") {
		for (var x = 0; x < g_width; x++) {
			for (var y = 0; y < g_height; y++) {
				g_myMatrix[x][y] = [0, ""]; // probability of saying α, agent's memory (as a string)
				var blockwidth = 4;
				if (x > (g_width / 2) ) {
					g_myMatrix[x][y] = [1, ""];
				}
				
			}
		}
	}<commit_msg>fix math error when initializing with two field scenario<commit_after>var g_myMatrix;
var g_width = 40;
var g_height = 40;

var g_interval;
var g_running = 0;
var g_tick = 0;

var g_initScenario = "random";

var g_lambda = 0.5; // how likely the agent is to change its behaviour; 0.2: slow change, 0.8: fast change, 0.5: default
var g_memoryLimit = 20; //10: very fast change, 100: very slow change
var g_alphaBias = 1; // fitness of alpha, bias towards alpha (if given a choice between alpha and beta)
var g_errorRate = 0;
var g_neighborRange = 1;

var g_logValues = new Array();

// matrix function from stackoverflow
function matrix(rows, cols, defaultValue) {
	var arr = [];

	for (var i = 0; i < rows; i++){
		arr.push([]);
		arr[i].push(new Array(cols));
		for(var j=0; j < cols; j++){
			arr[i][j] = defaultValue;
		}
	}
	return arr;
}


function setGridSize(i) {
	
	stopSim();
	g_tick = 0;
	document.getElementById('ticks').innerHTML = g_tick;
	document.getElementById("stepButton").disabled = true;
	document.getElementById("runStopButton").disabled = true;

	g_width = i;
	g_height = i;
	g_myMatrix = 0;
	
	document.getElementById("simCanvas").width = i * 4;
	document.getElementById("simCanvas").height = i * 4;

}


function chooseInitScenario(s) {
	
	//~ console.log("s=" + s);
	g_initScenario = s;
	
}

function setMemory(i) {
	g_memoryLimit = i;
}

function setLambda(i) {
	g_lambda = i;
}

function setAlphaBias(i) {
	g_alphaBias = i;
}

function setMemory(i) {
	g_memoryLimit = i;
}

function setLambda(i) {
	g_lambda = i;
}

function setAlphaBias(i) {
	g_alphaBias = i;
}

function setNeighborRange(i) {
	g_neighborRange = i;
}


function setWeighting(s) {
	var myClassName = "";
	var myDisabled = true;
	if (s === "none") {
		g_alphaBias = 1;
		myClassName = "grayed";
		myDisabled = true;
	} else if (s === "weighted") {
		myClassName = "";
		myDisabled = false;
	}
	document.getElementById("alphaBiasSpan").className = myClassName;
	document.getElementById("alphaBiasSlider").disabled = myDisabled;
}

function setErrorRate(i) {
	g_errorRate = i;
}
function initSim() {
	var myCanvas = document.getElementById("simCanvas");
	var myContext = myCanvas.getContext("2d");
	
	// clear canvases
	var plotCanvas = document.getElementById("plotCanvas");
	var plotContext = plotCanvas.getContext("2d");
	myCanvas.width = myCanvas.width;
	plotCanvas.width = plotCanvas.width;

	// draw lines on plot canvas
	plotContext.fillStyle = "#ccc";
	plotContext.font = 'bold 8pt Arial'
	for (var i = 0; i < 5; i++) {
		plotContext.fillRect(0, i*25, 800, 1);
		plotContext.fillText((100-(i*25)).toString(), 10, 10+i*25);
	}

	
	g_tick = 0;
	g_logValues = new Array();
	document.getElementById("stepButton").disabled = false;
	document.getElementById("runStopButton").disabled = false;

	g_myMatrix = matrix(g_height, g_width, 0);// initial probability, initial memory
	
	// purely random
	if (g_initScenario === "random") {
		for (var x = 0; x < g_width; x++) {
			for (var y = 0; y < g_height; y++) {
				g_myMatrix[x][y] = [0.5 + (Math.random() - 0.5)/2, ""]; // probability of saying α
			}
		}
	}

	//island
	if (g_initScenario === "island") {
		for (var x = 0; x < g_width; x++) {
			for (var y = 0; y < g_height; y++) {
				g_myMatrix[x][y] = [0, ""]; // probability of saying α
				var blockwidth = 4;
				if (x > (g_width / 2) - (blockwidth / 2) && x < (g_width / 2) + (blockwidth / 2) && y > (g_height / 2) - (blockwidth / 2) && y < (g_height / 2) + (blockwidth / 2) ) {
					g_myMatrix[x][y] = [1, ""];
				}
				
			}
		}
	}

	//two fields
	if (g_initScenario === "two fields") {
		for (var x = 0; x < g_width; x++) {
			for (var y = 0; y < g_height; y++) {
				g_myMatrix[x][y] = [0, ""]; // probability of saying α, agent's memory (as a string)
				var blockwidth = 4;
				if (x >= (g_width / 2) ) {
					g_myMatrix[x][y] = [1, ""];
				}
				
			}
		}
	}
{'fraction_non_alphanumeric': 0.16311411489472316, 'fraction_numerical': 0.021315310631661033, 'mean_word_length': 3.5184967704051675, 'pattern_counts': {'":': 0, '<': 25, '<?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': '4867725', 'n_tokens_mistral': 3184, 'n_tokens_neox': 2862, 'n_words': 754}