<commit_before>/*	$Id$ */
/*
 * Copyright (c) 2014 <NAME> <<EMAIL>>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __linux__
#include <bsd/stdlib.h> /* arc4random() */
#endif
#include <string.h>

#include <gtk/gtk.h>
#include <gsl/gsl_multifit.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_histogram.h>

#include "extern.h"

/*
 * For a given point "x" in the domain, fit ourselves to the polynomial
 * coefficients of degree "fitpoly + 1".
 */
static double
fitpoly(const double *fits, size_t poly, double x)
{
	double	 y, v;
	size_t	 i, j;

	for (y = 0.0, i = 0; i < poly; i++) {
		v = fits[i];
		for (j = 0; j < i; j++)
			v *= x;
		y += v;
	}
	return(y);
}

/*
 * Copy the "hot" data into "warm" holding.
 * While here, set our simulation's "work" parameter (if "fitpoly" is
 * set) to contain the necessary dependent variable.
 * Do this all as quickly as possible, as we're holding both the
 * simulation "hot" lock and the "warm" lock as well.
 */
static void
snapshot(struct sim *sim, struct simwarm *warm, 
	uint64_t truns, uint64_t tgens)
{
	double	 min, max, v, chisq, x;
	size_t	 i, j, k;

	/*
	 * If we have the same number of runs, don't bother snapshotting
	 * us--we're already up to date.
	 */
	if (warm->truns == truns) {
		assert(warm->tgens == tgens);
		return;
	}

	memcpy(warm->stats, sim->hot.statslsb, 
		sim->dims * sizeof(struct stats));
	memcpy(warm->islands, sim->hot.islandslsb, 
		sim->dims * sizeof(struct stats));
	warm->truns = truns;
	warm->tgens = tgens;

	v = stats_mean(&warm->stats[0]) +
		stats_mean(&warm->stats[1]);
	min = warm->smeans[0] = v / 2.0;
	for (i = 1; i < sim->dims - 1; i++) {
		v += stats_mean(&warm->stats[i + 1]);
		warm->smeans[i] = v / 3.0;
		v -= stats_mean(&warm->stats[i - 1]);
		if (warm->smeans[i] < min) {
			min = warm->smeans[i];
			warm->smeanmin = i;
		}
	}
	warm->smeans[i] = v / 2.0;
	if (warm->smeans[i] < min)
		warm->smeanmin = i;

	v = stats_extinctm(&warm->stats[0]) +
		stats_extinctm(&warm->stats[1]);
	max = warm->sextms[0] = v / 2.0;
	for (i = 1; i < sim->dims - 1; i++) {
		v += stats_extinctm(&warm->stats[i + 1]);
		warm->sextms[i] = v / 3.0;
		v -= stats_extinctm(&warm->stats[i - 1]);
		if (warm->sextms[i] > max) {
			max = warm->sextms[i];
			warm->sextmmax = i;<commit_msg>Fix buffer size.<commit_after>/*	$Id$ */
/*
 * Copyright (c) 2014 <NAME> <<EMAIL>>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __linux__
#include <bsd/stdlib.h> /* arc4random() */
#endif
#include <string.h>

#include <gtk/gtk.h>
#include <gsl/gsl_multifit.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_histogram.h>

#include "extern.h"

/*
 * For a given point "x" in the domain, fit ourselves to the polynomial
 * coefficients of degree "fitpoly + 1".
 */
static double
fitpoly(const double *fits, size_t poly, double x)
{
	double	 y, v;
	size_t	 i, j;

	for (y = 0.0, i = 0; i < poly; i++) {
		v = fits[i];
		for (j = 0; j < i; j++)
			v *= x;
		y += v;
	}
	return(y);
}

/*
 * Copy the "hot" data into "warm" holding.
 * While here, set our simulation's "work" parameter (if "fitpoly" is
 * set) to contain the necessary dependent variable.
 * Do this all as quickly as possible, as we're holding both the
 * simulation "hot" lock and the "warm" lock as well.
 */
static void
snapshot(struct sim *sim, struct simwarm *warm, 
	uint64_t truns, uint64_t tgens)
{
	double	 min, max, v, chisq, x;
	size_t	 i, j, k;

	/*
	 * If we have the same number of runs, don't bother snapshotting
	 * us--we're already up to date.
	 */
	if (warm->truns == truns) {
		assert(warm->tgens == tgens);
		return;
	}

	memcpy(warm->stats, sim->hot.statslsb, 
		sim->dims * sizeof(struct stats));
	memcpy(warm->islands, sim->hot.islandslsb, 
		sim->islands * sizeof(struct stats));
	warm->truns = truns;
	warm->tgens = tgens;

	v = stats_mean(&warm->stats[0]) +
		stats_mean(&warm->stats[1]);
	min = warm->smeans[0] = v / 2.0;
	for (i = 1; i < sim->dims - 1; i++) {
		v += stats_mean(&warm->stats[i + 1]);
		warm->smeans[i] = v / 3.0;
		v -= stats_mean(&warm->stats[i - 1]);
		if (warm->smeans[i] < min) {
			min = warm->smeans[i];
			warm->smeanmin = i;
		}
	}
	warm->smeans[i] = v / 2.0;
	if (warm->smeans[i] < min)
		warm->smeanmin = i;

	v = stats_extinctm(&warm->stats[0]) +
		stats_extinctm(&warm->stats[1]);
	max = warm->sextms[0] = v / 2.0;
	for (i = 1; i < sim->dims - 1; i++) {
		v += stats_extinctm(&warm->stats[i + 1]);
		warm->sextms[i] = v / 3.0;
		v -= stats_extinctm(&warm->stats[i - 1]);
		if (warm->sextms[i] > max) {
			max = warm->sextms[i];
			warm->sextmmax = i;
{'fraction_non_alphanumeric': 0.1555807916937054, 'fraction_numerical': 0.012329656067488644, 'mean_word_length': 3.480377906976744, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 101, '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': '4572646', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2271, 'n_words': 747}