11package com .jdoe .algorithms ;
22
3+ import org .apache .commons .math3 .linear .Array2DRowFieldMatrix ;
4+ import org .apache .commons .math3 .linear .Array2DRowRealMatrix ;
5+ import org .apache .commons .math3 .linear .RealMatrix ;
6+ import org .jetbrains .annotations .NotNull ;
7+
8+ import com .jdoe .util .GenericDOEUtil ;
9+
310public class CompositeDOE {
411
5- public static void centralCompositeDesign () {
12+ private static final String [] alphaParamLegalExpressions = { "orthogonal" , "o" , "rotatable" , "r" };
13+
14+ private static final String [] faceParamLegalExpressions = { "circumscribed" , "ccc" , "inscribed" , "cci" , "faced" , "ccf" };
15+
16+ public static void centralCompositeDesign ( @ NotNull int numberOfFactors , @ NotNull int [] centerPoints , @ NotNull String alpha ,
17+ @ NotNull String face ) {
18+
19+ validateCompositeDegisnParameters ( numberOfFactors , centerPoints , alpha , face );
20+
21+ RealMatrix fullFactorial2LevelMatrix = FactorialDOE .fullFactorial2Level ( numberOfFactors );
22+
23+ }
24+
25+ //<-----------------------------Utility Methods---------------------------------->
26+
27+ public static void validateCompositeDegisnParameters ( int numberOfFactors , int [] centerPoints , String alpha , String face ) {
28+ if ( numberOfFactors < 1 ) {
29+ throw new IllegalArgumentException ( "number of factors must be greater then 1" );
30+ }
31+ if ( centerPoints .length == 2 ) {
32+ throw new IllegalArgumentException (
33+ String .format ( "Invalid number of values for \" center\" (expected 2, but got %d )" , centerPoints .length ) );
34+ }
35+ if ( validateExpression ( alpha , alphaParamLegalExpressions ) == Boolean .FALSE ) {
36+ throw new IllegalArgumentException (
37+ String .format ( "Invalid value for \" alpha\" (expected format %d )" , alphaParamLegalExpressions .toString () ) );
38+ }
39+ if ( validateExpression ( alpha , faceParamLegalExpressions ) == Boolean .FALSE ) {
40+ throw new IllegalArgumentException (
41+ String .format ( "Invalid value for \" face\" (expected format %d )" , faceParamLegalExpressions .toString () ) );
42+ }
43+ }
44+
45+ public static Boolean validateExpression ( String expression , String [] legalExpressions ) {
46+ Boolean validInput = Boolean .FALSE ;
47+ for ( String legalExpression : legalExpressions ) {
48+ if ( legalExpression .equals ( expression ) ) {
49+ validInput = Boolean .TRUE ;
50+ break ;
51+ }
52+ }
53+ return validInput ;
54+ }
655
56+ public static Boolean matrixUnion ( RealMatrix firstMatrix , RealMatrix secondMatrix ) {
57+ double [][] finalMatrixRowModel = new double [ firstMatrix .getRowDimension () + secondMatrix .getRowDimension () ][];
58+ for ( int i = 0 ; i < firstMatrix .getRowDimension (); i ++ ) {
59+ finalMatrixRowModel [ i ] = firstMatrix .getRow ( i );
60+ }
61+ for ( int i = 0 ; i < secondMatrix .getRowDimension (); i ++ ) {
62+ finalMatrixRowModel [ i ] = secondMatrix .getRow ( i );
63+ }
64+ RealMatrix finalMatrix = new Array2DRowRealMatrix (finalMatrixRowModel );
65+ GenericDOEUtil .matrixLogger ( finalMatrix , "matrixUnion" );
766 }
867
968}
1069
1170//<-----------------------------STEPS---------------------------------->
1271
1372/**
14- * Detailed Steps to Port Central Composite Design Script to Java 1. Create CompositeDOE Class Structure Create CompositeDOE.java in
15- * com.jdoe.algorithms package Add imports: org.apache.commons.math3.linear.* for matrix operations Define method signature: public static
16- * RealMatrix centralCompositeDesign(int n, int[] center, String alpha, String face) Set default parameters handling for center, alpha, and
17- * face 2. Implement Input Validation Logic Add assertion: assert n > 1 : "\"n\" must be an integer greater than 1" Validate alpha parameter
73+ * Detailed Steps to Port Central Composite Design Script to Java
74+ *
75+ * $ 1. Create CompositeDOE Class Structure Create CompositeDOE.java in com.jdoe.algorithms package Add imports:
76+ * org.apache.commons.math3.linear.* for matrix operations Define method signature: public static RealMatrix centralCompositeDesign(int n,
77+ * int[] center, String alpha, String face) Set default parameters handling for center, alpha, and face
78+ *
79+ * $ 2. Implement Input Validation Logic Add assertion: assert n > 1 : "\"n\" must be an integer greater than 1" Validate alpha parameter
1880 * with: alpha.toLowerCase() and check against allowed values Validate face parameter with: face.toLowerCase() and check against allowed
1981 * values Validate center array length: if (center.length != 2) throw IllegalArgumentException Format error messages to match Python
20- * implementation 3. Implement Star Point Generation Create StarDOE.java class with star method Calculate alpha based on alpha type: For
21- * orthogonal: alpha = Math.pow(2 * factorial(n), 0.25) where factorial(n) = n! For rotatable: alpha = Math.pow(2, 0.5) for 2D, Math.pow(3,
22- * 0.5) for 3D, etc. Generate 2n star points with values [±alpha, 0, ..., 0], [0, ±alpha, ..., 0], etc. Return both star matrix and alpha
23- * value as an Object array 4. Enhance FactorialDOE Class Add ff2n method that generates 2-level factorial design Create 2^n × n matrix with
24- * values -1 and +1 Use bit manipulation: for each row i and column j, set value to ((i >> j) & 1) == 0 ? -1 : 1 Return RealMatrix object 5.
25- * Create UnionDOE Class Implement union method that combines two matrices vertically Use Array2DRowRealMatrix constructor to create new
26- * matrix with combined rows Copy data from both input matrices to the result matrix Return the concatenated matrix 6. Create
27- * RepeatCenterDOE Class Implement repeatCenter method that generates center points Create repeats × n matrix filled with zeros Use new
28- * Array2DRowRealMatrix(repeats, n) to initialize matrix Return the center point matrix 7. Implement Core Algorithm Logic Initialize H1 and
29- * H2 matrices based on face type For inscribed (cci): scale factorial points H1 = H1.scalarMultiply(1.0/a) For faced (ccf): set alpha to
30- * 1.0 For circumscribed (ccc): keep original factorial points Generate center points C1 and C2 using repeatCenter Combine matrices: H1 =
31- * union(H1, C1), H2 = union(H2, C2), H = union(H1, H2) 8. Handle Matrix Operations Implement matrix scaling using scalarMultiply() method
32- * from Commons Math Ensure all matrix dimensions are compatible for union operations Use getSubMatrix() and setSubMatrix() for matrix
33- * manipulations Return final RealMatrix object 9. Create Unit Tests Create CompositeDOETest.java with comprehensive test cases Test all
34- * three face types: ccc, cci, ccf Test both alpha types: orthogonal, rotatable Validate matrix dimensions: (2^n + 2n + sum(center)) × n
35- * Verify center point counts and star point distances 10. Add Documentation and Error Handling Add JavaDoc explaining parameters, return
36- * value, and exceptions Implement proper exception handling for invalid inputs Include example usage in documentation Follow the same error
37- * message format as Python implementation
82+ * implementation
83+ *
84+ * $ 3. Implement Star Point Generation Create StarDOE.java class with star method Calculate alpha based on alpha type: For orthogonal:
85+ * alpha = Math.pow(2 * factorial(n), 0.25) where factorial(n) = n! For rotatable: alpha = Math.pow(2, 0.5) for 2D, Math.pow(3, 0.5) for 3D,
86+ * etc. Generate 2n star points with values [±alpha, 0, ..., 0], [0, ±alpha, ..., 0], etc. Return both star matrix and alpha value as an
87+ * Object array
88+ *
89+ * 4. Enhance FactorialDOE Class Add ff2n method that generates 2-level factorial design Create 2^n × n matrix with values -1 and +1 Use bit
90+ * manipulation: for each row i and column j, set value to ((i >> j) & 1) == 0 ? -1 : 1 Return RealMatrix object
91+ *
92+ * 5. Create UnionDOE Class Implement union method that combines two matrices vertically Use Array2DRowRealMatrix constructor to create new
93+ * matrix with combined rows Copy data from both input matrices to the result matrix Return the concatenated matrix
94+ *
95+ * 6. Create RepeatCenterDOE Class Implement repeatCenter method that generates center points Create repeats × n matrix filled with zeros
96+ * Use new Array2DRowRealMatrix(repeats, n) to initialize matrix Return the center point matrix
97+ *
98+ * 7. Implement Core Algorithm Logic Initialize H1 andH2 matrices based on face type For inscribed (cci): scale factorial points H1 =
99+ * H1.scalarMultiply(1.0/a) For faced (ccf): set alpha to 1.0 For circumscribed (ccc): keep original factorial points Generate center points
100+ * C1 and C2 using repeatCenter Combine matrices: H1 = union(H1, C1), H2 = union(H2, C2), H = union(H1, H2)
101+ *
102+ * 8. Handle Matrix Operations Implement matrix scaling using scalarMultiply() method from Commons Math Ensure all matrix dimensions are
103+ * compatible for union operations Use getSubMatrix() and setSubMatrix() for matrix manipulations Return final RealMatrix object
104+ *
105+ * 9. Create Unit Tests Create CompositeDOETest.java with comprehensive test cases Test all three face types: ccc, cci, ccf Test both alpha
106+ * types: orthogonal, rotatable Validate matrix dimensions: (2^n + 2n + sum(center)) × n Verify center point counts and star point
107+ * distances
108+ *
109+ * 10. Add Documentation and Error Handling Add JavaDoc explaining parameters, return value, and exceptions Implement proper exception
110+ * handling for invalid inputs Include example usage in documentation Follow the same error message format as Python implementation
38111 */
0 commit comments