当前位置: 首页>>代码示例>>Java>>正文


Java SparseInstance类代码示例

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


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

示例1: getInstanceObject

import weka.core.SparseInstance; //导入依赖的package包/类
public static Instance getInstanceObject (String[] instanceText, 
        String[] globalFeatureVector, String docID, String classValue, Instances ds) throws Exception {
    
    FeatureVector instanceFeatureVector = getInstanceFeatureVector(instanceText, 
            globalFeatureVector, docID);
    
    
    Instance instance = new Instance(globalFeatureVector.length + 2);
    instance.setDataset(ds);
    instance.setValue(0, docID);
    for(int i = 0; i < globalFeatureVector.length; i++) {
    	double value = 0;
    	if(instanceFeatureVector.m_FeatureVector[0].containsKey(i)) {
    		value = instanceFeatureVector.m_FeatureVector[0].get(i);
    	}
    	
    	instance.setValue(i + 1, value);
    }
    instance.setValue(globalFeatureVector.length + 1, classValue);
    
    return new SparseInstance(instance);
}
 
开发者ID:NLPReViz,项目名称:emr-nlp-server,代码行数:23,代码来源:WekaDataSet.java

示例2: processSingleton

import weka.core.SparseInstance; //导入依赖的package包/类
private void processSingleton(Instance current,
  ArrayList<BinaryItem> singletons) throws Exception {

  if (current instanceof SparseInstance) {
    for (int j = 0; j < current.numValues(); j++) {
      int attIndex = current.index(j);
      singletons.get(attIndex).increaseFrequency();
    }
  } else {
    for (int j = 0; j < current.numAttributes(); j++) {
      if (!current.isMissing(j)) {
        if (current.attribute(j).numValues() == 1
          || current.value(j) == m_positiveIndex - 1) {
          singletons.get(j).increaseFrequency();
        }
      }
    }
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:20,代码来源:FPGrowth.java

示例3: processSingleton

import weka.core.SparseInstance; //导入依赖的package包/类
private void processSingleton(Instance current, 
    ArrayList<BinaryItem> singletons) throws Exception {
  
  if (current instanceof SparseInstance) {
    for (int j = 0; j < current.numValues(); j++) {
      int attIndex = current.index(j);
      singletons.get(attIndex).increaseFrequency();
    }
  } else {
    for (int j = 0; j < current.numAttributes(); j++) {
      if (!current.isMissing(j)) {
        if (current.attribute(j).numValues() == 1 
            || current.value(j) == m_positiveIndex - 1) {
          singletons.get(j).increaseFrequency();
        }
      }
    }
  }
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:20,代码来源:FPGrowth.java

示例4: testTypical

import weka.core.SparseInstance; //导入依赖的package包/类
/**
 * format must be different in precision (e.g., yyyy-MM instead of
 * yyyy-MM-dd) from the one in "weka.filters.data.FilterTest.arff", otherwise
 * this test will fail! 
 * Note: Sparse instances are skipped.
 */
public void testTypical() {
  m_Filter = getFilter();
  ((ChangeDateFormat) m_Filter).setDateFormat("yyyy-MM");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // all instance's must be different
  boolean equal = false;
  for (int i = 0; i < m_Instances.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (m_Comparator.compare(
          m_Instances.instance(i), result.instance(i)) == 0) {
      equal = true;
      break;
    }
  }
  if (equal)
    fail("Instances not changed!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:27,代码来源:ChangeDateFormatTest.java

示例5: testSameFormat

import weka.core.SparseInstance; //导入依赖的package包/类
/**
 * format must be the same as in "weka.filters.data.FilterTest.arff",
 * otherwise this test will fail!
 * Note: Sparse instances are skipped.
 */
public void testSameFormat() {
  m_Filter = getFilter();
  ((ChangeDateFormat) m_Filter).setDateFormat("yyyy-MM-dd");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // all instance's must be the same
  boolean equal = true;
  for (int i = 0; i < m_Instances.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (m_Comparator.compare(
          m_Instances.instance(i), result.instance(i)) != 0) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Instances modified!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:26,代码来源:ChangeDateFormatTest.java

示例6: testEquality

import weka.core.SparseInstance; //导入依赖的package包/类
/**
 * checks whether attribute value stays the same
 */
public void testEquality() {
  m_Filter = getFilter("A");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // check equality
  boolean equal = true;
  for (int i = 0; i < result.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (!Utils.eq(
          m_Instances.instance(i).value(m_AttIndex), 
          result.instance(i).value(m_AttIndex))) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Filter modifies attribute values)!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:24,代码来源:MathExpressionTest.java

示例7: testAbs

import weka.core.SparseInstance; //导入依赖的package包/类
public void testAbs() {
  m_Filter = getFilter("abs(A)");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // check equality
  boolean equal = true;
  for (int i = 0; i < result.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (!Utils.eq(
          Math.abs(m_Instances.instance(i).value(m_AttIndex)), 
          result.instance(i).value(m_AttIndex))) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Filter produces different result)!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:21,代码来源:MathExpressionTest.java

示例8: testsqrt

import weka.core.SparseInstance; //导入依赖的package包/类
public void testsqrt() {
  m_Filter = getFilter("sqrt(A)");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // check equality
  boolean equal = true;
  for (int i = 0; i < result.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (!Utils.eq(
          Math.sqrt(m_Instances.instance(i).value(m_AttIndex)), 
          result.instance(i).value(m_AttIndex))) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Filter produces different result)!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:21,代码来源:MathExpressionTest.java

示例9: testLog

import weka.core.SparseInstance; //导入依赖的package包/类
public void testLog() {
  m_Filter = getFilter("log(A)");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // check equality
  boolean equal = true;
  for (int i = 0; i < result.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (!Utils.eq(
          Math.log(m_Instances.instance(i).value(m_AttIndex)), 
          result.instance(i).value(m_AttIndex))) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Filter produces different result)!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:21,代码来源:MathExpressionTest.java

示例10: testExp

import weka.core.SparseInstance; //导入依赖的package包/类
public void testExp() {
  m_Filter = getFilter("exp(A)");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // check equality
  boolean equal = true;
  for (int i = 0; i < result.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (!Utils.eq(
          Math.exp(m_Instances.instance(i).value(m_AttIndex)), 
          result.instance(i).value(m_AttIndex))) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Filter produces different result)!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:21,代码来源:MathExpressionTest.java

示例11: testSin

import weka.core.SparseInstance; //导入依赖的package包/类
public void testSin() {
  m_Filter = getFilter("sin(A)");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // check equality
  boolean equal = true;
  for (int i = 0; i < result.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (!Utils.eq(
          Math.sin(m_Instances.instance(i).value(m_AttIndex)), 
          result.instance(i).value(m_AttIndex))) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Filter produces different result)!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:21,代码来源:MathExpressionTest.java

示例12: testCos

import weka.core.SparseInstance; //导入依赖的package包/类
public void testCos() {
  m_Filter = getFilter("cos(A)");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // check equality
  boolean equal = true;
  for (int i = 0; i < result.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (!Utils.eq(
          Math.cos(m_Instances.instance(i).value(m_AttIndex)), 
          result.instance(i).value(m_AttIndex))) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Filter produces different result)!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:21,代码来源:MathExpressionTest.java

示例13: testTan

import weka.core.SparseInstance; //导入依赖的package包/类
public void testTan() {
  m_Filter = getFilter("tan(A)");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // check equality
  boolean equal = true;
  for (int i = 0; i < result.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (!Utils.eq(
          Math.tan(m_Instances.instance(i).value(m_AttIndex)), 
          result.instance(i).value(m_AttIndex))) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Filter produces different result)!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:21,代码来源:MathExpressionTest.java

示例14: testRint

import weka.core.SparseInstance; //导入依赖的package包/类
public void testRint() {
  m_Filter = getFilter("rint(A)");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // check equality
  boolean equal = true;
  for (int i = 0; i < result.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (!Utils.eq(
          Math.rint(m_Instances.instance(i).value(m_AttIndex)), 
          result.instance(i).value(m_AttIndex))) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Filter produces different result)!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:21,代码来源:MathExpressionTest.java

示例15: testFloor

import weka.core.SparseInstance; //导入依赖的package包/类
public void testFloor() {
  m_Filter = getFilter("floor(A)");
  Instances result = useFilter();
  assertEquals(m_Instances.numAttributes(), result.numAttributes());
  assertEquals(m_Instances.numInstances(), result.numInstances());
  // check equality
  boolean equal = true;
  for (int i = 0; i < result.numInstances(); i++) {
    if (m_Instances.instance(i) instanceof SparseInstance)
      continue;
    if (!Utils.eq(
          Math.floor(m_Instances.instance(i).value(m_AttIndex)), 
          result.instance(i).value(m_AttIndex))) {
      equal = false;
      break;
    }
  }
  if (!equal)
    fail("Filter produces different result)!");
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:21,代码来源:MathExpressionTest.java


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