Beispiel #1
0
    def compute_kernel(self, xdatacls):

        if xdatacls.category == 0 or xdatacls.category == 3:
            ## self.K=mvm_kernel_eval.mvm_kernel_sparse(xdatacls,isymmetric, \
            ##                                          self.kernel_params, \
            ##                                          self.norm)
            isymmetric = 1
            self.K=mvm_kernel_eval.mvm_kernel_sparse(xdatacls,isymmetric, \
                                                     self.kernel_params, \
                                                     self.norm)
        elif xdatacls.category == 1:
            self.K=mvm_kernel_eval.kernel_category_2d(xdatacls, \
                                                      self.kernel_params, \
                                                      self.norm)
        elif xdatacls.category == 2:
            self.K=mvm_kernel_eval.kernel_categoryvec_2d(xdatacls, \
                                                      self.kernel_params, \
                                                      self.norm)
        self.K += self.xbias

        return
Beispiel #2
0
  def compute_kernel(self,xdatacls):

    if xdatacls.category==0 or xdatacls.category==3:
      ## self.K=mvm_kernel_eval.mvm_kernel_sparse(xdatacls,isymmetric, \
      ##                                          self.kernel_params, \
      ##                                          self.norm)
      isymmetric=1  
      self.K=mvm_kernel_eval.mvm_kernel_sparse(xdatacls,isymmetric, \
                                               self.kernel_params, \
                                               self.norm)
    elif xdatacls.category==1:
      self.K=mvm_kernel_eval.kernel_category_2d(xdatacls, \
                                                self.kernel_params, \
                                                self.norm)
    elif xdatacls.category==2:
      self.K=mvm_kernel_eval.kernel_categoryvec_2d(xdatacls, \
                                                self.kernel_params, \
                                                self.norm)
    self.K+=self.xbias
    
    return
Beispiel #3
0
    def create_diag_kernel(self,
                           xdatacls,
                           params_spec,
                           norm_spec,
                           itraintest=1):

        xdata_1 = xdatacls.xdata_tra
        nval = xdata_1[2].shape[1]
        xranges_1 = xdatacls.xranges_rel
        if itraintest != 1:
            xdata_2 = xdatacls.xdata_tes
            xranges_2 = xdatacls.xranges_rel_test
        else:
            xdata_2 = xdata_1
            xranges_2 = xranges_1

        nrow = xdatacls.nrow
        ncol = xdatacls.ncol

        ## create column, row order
        xdata_1_inv = [xdata_1[1], xdata_1[0]]
        xdata_1_inv = mvm_prepare.sort_table(xdata_1_inv, idata=0)
        xranges_1_inv = mvm_prepare.mvm_ranges(xdata_1_inv, ncol, None)
        if itraintest != 1:
            xdata_2_inv = [xdata_2[1], xdata_2[0]]
            xdata_2_inv = mvm_prepare.sort_table(xdata_2_inv, idata=0)
            xranges_2_inv = mvm_prepare.mvm_ranges(xdata_2_inv, ncol, None)
        else:
            xdata_2_inv = xdata_1_inv
            xranges_2_inv = xranges_1_inv

        cxdata = cls_dataitem()
        npart = 3
        cxdata.xdata_tra = [None] * npart
        cxdata.xdata_tes = [None] * npart

        for ilearner in range(nrow):
            (istart, nlength) = xranges_1[ilearner]
            nlength_1 = 0
            for icol in range(nlength):
                inboro = xdata_1[1][istart + icol]
                nlength_1 += xranges_1_inv[inboro][1]
            cxdata.xdata_tra=[np.zeros(nlength_1,dtype=int), \
                              np.zeros(nlength_1,dtype=int), \
                              np.zeros((nlength_1,nval))]
            if itraintest != 1:
                (istart, nlength) = xranges_2[ilearner]
                nlength_2 = 0
                for icol in range(nlength):
                    inboro = xdata_2[1][istart + icol]
                    nlength_2 += xranges_2_inv[inboro][1]
                cxdata.xdata_tes=[np.zeros(nlength_1,dtype=int), \
                                  np.zeros(nlength_1,dtype=int), \
                                  np.zeros((nlength_1,nval))]
            else:
                nlength_2 = nlength_1

        for ilearner in range(nrow):
            (istart, nlength_tra) = xranges_1[ilearner]
            for icol in range(nlength_tra):
                inboro = xdata_1[1][istart + icol]
                (istartr, nlengthr) = xranges_1_inv[inboro]
                xilearners = xdata_1_inv[istartr, istartr:nlengthr]
                ipos = 0
                for ilearnerc in xilearners:
                    (istartc, nlengthc) = xranges_1[ilearnerc]
                    for ipart in range(npart):
                        cxdata.xdata_tra[ipart][ipos:ipos+nlengthc] \
                              =xdata_1[ipart][istartc,istartc+nlengthc]
                        ipos += nlengthc
            if itraintest != 1:
                (istart, nlength_tes) = xranges_2[ilearner]
                for icol in range(nlength_tes):
                    inboro = xdata_2[1][istart + icol]
                    (istartr, nlengthr) = xranges_2_inv[inboro]
                    xilearners = xdata_2_inv[istartr, istartr:nlengthr]
                    ipos = 0
                    for ilearnerc in xilearners:
                        (istartc, nlengthc) = xranges_2[ilearnerc]
                        for ipart in range(npart):
                            cxdata.xdata_tes[ipart][ipos:ipos+nlengthc] \
                                  =xdata_2[ipart][istartc,istartc+nlengthc]
                            ipos += nlengthc

            cxdata.nrow = nrow

            if itraintest == 1:
                cxdata.nncol = nlength_tra
                self.dkernel[ilearner]=mvm_kernel_eval.mvm_kernel_sparse(cxdata,itraintest, \
                                             params_spec,norm_spec)
            else:
                cxdata.nncol = nlength_tes
                self.dkernel_test[ilearner]=mvm_kernel_eval.mvm_kernel_sparse(cxdata,itraintest, \
                                             params_spec,norm_spec)

        return
Beispiel #4
0
    def create_monolith(self, xdatacls, isymmetric, params_spec, norm_spec):

        self.Kmonolith=mvm_kernel_eval.mvm_kernel_sparse(xdatacls,isymmetric, \
                                         params_spec,norm_spec)

        return
Beispiel #5
0
  def create_diag_kernel(self,xdatacls,params_spec,norm_spec,itraintest=1):
    
    xdata_1=xdatacls.xdata_tra
    nval=xdata_1[2].shape[1]
    xranges_1=xdatacls.xranges_rel
    if itraintest!=1:
      xdata_2=xdatacls.xdata_tes
      xranges_2=xdatacls.xranges_rel_test
    else:
      xdata_2=xdata_1
      xranges_2=xranges_1
      
    nrow=xdatacls.nrow
    ncol=xdatacls.ncol

    ## create column, row order 
    xdata_1_inv=[xdata_1[1],xdata_1[0]]
    xdata_1_inv=mvm_prepare.sort_table(xdata_1_inv,idata=0)
    xranges_1_inv=mvm_prepare.mvm_ranges(xdata_1_inv,ncol,None)
    if itraintest!=1:
      xdata_2_inv=[xdata_2[1],xdata_2[0]]
      xdata_2_inv=mvm_prepare.sort_table(xdata_2_inv,idata=0)
      xranges_2_inv=mvm_prepare.mvm_ranges(xdata_2_inv,ncol,None)
    else:
      xdata_2_inv=xdata_1_inv
      xranges_2_inv=xranges_1_inv
      
    cxdata=cls_dataitem()
    npart=3
    cxdata.xdata_tra=[None]*npart 
    cxdata.xdata_tes=[None]*npart 

    for ilearner in range(nrow):
      (istart,nlength)=xranges_1[ilearner]
      nlength_1=0
      for icol in range(nlength):
        inboro=xdata_1[1][istart+icol]
        nlength_1+=xranges_1_inv[inboro][1]
      cxdata.xdata_tra=[np.zeros(nlength_1,dtype=int), \
                        np.zeros(nlength_1,dtype=int), \
                        np.zeros((nlength_1,nval))]
      if itraintest!=1:
        (istart,nlength)=xranges_2[ilearner]
        nlength_2=0
        for icol in range(nlength):
          inboro=xdata_2[1][istart+icol]
          nlength_2+=xranges_2_inv[inboro][1]
        cxdata.xdata_tes=[np.zeros(nlength_1,dtype=int), \
                          np.zeros(nlength_1,dtype=int), \
                          np.zeros((nlength_1,nval))]
      else:
        nlength_2=nlength_1


    
    for ilearner in range(nrow):
      (istart,nlength_tra)=xranges_1[ilearner]
      for icol in range(nlength_tra):
        inboro=xdata_1[1][istart+icol]
        (istartr,nlengthr)=xranges_1_inv[inboro]
        xilearners=xdata_1_inv[istartr,istartr:nlengthr]
        ipos=0
        for ilearnerc in xilearners:
          (istartc,nlengthc)=xranges_1[ilearnerc]
          for ipart in range(npart):
            cxdata.xdata_tra[ipart][ipos:ipos+nlengthc] \
                  =xdata_1[ipart][istartc,istartc+nlengthc]
            ipos+=nlengthc
      if itraintest!=1:
        (istart,nlength_tes)=xranges_2[ilearner]
        for icol in range(nlength_tes):
          inboro=xdata_2[1][istart+icol]
          (istartr,nlengthr)=xranges_2_inv[inboro]
          xilearners=xdata_2_inv[istartr,istartr:nlengthr]
          ipos=0
          for ilearnerc in xilearners:
            (istartc,nlengthc)=xranges_2[ilearnerc]
            for ipart in range(npart):
              cxdata.xdata_tes[ipart][ipos:ipos+nlengthc] \
                    =xdata_2[ipart][istartc,istartc+nlengthc]
              ipos+=nlengthc
        
      cxdata.nrow=nrow

      if itraintest==1:
        cxdata.nncol=nlength_tra
        self.dkernel[ilearner]=mvm_kernel_eval.mvm_kernel_sparse(cxdata,itraintest, \
                                     params_spec,norm_spec)
      else:
        cxdata.nncol=nlength_tes
        self.dkernel_test[ilearner]=mvm_kernel_eval.mvm_kernel_sparse(cxdata,itraintest, \
                                     params_spec,norm_spec)
        

    return
Beispiel #6
0
  def create_monolith(self,xdatacls,isymmetric,params_spec,norm_spec):

    self.Kmonolith=mvm_kernel_eval.mvm_kernel_sparse(xdatacls,isymmetric, \
                                     params_spec,norm_spec)

    return