Java Code Examples for com.jstarcraft.core.utility.RandomUtility#shuffle()

The following examples show how to use com.jstarcraft.core.utility.RandomUtility#shuffle() . 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: QuantityAttributeTestCase.java    From jstarcraft-ai with Apache License 2.0 6 votes vote down vote up
@Override
public void testConvertValue() {
    int size = 1000;
    float[] datas = new float[size];
    for (int index = 0; index < size; index++) {
        datas[index] = index;
    }
    RandomUtility.shuffle(datas);
    QuantityAttribute<Float> attribute = getQuantityAttribute();
    for (int index = 0; index < size; index++) {
        Assert.assertEquals(datas[index], attribute.convertData(datas[index]), 0F);
    }
    Assert.assertEquals(999F, attribute.getMaximum(), 0F);
    Assert.assertEquals(0F, attribute.getMinimum(), 0F);
    for (int index = 0; index < size; index++) {
        Assert.assertEquals(datas[index], attribute.convertData(datas[index]), 0F);
    }
    Assert.assertEquals(999F, attribute.getMaximum(), 0F);
    Assert.assertEquals(0F, attribute.getMinimum(), 0F);
}
 
Example 2
Source File: QualityAttributeTestCase.java    From jstarcraft-ai with Apache License 2.0 6 votes vote down vote up
@Override
public void testConvertValue() {
    int size = 1000;
    float[] datas = new float[size];
    for (int index = 0; index < size; index++) {
        datas[index] = index;
    }
    RandomUtility.shuffle(datas);
    QualityAttribute<Float> attribute = getQualityAttribute();
    for (int index = 0; index < size; index++) {
        Assert.assertEquals(index, attribute.convertData(datas[index]));
    }
    Assert.assertEquals(size, attribute.getSize());
    for (int index = 0; index < size; index++) {
        Assert.assertEquals(index, attribute.convertData(datas[index]));
    }
    Assert.assertEquals(size, attribute.getSize());
}
 
Example 3
Source File: KFoldCrossValidationSeparator.java    From jstarcraft-rns with Apache License 2.0 5 votes vote down vote up
public KFoldCrossValidationSeparator(DataModule dataModule, int number) {
    this.dataModule = dataModule;
    this.number = number;
    this.folds = new Integer[this.dataModule.getSize()];
    for (int index = 0, size = this.folds.length; index < size; index++) {
        this.folds[index] = index % number;
    }
    // 通过随机与交换的方式实现打乱排序的目的.
    RandomUtility.shuffle(this.folds);
}
 
Example 4
Source File: QuantityAttributeTestCase.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void testConcurrent() throws Exception {
    int size = 1000;
    float[] datas = new float[size];
    for (int index = 0; index < size; index++) {
        datas[index] = index;
    }
    RandomUtility.shuffle(datas);

    final int numberOfThread = 10;
    ExecutorService executor = Executors.newFixedThreadPool(numberOfThread);
    final CyclicBarrier barrier = new CyclicBarrier(numberOfThread + 1);
    QuantityAttribute<Float> attribute = getQuantityAttribute();
    for (int thread = 0; thread < numberOfThread; thread++) {
        executor.submit(() -> {
            try {
                barrier.await();
                for (int index = 0; index < size; index++) {
                    Assert.assertEquals(datas[index], attribute.convertData(datas[index]), 0F);
                }
                Assert.assertEquals(999F, attribute.getMaximum(), 0F);
                Assert.assertEquals(0F, attribute.getMinimum(), 0F);
                barrier.await();
            } catch (Exception exception) {
                Assert.fail();
            }
        });
    }
    // 等待所有线程开始
    barrier.await();
    // 等待所有线程结束
    barrier.await();
}
 
Example 5
Source File: QualityAttributeTestCase.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
@Override
public void testConcurrent() throws Exception {
    int size = 1000;
    float[] datas = new float[size];
    for (int index = 0; index < size; index++) {
        datas[index] = index;
    }
    RandomUtility.shuffle(datas);

    final int numberOfThread = 10;
    ExecutorService executor = Executors.newFixedThreadPool(numberOfThread);
    final CyclicBarrier barrier = new CyclicBarrier(numberOfThread + 1);
    QualityAttribute<Float> attribute = getQualityAttribute();
    for (int thread = 0; thread < numberOfThread; thread++) {
        executor.submit(() -> {
            try {
                barrier.await();
                for (int index = 0; index < size; index++) {
                    Assert.assertEquals(index, attribute.convertData(datas[index]));
                }
                Assert.assertEquals(size, attribute.getSize());
                barrier.await();
            } catch (Exception exception) {
                exception.printStackTrace();
                Assert.fail();
            }
        });
    }
    // 等待所有线程开始
    barrier.await();
    // 等待所有线程结束
    barrier.await();
}