def testInitHarmonicModel(self): # Define the input, and derive what the output should be freqList = [2.1, 3.4] freqNameList = ["f_1", "f_2"] maxNharmonics = 2 nParameters = 2 * maxNharmonics * len(freqList) covariateName = "t" regressorNames = [ "sin(2*pi*1*f_1*t)", "cos(2*pi*1*f_1*t)", "sin(2*pi*2*f_1*t)", "cos(2*pi*2*f_1*t)", "sin(2*pi*1*f_2*t)", "cos(2*pi*1*f_2*t)", "sin(2*pi*2*f_2*t)", "cos(2*pi*2*f_2*t)", ] designMatrix = np.empty((self.nObservations, nParameters)) runningIndex = 0 for n in range(len(freqList)): for k in range(1, maxNharmonics + 1): designMatrix[:, runningIndex] = np.sin(2 * pi * k * freqList[n] * self.time) designMatrix[:, runningIndex + 1] = np.cos(2 * pi * k * freqList[n] * self.time) runningIndex += 2 # Assert if the output is what it should be harmonicModel = HarmonicModel(self.time, covariateName, freqList, freqNameList, maxNharmonics) self.assertTrue(harmonicModel.nParameters() == nParameters) self.assertTrue(harmonicModel.regressorNames() == regressorNames) self.assertTrue(harmonicModel.nObservations() == self.nObservations) self.assertTrue(np.alltrue(harmonicModel.designMatrix() == designMatrix))
def testInitHarmonicModel(self): # Defining a harmonic model with no covariance matrix should be the # same as one with a diagonal covariance matrix with ones on the diagonal. freqList = [2.1] freqNameList = ["f_1"] maxNharmonics = 1 nParameters = 2 * maxNharmonics * len(freqList) covariateName = "t" regressorNames = ["sin(2*pi*1*f_1*t)", "cos(2*pi*1*f_1*t)"] covMatrixObserv = np.diag(np.ones(self.nObservations)) harmonicModel1 = HarmonicModel(self.time, covariateName, freqList, freqNameList, maxNharmonics) harmonicModel2 = HarmonicModel(self.time, covariateName, freqList, freqNameList, maxNharmonics, covMatrixObserv) self.assertTrue(np.alltrue(harmonicModel1.designMatrix() == harmonicModel2.designMatrix()))
def testInitHarmonicModel(self): # Define the input, and derive what the output should be freqList = [2.1, 3.4] freqNameList = ["f_1", "f_2"] maxNharmonics = 2 nParameters = 2*maxNharmonics*len(freqList) covariateName = "t" regressorNames = ["sin(2*pi*1*f_1*t)", "cos(2*pi*1*f_1*t)", \ "sin(2*pi*2*f_1*t)", "cos(2*pi*2*f_1*t)", \ "sin(2*pi*1*f_2*t)", "cos(2*pi*1*f_2*t)", \ "sin(2*pi*2*f_2*t)", "cos(2*pi*2*f_2*t)"] designMatrix = np.empty((self.nObservations, nParameters)) runningIndex = 0 for n in range(len(freqList)): for k in range(1,maxNharmonics+1): designMatrix[:,runningIndex] = np.sin(2*pi*k*freqList[n]*self.time) designMatrix[:,runningIndex+1] = np.cos(2*pi*k*freqList[n]*self.time) runningIndex += 2 # Assert if the output is what it should be harmonicModel = HarmonicModel(self.time, covariateName, freqList, freqNameList,maxNharmonics) self.assertTrue(harmonicModel.nParameters() == nParameters) self.assertTrue(harmonicModel.regressorNames() == regressorNames) self.assertTrue(harmonicModel.nObservations() == self.nObservations) self.assertTrue(np.alltrue(harmonicModel.designMatrix() == designMatrix))
def testInitHarmonicModel(self): # Defining a harmonic model with no covariance matrix should be the # same as one with a diagonal covariance matrix with ones on the diagonal. freqList = [2.1] freqNameList = ["f_1"] maxNharmonics = 1 nParameters = 2*maxNharmonics*len(freqList) covariateName = "t" regressorNames = ["sin(2*pi*1*f_1*t)", "cos(2*pi*1*f_1*t)"] covMatrixObserv = np.diag(np.ones(self.nObservations)) harmonicModel1 = HarmonicModel(self.time, covariateName, freqList, freqNameList, maxNharmonics) harmonicModel2 = HarmonicModel(self.time, covariateName, freqList, freqNameList, maxNharmonics, covMatrixObserv) self.assertTrue(np.alltrue(harmonicModel1.designMatrix() == harmonicModel2.designMatrix()))