def embed( P, alg, dim, repeat, seed ): if P.shape[0] > 2000: repeat /= 5 if alg == 'sne': spacetime.distribution = 'gaussian' Y,Z,E = spacetime.st_snep( P, dim, 0, repeat=repeat, init_seed=seed ) elif alg == 'tsne': spacetime.distribution = 'student' Y,Z,E = spacetime.st_snep( P, dim, 0, repeat=repeat, init_seed=seed ) elif alg == 'st': spacetime.distribution = 'student' Y,Z,E = spacetime.st_snep( P, dim-1, 1, repeat=repeat, init_seed=seed ) #elif ALG == 'multi-tsne': # tsne_multi_y,tsne_multi_w = tsne_multi.tsnep( P, 2, E=E ) #elif ALG == 'multi-st': # spacetime_y,spacetime_w = spacetime_multi.st_snep( P, 2, layers=2, E=E ) else: raise RuntimeError( 'unknown algorithm: %s' % alg ) return E
def __embed( P, result_file, methods, repeat ): ''' (optionally) compute the embeding and save to disk then load the embedding from disk ''' if not os.access( result_file, os.R_OK ): # some good configurations for NIPS22 spacetime.conv_threshold = 1e-9 spacetime.min_epochs = 500 spacetime.lrate_s = 500 spacetime.lrate_t = 1 sne_Y = None sne_E = 0 if 'sne' in methods: spacetime.distribution = 'gaussian' sne_Y,_tmp,sne_E = spacetime.st_snep( P, 3, 0, repeat=repeat ) tsne_Y = None tsne_E = 0 if 'tsne' in methods: spacetime.distribution = 'student' tsne_Y,_tmp,tsne_E = spacetime.st_snep( P, 3, 0, repeat=repeat ) spacetime_Y = spacetime_Z = None spacetime_E = 0 if 'st' in methods: spacetime.distribution = 'student' spacetime_Y,spacetime_Z,spacetime_E = \ spacetime.st_snep( P, 2, 1, repeat=repeat ) np.savez( result_file, sne_Y=sne_Y, sne_E=sne_E, tsne_Y=tsne_Y, tsne_E=tsne_E, spacetime_Y=spacetime_Y, spacetime_Z=spacetime_Z, spacetime_E=spacetime_E, ) print( 'loading results from %s' % result_file ) tmp = np.load( result_file ) return ( tmp['sne_Y'], tmp['sne_E'], tmp['tsne_Y'], tmp['tsne_E'], tmp['spacetime_Y'], tmp['spacetime_Z'], tmp['spacetime_E'] )
def __embed( P, result_file, repeat ): ''' (optionally) compute the embeding and save it to disk then load the embedding from disk ''' if not os.access( result_file, os.R_OK ): spacetime.conv_threshold = 1e-9 spacetime.min_epochs = 1000 spacetime.lrate_s = 500 spacetime.lrate_t = 1 Y, Z, E = spacetime.st_snep( P, 2, 1, repeat=repeat ) np.savez( result_file, Y=Y, Z=Z, E=E ) print( 'loading results from "%s"' % result_file ) tmp = np.load( result_file ) return tmp['Y'], tmp['Z'], tmp['E']
linewidths=1, c=z, cmap='RdYlGn', vmin=-np.abs( z ).max(), vmax= np.abs( z ).max() ) else: z = y[:,2] ax.scatter( y[:,0], y[:,1], s=50, linewidths=1, c=z, cmap='RdYlGn', vmin=-np.abs( z ).max(), vmax= np.abs( z ).max() ) plt.show() if __name__ == '__main__': P = load_school() spacetime.distribution = 'student' spacetime.lrate_s = 1 spacetime.lrate_t = .01 dim = 3 #spacetime_Y,spacetime_Z,E1= spacetime.st_snep( P, dim-1, 1, repeat=1 ) spacetime_Y,spacetime_Z,E2= spacetime.st_snep( P, dim, 0, repeat=3 ) #print( E1, E2 ) visualize( spacetime_Y, spacetime_Z ) #print( spacetime_Z )
from matplotlib.transforms import Bbox fig = plt.figure( figsize=[10,8] ) fig.suptitle( '' ) ax = fig.add_subplot( 111 ) ax.scatter( z[:,0], z[:,1], s=50, linewidths=1 ) #c=z, #cmap='RdYlGn', #vmin=-np.abs( z ).max(), #vmax= np.abs( z ).max() ) plt.show() if __name__ == '__main__': P = load( 3 ) spacetime.distribution = 'student' spacetime.min_epochs = 500 spacetime.lrate_s = 5 spacetime.lrate_t = .01 #dim = 2 spacetime_Y,spacetime_Z,E1= spacetime.st_snep( P, 0, 2, repeat=1 ) #spacetime_Y,spacetime_Z,E2= spacetime.st_snep( P, dim, 0, repeat=10 ) #print( E1, E2 ) visualize( spacetime_Z ) print( spacetime_Z )