Commit 76a56a0b authored by LANORE Vincent's avatar LANORE Vincent
Browse files

generate_pairs: added debug + changed default bin bounds + added png output

parent 8ef90930
......@@ -41,9 +41,10 @@ Options:
output prefix; files will be names <prefix>_1.tsv,
<prefix>_2.tsv and so on
-b, --bins <spec> bin specification in the form of a list of intervals
[default: [0,0.4],[0.4,0.6],[0.6,2]]
[default: [0.01,0.4],[0.4,0.6],[0.6,2]]
-s, --bin-size <size> number of pairs per bin [default: 100]
-p, --plot show plot of pair distributions [default: False]"""
-p, --plot show plot of pair distributions, otherwise it will
be written to a png file [default: False]"""
from diffsel_script_utils import *
......@@ -143,7 +144,10 @@ columns = ["p1_" + str(i) for i in range(20)] + ["p2_" + str(i) for i in range(2
pair_bins = [pd.DataFrame(columns = columns) for x in range(nb_bins)]
MESSAGE("Picking profile pairs and computing distances...")
nb_ok = 0
nb_it = 0
while min(map(lambda b: b.shape[0], pair_bins)) < binsize:
nb_it += 1
p1 = pick(profiles)
p2 = pick(profiles)
dist = jensen_shannon_distance(p1, p2)
......@@ -154,15 +158,23 @@ while min(map(lambda b: b.shape[0], pair_bins)) < binsize:
if in_bin(dist, i) and pair_bins[i].shape[0] < binsize:
new_row = p1.tolist() + p2.tolist() + [dist]
pair_bins[i].loc[len(pair_bins[i])] = new_row
nb_ok += 1
break
MESSAGE("%s%% of drawn pairs were kept." % data("%.1f" % (100 * nb_ok / nb_it)))
MESSAGE("Post-treatment of pair bins...")
for i in range(nb_bins):
pair_bins[i].sort_values(by=["distance"])
plot_bins = int(float(pair_bins[i]["distance"].max() - pair_bins[i]["distance"].min()) / 0.01)
pair_bins[i]["distance"].hist(bins = plot_bins)
plt.title("Distributions of pair distance classes")
if showplot:
MESSAGE("Showing plot...")
plt.show()
else:
plotfile = out + "_plot.png"
MESSAGE("Saving plot to " + data(plotfile))
plt.savefig(plotfile)
#===================================================================================================
print(step("Writing result to file"))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment