Skip to content

Instantly share code, notes, and snippets.

@giraldeau
Created November 1, 2016 19:44
Show Gist options
  • Save giraldeau/01c032ff4ad5a02d9aca0a87aff70f60 to your computer and use it in GitHub Desktop.
Save giraldeau/01c032ff4ad5a02d9aca0a87aff70f60 to your computer and use it in GitHub Desktop.
#!/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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment