示例#1
0
文件: fitfun.py 项目: myw/dataiap
def call_pls(chrom,xdata,factors,mask,data):
    """Runs pls on a subset of X-variables"""
    scores = []
    
    for i in range(chrom.shape[0]):
        if _remdup(chrom[i]) == 0:
            #extract vars from xdata
            slice = scipy.take(xdata,chrom[i,:].tolist(),1)
            collate = 0
            for nF in range(mask.shape[1]):
                #split in to training and test
                try:
                    pls_output = pls(slice,data['class'][:,0][:,nA],mask[:,nF].tolist(),factors)
                    
                    if min(pls_output['rmsec']) <= min(pls_output['rmsepc']):
                        collate += pls_output['RMSEPC']
                    else:
                        collate += 10.0**5
                except:
                    collate = 0
                
            if collate != 0:
                scores.append(collate/float(mask.shape[1]))
            else:
                scores.append(10.0**5)
        else:
            scores.append(10.0**5)
            
    return scipy.asarray(scores)[:,nA]    
示例#2
0
文件: fitfun.py 项目: myw/dataiap
def call_pls(chrom, xdata, factors, mask, data):
    """Runs pls on a subset of X-variables"""
    scores = []

    for i in range(chrom.shape[0]):
        if _remdup(chrom[i]) == 0:
            #extract vars from xdata
            slice = scipy.take(xdata, chrom[i, :].tolist(), 1)
            collate = 0
            for nF in range(mask.shape[1]):
                #split in to training and test
                try:
                    pls_output = pls(slice, data['class'][:, 0][:, nA],
                                     mask[:, nF].tolist(), factors)

                    if min(pls_output['rmsec']) <= min(pls_output['rmsepc']):
                        collate += pls_output['RMSEPC']
                    else:
                        collate += 10.0**5
                except:
                    collate = 0

            if collate != 0:
                scores.append(collate / float(mask.shape[1]))
            else:
                scores.append(10.0**5)
        else:
            scores.append(10.0**5)

    return scipy.asarray(scores)[:, nA]
示例#3
0
文件: fitfun.py 项目: myw/dataiap
def call_dfa(chrom, xdata, DFs, mask, data):
    """Runs DFA on subset of variables from "xdata" as 
    defined by "chrom" and returns a vector of fitness 
    scores to be fed back into the GA
    """
    Y = []
    for x in range(len(chrom)):
        if _remdup(chrom[x]) == 0:
            #extract vars from xdata
            slice = meancent(_slice(xdata, chrom[x]))
            collate = 0
            for nF in range(mask.shape[1]):
                #split in to training and test
                tr_slice, cv_slice, ts_slice, tr_grp, cv_grp, ts_grp, tr_nm, cv_nm, ts_nm = _split(
                    slice, data['class'][:, 0], mask[:, nF].tolist(),
                    data['label'])

                try:
                    u, v, eigs, dummy = cva(tr_slice, tr_grp, DFs)
                    projU = scipy.dot(cv_slice, v)
                    u = scipy.concatenate((u, projU), 0)
                    group2 = scipy.concatenate((tr_grp, cv_grp), 0)

                    B, W = _BW(u, group2)
                    L, A = scipy.linalg.eig(B, W)
                    order = _flip(
                        scipy.argsort(scipy.reshape(L.real, (len(L), ))))
                    Ls = _flip(scipy.sort(L.real))
                    eigval = Ls[0:DFs]

                    collate += sum(eigval)
                except:
                    continue

            if collate != 0:
                Y.append(float(mask.shape[1]) / collate)
            else:
                Y.append(10.0**5)
        else:
            Y.append(10.0**5)

    return scipy.array(Y)[:, nA]
示例#4
0
文件: fitfun.py 项目: myw/dataiap
def call_dfa(chrom,xdata,DFs,mask,data):
    """Runs DFA on subset of variables from "xdata" as 
    defined by "chrom" and returns a vector of fitness 
    scores to be fed back into the GA
    """
    Y = []
    for x in range(len(chrom)):
        if _remdup(chrom[x]) == 0:
            #extract vars from xdata
            slice = meancent(_slice(xdata,chrom[x]))
            collate = 0
            for nF in range(mask.shape[1]):
                #split in to training and test
                tr_slice,cv_slice,ts_slice,tr_grp,cv_grp,ts_grp,tr_nm,cv_nm,ts_nm=_split(slice,
                      data['class'][:,0],mask[:,nF].tolist(),data['label'])
                
                try:
                    u,v,eigs,dummy = cva(tr_slice,tr_grp,DFs)
                    projU = scipy.dot(cv_slice,v)
                    u = scipy.concatenate((u,projU),0)
                    group2 = scipy.concatenate((tr_grp,cv_grp),0)
            
                    B,W = _BW(u,group2)
                    L,A = scipy.linalg.eig(B,W)
                    order =  _flip(scipy.argsort(scipy.reshape(L.real,(len(L),))))
                    Ls =  _flip(scipy.sort(L.real))
                    eigval = Ls[0:DFs]
                    
                    collate += sum(eigval)
                except:
                    continue
                
            if collate != 0:
                Y.append(float(mask.shape[1])/collate)
            else:
                Y.append(10.0**5)
        else:
            Y.append(10.0**5)
            
    return scipy.array(Y)[:,nA]