Apply t-SNE to galaxy spectra from two different simulations.
First import some modules
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=False)
from sklearn.manifold import TSNE
Then load your spectra in to 2D arrays. This assumes that they are sampled on the same resolution grid, so each pixel (or feature) is being compared fairly.
illustris_spec = np.array(...)
eagle_spec = np.array(...)
np.random.shuffle(illustris_spec)
np.random.shuffle(eagle_spec)
combine the spectra from both simulations.
dat = np.vstack([illustris_spec, eagle_spec, vespa_spec])
Run the t-SNE with 2 components!
combined_tsne = TSNE(n_components=2).fit_transform(dat)
Plot the 2D t-SNE distribution, labelled by simulation.
fig = plt.figure()
alpha=0.8
size=4
Ni = len(illustris_spec)
Ne = len(eagle_spec)
plt.scatter(combined_tsne[:Ni,0], combined_tsne[:Ni,1], label='Illustris', alpha=alpha, s=size)
plt.scatter(combined_tsne[Ni:Ni+Ne,0], combined_tsne[Ni:Ni+Ne,1], label='EAGLE', alpha=alpha, s=size)
plt.legend()
plt.xticks([])
plt.yticks([])