Java Code Examples for com.jstarcraft.ai.data.DataModule#getSize()

The following examples show how to use com.jstarcraft.ai.data.DataModule#getSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomDataSorter.java    From jstarcraft-rns with Apache License 2.0 6 votes vote down vote up
@Override
public ReferenceModule sort(DataModule module) {
    int size = module.getSize();
    IntegerArray reference = new IntegerArray(size, size);
    for (int index = 0; index < size; index++) {
        reference.associateData(index);
    }
    int from = 0;
    int to = size;
    for (int index = from; index < to; index++) {
        int random = RandomUtility.randomInteger(from, to);
        int data = reference.getData(index);
        reference.setData(index, reference.getData(random));
        reference.setData(random, data);
    }
    return new ReferenceModule(reference, module);
}
 
Example 2
Source File: DataSplitter.java    From jstarcraft-ai with Apache License 2.0 6 votes vote down vote up
/**
 * 划分
 * 
 * @param module
 * @param number
 * @return
 */
default ReferenceModule[] split(DataModule module, int number) {
    int size = module.getSize();
    int maximum = size;
    int minimum = 1000;
    if (maximum < minimum) {
        maximum = minimum;
    }
    IntegerArray[] references = new IntegerArray[number];
    for (int index = 0; index < number; index++) {
        references[index] = new IntegerArray(minimum, maximum);
    }
    int cursor = 0;
    DataInstance instance = module.getInstance(cursor);
    while (cursor < size) {
        instance.setCursor(cursor);
        references[split(instance) % number].associateData(cursor);
        cursor++;
    }
    ReferenceModule[] modules = new ReferenceModule[number];
    for (int index = 0; index < number; index++) {
        modules[index] = new ReferenceModule(references[index], module);
    }
    return modules;
}
 
Example 3
Source File: DataSelector.java    From jstarcraft-ai with Apache License 2.0 6 votes vote down vote up
/**
 * 选择
 * 
 * @param module
 * @return
 */
default ReferenceModule select(DataModule module) {
    int size = module.getSize();
    if (size == 0) {
        return new ReferenceModule(module);
    }
    int maximum = size;
    int minimum = 1000;
    if (maximum < minimum) {
        maximum = minimum;
    }
    IntegerArray reference = new IntegerArray(minimum, maximum);
    int cursor = 0;
    DataInstance instance = module.getInstance(cursor);
    while (cursor < size) {
        instance.setCursor(cursor);
        if (select(instance)) {
            reference.associateData(cursor);
        }
        cursor++;
    }
    return new ReferenceModule(reference, module);
}
 
Example 4
Source File: GivenDataSeparator.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
public GivenDataSeparator(DataModule dataModule, int threshold) {
    this.dataModule = dataModule;
    this.trainReference = new IntegerArray();
    this.testReference = new IntegerArray();
    int size = dataModule.getSize();
    for (int index = 0; index < size; index++) {
        if (index < threshold) {
            this.trainReference.associateData(index);
        } else {
            this.testReference.associateData(index);
        }
    }
}
 
Example 5
Source File: ReferenceModule.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
public ReferenceModule(DataModule module) {
    int size = module.getSize();
    this.references = new IntegerArray(size, size);
    for (int index = 0; index < size; index++) {
        this.references.associateData(index);
    }
    this.module = module;
}
 
Example 6
Source File: DataSorter.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
/**
 * 排序
 * 
 * @param module
 * @return
 */
default ReferenceModule sort(DataModule module) {
    int size = module.getSize();
    if (size <= 1) {
        return new ReferenceModule(module);
    }
    IntegerArray reference = new IntegerArray(size, size);
    for (int index = 0; index < size; index++) {
        reference.associateData(index);
    }
    int cursor = 0;
    DataInstance leftInstance = module.getInstance(cursor);
    DataInstance rightInstance = module.getInstance(cursor);
    for (int left = 0; left < size - 1; left++) {
        leftInstance.setCursor(left);
        for (int right = left + 1; right < size; right++) {
            // TODO 注意:此处存在0的情况.
            rightInstance.setCursor(right);
            if (sort(leftInstance, rightInstance) > 0) {
                reference.setData(left, reference.getData(left) ^ reference.getData(right));
                reference.setData(right, reference.getData(right) ^ reference.getData(left));
                reference.setData(left, reference.getData(left) ^ reference.getData(right));
            }
        }
    }
    return new ReferenceModule(reference, module);
}