本文整理汇总了Java中com.rapidminer.example.table.DataRowReader类的典型用法代码示例。如果您正苦于以下问题:Java DataRowReader类的具体用法?Java DataRowReader怎么用?Java DataRowReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataRowReader类属于com.rapidminer.example.table包,在下文中一共展示了DataRowReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillTableWithRandomValues
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
/**
* After creation of a new MemoryExampleTable with given size all values are Double.NaN. Use
* this method to fill the table with random values in the range specified by minimum and
* maximum values of the attributes. Please note that the attributes in the example table must
* already have proper minimum and maximum values. This works only for numerical attribute.
* Nominal attribute values will be set to 0.
*/
private static void fillTableWithRandomValues(ExampleTable exampleTable, ExampleSet baseSet, RandomGenerator random) {
DataRowReader reader = exampleTable.getDataRowReader();
Attribute[] attributes = exampleTable.getAttributes();
while (reader.hasNext()) {
DataRow dataRow = reader.next();
for (int i = 0; i < attributes.length; i++) {
if (attributes[i] != null) {
if (!attributes[i].isNominal()) {
double min = baseSet.getStatistics(attributes[i], Statistics.MINIMUM);
double max = baseSet.getStatistics(attributes[i], Statistics.MAXIMUM);
if (max > min) {
dataRow.set(attributes[i], random.nextDoubleInRange(min, max));
} else {
dataRow.set(attributes[i], random.nextDouble() * 2 - 1);
}
} else {
dataRow.set(attributes[i], 0);
}
}
}
}
}
示例2: createDataRowReader
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
/**
* Returns a DataRowReader returning random values (generated with fixed
* random seed).
*/
public static DataRowReader createDataRowReader(int size, Attribute[] attributes) {
Random random = new Random(0);
List<DataRow> dataRows = new LinkedList<DataRow>();
for (int i = 0; i < size; i++) {
double[] data = new double[attributes.length];
for (int j = 0; j < data.length; j++) {
if (attributes[j].isNominal()) {
data[j] = random.nextInt(attributes[j].getMapping().getValues().size());
}
if (attributes[j].getValueType() == Ontology.INTEGER) {
data[j] = random.nextInt(200) - 100;
} else {
data[j] = 20.0 * random.nextDouble() - 10.0;
}
}
dataRows.add(new DoubleArrayDataRow(data));
}
return new ListDataRowReader(dataRows.iterator());
}
示例3: fillTableWithRandomValues
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
/**
* After creation of a new ExampleTable with given size all values are 0. Use this method to
* fill the table with random values in the range specified by minimum and maximum values of the
* attributes. Please note that the attributes in the example table must already have proper
* minimum and maximum values. This works only for numerical attribute. Nominal attribute values
* will be set to 0.
*/
private static void fillTableWithRandomValues(ExampleTable exampleTable, ExampleSet baseSet, RandomGenerator random) {
DataRowReader reader = exampleTable.getDataRowReader();
Attribute[] attributes = exampleTable.getAttributes();
while (reader.hasNext()) {
DataRow dataRow = reader.next();
for (int i = 0; i < attributes.length; i++) {
if (attributes[i] != null) {
if (!attributes[i].isNominal()) {
double min = baseSet.getStatistics(attributes[i], Statistics.MINIMUM);
double max = baseSet.getStatistics(attributes[i], Statistics.MAXIMUM);
if (max > min) {
dataRow.set(attributes[i], random.nextDoubleInRange(min, max));
} else {
dataRow.set(attributes[i], random.nextDouble() * 2 - 1);
}
} else {
dataRow.set(attributes[i], 0);
}
}
}
}
}
示例4: createDataRowReaderTest
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
@Test
public void createDataRowReaderTest() {
Attribute attribute1 = ExampleTestTools.attributeInt();
Attribute attribute2 = ExampleTestTools.attributeReal();
DataRowReader reader = ExampleTestTools.createDataRowReader(new double[][] { { 1, 2.5 }, { 7, 11.5 } });
ExampleSet testSet = ExampleSets.from(attribute1, attribute2)//
.withDataRowReader(reader)//
.build();
assertEquals(2, testSet.getAttributes().allSize());
assertEquals(2, testSet.size());
assertEquals(1, testSet.getExample(0).getValue(attribute1), 0);
assertEquals(7, testSet.getExample(1).getValue(attribute1), 0);
assertEquals(2.5, testSet.getExample(0).getValue(attribute2), 1.0e-12);
assertEquals(11.5, testSet.getExample(1).getValue(attribute2), 1.0e-12);
}
示例5: prepareCopyValueTask
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
/**
* Creates a {@link Callable} which copies the values from the source to the target
* {@link ExampleTable} by using the {@link DataRowReader}, only the values of the defined
* {@link Attribute}s will be copied.
*/
private Callable<Void> prepareCopyValueTask(ExampleTable source, ExampleTable target, Attribute[] attributes) {
return new Callable<Void>() {
@Override
public Void call() {
try {
startSignal.await();
DataRowReader sourceReader = source.getDataRowReader();
DataRowReader targetReader = target.getDataRowReader();
DataRow sourceRow = null;
DataRow targetRow = null;
while (sourceReader.hasNext() && targetReader.hasNext()) {
sourceRow = sourceReader.next();
targetRow = targetReader.next();
for (Attribute a : attributes) {
targetRow.set(a, sourceRow.get(a));
}
}
} catch (InterruptedException e) {
Assert.fail(Thread.currentThread().getName() + " " + e.getMessage());
}
return null;
}
};
}
示例6: fillTableWithRandomValues
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
/**
* After creation of a new MemoryExampleTable with given size all values are
* Double.NaN. Use this method to fill the table with random values in the
* range specified by minimum and maximum values of the attributes. Please
* note that the attributes in the example table must already have proper
* minimum and maximum values. This works only for numerical attribute.
* Nominal attribute values will be set to 0.
*/
private static void fillTableWithRandomValues(ExampleTable exampleTable, ExampleSet baseSet, RandomGenerator random) {
DataRowReader reader = exampleTable.getDataRowReader();
Attribute[] attributes = exampleTable.getAttributes();
while (reader.hasNext()) {
DataRow dataRow = reader.next();
for (int i = 0; i < attributes.length; i++) {
if (attributes[i] != null) {
if (!attributes[i].isNominal()) {
double min = baseSet.getStatistics(attributes[i], Statistics.MINIMUM);
double max = baseSet.getStatistics(attributes[i], Statistics.MAXIMUM);
if (max > min)
dataRow.set(attributes[i], random.nextDoubleInRange(min, max));
else
dataRow.set(attributes[i], random.nextDouble()*2 - 1);
} else {
dataRow.set(attributes[i], 0);
}
}
}
}
}
示例7: createExampleSet
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
@Override
public ExampleSet createExampleSet() throws OperatorException {
int dataRowType = getParameterAsInt(PARAMETER_DATAMANAGEMENT);
ResultSet resultSet = getResultSet();
List<Attribute> attributeList = null;
try {
attributeList = DatabaseHandler.createAttributes(resultSet);
} catch (SQLException e) {
throw new UserError(this, e, 304, e.getMessage());
}
setNominalValues(attributeList, resultSet, find(attributeList, getParameterAsString(PARAMETER_LABEL_ATTRIBUTE)));
DataRowReader reader = new ResultSetDataRowReader(new DataRowFactory(dataRowType, '.'), attributeList, resultSet);
ExampleTable table = new MemoryExampleTable(attributeList, reader);
// close statements etc.
tearDown();
return createExampleSet(table, this);
}
示例8: getDataRowReader
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
public DataRowReader getDataRowReader() {
try {
return new DatabaseDataRowReader(this.resultSet);
} catch (SQLException var2) {
throw new RuntimeException("Error while creating database DataRowReader: " + var2, var2);
}
}
示例9: fillTable
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
/**
* Fills the table with the length of the given complex numbers in the column of the attribute.
*/
private void fillTable(ExampleTable table, Attribute attribute, Peak[] values) throws OperatorException {
DataRowReader reader = table.getDataRowReader();
int k = 0;
while (reader.hasNext()) {
DataRow dataRow = reader.next();
dataRow.set(attribute, values[k++].getMagnitude());
checkForStop();
}
}
示例10: writeColumnValues
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
/**
* Writes the values provided by the {@link #columnFillers} into the table.
*/
private void writeColumnValues() {
DataRowReader tableReader = table.getDataRowReader();
int k = 0;
while (tableReader.hasNext()) {
DataRow dataRow = tableReader.next();
for (Entry<Attribute, IntToDoubleFunction> entry : columnFillers.entrySet()) {
dataRow.set(entry.getKey(), entry.getValue().applyAsDouble(k));
}
k++;
}
}
示例11: doWork
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
@Override
public final void doWork() throws OperatorException {
ExampleSet inputExampleSet = exampleSetInput.getData(ExampleSet.class);
ExampleSet applySet = null;
// check for needed copy of original exampleset
if (writesIntoExistingData()) {
int type = DataRowFactory.TYPE_DOUBLE_ARRAY;
if (inputExampleSet.getExampleTable() instanceof MemoryExampleTable) {
DataRowReader dataRowReader = inputExampleSet.getExampleTable().getDataRowReader();
if (dataRowReader.hasNext()) {
type = dataRowReader.next().getType();
}
}
// check if type is supported to be copied
if (type >= 0) {
applySet = MaterializeDataInMemory.materializeExampleSet(inputExampleSet, type);
}
}
if (applySet == null) {
applySet = (ExampleSet) inputExampleSet.clone();
}
// we apply on the materialized data, because writing can't take place in views anyway.
ExampleSet result = apply(applySet);
originalOutput.deliver(inputExampleSet);
exampleSetOutput.deliver(result);
}
示例12: createWithEverythingOrderCheck
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
@Test
public void createWithEverythingOrderCheck() {
Attribute attribute1 = ExampleTestTools.attributeInt();
Attribute attribute2 = ExampleTestTools.attributeReal();
DataRowReader reader1 = ExampleTestTools.createDataRowReader(new double[][] { { 1, 1.5 }, { 2, 2.5 } });
DataRowReader reader2 = ExampleTestTools.createDataRowReader(new double[][] { { 1, 1.5 }, { 2, 2.5 } });
ExampleSet testSet1 = ExampleSets.from(attribute1, attribute2)//
.withColumnFiller(attribute1, i -> 5)//
.withBlankSize(1)//
.addDataRow(new DoubleArrayDataRow(new double[] { 3, 3.5 }))//
.withDataRowReader(reader1)//
.addRow(new double[] { 4, 4.5 })//
.build();
ExampleSet testSet2 = ExampleSets.from(attribute1, attribute2)//
.addDataRow(new DoubleArrayDataRow(new double[] { 3, 3.5 }))//
.addRow(new double[] { 4, 4.5 })//
.withDataRowReader(reader2)//
.withBlankSize(1)//
.withColumnFiller(attribute1, i -> 5)//
.build();
assertEquals(5, testSet1.size(), 1.0e-12);
assertEquals(5, testSet2.size(), 1.0e-12);
for (int i = 0; i < testSet1.size(); i++) {
assertEquals(testSet1.getExample(i).getValue(attribute1), testSet2.getExample(i).getValue(attribute1), 1.0e-12);
assertEquals(testSet1.getExample(i).getValue(attribute2), testSet2.getExample(i).getValue(attribute2), 1.0e-12);
}
}
示例13: doWork
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
@Override
public final void doWork() throws OperatorException {
ExampleSet inputExampleSet = exampleSetInput.getData(ExampleSet.class);
ExampleSet applySet = null;
// check for needed copy of original exampleset
if (originalOutput.isConnected() && writesIntoExistingData()) {
int type = DataRowFactory.TYPE_DOUBLE_ARRAY;
if (inputExampleSet.getExampleTable() instanceof MemoryExampleTable) {
DataRowReader dataRowReader = inputExampleSet.getExampleTable().getDataRowReader();
if (dataRowReader.hasNext()) {
type = dataRowReader.next().getType();
}
}
// check if type is supported to be copied
if (type >= 0) {
applySet = MaterializeDataInMemory.materializeExampleSet(inputExampleSet, type);
}
}
if (applySet == null)
applySet = (ExampleSet) inputExampleSet.clone();
// we apply on the materialized data, because writing can't take place in views anyway.
ExampleSet result = apply(applySet);
originalOutput.deliver(inputExampleSet);
exampleSetOutput.deliver(result);
}
示例14: apply
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
@Override
public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
Tools.onlyNonMissingValues(exampleSet, "Fourier Transform");
// create new example table
int numberOfNewExamples = FastFourierTransform.getGreatestPowerOf2LessThan(exampleSet.size()) / 2;
ExampleTable exampleTable = new MemoryExampleTable(new LinkedList<Attribute>(), new DataRowFactory(DataRowFactory.TYPE_DOUBLE_ARRAY, '.'), numberOfNewExamples);
// create frequency attribute (for frequency)
Attribute frequencyAttribute = AttributeFactory.createAttribute("frequency", Ontology.REAL);
exampleTable.addAttribute(frequencyAttribute);
DataRowReader drr = exampleTable.getDataRowReader();
int k = 0;
while (drr.hasNext()) {
DataRow dataRow = drr.next();
dataRow.set(frequencyAttribute, FastFourierTransform.convertFrequency(k++, numberOfNewExamples, exampleSet.size()));
}
// create FFT values
Attribute label = exampleSet.getAttributes().getLabel();
// add FFT values
FastFourierTransform fft = new FastFourierTransform(WindowFunction.BLACKMAN_HARRIS);
SpectrumFilter filter = new SpectrumFilter(SpectrumFilter.NONE);
for (Attribute current : exampleSet.getAttributes()) {
if (current.isNumerical()) {
Complex[] result = fft.getFourierTransform(exampleSet, label, current);
Peak[] spectrum = filter.filter(result, exampleSet.size());
// create new attribute and fill table with values
Attribute newAttribute = AttributeFactory.createAttribute("fft(" + current.getName() + ")", Ontology.REAL);
exampleTable.addAttribute(newAttribute);
fillTable(exampleTable, newAttribute, spectrum);
}
}
ExampleSet resultSet = new SimpleExampleSet(exampleTable);
return resultSet;
}
示例15: getDataRowReader
import com.rapidminer.example.table.DataRowReader; //导入依赖的package包/类
public DataRowReader getDataRowReader() {
return new IndexCachedDatabaseExampleTable.CachedDataRowReader();
}