Exemple #1
0
    def GetCorrelationLoadings(self):
        """
        Returns the correlation loadings matrix based on T and inputMatrix.
        For variables in inputMatrix with std = 0, the value 0 is written
        in the correlation loadings matrix instead of 'Nan' as it should be
        (as for example in Matlab)
        """

        # Creates empty matrix for correlation loadings
        self.correlationLoadings = zeros(
            (shape(self.scores)[1], shape(self.originalMatrix)[1]), Float)

        # Calculates correlation loadings with formula:
        # correlation = cov(x,y)/(std(x)*std(y))

        # For each PC in score matrix
        for PC in range(shape(self.scores)[1]):
            PCscores = self.scores[:, PC]
            PCscoresSTD = std(PCscores)

            # For each variable/attribute in original matrix (not meancentered)
            for var in range(shape(self.originalMatrix)[1]):
                origVar = self.originalMatrix[:, var]
                origVarSTD = std(origVar)

                # If std = 0 for any variable an OverflowError occurs.
                # In such a case the value 0 is written in the matrix
                try:
                    self.correlationLoadings[PC, var] = cov(
                        PCscores, origVar) / (PCscoresSTD * origVarSTD)

                except OverflowError:
                    self.correlationLoadings[PC, var] = 0

        return self.correlationLoadings
Exemple #2
0
    def GetCorrelationLoadings(self):
        """
        Returns the correlation loadings matrix based on T and inputMatrix.
        For variables in inputMatrix with std = 0, the value 0 is written
        in the correlation loadings matrix instead of 'Nan' as it should be
        (as for example in Matlab)
        """

        # Creates empty matrix for correlation loadings
        self.correlationLoadings = zeros((shape(self.scores)[1], shape(self.originalMatrix)[1]), Float)

        # Calculates correlation loadings with formula:
        # correlation = cov(x,y)/(std(x)*std(y))

        # For each PC in score matrix
        for PC in range(shape(self.scores)[1]):
            PCscores = self.scores[:, PC]
            PCscoresSTD = std(PCscores)
            # For each variable/attribute in original matrix (not meancentered)
            for var in range(shape(self.originalMatrix)[1]):
                origVar = self.originalMatrix[:, var]
                origVarSTD = std(origVar)
                # If std = 0 for any variable an OverflowError occurs.
                # In such a case the value 0 is written in the matrix
                try:
                    self.correlationLoadings[PC, var] = cov(PCscores, origVar) / (PCscoresSTD * origVarSTD)
                except OverflowError:
                    self.correlationLoadings[PC, var] = 0

        return self.correlationLoadings
Exemple #3
0
def calcHist(fileName,attr_name,nbins=70):
    a=twiss(fileName)
    if default==0:
        if npy.isreal(a.__dict__[attr_name]):
            indx,frq=npy.histogram(a.__dict__[attr_name],bins=nbins)
    if default==1:
        if a.__dict__[attr_name].typecode()=='d':
            hits=Histogram(a.__dict__[attr_name],nbins)
            indx=hits[:,0];frq=hits[:,1]
    ave=npy.average(a.__dict__[attr_name])
    if default==0: stdev=npy.std(a.__dict__[attr_name])
    if default==1: stdev=std(a.__dict__[attr_name])
    else: print "data is not real"
    f=open(path+'/HIST.tfs','w')
    f.write('@ NAME       %0'+str(len(attr_name))+'s "'+attr_name+'"\n')
    f.write('@ '+attr_name+'AVE %le '+str(ave)+'\n')
    f.write('@ '+attr_name+'STD %le '+str(ave)+'\n')
    f.write("*"+'%5s %5s' % ("INDX", "FREQ")+"\n")
    f.write("$"+'%5s %5s' % ("%le", "%le")+"\n")
    for j in range(len(indx)):
        f.write('%5s   %5s' % (indx[j], frq[j])+"\n")
    f.close()