Пример #1
0
    def _updateWei(self):

        ###########
        ## Stats ##
        ###########

        fr = self.statsFrame

        # lambda
        lamb = self.currentParameters["lambda"]
        lambdaStr = helper_functions.roundToSF(lamb, NUMBER_OF_SF)
        fr.weiLambdaE.insertNew(lamb)

        # k
        k = self.currentParameters["k"]
        kStr = helper_functions.roundToSF(k, NUMBER_OF_SF)
        fr.weiKE.insertNew(k)

        # theta
        theta = self.currentParameters["theta"]
        thetaStr = helper_functions.roundToSF(theta, NUMBER_OF_SF)
        fr.weiThetaE.insertNew(theta)

        # Volume
        volume = calculateWeibullVolume(lamb, k, theta)
        volumeStr = helper_functions.roundToSF(volume, NUMBER_OF_SF)
        fr.totalEstimatedVolume_E.insertNew(volumeStr)

        # Error
        thicknessFunction = lambda x: theta * (
            (x / lamb)**(k - 2)) * math.exp(-((x / lamb)**k))
        error = regression_methods.meanRelativeSquaredError(
            self.sqrtAreaKM, self.thicknessM, thicknessFunction)
        errorStr = helper_functions.roundToSF(error, NUMBER_OF_SF)
        fr.relativeSquaredError_E.insertNew(errorStr)

        # Equation
        invLambdaStr = helper_functions.roundToSF(1 / lamb, NUMBER_OF_SF)
        kminus2Str = helper_functions.roundToSF(k - 2, NUMBER_OF_SF)
        equationStr = "T = " + thetaStr + "((" + invLambdaStr + "x)^" + kminus2Str + ")exp(-(" + invLambdaStr + "x)^" + kStr + ")"
        fr.equation_E.insertNew(equationStr)

        ############
        ## Graphs ##
        ############

        # Model
        startX = 0
        endX = (self.isopachs[-1].distanceFromVentKM() + 50) * SQRT_PI
        xs = helper_functions.getStaggeredPoints(startX, endX,
                                                 MODEL_PLOTTING_PRECISION)[1:]
        ys = [
            theta * ((x / lamb)**(k - 2)) * math.exp(-((x / lamb)**k))
            for x in xs
        ]
        self.modelGraphFrame.plotFilledLine(xs, ys, colours[0])
Пример #2
0
	def _updateWei(self):
		
		###########
		## Stats ##
		###########

		fr = self.statsFrame

		# lambda
		lamb = self.currentParameters["lambda"]
		lambdaStr = helper_functions.roundToSF(lamb, NUMBER_OF_SF)
		fr.weiLambdaE.insertNew(lamb)

		# k
		k = self.currentParameters["k"]
		kStr = helper_functions.roundToSF(k, NUMBER_OF_SF)
		fr.weiKE.insertNew(k)

		# theta
		theta = self.currentParameters["theta"]
		thetaStr = helper_functions.roundToSF(theta, NUMBER_OF_SF)
		fr.weiThetaE.insertNew(theta)

		# Volume
		volume = calculateWeibullVolume(lamb, k, theta)
		volumeStr = helper_functions.roundToSF(volume, NUMBER_OF_SF)
		fr.totalEstimatedVolume_E.insertNew(volumeStr)

		# Error
		thicknessFunction = lambda x : theta*((x/lamb)**(k-2))*math.exp(-((x/lamb)**k))
		error = regression_methods.meanRelativeSquaredError(self.sqrtAreaKM, self.thicknessM, thicknessFunction)
		errorStr = helper_functions.roundToSF(error, NUMBER_OF_SF)
		fr.relativeSquaredError_E.insertNew(errorStr)

		# Equation
		invLambdaStr = helper_functions.roundToSF(1/lamb, NUMBER_OF_SF)
		kminus2Str = helper_functions.roundToSF(k-2, NUMBER_OF_SF)
		equationStr = "T = " + thetaStr + "((" + invLambdaStr + "x)^" +kminus2Str + ")exp(-(" + invLambdaStr + "x)^" + kStr + ")"
		fr.equation_E.insertNew(equationStr)




		############
		## Graphs ##
		############

		# Model
		startX = 0
		endX = (self.isopachs[-1].distanceFromVentKM()+50)*SQRT_PI
		xs = helper_functions.getStaggeredPoints(startX,endX,MODEL_PLOTTING_PRECISION)[1:]
		ys = [theta*((x/lamb)**(k-2))*math.exp(-((x/lamb)**k)) for x in xs]
		self.modelGraphFrame.plotFilledLine(xs, ys, colours[0])
Пример #3
0
	def _updatePow(self):

		###########
		## Stats ##
		###########

		fr = self.statsFrame

		# Coefficient
		c = self.currentParameters["coefficient"]
		coefficientStr = helper_functions.roundToSF(c, NUMBER_OF_SF)
		fr.powCoefficient_E.insertNew(c)

		# Exponent
		m = self.currentParameters["exponent"]
		exponentStr = helper_functions.roundToSF(m, NUMBER_OF_SF)
		fr.powExponent_E.insertNew(m)

		# Proximal limit
		proximalLimitKM = self.currentParameters["proximalLimitKM"]
		proximalLimitStr = helper_functions.roundToSF(proximalLimitKM, NUMBER_OF_SF)
		fr.powProximalLimit_E.insertNew(proximalLimitKM)

		# Distal limit
		distalLimitKM = self.currentParameters["distalLimitKM"]
		distalLimitStr = helper_functions.roundToSF(distalLimitKM, NUMBER_OF_SF)
		fr.powDistalLimit_E.insertNew(distalLimitKM)

		# Volume
		volume = calculatePowerLawVolume(c, m, proximalLimitKM, distalLimitKM)
		volumeStr = helper_functions.roundToSF(volume, NUMBER_OF_SF)
		fr.totalEstimatedVolume_E.insertNew(volumeStr)

		# Error
		thicknessFunction = lambda x : c*(x**(-m))
		error = regression_methods.meanRelativeSquaredError(self.sqrtAreaKM, self.thicknessM, thicknessFunction)
		errorStr = helper_functions.roundToSF(error, NUMBER_OF_SF)
		fr.relativeSquaredError_E.insertNew(errorStr)

		# Equation
		equationStr = "T = " + coefficientStr
		if m > 0:
			equationStr += "x^-" + exponentStr
		elif m < 0:
			equationStr += "x^" + exponentStr[1:]
		fr.equation_E.insertNew(equationStr)

		# Suggested proximal limit
		suggestedProximalLimit = self.currentParameters["suggestedProximalLimit"]
		suggestedProximalLimitStr = helper_functions.roundToSF(suggestedProximalLimit, NUMBER_OF_SF)
		fr.powSuggestedProximalLimit_E.insertNew(suggestedProximalLimitStr)


		############
		## Graphs ##
		############

		startX = proximalLimitKM*SQRT_PI
		endX = distalLimitKM*SQRT_PI

		# Model
		xs = helper_functions.getStaggeredPoints(startX, endX, MODEL_PLOTTING_PRECISION)
		ys = [thicknessFunction(x) for x in xs]
		self.modelGraphFrame.plotFilledLine(xs, ys, color=colours[0])

		# Regression
		logXs = [np.log(a) for a in self.sqrtAreaKM]
		logYs = [np.log(t) for t in self.thicknessM]
		self.regressionGraphFrame.plotScatter(logXs, logYs, False)

		self.regressionGraphFrame.axes.set_xlabel(r"$\log{\sqrt{Area}}$")
		lineXs = [np.sqrt(startX), np.sqrt(endX)]
		lineYs = [np.log(c) - m*x for x in lineXs]
		self.regressionGraphFrame.plotLine(lineXs, lineYs, colours[0])
Пример #4
0
	def _updateExp(self, comboboxUpdate):

		n = self.currentParameters["numberOfSegments"]
		coefficients = self.currentParameters["segmentCoefficients"]
		exponents = self.currentParameters["segmentExponents"]
		limits = self.currentParameters["segmentLimits"]

		###########
		## Stats ##
		###########

		fr = self.statsFrame

		# Segment start
		start = limits[self.currentSegment]
		startStr = helper_functions.roundToSF(start, NUMBER_OF_SF)
		fr.expSegStartLimit_E.insertNew(start)
		fr.expSegStartLimit_E.setUserEditable(self.currentSegment != 0)

		# Segment end
		end = limits[self.currentSegment+1]
		endStr = helper_functions.roundToSF(end, NUMBER_OF_SF)
		fr.expSegEndLimit_E.insertNew(end)
		fr.expSegEndLimit_E.setUserEditable(self.currentSegment != n-1)

		# Segment coefficient
		coefficient = coefficients [self.currentSegment]
		coefficientStr = helper_functions.roundToSF(coefficient, NUMBER_OF_SF)
		fr.expSegCoefficent_E.insertNew(coefficient)

		# Segment exponent
		exponent = exponents[self.currentSegment]
		exponentStr = helper_functions.roundToSF(exponent, NUMBER_OF_SF)
		fr.expSegExponent_E.insertNew(exponent)

		# Segment volume
		segmentVolumes = [calculateExponentialSegmentVolume(coefficients[i], exponents[i], limits[i], limits[i+1]) for i in range(n)]
		segmentVolumeStr = helper_functions.roundToSF(segmentVolumes[self.currentSegment], NUMBER_OF_SF)
		fr.expSegVolume_E.insertNew(segmentVolumeStr)

		# Total volume
		totalVolume = sum(segmentVolumes)
		estimatedTotalVolumeStr = helper_functions.roundToSF(totalVolume, NUMBER_OF_SF)
		fr.totalEstimatedVolume_E.insertNew(estimatedTotalVolumeStr)

		# Error
		def thicknessFunction(x):
			for i in range(n):
				if limits[i] <= x < limits[i+1]:
					return coefficients[i]*math.exp(-exponents[i]*x)
		error = regression_methods.meanRelativeSquaredError(self.sqrtAreaKM, self.thicknessM, thicknessFunction)
		errorStr = helper_functions.roundToSF(error, NUMBER_OF_SF)
		fr.relativeSquaredError_E.insertNew(errorStr)

		# Equation
		equationStr = "T = " + coefficientStr
		if exponent > 0:
			equationStr += "exp(-" + exponentStr + "x)"
		elif exponent < 0:
			equationStr += "exp(" + exponentStr[1:] + "x)"
		fr.equation_E.insertNew(equationStr)



		############
		## Graphs ##
		############

		if not comboboxUpdate:
			# Model

			endXs = limits[1:-1] + [1.5*max(self.sqrtAreaKM)-0.5*min(self.sqrtAreaKM)]

			for i in range(n):
				xs = helper_functions.getStaggeredPoints(limits[i], endXs[i], MODEL_PLOTTING_PRECISION)
				ys = [coefficients[i]*math.exp(-exponents[i]*x) for x in xs]
				self.modelGraphFrame.plotFilledLine(xs, ys, color=colours[i])

			# Regression
			logThicknessM = [np.log(t) for t in self.thicknessM]
			self.regressionGraphFrame.plotScatter(self.sqrtAreaKM, logThicknessM, False)
			self.regressionGraphFrame.axes.set_xlabel(r"$\sqrt{Area}$")

			for i in range(n):
				xs = [limits[i], endXs[i]]
				ys = [np.log(thicknessFunction(x)) for x in xs]
				self.regressionGraphFrame.plotLine(xs,ys, color=colours[i])
Пример #5
0
	def _updatePow(self):
		
		###########
		## Stats ##
		###########

		fr = self.statsFrame

		# Coefficient
		c = self.currentParameters["coefficient"]
		coefficientStr = helper_functions.roundToSF(c, NUMBER_OF_SF)
		fr.powCoefficient_E.insertNew(c)

		# Exponent
		m = self.currentParameters["exponent"] 
		exponentStr = helper_functions.roundToSF(m, NUMBER_OF_SF)
		fr.powExponent_E.insertNew(m)

		# Proximal limit
		proximalLimitKM = self.currentParameters["proximalLimitKM"]
		proximalLimitStr = helper_functions.roundToSF(proximalLimitKM, NUMBER_OF_SF)
		fr.powProximalLimit_E.insertNew(proximalLimitKM)
		
		# Distal limit
		distalLimitKM = self.currentParameters["distalLimitKM"]
		distalLimitStr = helper_functions.roundToSF(distalLimitKM, NUMBER_OF_SF)
		fr.powDistalLimit_E.insertNew(distalLimitKM)
		
		# Volume
		volume = calculatePowerLawVolume(c, m, proximalLimitKM, distalLimitKM)
		volumeStr = helper_functions.roundToSF(volume, NUMBER_OF_SF)
		fr.totalEstimatedVolume_E.insertNew(volumeStr)

		# Error
		thicknessFunction = lambda x : c*(x**(-m))
		error = regression_methods.meanRelativeSquaredError(self.sqrtAreaKM, self.thicknessM, thicknessFunction)
		errorStr = helper_functions.roundToSF(error, NUMBER_OF_SF)
		fr.relativeSquaredError_E.insertNew(errorStr)

		# Equation
		equationStr = "T = " + coefficientStr
		if m > 0:
			equationStr += "x^-" + exponentStr
		elif m < 0:
			equationStr += "x^" + exponentStr[1:]
		fr.equation_E.insertNew(equationStr)

		# Suggested proximal limit
		suggestedProximalLimit = self.currentParameters["suggestedProximalLimit"]
		suggestedProximalLimitStr = helper_functions.roundToSF(suggestedProximalLimit, NUMBER_OF_SF)
		fr.powSuggestedProximalLimit_E.insertNew(suggestedProximalLimitStr)


		############
		## Graphs ##
		############

		startX = proximalLimitKM*SQRT_PI
		endX = distalLimitKM*SQRT_PI

		# Model
		xs = helper_functions.getStaggeredPoints(startX, endX, MODEL_PLOTTING_PRECISION)
		ys = [thicknessFunction(x) for x in xs]
		self.modelGraphFrame.plotFilledLine(xs, ys, color=colours[0])

		# Regression
		logXs = [np.log(a) for a in self.sqrtAreaKM]
		logYs = [np.log(t) for t in self.thicknessM]
		self.regressionGraphFrame.plotScatter(logXs, logYs, False)

		self.regressionGraphFrame.axes.set_xlabel(r"$\log{\sqrt{Area}}$")
		lineXs = [np.sqrt(startX), np.sqrt(endX)]
		lineYs = [np.log(c) - m*x for x in lineXs]
		self.regressionGraphFrame.plotLine(lineXs, lineYs, colours[0])
Пример #6
0
	def _updateExp(self, comboboxUpdate):
		
		n = self.currentParameters["numberOfSegments"]
		coefficients = self.currentParameters["segmentCoefficients"]
		exponents = self.currentParameters["segmentExponents"]
		limits = self.currentParameters["segmentLimits"]

		###########
		## Stats ##
		###########

		fr = self.statsFrame

		# Segment start
		start = limits[self.currentSegment]
		startStr = helper_functions.roundToSF(start, NUMBER_OF_SF)
		fr.expSegStartLimit_E.insertNew(start)
		fr.expSegStartLimit_E.setUserEditable(self.currentSegment != 0)

		# Segment end
		end = limits[self.currentSegment+1]
		endStr = helper_functions.roundToSF(end, NUMBER_OF_SF)
		fr.expSegEndLimit_E.insertNew(end)
		fr.expSegEndLimit_E.setUserEditable(self.currentSegment != n-1)

		# Segment coefficient
		coefficient = coefficients [self.currentSegment]
		coefficientStr = helper_functions.roundToSF(coefficient, NUMBER_OF_SF)
		fr.expSegCoefficent_E.insertNew(coefficient)
		
		# Segment exponent
		exponent = exponents[self.currentSegment]
		exponentStr = helper_functions.roundToSF(exponent, NUMBER_OF_SF)
		fr.expSegExponent_E.insertNew(exponent)
		
		# Segment volume
		segmentVolumes = [calculateExponentialSegmentVolume(coefficients[i], exponents[i], limits[i], limits[i+1]) for i in range(n)]
		segmentVolumeStr = helper_functions.roundToSF(segmentVolumes[self.currentSegment], NUMBER_OF_SF)
		fr.expSegVolume_E.insertNew(segmentVolumeStr)

		# Total volume
		totalVolume = sum(segmentVolumes)
		estimatedTotalVolumeStr = helper_functions.roundToSF(totalVolume, NUMBER_OF_SF)
		fr.totalEstimatedVolume_E.insertNew(estimatedTotalVolumeStr)

		# Error 
		def thicknessFunction(x):
			for i in range(n):
				if limits[i] <= x < limits[i+1]:
					return coefficients[i]*math.exp(-exponents[i]*x)
		error = regression_methods.meanRelativeSquaredError(self.sqrtAreaKM, self.thicknessM, thicknessFunction)
		errorStr = helper_functions.roundToSF(error, NUMBER_OF_SF)
		fr.relativeSquaredError_E.insertNew(errorStr)

		# Equation
		equationStr = "T = " + coefficientStr
		if exponent > 0:
			equationStr += "exp(-" + exponentStr + "x)"
		elif exponent < 0:
			equationStr += "exp(" + exponentStr[1:] + "x)"
		fr.equation_E.insertNew(equationStr)



		############
		## Graphs ##
		############
		
		if not comboboxUpdate:
			# Model

			endXs = limits[1:-1] + [1.5*max(self.sqrtAreaKM)-0.5*min(self.sqrtAreaKM)]

			for i in range(n):
				xs = helper_functions.getStaggeredPoints(limits[i], endXs[i], MODEL_PLOTTING_PRECISION)
				ys = [coefficients[i]*math.exp(-exponents[i]*x) for x in xs]
				self.modelGraphFrame.plotFilledLine(xs, ys, color=colours[i])

			# Regression
			logThicknessM = [np.log(t) for t in self.thicknessM]
			self.regressionGraphFrame.plotScatter(self.sqrtAreaKM, logThicknessM, False)
			self.regressionGraphFrame.axes.set_xlabel(r"$\sqrt{Area}$")
			
			for i in range(n):
				xs = [limits[i], endXs[i]]
				ys = [np.log(thicknessFunction(x)) for x in xs]
				self.regressionGraphFrame.plotLine(xs,ys, color=colours[i])