<commit_before>import numpy as np
import h5py
import os
cimport numpy as np
from libc.stdlib cimport malloc, free
import csv

DTYPE = np.double
ctypedef np.double_t DTYPE_t

DTYPE1 = np.int
ctypedef np.int_t DTYPE1_t

cdef int DIM = 30
cdef int id = 0

def initial(DTYPE_t N):
	global DIM
	cdef np.ndarray[DTYPE_t, ndim=2] n = np.zeros((DIM, 2))
	n[0, 0] = N
	n[0, 1] = 1.
	return n

def offspring(np.ndarray[DTYPE_t, ndim=2] n):
	cdef int length = n.shape[0]
	for i in range(0, length):
		birth_rate = n[i,1]
		num = n[i,0]
		num_offspring = np.random.poisson(num * birth_rate, 1)
		n[i, 0] = num_offspring
	return n

def mutation(np.ndarray[DTYPE_t, ndim=2] n, double Ub, double s):
	global DIM
	global id
	cdef int length = n.shape[0]
	cdef np.ndarray[DTYPE1_t, ndim=1] num_mut
	mut_list = []
	for i in range(0, length):
		num = n[i,0]
		#num_mut = np.random.poisson(Ub, num)
		num_mut_pre = np.floor(np.random.uniform(0,1,num) + Ub * np.ones(num))
		num_mut = num_mut_pre.astype(int)
		if num_mut.shape[0]>0 and i + 1 > DIM-1:
			DIM += 10
			id = 1
		mut_list.append(num_mut)
	cdef int *new = <int *>malloc(DIM * sizeof(int))
	n = np.zeros((DIM,2))
	for i in range(DIM):
		new[i] = 0
	cdef int mut_sum = 0
	cdef int tmp_num = 0
	for i in range(0, length):
		for mut in mut_list[i]:
			new[i+mut] += 1
		tmp_num = new[i]
		n[i,0] = tmp_num
		mut_sum += i*tmp_num
	for i in range(length, DIM):
		tmp_num = new[i]
		n[i,0] = tmp_num
		mut_sum += i*tmp_num
	total_num = np.sum(n[:,0])
	free(new)
	for i in range(0, DIM):
		birth_rate = (1.+i*s)/(1+s*mut_sum/total_num)
		n[i,1] = birth_rate if (birth_rate>0) else 0
	return n

def info(np.ndarray[DTYPE_t, ndim=2] n):
	N = np.sum(n[:,0])
	mut_list = np.argwhere(n[:,0]>0)
	min = np.min(mut_list)<commit_msg>Const PopulationSize, weight on ps<commit_after>import numpy as np
import collections
import math
import h5py
import os
cimport numpy as np
from libc.stdlib cimport malloc, free
import csv

DTYPE = np.double
ctypedef np.double_t DTYPE_t

DTYPE1 = np.int
ctypedef np.int_t DTYPE1_t

cdef int DIM = 30
cdef int id = 0

def initial(DTYPE_t N):
	global DIM
	cdef np.ndarray[DTYPE_t, ndim=2] n = np.zeros((DIM, 2))
	n[0, 0] = N
	n[0, 1] = 1.
	return n

def offspring(np.ndarray[DTYPE_t, ndim=2] n):
	cdef int length = n.shape[0]
	weight_array = np.zeros((length,1))
	mut_sum_real = np.dot(n[:,1],n[:,0])
	for i in range(0, length):
		weight_array[i,0] = n[i,1]*n[i,0]/mut_sum_real
	offspring_gene = np.random.choice(np.arange(length),size=int(np.sum(n[:,0])),replace=True,p=weight_array[:,0])
	offspring_distribution = collections.Counter(offspring_gene)
	for i in range(0, length):
		n[i,0] = offspring_distribution[i]
	#	birth_rate = n[i,1]
	#	num = n[i,0]
	#	num_offspring = np.random.poisson(num * birth_rate, 1)
	#	n[i, 0] = num_offspring
	return n

def mutation(np.ndarray[DTYPE_t, ndim=2] n, double Ub, double s):
	global DIM
	global id
	cdef int length = n.shape[0]
	cdef np.ndarray[DTYPE1_t, ndim=1] num_mut
	mut_list = []
	for i in range(0, length):
		num = int(n[i,0])
		num_mut = np.random.poisson(Ub, num)
	#	num_mut_pre = np.floor(np.random.uniform(0,1,num) + Ub * np.ones(num))
	#	num_mut = num_mut_pre.astype(int)
		if num_mut.shape[0]>0 and i + 1 > DIM-1:
			DIM += 10
			id = 1
		mut_list.append(num_mut)
	cdef int *new = <int *>malloc(DIM * sizeof(int))
	n = np.zeros((DIM,2))
	for i in range(DIM):
		new[i] = 0
	cdef int mut_sum = 0
	cdef int tmp_num = 0
	for i in range(0, length):
		for mut in mut_list[i]:
			new[i+mut] += 1
		tmp_num = new[i]
		n[i,0] = tmp_num
		mut_sum += i*tmp_num
	for i in range(length, DIM):
		tmp_num = new[i]
		n[i,0] = tmp_num
		mut_sum += i*tmp_num
	total_num = np.sum(n[:,0])
	free(new)
	for i in range(0, DIM):
	#	birth_rate = n[i,0]/total_num*(1. + s * (i - mut_sum / total_num))
		birth_rate = 1. + s * (i - mut_sum / total_num)
		n[i,1] = birth_rate if (birth_rate>0) else 0
	return n

def info(np.ndarray[DTYPE_t, ndim=2] n):
	N = np.sum(n[:,0])
	mut_list = np.argwhere(n[:,0]>0)
	min = np.min(mut_list)
{'fraction_non_alphanumeric': 0.1552454522800897, 'fraction_numerical': 0.02965362571642163, 'mean_word_length': 3.9312039312039313, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '2025671', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1859, 'n_words': 450}