Skip to content

Commit

Permalink
mostly conforms to pylint/pep8. just need to remove duplicate code, w…
Browse files Browse the repository at this point in the history
…hich likely amounts to removing redundant sripts.
  • Loading branch information
Alex Olivas committed Jul 10, 2020
1 parent 2a9d420 commit 15767ef
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 241 deletions.
12 changes: 9 additions & 3 deletions examples/basic_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/usr/bin/env python
'''
Basic example which creates a dummy test dataset and a
benchmark collection. This example 'trains' on the benchmark
set and displays the results of the comparison.
'''

import numpy

Expand All @@ -9,16 +14,17 @@
'Uniform': numpy.random.uniform(size=100)
}

n_benchmark_collections = 5
benchmark_labels = ['Benchmark_%d' % i for i in range(n_benchmark_collections)]
N_BENCHMARK_COLLECTIONS = 5
benchmark_labels = ['Benchmark_%d' % i for i in range(N_BENCHMARK_COLLECTIONS)]
benchmark_data = {
benchmark_label:{'Gaussian': numpy.random.normal(size=100),
'Uniform': numpy.random.uniform(size=100)}
for benchmark_label in benchmark_labels
}

# histogram the data
test_histograms = {name:numpy.histogram(data)[0] for name, data in test_data.items()}
test_histograms = {name:numpy.histogram(data)[0]
for name, data in test_data.items()}
benchmark_histograms = dict()
for name, bm_data in benchmark_data.items():
benchmark_histograms[name] = {n:numpy.histogram(data)[0]
Expand Down
25 changes: 18 additions & 7 deletions examples/classic_fit_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env python

'''
Example illustrating the classic method, meaning fitting by hand.
'''

import numpy
import pylab
import scipy.optimize
Expand All @@ -16,25 +20,32 @@
data.append(time)

def gauss(x, *p):
A, mu, sigma = p
return A*numpy.exp(-(x-mu)**2/(2.*sigma**2))
'''
The gaussian distribution.
'''
amplitude, mean, sigma = p
return amplitude*numpy.exp(-(x-mean)**2/(2.*sigma**2))

hist, bin_edges = numpy.histogram(data)
bin_centers = (bin_edges[:-1] + bin_edges[1:])/2
p0 = [1000., 0., 1.]
p1 = [1000., 0., 1.]
print(hist)
print(bin_centers)
coeff, var_matrix = scipy.optimize.curve_fit(gauss, bin_centers, hist, p0=p1)

print('Fitted amplitude = %f' % coeff[0])
print('Fitted mean = %f' % coeff[1])
print('Fitted standard deviation = %f' % coeff[2])
result = scipy.optimize.curve_fit(gauss, bin_centers, hist, p0=p1)
fitted_amplitude = result[0]
fitted_mean = result[1]
fitted_std_dev = result[2]

print('Fitted amplitude = %f' % fitted_amplitude)
print('Fitted mean = %f' % fitted_mean)
print('Fitted standard deviation = %f' % fitted_std_dev)

coeff = tuple(result[:3])
hist_fit = gauss(bin_centers, *coeff)
pylab.hist(data)
pylab.plot(bin_centers, gauss(bin_centers, *p0), label='Initial')
pylab.plot(bin_centers, hist_fit, label='Fitted data')

pylab.show()

132 changes: 0 additions & 132 deletions examples/gaussian_example.py

This file was deleted.

Loading

0 comments on commit 15767ef

Please sign in to comment.