Package weka.estimators

Examples of weka.estimators.KernelEstimator


      }
      if (distinct > 0) {
  numPrecision = deltaSum / distinct;
      }
    }
    m_PriorErrorEstimator = new KernelEstimator(numPrecision);
    m_ErrorEstimator = new KernelEstimator(numPrecision);
    m_ClassPriors[0] = m_ClassPriorsSum = 0;
    for (int i = 0; i < m_NumTrainClassVals; i++) {
      m_ClassPriors[0] += m_TrainClassVals[i] * m_TrainClassWeights[i];
      m_ClassPriorsSum += m_TrainClassWeights[i];
      m_PriorErrorEstimator.addValue(m_TrainClassVals[i],
View Full Code Here


      for (int j = 0; j < m_Instances.numClasses(); j++) {
  switch (attribute.type()) {
  case Attribute.NUMERIC:
    if (m_UseKernelEstimator) {
      m_Distributions[attIndex][j] =
        new KernelEstimator(numPrecision);
    } else {
      m_Distributions[attIndex][j] =
        new NormalEstimator(numPrecision);
    }
    break;
View Full Code Here

            if ((int)width > maxWidth) {
              maxWidth = (int)width;
            }
          } else if (m_Distributions[i][0] instanceof KernelEstimator) {
            containsKernel = true;
            KernelEstimator ke = (KernelEstimator)m_Distributions[i][j];
            int numK = ke.getNumKernels();
            String temps = "K" + numK + ": mean (weight)";
            if (maxAttWidth < temps.length()) {
              maxAttWidth = temps.length();
            }
            // check means + weights against maxWidth
            if (ke.getNumKernels() > 0) {
              double[] means = ke.getMeans();
              double[] weights = ke.getWeights();
              for (int k = 0; k < ke.getNumKernels(); k++) {
                String m = Utils.doubleToString(means[k], maxWidth, 4).trim();
                m += " (" + Utils.doubleToString(weights[k], maxWidth, 1).trim() + ")";
                if (maxWidth < m.length()) {
                  maxWidth = m.length();
                }
              }
            }
          } else if (m_Distributions[i][0] instanceof DiscreteEstimator) {
            DiscreteEstimator d = (DiscreteEstimator)m_Distributions[i][j];
            for (int k = 0; k < d.getNumSymbols(); k++) {
              String size = "" + d.getCount(k);
              if (size.length() > maxWidth) {
                maxWidth = size.length();
              }
            }
            int sum = ("" + d.getSumOfCounts()).length();
            if (sum > maxWidth) {
              maxWidth = sum;
            }
          }
        }
      }

      // Check width of class labels
      for (int i = 0; i < m_Instances.numClasses(); i++) {
        String cSize = m_Instances.classAttribute().value(i);
        if (cSize.length() > maxWidth) {
          maxWidth = cSize.length();
        }
      }

      // Check width of class priors
      for (int i = 0; i < m_Instances.numClasses(); i++) {
        String priorP =
          Utils.doubleToString(((DiscreteEstimator)m_ClassDistribution).getProbability(i),
                               maxWidth, 2).trim();
        priorP = "(" + priorP + ")";
        if (priorP.length() > maxWidth) {
          maxWidth = priorP.length();
        }
      }
   
      if (maxAttWidth < "Attribute".length()) {
        maxAttWidth = "Attribute".length();
      }

      if (maxAttWidth < "  weight sum".length()) {
        maxAttWidth = "  weight sum".length();
      }

      if (containsKernel) {
        if (maxAttWidth < "  [precision]".length()) {
          maxAttWidth = "  [precision]".length();
        }
      }

      maxAttWidth += 2;
   


      temp.append("\n\n");
      temp.append(pad("Class", " ",
                      (maxAttWidth + maxWidth + 1) - "Class".length(),
                      true));

      temp.append("\n");
      temp.append(pad("Attribute", " ", maxAttWidth - "Attribute".length(), false));
      // class labels
      for (int i = 0; i < m_Instances.numClasses(); i++) {
        String classL = m_Instances.classAttribute().value(i);
        temp.append(pad(classL, " ", maxWidth + 1 - classL.length(), true));
      }
      temp.append("\n");
      // class priors
      temp.append(pad("", " ", maxAttWidth, true));
      for (int i = 0; i < m_Instances.numClasses(); i++) {
        String priorP =
          Utils.doubleToString(((DiscreteEstimator)m_ClassDistribution).getProbability(i),
                               maxWidth, 2).trim();
        priorP = "(" + priorP + ")";
        temp.append(pad(priorP, " ", maxWidth + 1 - priorP.length(), true));
      }
      temp.append("\n");
      temp.append(pad("", "=", maxAttWidth +
                      (maxWidth * m_Instances.numClasses())
                      + m_Instances.numClasses() + 1, true));
      temp.append("\n");

      // loop over the attributes
      int counter = 0;
      for (int i = 0; i < m_Instances.numAttributes(); i++) {
        if (i == m_Instances.classIndex()) {
          continue;
        }
        String attName = m_Instances.attribute(i).name();
        temp.append(attName + "\n");
         
        if (m_Distributions[counter][0] instanceof NormalEstimator) {
          String meanL = "  mean";
          temp.append(pad(meanL, " ", maxAttWidth + 1 - meanL.length(), false));
          for (int j = 0; j < m_Instances.numClasses(); j++) {           
            // means
            NormalEstimator n = (NormalEstimator)m_Distributions[counter][j];
            String mean =
              Utils.doubleToString(n.getMean(), maxWidth, 4).trim();
            temp.append(pad(mean, " ", maxWidth + 1 - mean.length(), true));
          }
          temp.append("\n");           
          // now do std deviations
          String stdDevL = "  std. dev.";
          temp.append(pad(stdDevL, " ", maxAttWidth + 1 - stdDevL.length(), false));
          for (int j = 0; j < m_Instances.numClasses(); j++) {
            NormalEstimator n = (NormalEstimator)m_Distributions[counter][j];
            String stdDev =
              Utils.doubleToString(n.getStdDev(), maxWidth, 4).trim();
            temp.append(pad(stdDev, " ", maxWidth + 1 - stdDev.length(), true));
          }
          temp.append("\n");
          // now the weight sums
          String weightL = "  weight sum";
          temp.append(pad(weightL, " ", maxAttWidth + 1 - weightL.length(), false));
          for (int j = 0; j < m_Instances.numClasses(); j++) {
            NormalEstimator n = (NormalEstimator)m_Distributions[counter][j];
            String weight =
              Utils.doubleToString(n.getSumOfWeights(), maxWidth, 4).trim();
            temp.append(pad(weight, " ", maxWidth + 1 - weight.length(), true));
          }
          temp.append("\n");
          // now the precisions
          String precisionL = "  precision";
          temp.append(pad(precisionL, " ", maxAttWidth + 1 - precisionL.length(), false));
          for (int j = 0; j < m_Instances.numClasses(); j++) {
            NormalEstimator n = (NormalEstimator)m_Distributions[counter][j];
            String precision =
              Utils.doubleToString(n.getPrecision(), maxWidth, 4).trim();
            temp.append(pad(precision, " ", maxWidth + 1 - precision.length(), true));
          }
          temp.append("\n\n");
           
        } else if (m_Distributions[counter][0] instanceof DiscreteEstimator) {
          Attribute a = m_Instances.attribute(i);
          for (int j = 0; j < a.numValues(); j++) {
            String val = "  " + a.value(j);
            temp.append(pad(val, " ", maxAttWidth + 1 - val.length(), false));
            for (int k = 0; k < m_Instances.numClasses(); k++) {
              DiscreteEstimator d = (DiscreteEstimator)m_Distributions[counter][k];
              String count = "" + d.getCount(j);
              temp.append(pad(count, " ", maxWidth + 1 - count.length(), true));
            }
            temp.append("\n");
          }
          // do the totals
          String total = "  [total]";
          temp.append(pad(total, " ", maxAttWidth + 1 - total.length(), false));
          for (int k = 0; k < m_Instances.numClasses(); k++) {
            DiscreteEstimator d = (DiscreteEstimator)m_Distributions[counter][k];
            String count = "" + d.getSumOfCounts();
            temp.append(pad(count, " ", maxWidth + 1 - count.length(), true));
          }
          temp.append("\n\n");
        } else if (m_Distributions[counter][0] instanceof KernelEstimator) {
          String kL = "  [# kernels]";
          temp.append(pad(kL, " ", maxAttWidth + 1 - kL.length(), false));
          for (int k = 0; k < m_Instances.numClasses(); k++) {
            KernelEstimator ke = (KernelEstimator)m_Distributions[counter][k];
            String nk = "" + ke.getNumKernels();
            temp.append(pad(nk, " ", maxWidth + 1 - nk.length(), true));
          }
          temp.append("\n");
          // do num kernels, std. devs and precisions
          String stdDevL = "  [std. dev]";
          temp.append(pad(stdDevL, " ", maxAttWidth + 1 - stdDevL.length(), false));
          for (int k = 0; k < m_Instances.numClasses(); k++) {
            KernelEstimator ke = (KernelEstimator)m_Distributions[counter][k];
            String stdD = Utils.doubleToString(ke.getStdDev(), maxWidth, 4).trim();
            temp.append(pad(stdD, " ", maxWidth + 1 - stdD.length(), true));
          }
          temp.append("\n");
          String precL = "  [precision]";
          temp.append(pad(precL, " ", maxAttWidth + 1 - precL.length(), false));
          for (int k = 0; k < m_Instances.numClasses(); k++) {
            KernelEstimator ke = (KernelEstimator)m_Distributions[counter][k];
            String prec = Utils.doubleToString(ke.getPrecision(), maxWidth, 4).trim();
            temp.append(pad(prec, " ", maxWidth + 1 - prec.length(), true));
          }
          temp.append("\n");
          // first determine max number of kernels accross the classes
          int maxK = 0;
          for (int k = 0; k < m_Instances.numClasses(); k++) {
            KernelEstimator ke = (KernelEstimator)m_Distributions[counter][k];
            if (ke.getNumKernels() > maxK) {
              maxK = ke.getNumKernels();
            }
          }
          for (int j = 0; j < maxK; j++) {
            // means first
            String meanL = "  K" + (j+1) + ": mean (weight)";
            temp.append(pad(meanL, " ", maxAttWidth + 1 - meanL.length(), false));
            for (int k = 0; k < m_Instances.numClasses(); k++) {
              KernelEstimator ke = (KernelEstimator)m_Distributions[counter][k];
              double[] means = ke.getMeans();
              double[] weights = ke.getWeights();
              String m = "--";
              if (ke.getNumKernels() == 0) {
                m = "" + 0;
              } else if (j < ke.getNumKernels()) {
                m = Utils.doubleToString(means[j], maxWidth, 4).trim();
                m += " (" + Utils.doubleToString(weights[j], maxWidth, 1).trim() + ")";
              }
              temp.append(pad(m, " ", maxWidth + 1 - m.length(), true));
            }
View Full Code Here

      }
      if (distinct > 0) {
        numPrecision = deltaSum / distinct;
      }
    }
    m_PriorErrorEstimator = new KernelEstimator(numPrecision);
    m_ErrorEstimator = new KernelEstimator(numPrecision);
    m_ClassPriors[0] = m_ClassPriorsSum = 0;
    for (int i = 0; i < m_NumTrainClassVals; i++) {
      m_ClassPriors[0] += m_TrainClassVals[i] * m_TrainClassWeights[i];
      m_ClassPriorsSum += m_TrainClassWeights[i];
      m_PriorErrorEstimator.addValue(m_TrainClassVals[i],
View Full Code Here

      for( int j = 0; j < m_Instances.numClasses(); j++ ) {
        switch( attribute.type() ) {
          case Attribute.NUMERIC:
            if( m_UseKernelEstimator ) {
              m_Distributions[attIndex][j] =
                  new KernelEstimator( numPrecision );
            } else {
              m_Distributions[attIndex][j] =
                  new NormalEstimator( numPrecision );
            }
            break;
View Full Code Here

            if( (int) width > maxWidth ) {
              maxWidth = (int) width;
            }
          } else if( m_Distributions[i][0] instanceof KernelEstimator ) {
            containsKernel = true;
            KernelEstimator ke = (KernelEstimator) m_Distributions[i][j];
            int numK = ke.getNumKernels();
            String temps = "K" + numK + ": mean (weight)";
            if( maxAttWidth < temps.length() ) {
              maxAttWidth = temps.length();
            }
            // check means + weights against maxWidth
            if( ke.getNumKernels() > 0 ) {
              double[] means = ke.getMeans();
              double[] weights = ke.getWeights();
              for( int k = 0; k < ke.getNumKernels(); k++ ) {
                String m = Utils.doubleToString( means[k], maxWidth, 4 ).trim();
                m += " (" + Utils.doubleToString( weights[k], maxWidth, 1 ).trim() + ")";
                if( maxWidth < m.length() ) {
                  maxWidth = m.length();
                }
              }
            }
          } else if( m_Distributions[i][0] instanceof DiscreteEstimator ) {
            DiscreteEstimator d = (DiscreteEstimator) m_Distributions[i][j];
            for( int k = 0; k < d.getNumSymbols(); k++ ) {
              String size = "" + d.getCount( k );
              if( size.length() > maxWidth ) {
                maxWidth = size.length();
              }
            }
            int sum = ("" + d.getSumOfCounts()).length();
            if( sum > maxWidth ) {
              maxWidth = sum;
            }
          }
        }
      }

      // Check width of class labels
      for( int i = 0; i < m_Instances.numClasses(); i++ ) {
        String cSize = m_Instances.classAttribute().value( i );
        if( cSize.length() > maxWidth ) {
          maxWidth = cSize.length();
        }
      }

      // Check width of class priors
      for( int i = 0; i < m_Instances.numClasses(); i++ ) {
        String priorP =
            Utils.doubleToString( ((DiscreteEstimator) m_ClassDistribution).getProbability( i ),
            maxWidth, 2 ).trim();
        priorP = "(" + priorP + ")";
        if( priorP.length() > maxWidth ) {
          maxWidth = priorP.length();
        }
      }

      if( maxAttWidth < "Attribute".length() ) {
        maxAttWidth = "Attribute".length();
      }

      if( maxAttWidth < "  weight sum".length() ) {
        maxAttWidth = "  weight sum".length();
      }

      if( containsKernel ) {
        if( maxAttWidth < "  [precision]".length() ) {
          maxAttWidth = "  [precision]".length();
        }
      }

      maxAttWidth += 2;



      temp.append( "\n\n" );
      temp.append( pad( "Class", " ",
          (maxAttWidth + maxWidth + 1) - "Class".length(),
          true ) );

      temp.append( "\n" );
      temp.append( pad( "Attribute", " ", maxAttWidth - "Attribute".length(), false ) );
      // class labels
      for( int i = 0; i < m_Instances.numClasses(); i++ ) {
        String classL = m_Instances.classAttribute().value( i );
        temp.append( pad( classL, " ", maxWidth + 1 - classL.length(), true ) );
      }
      temp.append( "\n" );
      // class priors
      temp.append( pad( "", " ", maxAttWidth, true ) );
      for( int i = 0; i < m_Instances.numClasses(); i++ ) {
        String priorP =
            Utils.doubleToString( ((DiscreteEstimator) m_ClassDistribution).getProbability( i ),
            maxWidth, 2 ).trim();
        priorP = "(" + priorP + ")";
        temp.append( pad( priorP, " ", maxWidth + 1 - priorP.length(), true ) );
      }
      temp.append( "\n" );
      temp.append( pad( "", "=", maxAttWidth +
          (maxWidth * m_Instances.numClasses()) + m_Instances.numClasses() + 1, true ) );
      temp.append( "\n" );

      // loop over the attributes
      int counter = 0;
      for( int i = 0; i < m_Instances.numAttributes(); i++ ) {
        if( i == m_Instances.classIndex() ) {
          continue;
        }
        String attName = m_Instances.attribute( i ).name();
        temp.append( attName + "\n" );

        if( m_Distributions[counter][0] instanceof NormalEstimator ) {
          String meanL = "  mean";
          temp.append( pad( meanL, " ", maxAttWidth + 1 - meanL.length(), false ) );
          for( int j = 0; j < m_Instances.numClasses(); j++ ) {
            // means
            NormalEstimator n = (NormalEstimator) m_Distributions[counter][j];
            String mean =
                Utils.doubleToString( n.getMean(), maxWidth, 4 ).trim();
            temp.append( pad( mean, " ", maxWidth + 1 - mean.length(), true ) );
          }
          temp.append( "\n" );
          // now do std deviations
          String stdDevL = "  std. dev.";
          temp.append( pad( stdDevL, " ", maxAttWidth + 1 - stdDevL.length(), false ) );
          for( int j = 0; j < m_Instances.numClasses(); j++ ) {
            NormalEstimator n = (NormalEstimator) m_Distributions[counter][j];
            String stdDev =
                Utils.doubleToString( n.getStdDev(), maxWidth, 4 ).trim();
            temp.append( pad( stdDev, " ", maxWidth + 1 - stdDev.length(), true ) );
          }
          temp.append( "\n" );
          // now the weight sums
          String weightL = "  weight sum";
          temp.append( pad( weightL, " ", maxAttWidth + 1 - weightL.length(), false ) );
          for( int j = 0; j < m_Instances.numClasses(); j++ ) {
            NormalEstimator n = (NormalEstimator) m_Distributions[counter][j];
            String weight =
                Utils.doubleToString( n.getSumOfWeights(), maxWidth, 4 ).trim();
            temp.append( pad( weight, " ", maxWidth + 1 - weight.length(), true ) );
          }
          temp.append( "\n" );
          // now the precisions
          String precisionL = "  precision";
          temp.append( pad( precisionL, " ", maxAttWidth + 1 - precisionL.length(), false ) );
          for( int j = 0; j < m_Instances.numClasses(); j++ ) {
            NormalEstimator n = (NormalEstimator) m_Distributions[counter][j];
            String precision =
                Utils.doubleToString( n.getPrecision(), maxWidth, 4 ).trim();
            temp.append( pad( precision, " ", maxWidth + 1 - precision.length(), true ) );
          }
          temp.append( "\n\n" );

        } else if( m_Distributions[counter][0] instanceof DiscreteEstimator ) {
          Attribute a = m_Instances.attribute( i );
          for( int j = 0; j < a.numValues(); j++ ) {
            String val = "  " + a.value( j );
            temp.append( pad( val, " ", maxAttWidth + 1 - val.length(), false ) );
            for( int k = 0; k < m_Instances.numClasses(); k++ ) {
              DiscreteEstimator d = (DiscreteEstimator) m_Distributions[counter][k];
              String count = "" + d.getCount( j );
              temp.append( pad( count, " ", maxWidth + 1 - count.length(), true ) );
            }
            temp.append( "\n" );
          }
          // do the totals
          String total = "  [total]";
          temp.append( pad( total, " ", maxAttWidth + 1 - total.length(), false ) );
          for( int k = 0; k < m_Instances.numClasses(); k++ ) {
            DiscreteEstimator d = (DiscreteEstimator) m_Distributions[counter][k];
            String count = "" + d.getSumOfCounts();
            temp.append( pad( count, " ", maxWidth + 1 - count.length(), true ) );
          }
          temp.append( "\n\n" );
        } else if( m_Distributions[counter][0] instanceof KernelEstimator ) {
          String kL = "  [# kernels]";
          temp.append( pad( kL, " ", maxAttWidth + 1 - kL.length(), false ) );
          for( int k = 0; k < m_Instances.numClasses(); k++ ) {
            KernelEstimator ke = (KernelEstimator) m_Distributions[counter][k];
            String nk = "" + ke.getNumKernels();
            temp.append( pad( nk, " ", maxWidth + 1 - nk.length(), true ) );
          }
          temp.append( "\n" );
          // do num kernels, std. devs and precisions
          String stdDevL = "  [std. dev]";
          temp.append( pad( stdDevL, " ", maxAttWidth + 1 - stdDevL.length(), false ) );
          for( int k = 0; k < m_Instances.numClasses(); k++ ) {
            KernelEstimator ke = (KernelEstimator) m_Distributions[counter][k];
            String stdD = Utils.doubleToString( ke.getStdDev(), maxWidth, 4 ).trim();
            temp.append( pad( stdD, " ", maxWidth + 1 - stdD.length(), true ) );
          }
          temp.append( "\n" );
          String precL = "  [precision]";
          temp.append( pad( precL, " ", maxAttWidth + 1 - precL.length(), false ) );
          for( int k = 0; k < m_Instances.numClasses(); k++ ) {
            KernelEstimator ke = (KernelEstimator) m_Distributions[counter][k];
            String prec = Utils.doubleToString( ke.getPrecision(), maxWidth, 4 ).trim();
            temp.append( pad( prec, " ", maxWidth + 1 - prec.length(), true ) );
          }
          temp.append( "\n" );
          // first determine max number of kernels accross the classes
          int maxK = 0;
          for( int k = 0; k < m_Instances.numClasses(); k++ ) {
            KernelEstimator ke = (KernelEstimator) m_Distributions[counter][k];
            if( ke.getNumKernels() > maxK ) {
              maxK = ke.getNumKernels();
            }
          }
          for( int j = 0; j < maxK; j++ ) {
            // means first
            String meanL = "  K" + (j + 1) + ": mean (weight)";
            temp.append( pad( meanL, " ", maxAttWidth + 1 - meanL.length(), false ) );
            for( int k = 0; k < m_Instances.numClasses(); k++ ) {
              KernelEstimator ke = (KernelEstimator) m_Distributions[counter][k];
              double[] means = ke.getMeans();
              double[] weights = ke.getWeights();
              String m = "--";
              if( ke.getNumKernels() == 0 ) {
                m = "" + 0;
              } else if( j < ke.getNumKernels() ) {
                m = Utils.doubleToString( means[j], maxWidth, 4 ).trim();
                m += " (" + Utils.doubleToString( weights[j], maxWidth, 1 ).trim() + ")";
              }
              temp.append( pad( m, " ", maxWidth + 1 - m.length(), true ) );
            }
View Full Code Here

      for (int j = 0; j < m_Instances.numClasses(); j++) {
  switch (attribute.type()) {
  case Attribute.NUMERIC:
    if (m_UseKernelEstimator) {
      m_Distributions[attIndex][j] =
        new KernelEstimator(numPrecision);
    } else {
      m_Distributions[attIndex][j] =
        new NormalEstimator(numPrecision);
    }
    break;
View Full Code Here

            if ((int)width > maxWidth) {
              maxWidth = (int)width;
            }
          } else if (m_Distributions[i][0] instanceof KernelEstimator) {
            containsKernel = true;
            KernelEstimator ke = (KernelEstimator)m_Distributions[i][j];
            int numK = ke.getNumKernels();
            String temps = "K" + numK + ": mean (weight)";
            if (maxAttWidth < temps.length()) {
              maxAttWidth = temps.length();
            }
            // check means + weights against maxWidth
            if (ke.getNumKernels() > 0) {
              double[] means = ke.getMeans();
              double[] weights = ke.getWeights();
              for (int k = 0; k < ke.getNumKernels(); k++) {
                String m = Utils.doubleToString(means[k], maxWidth, 4).trim();
                m += " (" + Utils.doubleToString(weights[k], maxWidth, 1).trim() + ")";
                if (maxWidth < m.length()) {
                  maxWidth = m.length();
                }
              }
            }
          } else if (m_Distributions[i][0] instanceof DiscreteEstimator) {
            DiscreteEstimator d = (DiscreteEstimator)m_Distributions[i][j];
            for (int k = 0; k < d.getNumSymbols(); k++) {
              String size = "" + d.getCount(k);
              if (size.length() > maxWidth) {
                maxWidth = size.length();
              }
            }
            int sum = ("" + d.getSumOfCounts()).length();
            if (sum > maxWidth) {
              maxWidth = sum;
            }
          }
        }
      }

      // Check width of class labels
      for (int i = 0; i < m_Instances.numClasses(); i++) {
        String cSize = m_Instances.classAttribute().value(i);
        if (cSize.length() > maxWidth) {
          maxWidth = cSize.length();
        }
      }

      // Check width of class priors
      for (int i = 0; i < m_Instances.numClasses(); i++) {
        String priorP =
          Utils.doubleToString(((DiscreteEstimator)m_ClassDistribution).getProbability(i),
                               maxWidth, 2).trim();
        priorP = "(" + priorP + ")";
        if (priorP.length() > maxWidth) {
          maxWidth = priorP.length();
        }
      }
   
      if (maxAttWidth < "Attribute".length()) {
        maxAttWidth = "Attribute".length();
      }

      if (maxAttWidth < "  weight sum".length()) {
        maxAttWidth = "  weight sum".length();
      }

      if (containsKernel) {
        if (maxAttWidth < "  [precision]".length()) {
          maxAttWidth = "  [precision]".length();
        }
      }

      maxAttWidth += 2;
   


      temp.append("\n\n");
      temp.append(pad("Class", " ",
                      (maxAttWidth + maxWidth + 1) - "Class".length(),
                      true));

      temp.append("\n");
      temp.append(pad("Attribute", " ", maxAttWidth - "Attribute".length(), false));
      // class labels
      for (int i = 0; i < m_Instances.numClasses(); i++) {
        String classL = m_Instances.classAttribute().value(i);
        temp.append(pad(classL, " ", maxWidth + 1 - classL.length(), true));
      }
      temp.append("\n");
      // class priors
      temp.append(pad("", " ", maxAttWidth, true));
      for (int i = 0; i < m_Instances.numClasses(); i++) {
        String priorP =
          Utils.doubleToString(((DiscreteEstimator)m_ClassDistribution).getProbability(i),
                               maxWidth, 2).trim();
        priorP = "(" + priorP + ")";
        temp.append(pad(priorP, " ", maxWidth + 1 - priorP.length(), true));
      }
      temp.append("\n");
      temp.append(pad("", "=", maxAttWidth +
                      (maxWidth * m_Instances.numClasses())
                      + m_Instances.numClasses() + 1, true));
      temp.append("\n");

      // loop over the attributes
      int counter = 0;
      for (int i = 0; i < m_Instances.numAttributes(); i++) {
        if (i == m_Instances.classIndex()) {
          continue;
        }
        String attName = m_Instances.attribute(i).name();
        temp.append(attName + "\n");
         
        if (m_Distributions[counter][0] instanceof NormalEstimator) {
          String meanL = "  mean";
          temp.append(pad(meanL, " ", maxAttWidth + 1 - meanL.length(), false));
          for (int j = 0; j < m_Instances.numClasses(); j++) {           
            // means
            NormalEstimator n = (NormalEstimator)m_Distributions[counter][j];
            String mean =
              Utils.doubleToString(n.getMean(), maxWidth, 4).trim();
            temp.append(pad(mean, " ", maxWidth + 1 - mean.length(), true));
          }
          temp.append("\n");           
          // now do std deviations
          String stdDevL = "  std. dev.";
          temp.append(pad(stdDevL, " ", maxAttWidth + 1 - stdDevL.length(), false));
          for (int j = 0; j < m_Instances.numClasses(); j++) {
            NormalEstimator n = (NormalEstimator)m_Distributions[counter][j];
            String stdDev =
              Utils.doubleToString(n.getStdDev(), maxWidth, 4).trim();
            temp.append(pad(stdDev, " ", maxWidth + 1 - stdDev.length(), true));
          }
          temp.append("\n");
          // now the weight sums
          String weightL = "  weight sum";
          temp.append(pad(weightL, " ", maxAttWidth + 1 - weightL.length(), false));
          for (int j = 0; j < m_Instances.numClasses(); j++) {
            NormalEstimator n = (NormalEstimator)m_Distributions[counter][j];
            String weight =
              Utils.doubleToString(n.getSumOfWeights(), maxWidth, 4).trim();
            temp.append(pad(weight, " ", maxWidth + 1 - weight.length(), true));
          }
          temp.append("\n");
          // now the precisions
          String precisionL = "  precision";
          temp.append(pad(precisionL, " ", maxAttWidth + 1 - precisionL.length(), false));
          for (int j = 0; j < m_Instances.numClasses(); j++) {
            NormalEstimator n = (NormalEstimator)m_Distributions[counter][j];
            String precision =
              Utils.doubleToString(n.getPrecision(), maxWidth, 4).trim();
            temp.append(pad(precision, " ", maxWidth + 1 - precision.length(), true));
          }
          temp.append("\n\n");
           
        } else if (m_Distributions[counter][0] instanceof DiscreteEstimator) {
          Attribute a = m_Instances.attribute(i);
          for (int j = 0; j < a.numValues(); j++) {
            String val = "  " + a.value(j);
            temp.append(pad(val, " ", maxAttWidth + 1 - val.length(), false));
            for (int k = 0; k < m_Instances.numClasses(); k++) {
              DiscreteEstimator d = (DiscreteEstimator)m_Distributions[counter][k];
              String count = "" + d.getCount(j);
              temp.append(pad(count, " ", maxWidth + 1 - count.length(), true));
            }
            temp.append("\n");
          }
          // do the totals
          String total = "  [total]";
          temp.append(pad(total, " ", maxAttWidth + 1 - total.length(), false));
          for (int k = 0; k < m_Instances.numClasses(); k++) {
            DiscreteEstimator d = (DiscreteEstimator)m_Distributions[counter][k];
            String count = "" + d.getSumOfCounts();
            temp.append(pad(count, " ", maxWidth + 1 - count.length(), true));
          }
          temp.append("\n\n");
        } else if (m_Distributions[counter][0] instanceof KernelEstimator) {
          String kL = "  [# kernels]";
          temp.append(pad(kL, " ", maxAttWidth + 1 - kL.length(), false));
          for (int k = 0; k < m_Instances.numClasses(); k++) {
            KernelEstimator ke = (KernelEstimator)m_Distributions[counter][k];
            String nk = "" + ke.getNumKernels();
            temp.append(pad(nk, " ", maxWidth + 1 - nk.length(), true));
          }
          temp.append("\n");
          // do num kernels, std. devs and precisions
          String stdDevL = "  [std. dev]";
          temp.append(pad(stdDevL, " ", maxAttWidth + 1 - stdDevL.length(), false));
          for (int k = 0; k < m_Instances.numClasses(); k++) {
            KernelEstimator ke = (KernelEstimator)m_Distributions[counter][k];
            String stdD = Utils.doubleToString(ke.getStdDev(), maxWidth, 4).trim();
            temp.append(pad(stdD, " ", maxWidth + 1 - stdD.length(), true));
          }
          temp.append("\n");
          String precL = "  [precision]";
          temp.append(pad(precL, " ", maxAttWidth + 1 - precL.length(), false));
          for (int k = 0; k < m_Instances.numClasses(); k++) {
            KernelEstimator ke = (KernelEstimator)m_Distributions[counter][k];
            String prec = Utils.doubleToString(ke.getPrecision(), maxWidth, 4).trim();
            temp.append(pad(prec, " ", maxWidth + 1 - prec.length(), true));
          }
          temp.append("\n");
          // first determine max number of kernels accross the classes
          int maxK = 0;
          for (int k = 0; k < m_Instances.numClasses(); k++) {
            KernelEstimator ke = (KernelEstimator)m_Distributions[counter][k];
            if (ke.getNumKernels() > maxK) {
              maxK = ke.getNumKernels();
            }
          }
          for (int j = 0; j < maxK; j++) {
            // means first
            String meanL = "  K" + (j+1) + ": mean (weight)";
            temp.append(pad(meanL, " ", maxAttWidth + 1 - meanL.length(), false));
            for (int k = 0; k < m_Instances.numClasses(); k++) {
              KernelEstimator ke = (KernelEstimator)m_Distributions[counter][k];
              double[] means = ke.getMeans();
              double[] weights = ke.getWeights();
              String m = "--";
              if (ke.getNumKernels() == 0) {
                m = "" + 0;
              } else if (j < ke.getNumKernels()) {
                m = Utils.doubleToString(means[j], maxWidth, 4).trim();
                m += " (" + Utils.doubleToString(weights[j], maxWidth, 1).trim() + ")";
              }
              temp.append(pad(m, " ", maxWidth + 1 - m.length(), true));
            }
View Full Code Here

TOP

Related Classes of weka.estimators.KernelEstimator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.