Java Code Examples for com.jstarcraft.core.utility.RandomUtility#randomBoolean()
The following examples show how to use
com.jstarcraft.core.utility.RandomUtility#randomBoolean() .
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: RowGlobalMatrixTestCase.java From jstarcraft-ai with Apache License 2.0 | 6 votes |
@Override protected RowGlobalMatrix getRandomMatrix(int dimension) { MathMatrix from = DenseMatrix.valueOf(1, dimension); HashMatrix table = new HashMatrix(true, dimension, dimension, new Long2FloatRBTreeMap()); for (int rowIndex = 0; rowIndex < dimension - 1; rowIndex++) { for (int columnIndex = 0; columnIndex < dimension; columnIndex++) { if (RandomUtility.randomBoolean()) { table.setValue(rowIndex, columnIndex, 0F); } } } MathMatrix to = SparseMatrix.valueOf(dimension - 1, dimension, table); RowGlobalMatrix matrix = RowGlobalMatrix.attachOf(from, to); matrix.iterateElement(MathCalculator.SERIAL, (scalar) -> { scalar.setValue(RandomUtility.randomInteger(dimension)); }); return matrix; }
Example 2
Source File: ColumnArrayMatrixTestCase.java From jstarcraft-ai with Apache License 2.0 | 6 votes |
@Override protected ColumnArrayMatrix getRandomMatrix(int dimension) { HashMatrix table = new HashMatrix(true, dimension, dimension, new Long2FloatRBTreeMap()); for (int rowIndex = 0; rowIndex < dimension; rowIndex++) { for (int columnIndex = 0; columnIndex < dimension; columnIndex++) { if (RandomUtility.randomBoolean()) { table.setValue(rowIndex, columnIndex, 0F); } } } SparseMatrix data = SparseMatrix.valueOf(dimension, dimension, table); ArrayVector[] vectors = new ArrayVector[dimension]; for (int columnIndex = 0; columnIndex < dimension; columnIndex++) { vectors[columnIndex] = new ArrayVector(data.getColumnVector(columnIndex)); } ColumnArrayMatrix matrix = ColumnArrayMatrix.valueOf(dimension, vectors); matrix.iterateElement(MathCalculator.SERIAL, (scalar) -> { scalar.setValue(RandomUtility.randomInteger(dimension)); }); return matrix; }
Example 3
Source File: RowArrayMatrixTestCase.java From jstarcraft-ai with Apache License 2.0 | 6 votes |
@Override protected RowArrayMatrix getRandomMatrix(int dimension) { HashMatrix table = new HashMatrix(true, dimension, dimension, new Long2FloatRBTreeMap()); for (int rowIndex = 0; rowIndex < dimension; rowIndex++) { for (int columnIndex = 0; columnIndex < dimension; columnIndex++) { if (RandomUtility.randomBoolean()) { table.setValue(rowIndex, columnIndex, 0F); } } } SparseMatrix data = SparseMatrix.valueOf(dimension, dimension, table); ArrayVector[] vectors = new ArrayVector[dimension]; for (int rowIndex = 0; rowIndex < dimension; rowIndex++) { vectors[rowIndex] = new ArrayVector(data.getRowVector(rowIndex)); } RowArrayMatrix matrix = RowArrayMatrix.valueOf(dimension, vectors); matrix.iterateElement(MathCalculator.SERIAL, (scalar) -> { scalar.setValue(RandomUtility.randomInteger(dimension)); }); return matrix; }
Example 4
Source File: SparseMatrixTestCase.java From jstarcraft-ai with Apache License 2.0 | 6 votes |
@Override protected SparseMatrix getRandomMatrix(int dimension) { HashMatrix table = new HashMatrix(true, dimension, dimension, new Long2FloatRBTreeMap()); for (int rowIndex = 0; rowIndex < dimension; rowIndex++) { for (int columnIndex = 0; columnIndex < dimension; columnIndex++) { if (RandomUtility.randomBoolean()) { table.setValue(rowIndex, columnIndex, 0F); } } } SparseMatrix matrix = SparseMatrix.valueOf(dimension, dimension, table); matrix.iterateElement(MathCalculator.SERIAL, (scalar) -> { scalar.setValue(RandomUtility.randomInteger(dimension)); }); return matrix; }
Example 5
Source File: ColumnGlobalMatrixTestCase.java From jstarcraft-ai with Apache License 2.0 | 6 votes |
@Override protected ColumnGlobalMatrix getRandomMatrix(int dimension) { MathMatrix from = DenseMatrix.valueOf(dimension, 1); HashMatrix table = new HashMatrix(true, dimension, dimension, new Long2FloatRBTreeMap()); for (int rowIndex = 0; rowIndex < dimension; rowIndex++) { for (int columnIndex = 0; columnIndex < dimension - 1; columnIndex++) { if (RandomUtility.randomBoolean()) { table.setValue(rowIndex, columnIndex, 0F); } } } MathMatrix to = SparseMatrix.valueOf(dimension, dimension - 1, table); ColumnGlobalMatrix matrix = ColumnGlobalMatrix.attachOf(from, to); matrix.iterateElement(MathCalculator.SERIAL, (scalar) -> { scalar.setValue(RandomUtility.randomInteger(dimension)); }); return matrix; }
Example 6
Source File: RowHashMatrixTestCase.java From jstarcraft-ai with Apache License 2.0 | 5 votes |
@Override protected HashMatrix getRandomMatrix(int dimension) { HashMatrix matrix = new HashMatrix(true, dimension, dimension, new Long2FloatRBTreeMap()); for (int rowIndex = 0; rowIndex < dimension; rowIndex++) { for (int columnIndex = 0; columnIndex < dimension; columnIndex++) { if (RandomUtility.randomBoolean()) { matrix.setValue(rowIndex, columnIndex, 0F); } } } return matrix; }
Example 7
Source File: ColumnHashMatrixTestCase.java From jstarcraft-ai with Apache License 2.0 | 5 votes |
@Override protected HashMatrix getRandomMatrix(int dimension) { HashMatrix matrix = new HashMatrix(false, dimension, dimension, new Long2FloatRBTreeMap()); for (int columnIndex = 0; columnIndex < dimension; columnIndex++) { for (int rowIndex = 0; rowIndex < dimension; rowIndex++) { if (RandomUtility.randomBoolean()) { matrix.setValue(rowIndex, columnIndex, 0F); } } } return matrix; }
Example 8
Source File: ContentCodecTestCase.java From jstarcraft-core with Apache License 2.0 | 4 votes |
@Test public void testComplex() throws Exception { // 基于对象的协议测试 MockComplexObject object = MockComplexObject.instanceOf(0, "birdy", "hong", 10, Instant.now(), MockEnumeration.TERRAN); testConvert(MockComplexObject.class, object); int dimension = 50; Table<Integer, Integer, Double> dataTable = HashBasedTable.create(); for (int rowIndex = 0; rowIndex < dimension; rowIndex++) { for (int columnIndex = 0; columnIndex < dimension; columnIndex++) { if (RandomUtility.randomBoolean()) { dataTable.put(rowIndex, columnIndex, 1D); } } } MockMatrix matrix = MockMatrix.instanceOf(dimension, dimension, dataTable); testConvert(MockMatrix.class, matrix); // 基于枚举的协议测试 testConvert(MockEnumeration.class, MockEnumeration.TERRAN); // 基于数组的协议测试 MockEnumeration[] enumerationArray = MockEnumeration.values(); testConvert(MockEnumeration[].class, enumerationArray); MockComplexObject[] objectArray = new MockComplexObject[] { object }; testConvert(MockComplexObject[].class, objectArray); // 基于集合的协议测试 List<MockEnumeration> enumerationList = new ArrayList<>(enumerationArray.length); Collections.addAll(enumerationList, enumerationArray); testConvert(TypeUtility.parameterize(ArrayList.class, MockEnumeration.class), enumerationList); Set<MockEnumeration> enumerationSet = new HashSet<>(enumerationList); testConvert(TypeUtility.parameterize(HashSet.class, MockEnumeration.class), enumerationSet); List<Integer> integerList = new ArrayList<>(5); Collections.addAll(integerList, new Integer[] { 0, 1, 2, 3, 4 }); testConvert(TypeUtility.parameterize(ArrayList.class, Integer.class), integerList); Set<Integer> integerSet = new TreeSet<>(integerList); testConvert(TypeUtility.parameterize(TreeSet.class, Integer.class), integerSet); List<MockComplexObject> objectList = new ArrayList<>(objectArray.length); Collections.addAll(objectList, objectArray); testConvert(TypeUtility.parameterize(ArrayList.class, MockComplexObject.class), objectList); Set<MockComplexObject> objectSet = new HashSet<>(objectList); testConvert(TypeUtility.parameterize(HashSet.class, MockComplexObject.class), objectSet); // 基于映射的协议测试 Map<String, MockComplexObject> map = new HashMap<>(); for (MockComplexObject element : objectList) { map.put(element.getFirstName(), element); } testConvert(TypeUtility.parameterize(HashMap.class, String.class, MockComplexObject.class), map); }