public double SVMOutput(int index,Instance inst) throws Exception {
  double result=0;
  if (m_KernelIsLinear) {
    if (m_sparseWeights == null) {
      int n1=inst.numValues();
      for (int p=0; p < n1; p++) {
        if (inst.index(p) != m_classIndex) {
          result+=m_weights[inst.index(p)] * inst.valueSparse(p);
        }
      }
    }
 else {
      int n1=inst.numValues();
      int n2=m_sparseWeights.length;
      for (int p1=0, p2=0; p1 < n1 && p2 < n2; ) {
        int ind1=inst.index(p1);
        int ind2=m_sparseIndices[p2];
        if (ind1 == ind2) {
          if (ind1 != m_classIndex) {
            result+=inst.valueSparse(p1) * m_sparseWeights[p2];
          }
          p1++;
          p2++;
        }
 else         if (ind1 > ind2) {
          p2++;
        }
 else {
          p1++;
        }
      }
    }
  }
 else {
    for (int i=m_supportVectors.getNext(-1); i != -1; i=m_supportVectors.getNext(i)) {
      result+=m_class[i] * m_alpha[i] * m_kernel.eval(index,i,inst);
    }
  }
  result-=m_b;
  return result;
}

public double SVMOutput ( int index , Instance inst ) throws Exception { double result = 0 ; if ( m_KernelIsLinear ) { if ( m_sparseWeights == null ) { int n1 = inst . numValues ( ) ; for ( int p = 0 ; p < n1 ; p ++ ) { if ( inst . index ( p ) != m_classIndex ) { result += m_weights [ inst . index ( p ) ] * inst . valueSparse ( p ) ; } } } else { int n1 = inst . numValues ( ) ; int n2 = m_sparseWeights . length ; for ( int p1 = 0 , p2 = 0 ; p1 < n1 && p2 < n2 ; ) { int ind1 = inst . index ( p1 ) ; int ind2 = m_sparseIndices [ p2 ] ; if ( ind1 == ind2 ) { if ( ind1 != m_classIndex ) { result += inst . valueSparse ( p1 ) * m_sparseWeights [ p2 ] ; } p1 ++ ; p2 ++ ; } else if ( ind1 > ind2 ) { p2 ++ ; } else { p1 ++ ; } } } } else { for ( int i = m_supportVectors . getNext ( - 1 ) ; i != - 1 ; i = m_supportVectors . getNext ( i ) ) { result += m_class [ i ] * m_alpha [ i ] * m_kernel . eval ( index , i , inst ) ; } } result -= m_b ; return result ; }
computes svm output for given instance .
