<commit_before>import packages.project as project
import packages.primitive as primitive
import packages.io
import argparse
from matplotlib import pyplot as plt
import numpy as np

parser = argparse.ArgumentParser(description='Compare ground truth noise distribution (continuous generator and generated samples) and the result of the optimisation.')
parser.add_argument('projectdir')

args = parser.parse_args()

nbBins   = 200
rangeMin = -0.2
rangeMax =  0.2

projectdir = args.projectdir
if projectdir[-1] == '/':
    projectdir = projectdir[:-1]

projectname  = projectdir.split('/')[-1]
projectfile  = projectdir+'/gt/'+projectname+'.prj'
gtlinesfile  = projectdir+'/gt/primitives.csv'
gtassignfile = projectdir+'/gt/points_primitives.csv'
cloudfile    = projectdir+'/cloud.ply'

print 'Processing project ', projectname

project  = project.PyProject(projectfile)
cloud    = packages.io.readPointCloudFromPly(cloudfile)
gtlines  = primitive.readPrimitivesFromFile(gtlinesfile)
gtassign = packages.io.readPointAssignementFromFiles(gtassignfile)

# Generate UI
fig, ax1 = plt.subplots()
ax1.set_ylabel('Distribution', color='g')


# Generate noise kernel PDF curves
x = np.linspace(rangeMin, rangeMax, nbBins)

for k in project.kernels:
    pdf = k.getPDF(x)
    ax1.plot(x, pdf, color='g')
    ax1.fill_between(x, pdf, 0, color='g' )


# Compute the distance between each point and its assigned primitive
d = [ [x.distanceTo(cloud[a[0]]) for x in gtlines if x.uid == a[1]][0] for a in gtassign]

# Generate histogram and display it
hist, bins = np.histogram(d, nbBins/2, (rangeMin, rangeMax))
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) / 2

ax2 = ax1.twinx()
ax2.bar(center, hist, align='center', width=width)
<commit_msg>Now recompute the GT PDF from the GT histogram and display behind it<commit_after>import packages.project as project
import packages.primitive as primitive
import packages.io
import argparse
from matplotlib import pyplot as plt
import matplotlib.mlab as mlab
import numpy as np

parser = argparse.ArgumentParser(description='Compare ground truth noise distribution (continuous generator and generated samples) and the result of the optimisation.')
parser.add_argument('projectdir')

args = parser.parse_args()

nbBins   = 200
rangeMin = -0.2
rangeMax =  0.2

projectdir = args.projectdir
if projectdir[-1] == '/':
    projectdir = projectdir[:-1]

projectname  = projectdir.split('/')[-1]
projectfile  = projectdir+'/gt/'+projectname+'.prj'
gtlinesfile  = projectdir+'/gt/primitives.csv'
gtassignfile = projectdir+'/gt/points_primitives.csv'
cloudfile    = projectdir+'/cloud.ply'

print 'Processing project ', projectname

project  = project.PyProject(projectfile)
cloud    = packages.io.readPointCloudFromPly(cloudfile)
gtlines  = primitive.readPrimitivesFromFile(gtlinesfile)
gtassign = packages.io.readPointAssignementFromFiles(gtassignfile)

# Generate UI
fig, ax1 = plt.subplots()
ax1.set_ylabel('PDF')


# Generate noise kernel PDF curves
x = np.linspace(rangeMin, rangeMax, nbBins)

for k in project.kernels:
    pdf = k.getPDF(x)
    ax1.plot(x, pdf, color='#dbb971', linestyle='--')
    

# Compute the distance between each point and its assigned primitive
d = [ [primVar.distanceTo(cloud[a[0]]) for primVar in gtlines if primVar.uid == a[1]][0] for a in gtassign]

# Generate histogram and display it
hist, bins = np.histogram(d, nbBins/5, (rangeMin, rangeMax))
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) / 2

ax2 = ax1.twinx()
ax2.set_ylabel('Noise')
ax2.bar(center, hist, align='center', color='#dbb971', width=width, edgecolor = "none")

# Compute PDF of the gt histogram and display
mean = np.mean(d)
variance = np.var(d)
sigma = np.sqrt(variance)
mpdf = mlab.normpdf(x,mean,sigma)
ax1.plot(x, mpdf, linewidth=3, color='#dbb971')
ax1.fill_between(x, mpdf, 0, color='#eddebc' )

{'fraction_non_alphanumeric': 0.1275879917184265, 'fraction_numerical': 0.018115942028985508, 'mean_word_length': 5.125198098256735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4131094', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1308, 'n_words': 346}