Exemple #1
0
    def __init__(
        self,
        model,
        outputName,
        loudnessLevelFunction=None,
        loudnessLevel='abs'
    ):

        self.iterator = StationaryLoudnessIterator(
            model,
            outputName,
            loudnessLevelFunction
        )

        self.targetLoudnessLevel = loudnessLevel
        self.tol = 0.02
        self.nIters = 20
        self.predictions = None
        self.converged = False
        self.alpha = 0.5

        if ((type(loudnessLevel) is str) or (loudnessLevel == 2.4)):
            self.freqs = freqsISO389
            self.sPLs = thresholdsISO389
            self.targetLoudnessLevel = 2.4
        else:
            contour = ISO2262003LoudnessContours()
            self.freqs, self.sPLs = contour.phonToSPL(
                None,
                loudnessLevel
            )
Exemple #2
0
class StationaryLoudnessContourPredictor():

    def __init__(self, model, outputName, loudnessLevelFunction = None, loudnessLevel = 'abs'):

        self.iterator = StationaryLoudnessIterator(model, outputName, loudnessLevelFunction)

        self.targetLoudnessLevel = loudnessLevel
        self.tol = 0.02
        self.nIters = 20
        self.predictions = None
        self.converged = False
        self.alpha = 0.5

        if ((type(loudnessLevel) is str) or (loudnessLevel == 2.4)):
            self.freqs = freqsISO389
            self.sPLs = thresholdsISO389
            self.targetLoudnessLevel = 2.4
        else:
            contour = ISO2262003LoudnessContours()
            sef.freqs, self.sPLs = contour.phonToSPL(None, loudnessLevel)

    def process(self):

        self.predictions = np.zeros(self.freqs.size)
        self.converged = np.zeros(self.freqs.size, dtype = bool)
        for i, freq in enumerate(self.freqs):
            print 'Freq: %0.2f, initial guess: %0.2f' % (freq, self.sPLs[i])
            levels = np.zeros(self.freqs.size) - 100
            levels[i] = self.sPLs[i]
            self.predictions[i] = self.sPLs[i]
            self.predictions[i] += self.iterator.process(self.freqs,
                    levels, 
                    None,
                    self.targetLoudnessLevel, 
                    self.tol, 
                    self.nIters,
                    self.alpha)
            self.converged[i] = self.iterator.converged

    def plotPredictions(self):

        plt.semilogx(self.freqs, self.sPLs, label = 'ISO target')
        plt.semilogx(self.freqs, self.predictions, color = 'r', 
                linestyle = '--', label = 'Predicted')
        plt.legend()
        plt.show()

    def computeErrors(self):
        '''
        Returns a tuple of error vector (target - prediction), RMSE and maximum
        absolute error.
        '''
        error = self.sPLs - self.predictions
        rMSE = np.sqrt(np.mean(error * error))
        maxE = np.max(np.abs(error))
        return (error, rMSE, maxE)

    def getResults(self):
        outputDic = {}
        outputDic['Errors'], outputDic['RMSE'], outputDic['MXAE'] = self.computeErrors()
        outputDic['Frequencies'] = self.freqs
        outputDic['Targets'] = self.sPLs
        outputDic['Predictions'] = self.predictions
        outputDic['Converged'] = self.converged
        return outputDic
Exemple #3
0
class StationaryLoudnessContourPredictor():

    def __init__(
        self,
        model,
        outputName,
        loudnessLevelFunction=None,
        loudnessLevel='abs'
    ):

        self.iterator = StationaryLoudnessIterator(
            model,
            outputName,
            loudnessLevelFunction
        )

        self.targetLoudnessLevel = loudnessLevel
        self.tol = 0.02
        self.nIters = 20
        self.predictions = None
        self.converged = False
        self.alpha = 0.5

        if ((type(loudnessLevel) is str) or (loudnessLevel == 2.4)):
            self.freqs = freqsISO389
            self.sPLs = thresholdsISO389
            self.targetLoudnessLevel = 2.4
        else:
            contour = ISO2262003LoudnessContours()
            self.freqs, self.sPLs = contour.phonToSPL(
                None,
                loudnessLevel
            )

    def process(self):

        self.predictions = np.zeros(self.freqs.size)
        self.converged = np.zeros(
            self.freqs.size,
            dtype=bool
        )
        for i, freq in enumerate(self.freqs):
            print 'Freq: %0.2f, initial guess: %0.2f' % (freq, self.sPLs[i])
            levels = np.zeros(self.freqs.size) - 100
            levels[i] = self.sPLs[i]
            self.predictions[i] = self.sPLs[i]
            self.predictions[i] += self.iterator.process(
                self.freqs,
                levels,
                None,
                self.targetLoudnessLevel,
                self.tol,
                self.nIters,
                self.alpha
            )
            self.converged[i] = self.iterator.converged

    def plotPredictions(self):

        plt.semilogx(self.freqs, self.sPLs, label='ISO target')
        plt.semilogx(
            self.freqs, self.predictions, color='r',
            linestyle='--', label='Predicted')
        plt.legend()
        plt.show()

    def computeErrors(self):
        '''
        Returns a tuple of error vector (target - prediction), RMSE and maximum
        absolute error.
        '''
        error = self.sPLs - self.predictions
        rMSE = np.sqrt(np.mean(error * error))
        maxE = np.max(np.abs(error))
        return (error, rMSE, maxE)

    def getResults(self):
        outputDic = {}
        outputDic['Errors'], outputDic['RMSE'], outputDic['MXAE'] = \
            self.computeErrors()

        outputDic['Frequencies'] = self.freqs
        outputDic['Targets'] = self.sPLs
        outputDic['Predictions'] = self.predictions
        outputDic['Converged'] = self.converged
        return outputDic