Skip to content

Commit 93cde3e

Browse files
committed
add more convenience methods
1 parent 70c4662 commit 93cde3e

File tree

1 file changed

+92
-2
lines changed

1 file changed

+92
-2
lines changed

src/main/java/net/jamu/matrix/Statistics.java

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,41 @@ public static MatrixF zscoreRowsInplace(MatrixF A, MomentsF moments) {
720720
}
721721

722722
/**
723-
* Rescales all elements in the matrix {@code A} into the range
723+
* Rescales all elements in a copy of the matrix {@code A} into the range
724+
* {@code [lowerBound, upperBound]}. Matrix {@code A} doesn't get mutated.
725+
*
726+
* @param A
727+
* the matrix to rescale
728+
* @param lowerBound
729+
* the minimum value of an element after rescaling
730+
* @param upperBound
731+
* the maximum value of an element after rescaling
732+
* @return a copy of matrix {@code A} with all elements rescaled
733+
* @since 1.4.6
734+
*/
735+
public static MatrixD rescale(MatrixD A, double lowerBound, double upperBound) {
736+
return rescaleInplace(A.copy(), lowerBound, upperBound);
737+
}
738+
739+
/**
740+
* Rescales all elements in a copy of the matrix {@code A} into the range
741+
* {@code [lowerBound, upperBound]}. Matrix {@code A} doesn't get mutated.
742+
*
743+
* @param A
744+
* the matrix to rescale
745+
* @param lowerBound
746+
* the minimum value of an element after rescaling
747+
* @param upperBound
748+
* the maximum value of an element after rescaling
749+
* @return a copy of matrix {@code A} with all elements rescaled
750+
* @since 1.4.6
751+
*/
752+
public static MatrixF rescale(MatrixF A, float lowerBound, float upperBound) {
753+
return rescaleInplace(A.copy(), lowerBound, upperBound);
754+
}
755+
756+
/**
757+
* Rescales all elements in the matrix {@code A} in-place into the range
724758
* {@code [lowerBound, upperBound]}.
725759
*
726760
* @param A
@@ -754,7 +788,7 @@ public static MatrixD rescaleInplace(MatrixD A, double lowerBound, double upperB
754788
}
755789

756790
/**
757-
* Rescales all elements in the matrix {@code A} into the range
791+
* Rescales all elements in the matrix {@code A} in-place into the range
758792
* {@code [lowerBound, upperBound]}.
759793
*
760794
* @param A
@@ -939,6 +973,34 @@ public static ComplexMatrixF zscoreColumnsInplace(ComplexMatrixF A) {
939973
return A;
940974
}
941975

976+
/**
977+
* Randomly permutes the columns in a copy of matrix {@code A} using a
978+
* default source of randomness. All permutations occur with approximately
979+
* equal probability. Matrix {@code A} doesn't get mutated.
980+
*
981+
* @param A
982+
* the matrix whose columns will be permuted at random
983+
* @return a copy of matrix {@code A} with columns randomly permuted
984+
* @since 1.4.6
985+
*/
986+
public static MatrixD shuffleColumns(MatrixD A) {
987+
return shuffleColumnsInplace(A.copy(), null);
988+
}
989+
990+
/**
991+
* Randomly permutes the columns in a copy of matrix {@code A} using a
992+
* default source of randomness. All permutations occur with approximately
993+
* equal probability. Matrix {@code A} doesn't get mutated.
994+
*
995+
* @param A
996+
* the matrix whose columns will be permuted at random
997+
* @return a copy of matrix {@code A} with columns randomly permuted
998+
* @since 1.4.6
999+
*/
1000+
public static MatrixF shuffleColumns(MatrixF A) {
1001+
return shuffleColumnsInplace(A.copy(), null);
1002+
}
1003+
9421004
/**
9431005
* Randomly permutes the columns in matrix {@code A} in place using a
9441006
* default source of randomness. All permutations occur with approximately
@@ -1031,6 +1093,34 @@ private static void swap(int aoff1, Object a, Object tmp, int len, int aoff2) {
10311093
}
10321094
}
10331095

1096+
/**
1097+
* Randomly permutes the rows in a copy of matrix {@code A} using a default
1098+
* source of randomness. All permutations occur with approximately equal
1099+
* probability. Matrix {@code A} doesn't get mutated.
1100+
*
1101+
* @param A
1102+
* the matrix whose rows will be permuted at random
1103+
* @return a copy of matrix {@code A} with rows randomly permuted
1104+
* @since 1.4.6
1105+
*/
1106+
public static MatrixD shuffleRows(MatrixD A) {
1107+
return shuffleRowsInplace(A.copy(), null);
1108+
}
1109+
1110+
/**
1111+
* Randomly permutes the rows in a copy of matrix {@code A} using a default
1112+
* source of randomness. All permutations occur with approximately equal
1113+
* probability. Matrix {@code A} doesn't get mutated.
1114+
*
1115+
* @param A
1116+
* the matrix whose rows will be permuted at random
1117+
* @return a copy of matrix {@code A} with rows randomly permuted
1118+
* @since 1.4.6
1119+
*/
1120+
public static MatrixF shuffleRows(MatrixF A) {
1121+
return shuffleRowsInplace(A.copy(), null);
1122+
}
1123+
10341124
/**
10351125
* Randomly permutes the rows in matrix {@code A} in place using a
10361126
* default source of randomness. All permutations occur with approximately

0 commit comments

Comments
 (0)