本文整理汇总了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);
}
示例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();
}
}
}
}
}
示例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();
}
}
}
}
}
示例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!");
}
示例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!");
}
示例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)!");
}
示例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)!");
}
示例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)!");
}
示例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)!");
}
示例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)!");
}
示例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)!");
}
示例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)!");
}
示例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)!");
}
示例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)!");
}
示例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)!");
}