noisyTrainSpectra = distort.add_noise(trainSpectra, level=noiseLevel, seed=0) noisyTestSpectra = distort.add_noise(testSpectra, level=noiseLevel, seed=numSpecsTotal) for i in range(3): noisyTrainSpectra = distort.add_distortions(noisyTrainSpectra, level=noiseLevel*2, seed=i * numSpecsTotal) noisyTestSpectra = distort.add_ghost_peaks(noisyTestSpectra, level=noiseLevel*2, seed=2*i * numSpecsTotal) noisyTestSpectra = distort.add_distortions(noisyTestSpectra, level=noiseLevel*2, seed=2*i * numSpecsTotal) noisyTrainSpectra = distort.add_ghost_peaks(noisyTrainSpectra, level=noiseLevel*2, seed=i * numSpecsTotal) print(f'Distorting spectra took {round(time.time()-t0, 2)} seconds') trainSpectra = prepareSpecSet(trainSpectra, addDimension=False) testSpectra = prepareSpecSet(testSpectra, addDimension=False) noisyTrainSpectra = prepareSpecSet(noisyTrainSpectra, addDimension=False) noisyTestSpectra = prepareSpecSet(noisyTestSpectra, addDimension=False) rec: Reconstructor = getDenseReconstructor(dropout=0.0) t0 = time.time() history = rec.fit(noisyTrainSpectra, trainSpectra, epochs=10, validation_data=(noisyTestSpectra, testSpectra), batch_size=32, shuffle=True) print(f"Training took {round(time.time()-t0, 2)} seconds.") t0 = time.time() reconstructedSpecs = rec.call(noisyTestSpectra) print(f'reconstruction took {round(time.time()-t0, 2)} seconds') # histPLot = out.getHistPlot(history.history, annotate=True) specPlot, boxPlot = out.getSpectraComparisons(testSpectra, noisyTestSpectra, reconstructedSpecs, includeSavGol=False, randomIndSeed=9,
noisyTrainSpectra = distort.add_noise(trainSpectra, level=noiseLevel, seed=0) noisyTestSpectra = distort.add_noise(testSpectra, level=noiseLevel, seed=numSpecsTotal) for i in range(3): noisyTrainSpectra = distort.add_distortions(noisyTrainSpectra, level=noiseLevel*2, seed=i * numSpecsTotal) noisyTestSpectra = distort.add_ghost_peaks(noisyTestSpectra, level=noiseLevel*2, seed=2*i * numSpecsTotal) noisyTestSpectra = distort.add_distortions(noisyTestSpectra, level=noiseLevel*2, seed=2*i * numSpecsTotal) noisyTrainSpectra = distort.add_ghost_peaks(noisyTrainSpectra, level=noiseLevel*2, seed=i * numSpecsTotal) print(f'Distorting spectra took {round(time.time()-t0, 2)} seconds') trainSpectra = prepareSpecSet(trainSpectra, addDimension=False) testSpectra = prepareSpecSet(testSpectra, addDimension=False) noisyTrainSpectra = prepareSpecSet(noisyTrainSpectra, addDimension=False) noisyTestSpectra = prepareSpecSet(noisyTestSpectra, addDimension=False) rec: Reconstructor = getDenseReconstructor(dropout=0.0 if randomShuffle else 0.00) t0 = time.time() history = rec.fit(noisyTrainSpectra, trainSpectra, epochs=10, validation_data=(noisyTestSpectra, testSpectra), batch_size=32, shuffle=True) print(f"Training took {round(time.time()-t0, 2)} seconds.") t0 = time.time() reconstructedSpecs = rec.call(noisyTestSpectra) print(f'reconstruction took {round(time.time()-t0, 2)} seconds') noisyTestSpectraEncoded = rec.encoder(noisyTestSpectra) noisyTrainSpectraEncoded = rec.encoder(noisyTrainSpectra) corrPlot = out.getCorrelationPCAPlot(noisyTestSpectraEncoded, reconstructedSpecs, testSpectra, noisyTrainSpectraEncoded)
np.random.seed(42) for i in range(3): noisyTrainSpectra = distort.add_noise(trainSpectra, level=noiseLevel * (i + 1) * 0.5) noisyTrainSpectra = distort.add_distortions(noisyTrainSpectra, level=noiseLevel * (i + 1) * 2) noisyTrainSpectra = distort.add_ghost_peaks(noisyTrainSpectra, level=noiseLevel * (i + 1) * 2) print(f'Distorting spectra took {round(time.time()-t0, 2)} seconds') trainSpectra = prepareSpecSet(trainSpectra) testSpectra = prepareSpecSet(cleanSpecs, transpose=False) noisyTrainSpectra = prepareSpecSet(noisyTrainSpectra) noisyTestSpectra = prepareSpecSet(noisySpecs, transpose=False) rec = getDenseReconstructor(dropout=0.5) history = rec.fit(noisyTrainSpectra, trainSpectra, epochs=10, validation_data=(noisyTestSpectra, testSpectra), batch_size=32, shuffle=True) reconstructedSpecs = rec.call(noisyTestSpectra) specPlot, boxPlot = out.getSpectraComparisons(testSpectra, noisyTestSpectra, reconstructedSpecs, includeSavGol=False, wavenumbers=wavenums, title=experimentTitle)