def calculateAllAverages(self, start, stop, receiver, emitter, avgMatrix):
        calculateNxxLookUp = mp.memoize(calculateNxx)
        calculateNxyLookUp = mp.memoize(calculateNxy)
        fLookUP = mp.memoize(f)
        gLookUP = mp.memoize(g)

        start = int(float(mp.nstr(start)))
        stop = int(float(mp.nstr(stop)))

        for j in range(start, stop):
            if (start == 0):
                val = (((j * 100) / receiver.nElements) * self.nThreads)
                print(
                    mp.nstr(((j * 100) / receiver.nElements) * self.nThreads,
                            4), "%")

                self.emit(QtCore.SIGNAL('PROGRESS'), val)

            a11 = mp.mpf('0')
            a12 = mp.mpf('0')
            a13 = mp.mpf('0')
            a22 = mp.mpf('0')
            a23 = mp.mpf('0')
            a33 = mp.mpf('0')

            emEle = int(float(mp.nstr(emitter.nElements)))

            for i in range(emEle):
                delx, dely, delz = calculateDistance(
                    emitter.smallBlocksStructure[i],
                    receiver.smallBlocksStructure[j])
                dx = emitter.widthSmall
                dy = emitter.depthSmall
                dz = emitter.heightSmall

                a11 += calculateNxxLookUp(delx, dely, delz, dx, dy, dz,
                                          emitter, fLookUP)
                a12 += calculateNxyLookUp(delx, dely, delz, dx, dy, dz,
                                          emitter, gLookUP)
                a13 += calculateNxyLookUp(delx, delz, dely, dx, dz, dy,
                                          emitter, gLookUP)
                a22 += calculateNxxLookUp(dely, delx, delz, dy, dx, dz,
                                          emitter, fLookUP)
                a23 += calculateNxyLookUp(dely, delz, delx, dy, dz, dx,
                                          emitter, gLookUP)
                # a31 = a13
                # a32 = a23
                a33 += calculateNxxLookUp(delz, dely, delx, dz, dy, dx,
                                          emitter, fLookUP)

            a11 = a11 / emitter.nElements
            a12 = a12 / emitter.nElements
            a13 = a13 / emitter.nElements
            a22 = a22 / emitter.nElements
            a23 = a23 / emitter.nElements
            a33 = a33 / emitter.nElements

            avgMatrix.append([a11, a12, a13, a12, a22, a23, a13, a23, a33])
        return avgMatrix
示例#2
0
    def __init__(
        self,
        func: Func,
        x_range: Tuple[Real, Real],
        derivatives: Dict[int, Func] = None,
        **_,
    ):
        """Initialize AnalyzedFuncBase with explicit MRO.

        Parameters
        ----------
        func
            The function to analyze
        x_range
            The interval of x-values. This is treated as an
            open interval except when finding absolute extrema.
        derivatives
            A dictionary of derivatives. ``derivatives[nth]``
            is the nth derivative of the function.
        _
            Unused arguments intended for other ``AnalyzedFuncBase``
            children.

        """

        self.x_range = Interval(*x_range)
        self._derivatives = derivatives
        self.func_plotted = SaveXY(func)
        self.func_memoized = mp.memoize(self.func_plotted)
示例#3
0
    def derivatives(self) -> Dict[int, Func]:
        """Return all known derivatives of the function.

        Returns
        -------
        derivatives : Dict[int, Callable[[Real], Real]
            A dictionary of known derivatives of the function being
            analyzed.

        """
        if self._derivatives:
            return {
                derivative: mp.memoize(func)
                for derivative, func in self._derivatives.items()
            }
        return {}
示例#4
0
http://christian.mendl.net/pages/software.html
http://nsb-entropy.sourceforge.net
Ilya Nemenman, Fariel Shafee, and William Bialek. Entropy and Inference,
Revisited. arXiv:physics/0108025
Ilya Nemenman, William Bialek, and Rob de Ruyter van Steveninck. Entropy and
information in neural spike trains: Progress on the sampling problem. Physical
Review E 69, 056111 (2004)

"""
 
from mpmath import psi, rf, power, quadgl, mp, memoize
import numpy as np

DPS = 40

psi = memoize(psi)
rf = memoize(rf)
power = memoize(power)

def make_nxkx(n, K):
  """
  Return the histogram of the input histogram n assuming that the number of
  all bins is K.
  
  >>> from numpy import array
  >>> nTest = array([4, 2, 3, 0, 2, 4, 0, 0, 2])
  >>> make_nxkx(nTest, 9)
  {0: 3, 2: 3, 3: 1, 4: 2}
  """
  nxkx = {}
  nn = n[n>0]
示例#5
0
import mpmath as mp

import logging

#define memoize function to improve performance TODO: Evaluate if this is indeed a speedup in terms of performance
memopower = mp.memoize(mp.power)
memolog1p = mp.memoize(mp.log1p)
memoexp = mp.memoize(mp.exp)
memolog = mp.memoize(mp.log)
'''

def calculateKmerLikelihood(observedCounts,expectedCounts,kmerError,k,validKmers):


	#We use a mpmath float to have a sufficiently precise numerical representation
	probability = mp.mpf(0)

	#Split probability for analysis purposes
	unexpectedProbability = mp.mpf(0)
	
	#Calculate default value for expected counts
	sharedKmers = set(observedCounts.keys()).difference(set(expectedCounts.keys()))
	expectedDefaultValue = kmerError*sum(observedCounts.values())/len(sharedKmers)
	#print("Expected Count for Zeros:"+str(expectedDefaultValue))

	for kmerID in validKmers:

		#If we didn't observe a kmer at all we assume we observed it 0 times
		observedCount = 0

		expectedCount = expectedDefaultValue