def createDictionary(self):
        fileName = QtGui.QFileDialog.getSaveFileName(self , 'Save dictionary to a file' , expanduser('~')+'/dictionary' , 'Matlab file (*.mat);;Python pickle (*.p);;Comma sep. values (*.csv);;Excel file (*.xlsx)')
        if len(fileName) == 0:
            return
        self.displayInformation('Saving dictionary...' , flag='new')
        
        fileName = str(fileName)

        self.setDictionaryConfig()
        self.setAlgorithmConfig()

        config = generateFinalConfig(self.dictionaryConfig , self.dataMatrixes[self.filePath][1] , self.dataMatrixes[self.filePath][2])
        time   = np.arange(0,self.dataMatrixes[self.filePath][1]['numberOfSamples'])
        
        dictionary = generateDictionary(time , config)

        if fileName[-4:] == '.mat':
            dic = {col_name : dictionary[col_name].values for col_name in dictionary.columns.values}
            savemat(fileName , dic)
        elif fileName[-2:] == '.p':
            dictionary.to_pickle(fileName)
        elif fileName[-4:] == '.csv':
            dictionary.to_csv(fileName)
        elif fileName[-5:] == '.xlsx':
            dictionary.to_excel(fileName, sheet_name='dictionary')
        
        self.displayInformation('Dictionary saved.' , flag='new')
	def initializeVariables(self , dataMatrixes , dictionaryConfig):
		self.input  = dataMatrixes
		self.output = []

		self.files2run     = self.input.keys()
		self.numberOfFiles = len(self.input)

		maximumLength = 0
		for f in self.files2run:
			if self.input[f][1]['numberOfSamples'] > maximumLength:
				maximumLength = self.input[f][1]['numberOfSamples']
		self.timeVector = np.arange(0,maximumLength)

		self.dictionaryConfig = dictionaryConfig
		self.dictionary       = generateDictionary(self.timeVector , retranslateDictionaryConfig(self.dictionaryConfig))
Beispiel #3
0
    def initializeVariables(self, dataMatrixes, dictionaryConfig):
        self.input = dataMatrixes
        self.output = []

        self.files2run = self.input.keys()
        self.numberOfFiles = len(self.input)

        maximumLength = 0
        for f in self.files2run:
            if self.input[f][1]['numberOfSamples'] > maximumLength:
                maximumLength = self.input[f][1]['numberOfSamples']
        self.timeVector = np.arange(0, maximumLength)

        self.dictionaryConfig = dictionaryConfig
        self.dictionary = generateDictionary(
            self.timeVector,
            retranslateDictionaryConfig(self.dictionaryConfig))
	config['flags']                            = flags
	config['algorithm']                        = 'smp'
	config['minS']                             = 32
	config['maxS']                             = numberOfSamples
	config['density']                          = 0.01
	config['maxNumberOfIterations']            = 4
	config['minEnergyExplained']               = 0.99
	config['samplingFrequency']                = samplingFrequency
	config['minNFFT']                          = 256 # 2*samplingFrequency

# optional config for t-f map drawing
	# config['mapFreqRange']    = [0.0 , samplingFrequency/2]
	# config['mapStructFreqs']  = [0.0 , samplingFrequency/2]
	# config['mapStructSigmas'] = [0.0 , 4.0]
	
	dictionary = generateDictionary(time , config)

	book       = calculateMP(dictionary , signal , config)
	# print book

# plot resulting functions
	plt.figure()
	plt.subplot(4,1,1)
	plt.plot(time,signal,'k')
	plt.plot(time,sum(book['reconstruction']).real , 'r')

	plt.subplot(4,1,2)
	plt.plot(time,book['reconstruction'][0].real , 'r')

	plt.subplot(4,1,3)
	plt.plot(time,book['reconstruction'][1].real , 'r')
flags['useRectA'] = 0
flags['useGradientOptimization'] = 1
flags['displayInfo'] = 0

config = {}
config['flags'] = flags
config['algorithm'] = 'smp'
config['minS'] = 32
config['maxS'] = numberOfSamples
config['density'] = 0.01
config['maxNumberOfIterations'] = 4
config['minEnergyExplained'] = 0.99
config['samplingFrequency'] = samplingFrequency
config['minNFFT'] = 2 * samplingFrequency

dictionary = generateDictionary(time, config)
book = calculateMP(dictionary, signal, config)

flags = {}
flags['useAsymA'] = 1
flags['useRectA'] = 0
flags['useGradientOptimization'] = 1
flags['displayInfo'] = 0
config['flags'] = flags

advancedDictionary = generateDictionary(time, config)
advancedBook = calculateMP(advancedDictionary, advancedSignal, config)

flags = {}
flags['useAsymA'] = 1
flags['useRectA'] = 1
    config['flags'] = flags
    config['algorithm'] = 'smp'
    config['minS'] = 32
    config['maxS'] = numberOfSamples
    config['density'] = 0.01
    config['maxNumberOfIterations'] = 4
    config['minEnergyExplained'] = 0.99
    config['samplingFrequency'] = samplingFrequency
    config['minNFFT'] = 256  # 2*samplingFrequency

    # optional config for t-f map drawing
    # config['mapFreqRange']    = [0.0 , samplingFrequency/2]
    # config['mapStructFreqs']  = [0.0 , samplingFrequency/2]
    # config['mapStructSigmas'] = [0.0 , 4.0]

    dictionary = generateDictionary(time, config)

    book = calculateMP(dictionary, signal, config)
    # print book

    # plot resulting functions
    plt.figure()
    plt.subplot(4, 1, 1)
    plt.plot(time, signal, 'k')
    plt.plot(time, sum(book['reconstruction']).real, 'r')

    plt.subplot(4, 1, 2)
    plt.plot(time, book['reconstruction'][0].real, 'r')

    plt.subplot(4, 1, 3)
    plt.plot(time, book['reconstruction'][1].real, 'r')
flags["useRectA"] = 0
flags["useGradientOptimization"] = 1
flags["displayInfo"] = 0

config = {}
config["flags"] = flags
config["algorithm"] = "smp"
config["minS"] = 32
config["maxS"] = numberOfSamples
config["density"] = 0.01
config["maxNumberOfIterations"] = 4
config["minEnergyExplained"] = 0.99
config["samplingFrequency"] = samplingFrequency
config["minNFFT"] = 2 * samplingFrequency

dictionary = generateDictionary(time, config)
book = calculateMP(dictionary, signal, config)

flags = {}
flags["useAsymA"] = 1
flags["useRectA"] = 0
flags["useGradientOptimization"] = 1
flags["displayInfo"] = 0
config["flags"] = flags

advancedDictionary = generateDictionary(time, config)
advancedBook = calculateMP(advancedDictionary, advancedSignal, config)

flags = {}
flags["useAsymA"] = 1
flags["useRectA"] = 1