<commit_before>#!/usr/bin/env julia

import Distributions: mgf, Binomial
import JSON

"""
	gen( x, n, p, name )

Generate fixture data and write to file.

# Arguments

* `x`: input value
* `n`: number of trials
* `p`: success probability
* `name::AbstractString`: output filename

# Examples

``` julia
julia> x = rand( 1000 ) * 15;
julia> n = round( Int, rand( 1000 ) * 20 );
julia> p = rand( 1000 );
julia> gen( x, n, p, "data.json" );
```
"""
function gen( x, n, p, name )
	z = Array( Float64, length(x) );
	for i in eachindex(x)
		z[ i ] = mgf( Binomial( n[i], p[i] ), x[i] );
	end

	# Store data to be written to file as a collection:
	data = Dict([
		("x", x),
		("n", n),
		("p", p),
		("expected", z)
	]);

	# Based on the script directory, create an output filepath:
	filepath = joinpath( dir, name );

	# Write the data to the output filepath as JSON:
	outfile = open( filepath, "w" );
	write( outfile, JSON.json(data) );
	close( outfile );
end

# Get the filename:
file = @__FILE__;

# Extract the directory in which this file resides:
dir = dirname( file );

# Random (small n, small p):
x = rand( 1000 ) * 15;
n = round( Int, rand( 1000 ) * 20 )	;
p = rand( 1000 ) * 0.2;
gen( x, n, p, "small_small.json" );

# Random (small n, high p):
x = rand( 1000 ) * 15;
n = round( Int, rand( 1000 ) * 20 );
p = rand( 1000 ) * 0.25 + 0.50;
gen( x, n, p, "small_high.json" );

# Random (high n, high p):
x = rand( 1000 ) * 15;
n = round( Int, rand( 1000 ) * 40 );
p = rand( 1000 ) * 0.25 + 0.50;
gen( x, n, p, "high_high.json" );

# Random (high n, small p):
x = rand( 1000 ) * 15;
n = round( Int, rand( 1000 ) * 40 );
p = rand( 1000 ) * 0.2;
gen( x, n, p, "high_small.json" );<commit_msg>Escape quotes<commit_after>#!/usr/bin/env julia

import Distributions: mgf, Binomial
import JSON

"""
	gen( x, n, p, name )

Generate fixture data and write to file.

# Arguments

* `x`: input value
* `n`: number of trials
* `p`: success probability
* `name::AbstractString`: output filename

# Examples

``` julia
julia> x = rand( 1000 ) * 15.0;
julia> n = round( Int, rand( 1000 ) * 20.0 );
julia> p = rand( 1000 );
julia> gen( x, n, p, \"data.json\" );
```
"""
function gen( x, n, p, name )
	z = Array( Float64, length(x) );
	for i in eachindex(x)
		z[ i ] = mgf( Binomial( n[i], p[i] ), x[i] );
	end

	# Store data to be written to file as a collection:
	data = Dict([
		("x", x),
		("n", n),
		("p", p),
		("expected", z)
	]);

	# Based on the script directory, create an output filepath:
	filepath = joinpath( dir, name );

	# Write the data to the output filepath as JSON:
	outfile = open( filepath, "w" );
	write( outfile, JSON.json(data) );
	close( outfile );
end

# Get the filename:
file = @__FILE__;

# Extract the directory in which this file resides:
dir = dirname( file );

# Random (small n, small p):
x = rand( 1000 ) * 15.0;
n = round( Int, rand( 1000 ) * 20.0 )	;
p = rand( 1000 ) * 0.2;
gen( x, n, p, "small_small.json" );

# Random (small n, high p):
x = rand( 1000 ) * 15.0;
n = round( Int, rand( 1000 ) * 20.0 );
p = rand( 1000 ) * 0.25 + 0.50;
gen( x, n, p, "small_high.json" );

# Random (high n, high p):
x = rand( 1000 ) * 15.0;
n = round( Int, rand( 1000 ) * 40.0 );
p = rand( 1000 ) * 0.25 + 0.50;
gen( x, n, p, "high_high.json" );

# Random (high n, small p):
x = rand( 1000 ) * 15.0;
n = round( Int, rand( 1000 ) * 40.0 );
p = rand( 1000 ) * 0.2;
gen( x, n, p, "high_small.json" );
{'fraction_non_alphanumeric': 0.18753674309229865, 'fraction_numerical': 0.06055261610817166, 'mean_word_length': 3.232587064676617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2280625', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1354, 'n_words': 493}