• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Sourcable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中weka.classifiers.Sourcable的典型用法代码示例。如果您正苦于以下问题:Java Sourcable类的具体用法?Java Sourcable怎么用?Java Sourcable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Sourcable类属于weka.classifiers包,在下文中一共展示了Sourcable类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: toSource

import weka.classifiers.Sourcable; //导入依赖的package包/类
/**
 * Returns the boosted model as Java source code.
 * 
 * @param className the classname of the generated class
 * @return the tree as Java source code
 * @throws Exception if something goes wrong
 */
@Override
public String toSource(String className) throws Exception {

  if (m_NumIterationsPerformed == 0) {
    throw new Exception("No model built yet");
  }
  if (!(m_Classifiers[0] instanceof Sourcable)) {
    throw new Exception("Base learner " + m_Classifier.getClass().getName()
      + " is not Sourcable");
  }

  StringBuffer text = new StringBuffer("class ");
  text.append(className).append(" {\n\n");

  text.append("  public static double classify(Object[] i) {\n");

  if (m_NumIterationsPerformed == 1) {
    text.append("    return " + className + "_0.classify(i);\n");
  } else {
    text.append("    double [] sums = new double [" + m_NumClasses + "];\n");
    for (int i = 0; i < m_NumIterationsPerformed; i++) {
      text.append("    sums[(int) " + className + '_' + i
        + ".classify(i)] += " + m_Betas[i] + ";\n");
    }
    text.append("    double maxV = sums[0];\n" + "    int maxI = 0;\n"
      + "    for (int j = 1; j < " + m_NumClasses + "; j++) {\n"
      + "      if (sums[j] > maxV) { maxV = sums[j]; maxI = j; }\n"
      + "    }\n    return (double) maxI;\n");
  }
  text.append("  }\n}\n");

  for (int i = 0; i < m_Classifiers.length; i++) {
    text.append(((Sourcable) m_Classifiers[i]).toSource(className + '_' + i));
  }
  return text.toString();
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:44,代码来源:AdaBoostM1.java


示例2: toSource

import weka.classifiers.Sourcable; //导入依赖的package包/类
/**
  * Returns the boosted model as Java source code.
  *
  * @param className the classname of the generated class
  * @return the tree as Java source code
  * @throws Exception if something goes wrong
  */
 public String toSource(String className) throws Exception {

   if (m_NumIterationsPerformed == 0) {
     throw new Exception("No model built yet");
   }
   if (!(m_Classifiers[0] instanceof Sourcable)) {
     throw new Exception("Base learner " + m_Classifier.getClass().getName()
		  + " is not Sourcable");
   }

   StringBuffer text = new StringBuffer("class ");
   text.append(className).append(" {\n\n");

   text.append("  public static double classify(Object[] i) {\n");

   if (m_NumIterationsPerformed == 1) {
     text.append("    return " + className + "_0.classify(i);\n");
   } else {
     text.append("    double [] sums = new double [" + m_NumClasses + "];\n");
     for (int i = 0; i < m_NumIterationsPerformed; i++) {
text.append("    sums[(int) " + className + '_' + i 
	    + ".classify(i)] += " + m_Betas[i] + ";\n");
     }
     text.append("    double maxV = sums[0];\n" +
	  "    int maxI = 0;\n"+
	  "    for (int j = 1; j < " + m_NumClasses + "; j++) {\n"+
	  "      if (sums[j] > maxV) { maxV = sums[j]; maxI = j; }\n"+
	  "    }\n    return (double) maxI;\n");
   }
   text.append("  }\n}\n");

   for (int i = 0; i < m_Classifiers.length; i++) {
text.append(((Sourcable)m_Classifiers[i])
	    .toSource(className + '_' + i));
   }
   return text.toString();
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:45,代码来源:AdaBoostM1.java


示例3: modelToSourcableModel

import weka.classifiers.Sourcable; //导入依赖的package包/类
public static String modelToSourcableModel(Classifier model, String className) throws Exception {
    if (model instanceof Sourcable) {
        Sourcable sourcable = (Sourcable) model;
        return sourcable.toSource(className);

    }
    return null;
}
 
开发者ID:wittawatj,项目名称:ctwt,代码行数:9,代码来源:SourcableHelper.java


示例4: toSource

import weka.classifiers.Sourcable; //导入依赖的package包/类
/**
 * Returns the boosted model as Java source code.
 *
 * @param className the classname in the generated code
 * @return the tree as Java source code
 * @throws Exception if something goes wrong
 */
public String toSource(String className) throws Exception {

  if (m_NumGenerated == 0) {
    throw new Exception("No model built yet");
  }
  if (!(m_Classifiers.get(0)[0] instanceof Sourcable)) {
    throw new Exception("Base learner " + m_Classifier.getClass().getName()
      + " is not Sourcable");
  }

  StringBuffer text = new StringBuffer("class ");
  text.append(className).append(" {\n\n");
  text.append("  private static double RtoP(double []R, int j) {\n"
    + "    double Rcenter = 0;\n"
    + "    for (int i = 0; i < R.length; i++) {\n"
    + "      Rcenter += R[i];\n" + "    }\n" + "    Rcenter /= R.length;\n"
    + "    double Rsum = 0;\n" + "    for (int i = 0; i < R.length; i++) {\n"
    + "      Rsum += Math.exp(R[i] - Rcenter);\n" + "    }\n"
    + "    return Math.exp(R[j]) / Rsum;\n" + "  }\n\n");

  text.append("  public static double classify(Object[] i) {\n"
    + "    double [] d = distribution(i);\n" + "    double maxV = d[0];\n"
    + "    int maxI = 0;\n" + "    for (int j = 1; j < " + m_NumClasses
    + "; j++) {\n" + "      if (d[j] > maxV) { maxV = d[j]; maxI = j; }\n"
    + "    }\n    return (double) maxI;\n  }\n\n");

  text.append("  public static double [] distribution(Object [] i) {\n");
  text.append("    double [] Fs = new double [" + m_NumClasses + "];\n");
  text.append("    double [] Fi = new double [" + m_NumClasses + "];\n");
  text.append("    double Fsum;\n");
  for (int i = 0; i < m_NumGenerated; i++) {
    text.append("    Fsum = 0;\n");
    for (int j = 0; j < m_NumClasses; j++) {
      text.append("    Fi[" + j + "] = " + className + '_' + j + '_' + i
        + ".classify(i); Fsum += Fi[" + j + "];\n");
      if (m_NumClasses == 2) {
        text.append("    Fi[1] = -Fi[0];\n"); // 2-class case is special
        break;
      }
    }
    text.append("    Fsum /= " + m_NumClasses + ";\n");
    text.append("    for (int j = 0; j < " + m_NumClasses + "; j++) {");
    text.append(" Fs[j] += (Fi[j] - Fsum) * " + (m_NumClasses - 1) + " / "
      + m_NumClasses + "; }\n");
  }

  text.append("    double [] dist = new double [" + m_NumClasses + "];\n"
    + "    for (int j = 0; j < " + m_NumClasses + "; j++) {\n"
    + "      dist[j] = RtoP(Fs, j);\n" + "    }\n    return dist;\n");
  text.append("  }\n}\n");

  for (int i = 0; i < m_Classifiers.get(0).length; i++) {
    for (int j = 0; j < m_Classifiers.size(); j++) {
      text.append(((Sourcable) m_Classifiers.get(j)[i]).toSource(
        className + '_' + i + '_' + j));
    }
    if (m_NumClasses == 2) {
      break; // Only need one classifier per iteration in this case
    }
  }
  return text.toString();
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:70,代码来源:LogitBoost.java


示例5: toSource

import weka.classifiers.Sourcable; //导入依赖的package包/类
/**
  * Returns the boosted model as Java source code.
  *
  * @param className the classname in the generated code
  * @return the tree as Java source code
  * @throws Exception if something goes wrong
  */
 public String toSource(String className) throws Exception {

   if (m_NumGenerated == 0) {
     throw new Exception("No model built yet");
   }
   if (!(m_Classifiers[0][0] instanceof Sourcable)) {
     throw new Exception("Base learner " + m_Classifier.getClass().getName()
		  + " is not Sourcable");
   }

   StringBuffer text = new StringBuffer("class ");
   text.append(className).append(" {\n\n");
   text.append("  private static double RtoP(double []R, int j) {\n"+
	"    double Rcenter = 0;\n"+
	"    for (int i = 0; i < R.length; i++) {\n"+
	"      Rcenter += R[i];\n"+
	"    }\n"+
	"    Rcenter /= R.length;\n"+
	"    double Rsum = 0;\n"+
	"    for (int i = 0; i < R.length; i++) {\n"+
	"      Rsum += Math.exp(R[i] - Rcenter);\n"+
	"    }\n"+
	"    return Math.exp(R[j]) / Rsum;\n"+
	"  }\n\n");

   text.append("  public static double classify(Object[] i) {\n" +
               "    double [] d = distribution(i);\n" +
               "    double maxV = d[0];\n" +
	"    int maxI = 0;\n"+
	"    for (int j = 1; j < " + m_NumClasses + "; j++) {\n"+
	"      if (d[j] > maxV) { maxV = d[j]; maxI = j; }\n"+
	"    }\n    return (double) maxI;\n  }\n\n");

   text.append("  public static double [] distribution(Object [] i) {\n");
   text.append("    double [] Fs = new double [" + m_NumClasses + "];\n");
   text.append("    double [] Fi = new double [" + m_NumClasses + "];\n");
   text.append("    double Fsum;\n");
   for (int i = 0; i < m_NumGenerated; i++) {
     text.append("    Fsum = 0;\n");
     for (int j = 0; j < m_NumClasses; j++) {
text.append("    Fi[" + j + "] = " + className + '_' +j + '_' + i 
	    + ".classify(i); Fsum += Fi[" + j + "];\n");
     }
     text.append("    Fsum /= " + m_NumClasses + ";\n");
     text.append("    for (int j = 0; j < " + m_NumClasses + "; j++) {");
     text.append(" Fs[j] += (Fi[j] - Fsum) * "
	  + (m_NumClasses - 1) + " / " + m_NumClasses + "; }\n");
   }
   
   text.append("    double [] dist = new double [" + m_NumClasses + "];\n" +
	"    for (int j = 0; j < " + m_NumClasses + "; j++) {\n"+
	"      dist[j] = RtoP(Fs, j);\n"+
	"    }\n    return dist;\n");
   text.append("  }\n}\n");

   for (int i = 0; i < m_Classifiers.length; i++) {
     for (int j = 0; j < m_Classifiers[i].length; j++) {
text.append(((Sourcable)m_Classifiers[i][j])
	    .toSource(className + '_' + i + '_' + j));
     }
   }
   return text.toString();
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:71,代码来源:LogitBoost.java


示例6: toSource

import weka.classifiers.Sourcable; //导入依赖的package包/类
/**
  * Returns the boosted model as Java source code.
  *
  * @param className the classname in the generated code
  * @return the tree as Java source code
  * @throws Exception if something goes wrong
  */
 public String toSource(String className) throws Exception {

   if (m_NumGenerated == 0) {
     throw new Exception("No model built yet");
   }
   if (!(m_Classifiers.get(0)[0] instanceof Sourcable)) {
     throw new Exception("Base learner " + m_Classifier.getClass().getName()
		  + " is not Sourcable");
   }

   StringBuffer text = new StringBuffer("class ");
   text.append(className).append(" {\n\n");
   text.append("  private static double RtoP(double []R, int j) {\n"+
	"    double Rcenter = 0;\n"+
	"    for (int i = 0; i < R.length; i++) {\n"+
	"      Rcenter += R[i];\n"+
	"    }\n"+
	"    Rcenter /= R.length;\n"+
	"    double Rsum = 0;\n"+
	"    for (int i = 0; i < R.length; i++) {\n"+
	"      Rsum += Math.exp(R[i] - Rcenter);\n"+
	"    }\n"+
	"    return Math.exp(R[j]) / Rsum;\n"+
	"  }\n\n");

   text.append("  public static double classify(Object[] i) {\n" +
               "    double [] d = distribution(i);\n" +
               "    double maxV = d[0];\n" +
	"    int maxI = 0;\n"+
	"    for (int j = 1; j < " + m_NumClasses + "; j++) {\n"+
	"      if (d[j] > maxV) { maxV = d[j]; maxI = j; }\n"+
	"    }\n    return (double) maxI;\n  }\n\n");

   text.append("  public static double [] distribution(Object [] i) {\n");
   text.append("    double [] Fs = new double [" + m_NumClasses + "];\n");
   text.append("    double [] Fi = new double [" + m_NumClasses + "];\n");
   text.append("    double Fsum;\n");
   for (int i = 0; i < m_NumGenerated; i++) {
     text.append("    Fsum = 0;\n");
     for (int j = 0; j < m_NumClasses; j++) {
text.append("    Fi[" + j + "] = " + className + '_' +j + '_' + i 
	    + ".classify(i); Fsum += Fi[" + j + "];\n");
       if (m_NumClasses == 2) {
         text.append("    Fi[1] = -Fi[0];\n"); // 2-class case is special
         break;
       }
     }
     text.append("    Fsum /= " + m_NumClasses + ";\n");
     text.append("    for (int j = 0; j < " + m_NumClasses + "; j++) {");
     text.append(" Fs[j] += (Fi[j] - Fsum) * "
	  + (m_NumClasses - 1) + " / " + m_NumClasses + "; }\n");
   }
   
   text.append("    double [] dist = new double [" + m_NumClasses + "];\n" +
	"    for (int j = 0; j < " + m_NumClasses + "; j++) {\n"+
	"      dist[j] = RtoP(Fs, j);\n"+
	"    }\n    return dist;\n");
   text.append("  }\n}\n");

   for (int i = 0; i < m_Classifiers.get(0).length; i++) {
     for (int j = 0; j < m_Classifiers.size(); j++) {
text.append(((Sourcable)m_Classifiers.get(j)[i])
	    .toSource(className + '_' + i + '_' + j));
     }
     if (m_NumClasses == 2) {
       break; // Only need one classifier per iteration in this case
     }
   }
   return text.toString();
 }
 
开发者ID:umple,项目名称:umple,代码行数:78,代码来源:LogitBoost.java



注:本文中的weka.classifiers.Sourcable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ActionExec类代码示例发布时间:2022-05-22
下一篇:
Java WorkspaceEdit类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap