<commit_before>## helper functions for visualizing component score prior likelihoods
## last updated: 10.12.16 <EMAIL>

import matplotlib as mp 
mp.use('TkAgg') #set backend
import matplotlib.pyplot as plt
from random import choice
import numpy as np
import os
def get_hist_bins(score,numBins):
	if score == "ihs":
		scorerange = [-3., 3.]#[-4., 4.]
		ylims = [0, .1]#.25]
	elif score == "delihh":
		scorerange = [-2., 3.]
		ylims = [0, .1]#.25]
	elif score == "fst":
		scorerange = [-.05, 1.]#[-2., 4.5]
		ylims = [0, .1]#.25]
	elif score == "deldaf" or score =="fst_deldaf":
		scorerange = [-1., 1.]
		ylims = [0, .1]#.25]
	elif score == "xp" or score =="xpehh":
		scorerange = [-3., 3.]#[-3., 7.]
		ylims = [0, .1]#.25]
	elif score=="nsl":
		scorerange = [-3., 3.]#-4., 4.]
		ylims = [0, .1]#.25]
	else:
		print("error: " + score)
	binlen = (scorerange[1] - scorerange[0])/float(numBins-1)
	bins = [scorerange[0] + binlen * i for i in range(numBins)]
	return bins, scorerange, ylims
def read_likes_file(likesfilename):
	'''parses a file from e.g. write_hists_to_files'''
	starts, ends, vals = [], [], []
	openfile = open(likesfilename, 'r')
	for line in openfile:
		entries = line.split()
		start, end, val = [float(x) for x in entries]
		for item in ['start', 'end', 'val']:
			eval(item + "s").append(eval(item))
	openfile.close()
	return starts, ends, vals
def get_old_likes():
	likesloc = "combine/old_likes/"
	scores = ['ihs', 'delihh', 'fst', 'xp', 'deldaf']
	pops = range(1,5)
	models = ['default_112115_825am', 'default_default_101715_12pm', 'gradient_101915_treebase_6_best', 'nulldefault', 'nulldefault_constantsize']
	dists = ['causal', 'linked', 'neut']
	likesdict = {}
	for model in models:
		for score in scores:
			for dist in dists:
				for pop in pops:
					likesfilename = likesloc + score + "_" + model + "_" + str(pop) + "_likes_" + dist + ".txt"
					assert os.path.isfile(likesfilename)
					#if not os.path.isfile(likesfilename):
					#	print("missing file: " + likesfilename)
					key = (model, score, dist, pop)
					starts, ends, vals = read_likes_file(likesfilename)
					likesdict[key] = [starts, ends, vals]
	return likesdict
def plot_likes(starts, ends, vals, ax, xlims, ylims, color='blue'):
	assert len(starts) == len(ends)
	midpoints = [(starts[i] + ends[i])/2 for i in range(len(starts))]

	bar_width = (starts[0] - ends[0])/3
	if color == "blue":
		offset = 0
	elif color == "red":
		offset = bar_width
	elif color == "green":
		offset = (-1 * bar_width)

	plot_xvals = [midpoints[i] + offset for i in range(len(midpoints))]

	#ax.scatter(midpoints, vals, color=color)
	ax.bar(plot_xvals, vals, bar_width, color=color)

	ax.set_xlim(xlims)
	ax.set_ylim(ylims)
	return ax
def read_demographics_from_filename(filename):
	'''specific to a set of models/pops; facilitates quick visualization of arbitrary comparisons'''
	models = ['default_112115_825am', 'default_default_101715_12pm', 'gradient_101915_treebase_6_best','nulldefault_constantsize', 'nulldefault']<commit_msg>histogram spacing<commit_after>## helper functions for visualizing component score prior likelihoods
## last updated: 10.12.16 <EMAIL>

import matplotlib as mp 
mp.use('TkAgg') #set backend
import matplotlib.pyplot as plt
from random import choice
import numpy as np
import os
def get_hist_bins(score,numBins):
	if score == "ihs":
		scorerange = [-3., 3.]#[-4., 4.]
		ylims = [0, .1]#.25]
	elif score == "delihh":
		scorerange = [-2., 3.]
		ylims = [0, .1]#.25]
	elif score == "fst":
		scorerange = [-.05, 1.]#[-2., 4.5]
		ylims = [0, .1]#.25]
	elif score == "deldaf" or score =="fst_deldaf":
		scorerange = [-1., 1.]
		ylims = [0, .1]#.25]
	elif score == "xp" or score =="xpehh":
		scorerange = [-3., 3.]#[-3., 7.]
		ylims = [0, .1]#.25]
	elif score=="nsl":
		scorerange = [-3., 3.]#-4., 4.]
		ylims = [0, .1]#.25]
	else:
		print("error: " + score)
	binlen = (scorerange[1] - scorerange[0])/float(numBins-1)
	bins = [scorerange[0] + binlen * i for i in range(numBins)]
	return bins, scorerange, ylims
def read_likes_file(likesfilename):
	'''parses a file from e.g. write_hists_to_files'''
	starts, ends, vals = [], [], []
	openfile = open(likesfilename, 'r')
	for line in openfile:
		entries = line.split()
		start, end, val = [float(x) for x in entries]
		for item in ['start', 'end', 'val']:
			eval(item + "s").append(eval(item))
	openfile.close()
	return starts, ends, vals
def get_old_likes():
	likesloc = "combine/old_likes/"
	scores = ['ihs', 'delihh', 'fst', 'xp', 'deldaf']
	pops = range(1,5)
	models = ['default_112115_825am', 'default_default_101715_12pm', 'gradient_101915_treebase_6_best', 'nulldefault', 'nulldefault_constantsize']
	dists = ['causal', 'linked', 'neut']
	likesdict = {}
	for model in models:
		for score in scores:
			for dist in dists:
				for pop in pops:
					likesfilename = likesloc + score + "_" + model + "_" + str(pop) + "_likes_" + dist + ".txt"
					assert os.path.isfile(likesfilename)
					#if not os.path.isfile(likesfilename):
					#	print("missing file: " + likesfilename)
					key = (model, score, dist, pop)
					starts, ends, vals = read_likes_file(likesfilename)
					likesdict[key] = [starts, ends, vals]
	return likesdict
def plot_likes(starts, ends, vals, ax, xlims, ylims, color='blue'):
	assert len(starts) == len(ends)
	midpoints = [(starts[i] + ends[i])/2 for i in range(len(starts))]

	bar_width = (starts[0] - ends[0])/5
	if color == "blue":
		offset = 0
	elif color == "red":
		offset = bar_width
	elif color == "green":
		offset = (-1 * bar_width)

	plot_xvals = [midpoints[i] + offset for i in range(len(midpoints))]

	#ax.scatter(midpoints, vals, color=color)
	ax.bar(plot_xvals, vals, bar_width, color=color)

	ax.set_xlim(xlims)
	ax.set_ylim(ylims)
	return ax
def read_demographics_from_filename(filename):
	'''specific to a set of models/pops; facilitates quick visualization of arbitrary comparisons'''
	models = ['default_112115_825am', 'default_default_101715_12pm', 'gradient_101915_treebase_6_best','nulldefault_constantsize', 'nulldefault']
{'fraction_non_alphanumeric': 0.17109634551495018, 'fraction_numerical': 0.037209302325581395, 'mean_word_length': 4.2539267015706805, 'pattern_counts': {'":': 18, '<': 5, '<?xml version=': 0, '>': 5, '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': '3064191', 'n_tokens_mistral': 2644, 'n_tokens_neox': 2348, 'n_words': 604}