protected Object instanceToArray(Instance instance) throws Exception {
    int     index;
    int     count;
    int     i;
    Object  result;

    // determine number of non-zero attributes
    count = 0;

    for (i = 0; i < instance.numValues(); i++) {
      if (instance.index(i) == instance.classIndex())
        continue;
      if (instance.valueSparse(i) != 0)
        count++;
    }

    if (m_Bias >= 0) {
      count++;
    }

    Class[] intDouble = new Class[] { int.class, double.class };
    Constructor nodeConstructor = Class.forName(CLASS_FEATURENODE).getConstructor(intDouble);

    // fill array
    result = Array.newInstance(Class.forName(CLASS_FEATURENODE), count);
    index  = 0;
    for (i = 0; i < instance.numValues(); i++) {

      int idx = instance.index(i);
      double val = instance.valueSparse(i);

      if (idx == instance.classIndex())
        continue;
      if (val == 0)
        continue;

      Object node = nodeConstructor.newInstance(Integer.valueOf(idx+1), Double.valueOf(val));
      Array.set(result, index, node);
      index++;
    }

    // add bias term
    if (m_Bias >= 0) {
      Integer idx = Integer.valueOf(instance.numAttributes()+1);
      Double value = Double.valueOf(m_Bias);
      Object node = nodeConstructor.newInstance(idx, value);
      Array.set(result, index, node);
    }

    return result;
  }