Beispiel #1
0
def DFTexact(times, f, maxnumharms=20):
    """
    DFTexact(times, f, maxnumharms=20):
       Return an array of 'maxnumharms' complex amplitudes
       corresponding to the harmonics of the 'times' (in sec)
       with a fundamental at frequency 'f' Hz.
    """
    const = -TWOPI*(Num.arange(maxnumharms, dtype=Num.float)+1.0)*f*complex(0.0, 1.0)
    return Num.add.reduce(Num.exp(Num.outerproduct(const,times)), axis=1)
Beispiel #2
0
def DFTexact(times, f, maxnumharms=20):
    """
    DFTexact(times, f, maxnumharms=20):
       Return an array of 'maxnumharms' complex amplitudes
       corresponding to the harmonics of the 'times' (in sec)
       with a fundamental at frequency 'f' Hz.
    """
    const = -TWOPI*(Num.arange(maxnumharms, dtype=Num.float)+1.0)*f*complex(0.0, 1.0)
    return Num.add.reduce(Num.exp(Num.outerproduct(const,times)), axis=1)
    def ComputeHLH(self, y, kernely=vector.CLinearKernel()):
        ny = y.shape
        if len(ny) > 1:
            lMat = kernely.Dot(y, y)
        else:
            lMat = numpy.outerproduct(y, y)

        sL = numpy.sum(lMat, axis=1)
        ssL = numpy.sum(sL)
        # hlhMat
        return lMat - numpy.add.outer(sL, sL)/ny[0] + ssL/(ny[0]*ny[0])
Beispiel #4
0
    def ComputeHLH(self, y, kernely=vector.CLinearKernel()):
        ny = y.shape
        if len(ny) > 1:
            lMat = kernely.Dot(y, y)
        else:
            lMat = numpy.outerproduct(y, y)

        sL = numpy.sum(lMat, axis=1)
        ssL = numpy.sum(sL)
        # hlhMat
        return lMat - numpy.add.outer(sL, sL) / ny[0] + ssL / (ny[0] * ny[0])
    def BiasedHSIC(self, x, y, kernelx=vector.CLinearKernel(), \
                   kernely=vector.CLinearKernel()):
        nx = x.shape
        ny = y.shape
        assert nx[0] == ny[0], \
               "Argument 1 and 2 have different number of data points"

        if len(nx) > 1:
            kMat = kernelx.Dot(x, x)
        else:
            kMat = numpy.outerproduct(x, x)

        hlhMat = ComputeHLH(y, kernely)
        return numpy.sum(numpy.sum(kMat * hlhMat)) / ((nx[0]-1)*(nx[0]-1))
Beispiel #6
0
    def BiasedHSIC(self, x, y, kernelx=vector.CLinearKernel(), \
                   kernely=vector.CLinearKernel()):
        nx = x.shape
        ny = y.shape
        assert nx[0] == ny[0], \
               "Argument 1 and 2 have different number of data points"

        if len(nx) > 1:
            kMat = kernelx.Dot(x, x)
        else:
            kMat = numpy.outerproduct(x, x)

        hlhMat = ComputeHLH(y, kernely)
        return numpy.sum(numpy.sum(kMat * hlhMat)) / ((nx[0] - 1) *
                                                      (nx[0] - 1))
Beispiel #7
0
    def ComputeHLH(self, y, kernely=vector.CLinearKernel()):
        """
        Compute HLH give the labels.
            @param y The labels.
            @param kernely The kernel on the labels, default to linear kernel.
        """
        ny = y.shape
        if len(ny) > 1:
            lMat = kernely.Dot(y, y)
        else:
            lMat = numpy.outerproduct(y, y)

        sL = numpy.sum(lMat, axis=1)
        ssL = numpy.sum(sL)
        # hlhMat
        return lMat - numpy.add.outer(sL, sL) / ny[0] + ssL / (ny[0] * ny[0])
Beispiel #8
0
 def _create_data(self):
     a1 = numpy.arange(10) * 18.0 - 90.
     a2 = numpy.arange(10) * 36.0 - 180.
     d = numpy.outerproduct(numpy.sin(a1*numpy.pi/360.), 
                         numpy.cos(a2*numpy.pi/360.))
     d.shape=(1,1,10,10)
     a1a = cdms.createAxis(a1)
     a1a.designateLatitude()
     a2a = cdms.createAxis(a2)
     a2a.designateLongitude()
     a3a = cdms.createAxis([1979.])
     a3a.designateTime()
     a4a = cdms.createAxis([0.5])
     a4a.designateLevel()
     data = cdms.MV2.array(d, axes=[a3a, a4a, a1a ,a2a])
     self.data = data
Beispiel #9
0
 def _create_data(self):
     a1 = numpy.arange(10) * 18.0 - 90.
     a2 = numpy.arange(10) * 36.0 - 180.
     d = numpy.outerproduct(numpy.sin(a1 * numpy.pi / 360.),
                            numpy.cos(a2 * numpy.pi / 360.))
     d.shape = (1, 1, 10, 10)
     a1a = cdms.createAxis(a1)
     a1a.designateLatitude()
     a2a = cdms.createAxis(a2)
     a2a.designateLongitude()
     a3a = cdms.createAxis([1979.])
     a3a.designateTime()
     a4a = cdms.createAxis([0.5])
     a4a.designateLevel()
     data = cdms.MV2.array(d, axes=[a3a, a4a, a1a, a2a])
     self.data = data
Beispiel #10
0
    def BiasedHSIC(self, x, y, kernelx=vector.CLinearKernel(), kernely=vector.CLinearKernel()):
        """
        Compute the biased estimator of HSIC.
            @param x The data.
            @param y The labels.
            @param kernelx The kernel on the data, default to linear kernel.
            @param kernely The kernel on the labels, default to linear kernel.
        """

        nx = x.shape
        ny = y.shape
        assert nx[0] == ny[0], \
            "Argument 1 and 2 have different number of data points"

        if len(nx) > 1:
            kMat = kernelx.Dot(x, x)
        else:
            kMat = numpy.outerproduct(x, x)

        hlhMat = self.ComputeHLH(y, kernely)
        return numpy.sum(numpy.sum(kMat * hlhMat)) / ((nx[0] - 1) * (nx[0] - 1))
Beispiel #11
0
# Recenter on center of mass of selection
ca_pos -= ca_com[:,np.newaxis]
kg = asel.masses()*(1.6605388e-27)
# Remove rotational degrees of freedom
ref = ca_pos[0]
for coor in ca_pos[1:]:
    rotmatrix =rotation_matrix(coor, ref, kg)
    coor[:] =coor*rotmatrix

ca = np.reshape(ca_pos, (num_ts, -1))
ca_avg = np.average(ca)
ca2 = ca - ca_avg[np.newaxis,:]
ca_cov = np.zeros((num_coor, num_coor),np.float)
for ts in ca2:
    ca_cov += np.outerproduct(ts, ts)
ca_cov /= num_ts
ca_cov1 = ca_cov*mass_matrix
del ca_cov
ca_cov2 = np.dot(mass_matrix, ca_cov1)
del ca_cov1

N_av = 6.0221367e23
hplanck_bar = 6.6260755e-34/(2*np.pi)
k =  1.3806580000000001e-23
T = 300 # kelvin
eigenv, eigenvec = np.linalg.eigvals(ca_cov2)
real = [e.real/100. for e in eigenv]
f = file('eigenval.dat', 'w')
for i, val in enumerate(real):
    f.write(`i+1` + '\t' + `val` + '\n')
Beispiel #12
0
# Recenter on center of mass of selection
ca_pos -= ca_com[:, np.NewAxis]

# Remove rotational degrees of freedom
ref = ca_pos[0]
for coor in ca_pos[1:]:
    rotmatrix = rms_fitting.rms_rotation_matrix(coor, ref, kg)
    coor[:] = np.matrixmultiply(coor, rotmatrix).astype(np.Float32)

ca = np.reshape(ca_pos, (num_ts, -1))
ca_avg = np.average(ca)
ca2 = ca - ca_avg[np.NewAxis, :]
ca_cov = np.zeros((num_coor, num_coor), np.Float)
for ts in ca2:
    ca_cov += np.outerproduct(ts, ts)
ca_cov /= num_ts
ca_cov1 = np.matrixmultiply(ca_cov, mass_matrix)
del ca_cov
ca_cov2 = np.matrixmultiply(mass_matrix, ca_cov1)
del ca_cov1

N_av = 6.0221367e23
hplanck_bar = 6.6260755e-34 / (2 * np.pi)
k = 1.3806580000000001e-23
T = 300  # kelvin
eigenv, eigenvec = la.eigenvectors(ca_cov2)
real = [e.real / 100. for e in eigenv]
f = open('eigenval.dat', 'w')
for i, val in enumerate(real):
    f.write( ` i + 1 ` + '\t' + ` val ` + '\n')