#!/usr/bin/python3 ''' Created on Nov 1, 2016 Generate data with two random gaussian samples with a tag. Basic code to test the tag recovery from the concatenated and shuffled samples. @author: francis ''' import pandas as pd import numpy as np import matplotlib.pyplot as plt class Gauss(object): def __init__(self, mean=0, stddev=1): self.mean = mean self.stddev = stddev def gen_samples(self, n, tag=0): samples = self.stddev * np.random.randn(n) + self.mean; return pd.DataFrame({'tag': tag, 'samples': samples}) def main(): ok = Gauss(200, 50).gen_samples(1000, 0) bad = Gauss(500, 50).gen_samples(100, 1) mix = pd.concat([ok, bad], ignore_index=True) mix = mix.reindex(np.random.permutation(mix.index)) print(mix) plt.figure() plt.subplot(2, 1, 1) bins = 50 alpha = 0.5 ok.samples.plot(kind='hist', alpha=alpha) bad.samples.plot(kind='hist', alpha=alpha) plt.subplot(2, 1, 2) mix.samples.plot(kind='hist', bins=bins) plt.savefig("mix.png") if __name__ == '__main__': main()