Ver3.0 ๐งฎ ์๋ฐ ์์น ๊ณ์ฐ๊ณผ Apache Commons Math๋ฅผ ํ์ฉํ ๊ณผํ ๊ณ์ฐ ์๋ฒฝ ๊ฐ์ด๋

๐งฎ ์๋ฐ ์์น ๊ณ์ฐ๊ณผ Apache Commons Math๋ฅผ ํ์ฉํ ๊ณผํ ๊ณ์ฐ ์๋ฒฝ ๊ฐ์ด๋
๋ณต์กํ ์ํ ๊ณ์ฐ์ ์๋ฐ๋ก ์ฝ๊ณ ์ ํํ๊ฒ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ
์๋
! ๐ ์ค๋์ ์๋ฐ๋ก ๊ณผํ ๊ณ์ฐ์ ํ ๋ ์ ๋ง ์ ์ฉํ Apache Commons Math ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ํด ์ด์ผ๊ธฐํด๋ณผ๊ฒ. ํ๋ก๊ทธ๋๋ฐ์ ํ๋ค ๋ณด๋ฉด ๋ณต์กํ ์ํ ๊ณ์ฐ์ด ํ์ํ ์๊ฐ์ด ๊ผญ ์ค์์? ํต๊ณ ๋ถ์, ์ ํ๋์, ๋ฏธ์ ๋ถ, ์ต์ ํ ๋ฌธ์ ๋ฑ๋ฑ... ์ด๋ฐ ๊ฑธ ์ง์ ๊ตฌํํ๋ ค๋ฉด ๋จธ๋ฆฌ๊ฐ ์ํ์ง. ๐ต
๊ทธ๋ฐ๋ฐ Apache Commons Math๋ฅผ ์ฌ์ฉํ๋ฉด ์ด๋ฐ ๋ณต์กํ ๊ณ์ฐ๋ค์ ํจ์ฌ ์ฝ๊ฒ ์ฒ๋ฆฌํ ์ ์์ด. ๋ง์น ์ํ ์ ๋ฌธ๊ฐ๋ฅผ ์์ ๋๊ณ ์ผํ๋ ๋๋์ด๋๊น? ์ด ๊ธ์์๋ ์๋ฐ์ ๊ธฐ๋ณธ ์์น ๊ณ์ฐ๋ถํฐ Apache Commons Math์ ๊ณ ๊ธ ๊ธฐ๋ฅ๊น์ง ์น๊ตฌ์ฒ๋ผ ํธํ๊ฒ ์ค๋ช
ํด์ค๊ฒ!
๐ฏ ์๋ฐ ๊ธฐ๋ณธ ์์น ๊ณ์ฐ์ ์ดํด
๋จผ์ ์๋ฐ๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณตํ๋ ์์น ๊ณ์ฐ ๊ธฐ๋ฅ๋ถํฐ ์ดํด๋ณด์. ์๋ฐ๋ java.lang.Math ํด๋์ค๋ฅผ ํตํด ๋ค์ํ ์ํ ํจ์๋ฅผ ์ ๊ณตํ๊ณ ์์ด. ์ผ๊ฐํจ์, ์ง์ํจ์, ๋ก๊ทธํจ์ ๊ฐ์ ๊ธฐ๋ณธ์ ์ธ ๊ฒ๋ค ๋ง์ด์ผ.
๐ ์๋ฐ์ ๊ธฐ๋ณธ ์์น ํ์
์๋ฐ์์ ์ซ์๋ฅผ ๋ค๋ฃฐ ๋๋ ์ฌ๋ฌ ๊ฐ์ง ํ์
์ด ์์ด:
์ ์ํ: byte(8๋นํธ), short(16๋นํธ), int(32๋นํธ), long(64๋นํธ)
์ค์ํ: float(32๋นํธ), double(64๋นํธ)
๊ณผํ ๊ณ์ฐ์์๋ ์ฃผ๋ก double์ ์ฌ์ฉํด. ์๋ํ๋ฉด ์ ๋ฐ๋๊ฐ ๋๊ฑฐ๋ ! float๋ ์์์ ์ดํ ์ฝ 7์๋ฆฌ, double์ ์ฝ 15์๋ฆฌ๊น์ง ์ ํํ๊ฒ ํํํ ์ ์์ด.
// ๊ธฐ๋ณธ Math ํด๋์ค ์ฌ์ฉ ์์
public class BasicMathExample {
public static void main(String[] args) {
// ์ ๊ณฑ๊ทผ ๊ณ์ฐ
double sqrt = Math.sqrt(16.0);
System.out.println("16์ ์ ๊ณฑ๊ทผ: " + sqrt);
// ๊ฑฐ๋ญ์ ๊ณฑ
double power = Math.pow(2, 10);
System.out.println("2์ 10์น: " + power);
// ์ผ๊ฐํจ์ (๋ผ๋์ ๋จ์)
double sin = Math.sin(Math.PI / 2);
System.out.println("sin(ฯ/2): " + sin);
// ๋ก๊ทธ ํจ์
double log = Math.log(Math.E);
System.out.println("ln(e): " + log);
// ์ ๋๊ฐ
double abs = Math.abs(-15.7);
System.out.println("|-15.7|: " + abs);
}
}
๊ธ์ต ๊ณ์ฐ์ฒ๋ผ ์ ํํ ์์์ ์ฐ์ฐ์ด ํ์ํ๋ค๋ฉด BigDecimal ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ ๊ฒ ์ข์.
๐ Apache Commons Math ์์ํ๊ธฐ
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก Apache Commons Math์ ๋ํด ์์๋ณด์! ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ Apache Software Foundation์์ ๋ง๋ ์คํ์์ค ํ๋ก์ ํธ๋ก, ์๋ฐ ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ ๊ณตํ์ง ์๋ ๊ณ ๊ธ ์ํ ๊ธฐ๋ฅ๋ค์ ์ ๊ณตํด. ๐
๐ก Apache Commons Math๊ฐ ์ ๊ณตํ๋ ์ฃผ์ ๊ธฐ๋ฅ
1. ํต๊ณ (Statistics): ํ๊ท , ๋ถ์ฐ, ํ์คํธ์ฐจ, ์๊ด๊ณ์, ํ๊ท๋ถ์ ๋ฑ
2. ์ ํ๋์ (Linear Algebra): ํ๋ ฌ ์ฐ์ฐ, ๊ณ ์ ๊ฐ ๋ถํด, LU ๋ถํด ๋ฑ
3. ์์น ํด์ (Numerical Analysis): ์ ๋ถ, ๋ฏธ๋ถ, ๋ฐฉ์ ์ ํ์ด
4. ์ต์ ํ (Optimization): ํจ์ ์ต์ํ/์ต๋ํ ๋ฌธ์ ํด๊ฒฐ
5. ํ๋ฅ ๋ถํฌ (Probability Distributions): ์ ๊ท๋ถํฌ, ์ดํญ๋ถํฌ, ํฌ์์ก๋ถํฌ ๋ฑ
6. ํน์ ํจ์ (Special Functions): ๊ฐ๋งํจ์, ๋ฒ ํํจ์, ๋ฒ ์
ํจ์ ๋ฑ
7. ๋ณต์์ (Complex Numbers): ๋ณต์์ ์ฐ์ฐ
8. ๋ถ์ (Fractions): ์ ํํ ๋ถ์ ๊ณ์ฐ
๐ฆ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น ๋ฐ ์ค์
Apache Commons Math๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ๋จผ์ ํ๋ก์ ํธ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ถ๊ฐํด์ผ ํด. Maven์ ์ฌ์ฉํ๋ค๋ฉด pom.xml์ ๋ค์ ์์กด์ฑ์ ์ถ๊ฐํ๋ฉด ๋ผ:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
Gradle์ ์ฌ์ฉํ๋ค๋ฉด build.gradle์ ์ด๋ ๊ฒ ์ถ๊ฐํด:
implementation 'org.apache.commons:commons-math3:3.6.1'
๐ ํต๊ณ ๊ณ์ฐ ๋ง์คํฐํ๊ธฐ
ํต๊ณ๋ ๋ฐ์ดํฐ ๋ถ์์ ๊ธฐ๋ณธ์ด์ง! Apache Commons Math๋ ๊ฐ๋ ฅํ ํต๊ณ ๊ธฐ๋ฅ์ ์ ๊ณตํด. DescriptiveStatistics์ SummaryStatistics ํด๋์ค๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฐ์ดํฐ์ ๊ธฐ๋ณธ ํต๊ณ๋์ ์ฝ๊ฒ ๊ณ์ฐํ ์ ์์ด.
๐ฒ ๊ธฐ์ ํต๊ณ๋ ๊ณ์ฐ
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
public class StatisticsExample {
public static void main(String[] args) {
// DescriptiveStatistics ๊ฐ์ฒด ์์ฑ
DescriptiveStatistics stats = new DescriptiveStatistics();
// ๋ฐ์ดํฐ ์ถ๊ฐ
double[] data = {12.5, 18.3, 15.7, 22.1, 19.8, 14.2, 16.9, 20.4, 17.6, 21.3};
for (double value : data) {
stats.addValue(value);
}
// ๋ค์ํ ํต๊ณ๋ ๊ณ์ฐ
System.out.println("ํ๊ท (Mean): " + stats.getMean());
System.out.println("์ค์๊ฐ (Median): " + stats.getPercentile(50));
System.out.println("ํ์คํธ์ฐจ (Std Dev): " + stats.getStandardDeviation());
System.out.println("๋ถ์ฐ (Variance): " + stats.getVariance());
System.out.println("์ต์๊ฐ (Min): " + stats.getMin());
System.out.println("์ต๋๊ฐ (Max): " + stats.getMax());
System.out.println("๋ฒ์ (Range): " + (stats.getMax() - stats.getMin()));
System.out.println("์๋ (Skewness): " + stats.getSkewness());
System.out.println("์ฒจ๋ (Kurtosis): " + stats.getKurtosis());
// ๋ฐฑ๋ถ์์ ๊ณ์ฐ
System.out.println("25th ๋ฐฑ๋ถ์์: " + stats.getPercentile(25));
System.out.println("75th ๋ฐฑ๋ถ์์: " + stats.getPercentile(75));
}
}
๐ DescriptiveStatistics
๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅํ๊ณ , ๋ฐฑ๋ถ์์๋ ์ค์๊ฐ ๊ฐ์ ์์ ํต๊ณ๋์ ๊ณ์ฐํ ์ ์์ด. ๋ฐ์ดํฐ๊ฐ ๋ง์ง ์์ ๋ ์ ์ฉํด!
โก SummaryStatistics
๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ์ง ์๊ณ ํต๊ณ๋๋ง ์ ๋ฐ์ดํธํด. ๋ฉ๋ชจ๋ฆฌ ํจ์จ์ ์ด์ง๋ง ๋ฐฑ๋ถ์์๋ ๊ณ์ฐํ ์ ์์ด. ๋์ฉ๋ ๋ฐ์ดํฐ์ ์ ํฉ!
๐ ์๊ด๊ด๊ณ ๋ถ์
๋ ๋ณ์ ๊ฐ์ ๊ด๊ณ๋ฅผ ์๊ณ ์ถ์ ๋๋ ์๊ด๊ณ์๋ฅผ ๊ณ์ฐํ๋ฉด ๋ผ. Pearson ์๊ด๊ณ์๊ฐ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋์ง:
import org.apache.commons.math3.stat.correlation.PearsonsCorrelation;
import org.apache.commons.math3.stat.correlation.SpearmansCorrelation;
public class CorrelationExample {
public static void main(String[] args) {
// ๋ ๋ณ์์ ๋ฐ์ดํฐ
double[] x = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
double[] y = {2.1, 4.3, 6.2, 8.1, 10.3, 12.1, 14.2, 16.0, 18.1, 20.3};
// Pearson ์๊ด๊ณ์ ๊ณ์ฐ
PearsonsCorrelation pearson = new PearsonsCorrelation();
double pearsonCorr = pearson.correlation(x, y);
System.out.println("Pearson ์๊ด๊ณ์: " + pearsonCorr);
// Spearman ์์ ์๊ด๊ณ์ ๊ณ์ฐ
SpearmansCorrelation spearman = new SpearmansCorrelation();
double spearmanCorr = spearman.correlation(x, y);
System.out.println("Spearman ์๊ด๊ณ์: " + spearmanCorr);
}
}
๐ ์๊ด๊ณ์ ํด์ ๊ฐ์ด๋
1.0: ์๋ฒฝํ ์์ ์๊ด๊ด๊ณ (ํ ๋ณ์๊ฐ ์ฆ๊ฐํ๋ฉด ๋ค๋ฅธ ๋ณ์๋ ์ ํํ ๋น๋กํด์ ์ฆ๊ฐ)
0.7 ~ 0.9: ๊ฐํ ์์ ์๊ด๊ด๊ณ
0.4 ~ 0.6: ์ค๊ฐ ์ ๋์ ์์ ์๊ด๊ด๊ณ
0.1 ~ 0.3: ์ฝํ ์์ ์๊ด๊ด๊ณ
0.0: ์๊ด๊ด๊ณ ์์
-0.1 ~ -0.3: ์ฝํ ์์ ์๊ด๊ด๊ณ
-0.4 ~ -0.6: ์ค๊ฐ ์ ๋์ ์์ ์๊ด๊ด๊ณ
-0.7 ~ -0.9: ๊ฐํ ์์ ์๊ด๊ด๊ณ
-1.0: ์๋ฒฝํ ์์ ์๊ด๊ด๊ณ (ํ ๋ณ์๊ฐ ์ฆ๊ฐํ๋ฉด ๋ค๋ฅธ ๋ณ์๋ ์ ํํ ๋น๋กํด์ ๊ฐ์)
๐ ํ๊ท ๋ถ์
ํ๊ท ๋ถ์์ ๋ณ์ ๊ฐ์ ๊ด๊ณ๋ฅผ ๋ชจ๋ธ๋งํ๋ ๊ฐ๋ ฅํ ๋๊ตฌ์ผ. ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ๋จ์ ์ ํ ํ๊ท๋ถํฐ ์์ํด๋ณด์:
import org.apache.commons.math3.stat.regression.SimpleRegression;
public class RegressionExample {
public static void main(String[] args) {
SimpleRegression regression = new SimpleRegression();
// ๋ฐ์ดํฐ ํฌ์ธํธ ์ถ๊ฐ (x, y)
regression.addData(1.0, 2.5);
regression.addData(2.0, 4.8);
regression.addData(3.0, 7.2);
regression.addData(4.0, 9.5);
regression.addData(5.0, 12.1);
regression.addData(6.0, 14.3);
// ํ๊ท ๊ณ์ ์ถ๋ ฅ
System.out.println("๊ธฐ์ธ๊ธฐ (Slope): " + regression.getSlope());
System.out.println("์ ํธ (Intercept): " + regression.getIntercept());
System.out.println("Rยฒ (๊ฒฐ์ ๊ณ์): " + regression.getRSquare());
System.out.println("ํ์ค์ค์ฐจ: " + regression.getSlopeStdErr());
// ์์ธก
double predictedY = regression.predict(7.0);
System.out.println("x=7์ผ ๋ ์์ธก๊ฐ: " + predictedY);
// ํ๊ท์ ์ถ๋ ฅ
System.out.printf("ํ๊ท์: y = %.3fx + %.3f%n",
regression.getSlope(), regression.getIntercept());
}
}
๋ค์ค ํ๊ท ๋ถ์์ด ํ์ํ๋ค๋ฉด OLSMultipleLinearRegression ํด๋์ค๋ฅผ ์ฌ์ฉํ ์ ์์ด:
import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression;
public class MultipleRegressionExample {
public static void main(String[] args) {
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
// y ๊ฐ๋ค
double[] y = {10.5, 15.2, 20.8, 25.3, 30.1};
// x ๊ฐ๋ค (๊ฐ ํ์ ํ๋์ ๊ด์ธก์น, ๊ฐ ์ด์ ํ๋์ ๋
๋ฆฝ๋ณ์)
double[][] x = {
{1.0, 2.0}, // ์ฒซ ๋ฒ์งธ ๊ด์ธก์น์ x1, x2
{2.0, 3.5},
{3.0, 5.0},
{4.0, 6.5},
{5.0, 8.0}
};
regression.newSampleData(y, x);
// ํ๊ท ๊ณ์ ์ถ๋ ฅ
double[] beta = regression.estimateRegressionParameters();
System.out.println("์ ํธ: " + beta[0]);
System.out.println("x1 ๊ณ์: " + beta[1]);
System.out.println("x2 ๊ณ์: " + beta[2]);
// Rยฒ ์ถ๋ ฅ
System.out.println("Rยฒ: " + regression.calculateRSquared());
}
}
๐ข ์ ํ๋์ ์ฐ์ฐ
์ ํ๋์๋ ๊ณผํ ๊ณ์ฐ์ ํต์ฌ์ด์ผ! ํ๋ ฌ ์ฐ์ฐ, ์ฐ๋ฆฝ๋ฐฉ์ ์ ํ์ด, ๊ณ ์ ๊ฐ ๋ถํด ๋ฑ ๋ค์ํ ์์ ์ Apache Commons Math๋ก ์ฝ๊ฒ ์ฒ๋ฆฌํ ์ ์์ด. ๐งฎ
๐ ํ๋ ฌ ๊ธฐ๋ณธ ์ฐ์ฐ
import org.apache.commons.math3.linear.*;
public class MatrixExample {
public static void main(String[] args) {
// ํ๋ ฌ ์์ฑ
double[][] matrixData1 = {
{1.0, 2.0, 3.0},
{4.0, 5.0, 6.0},
{7.0, 8.0, 9.0}
};
RealMatrix matrix1 = MatrixUtils.createRealMatrix(matrixData1);
double[][] matrixData2 = {
{9.0, 8.0, 7.0},
{6.0, 5.0, 4.0},
{3.0, 2.0, 1.0}
};
RealMatrix matrix2 = MatrixUtils.createRealMatrix(matrixData2);
// ํ๋ ฌ ๋ง์
RealMatrix sum = matrix1.add(matrix2);
System.out.println("ํ๋ ฌ ๋ง์
๊ฒฐ๊ณผ:");
printMatrix(sum);
// ํ๋ ฌ ๋บ์
RealMatrix diff = matrix1.subtract(matrix2);
System.out.println("\nํ๋ ฌ ๋บ์
๊ฒฐ๊ณผ:");
printMatrix(diff);
// ํ๋ ฌ ๊ณฑ์
RealMatrix product = matrix1.multiply(matrix2);
System.out.println("\nํ๋ ฌ ๊ณฑ์
๊ฒฐ๊ณผ:");
printMatrix(product);
// ์ค์นผ๋ผ ๊ณฑ์
RealMatrix scaled = matrix1.scalarMultiply(2.0);
System.out.println("\n์ค์นผ๋ผ ๊ณฑ์
๊ฒฐ๊ณผ (2๋ฐฐ):");
printMatrix(scaled);
// ์ ์น ํ๋ ฌ
RealMatrix transpose = matrix1.transpose();
System.out.println("\n์ ์น ํ๋ ฌ:");
printMatrix(transpose);
// ํ๋ ฌ์ ๊ณ์ฐ
double det = new LUDecomposition(matrix1).getDeterminant();
System.out.println("\nํ๋ ฌ์: " + det);
}
private static void printMatrix(RealMatrix matrix) {
for (int i = 0; i < matrix.getRowDimension(); i++) {
for (int j = 0; j < matrix.getColumnDimension(); j++) {
System.out.printf("%8.2f ", matrix.getEntry(i, j));
}
System.out.println();
}
}
}
๐ฏ ์ฐ๋ฆฝ๋ฐฉ์ ์ ํ์ด
์ฐ๋ฆฝ๋ฐฉ์ ์์ ํธ๋ ๊ฑด ๊ณผํ ๊ณ์ฐ์์ ์ ๋ง ์์ฃผ ๋์ค๋ ์์ ์ด์ผ. Ax = b ํํ์ ๋ฐฉ์ ์์ ํ์ด๋ณด์:
import org.apache.commons.math3.linear.*;
public class LinearSystemExample {
public static void main(String[] args) {
// ์ฐ๋ฆฝ๋ฐฉ์ ์:
// 2x + 3y + z = 1
// 4x + y + 2z = 2
// x + 2y + 3z = 3
// ๊ณ์ ํ๋ ฌ A
double[][] coefficients = {
{2.0, 3.0, 1.0},
{4.0, 1.0, 2.0},
{1.0, 2.0, 3.0}
};
RealMatrix A = MatrixUtils.createRealMatrix(coefficients);
// ์์ ๋ฒกํฐ b
double[] constants = {1.0, 2.0, 3.0};
RealVector b = MatrixUtils.createRealVector(constants);
// LU ๋ถํด๋ฅผ ์ด์ฉํ ํด ๊ตฌํ๊ธฐ
DecompositionSolver solver = new LUDecomposition(A).getSolver();
RealVector solution = solver.solve(b);
System.out.println("ํด:");
System.out.println("x = " + solution.getEntry(0));
System.out.println("y = " + solution.getEntry(1));
System.out.println("z = " + solution.getEntry(2));
// ๊ฒ์ฆ: A * x = b ํ์ธ
RealVector result = A.operate(solution);
System.out.println("\n๊ฒ์ฆ (A * x):");
for (int i = 0; i < result.getDimension(); i++) {
System.out.printf("%.6f (์๋ ๊ฐ: %.6f)%n",
result.getEntry(i), constants[i]);
}
}
}
๐ ๊ณ ์ ๊ฐ๊ณผ ๊ณ ์ ๋ฒกํฐ
๊ณ ์ ๊ฐ ๋ถํด๋ ํ๋ ฌ์ ํน์ฑ์ ์ดํดํ๋ ๋ฐ ์ค์ํ ๋๊ตฌ์ผ. ์ฃผ์ฑ๋ถ ๋ถ์(PCA)์ด๋ ์์ ์ฑ ๋ถ์์์ ๋ง์ด ์ฌ์ฉ๋์ง:
import org.apache.commons.math3.linear.*;
public class EigenExample {
public static void main(String[] args) {
// ๋์นญ ํ๋ ฌ ์์ฑ
double[][] matrixData = {
{4.0, 1.0, 2.0},
{1.0, 3.0, 1.0},
{2.0, 1.0, 5.0}
};
RealMatrix matrix = MatrixUtils.createRealMatrix(matrixData);
// ๊ณ ์ ๊ฐ ๋ถํด
EigenDecomposition eigen = new EigenDecomposition(matrix);
// ๊ณ ์ ๊ฐ ์ถ๋ ฅ
System.out.println("๊ณ ์ ๊ฐ:");
double[] eigenvalues = eigen.getRealEigenvalues();
for (int i = 0; i < eigenvalues.length; i++) {
System.out.printf("ฮป%d = %.6f%n", i+1, eigenvalues[i]);
}
// ๊ณ ์ ๋ฒกํฐ ์ถ๋ ฅ
System.out.println("\n๊ณ ์ ๋ฒกํฐ:");
for (int i = 0; i < eigenvalues.length; i++) {
RealVector eigenvector = eigen.getEigenvector(i);
System.out.printf("v%d = [", i+1);
for (int j = 0; j < eigenvector.getDimension(); j++) {
System.out.printf("%.6f", eigenvector.getEntry(j));
if (j < eigenvector.getDimension() - 1) {
System.out.print(", ");
}
}
System.out.println("]");
}
// ํ๋ ฌ์ (๊ณ ์ ๊ฐ์ ๊ณฑ)
System.out.println("\nํ๋ ฌ์: " + eigen.getDeterminant());
}
}
๐ก ๊ณ ์ ๊ฐ ๋ถํด์ ํ์ฉ
์ฃผ์ฑ๋ถ ๋ถ์(PCA): ๋ฐ์ดํฐ์ ์ฐจ์์ ์ถ์ํ๋ฉด์ ์ค์ํ ์ ๋ณด๋ ์ ์ง
์์ ์ฑ ๋ถ์: ์์คํ
์ ์์ ์ฑ์ ํ๋จ (๋ชจ๋ ๊ณ ์ ๊ฐ์ ์ค์๋ถ๊ฐ ์์๋ฉด ์์ )
์ง๋ ๋ถ์: ๊ตฌ์กฐ๋ฌผ์ ๊ณ ์ ์ง๋์์ ์ง๋ ๋ชจ๋ ๊ณ์ฐ
๊ทธ๋ํ ์ด๋ก : ๋คํธ์ํฌ์ ์ค์ฌ์ฑ๊ณผ ์ปค๋ฎค๋ํฐ ๊ตฌ์กฐ ๋ถ์
์์์ญํ: ์๋์ง ์ค์์ ์ํ ๋ฒกํฐ ๊ณ์ฐ
๐ ํ๋ฅ ๋ถํฌ์ ๋์ ์์ฑ
ํ๋ฅ ๋ถํฌ๋ ํต๊ณ์ ์๋ฎฌ๋ ์ด์ ์ ๊ธฐ์ด์ผ! Apache Commons Math๋ ๋ค์ํ ํ๋ฅ ๋ถํฌ๋ฅผ ์ง์ํ๊ณ , ๊ฐ ๋ถํฌ์์ ๋์๋ฅผ ์์ฑํ๊ฑฐ๋ ํ๋ฅ ์ ๊ณ์ฐํ ์ ์์ด. ๐ฒ
๐ฐ ์ ๊ท๋ถํฌ (Normal Distribution)
์ ๊ท๋ถํฌ๋ ์์ฐ ํ์์์ ๊ฐ์ฅ ํํ๊ฒ ๋ํ๋๋ ๋ถํฌ์ผ. ํ๊ท ๊ณผ ํ์คํธ์ฐจ๋ก ์ ์๋์ง:
import org.apache.commons.math3.distribution.NormalDistribution;
public class NormalDistributionExample {
public static void main(String[] args) {
// ํ๊ท 100, ํ์คํธ์ฐจ 15์ธ ์ ๊ท๋ถํฌ (์: IQ ๋ถํฌ)
NormalDistribution normal = new NormalDistribution(100, 15);
// ํ๋ฅ ๋ฐ๋ ํจ์ (PDF) ๊ฐ
double pdf = normal.density(100);
System.out.println("x=100์์์ PDF: " + pdf);
// ๋์ ๋ถํฌ ํจ์ (CDF) ๊ฐ
double cdf = normal.cumulativeProbability(115);
System.out.println("P(X โค 115): " + cdf);
// ๊ตฌ๊ฐ ํ๋ฅ
double prob = normal.probability(85, 115);
System.out.println("P(85 โค X โค 115): " + prob);
// ๋ฐฑ๋ถ์์ (์ญ CDF)
double percentile95 = normal.inverseCumulativeProbability(0.95);
System.out.println("95th ๋ฐฑ๋ถ์์: " + percentile95);
// ๋์ ์์ฑ
System.out.println("\n์ ๊ท๋ถํฌ ๋์ 10๊ฐ:");
for (int i = 0; i < 10; i++) {
System.out.printf("%.2f ", normal.sample());
}
System.out.println();
// ํ๊ท ๊ณผ ํ์คํธ์ฐจ
System.out.println("\nํ๊ท : " + normal.getNumericalMean());
System.out.println("ํ์คํธ์ฐจ: " + Math.sqrt(normal.getNumericalVariance()));
}
}
๐ฒ ๋ค์ํ ํ๋ฅ ๋ถํฌ
์ดํญ๋ถํฌ (Binomial)
์ฑ๊ณต/์คํจ๊ฐ ์๋ ๋ ๋ฆฝ ์ํ์ n๋ฒ ๋ฐ๋ณตํ ๋ ์ฑ๊ณต ํ์์ ๋ถํฌ. ๋์ ๋์ง๊ธฐ, ํ์ง ๊ฒ์ฌ ๋ฑ์ ์ฌ์ฉ!
ํฌ์์ก๋ถํฌ (Poisson)
๋จ์ ์๊ฐ/๊ณต๊ฐ์์ ๋ฐ์ํ๋ ์ฌ๊ฑด์ ํ์ ๋ถํฌ. ๊ณ ๊ฐ ๋์ฐฉ, ๊ตํต์ฌ๊ณ ๋ฐ์ ๋ฑ์ ํ์ฉ!
import org.apache.commons.math3.distribution.*;
public class VariousDistributionsExample {
public static void main(String[] args) {
// ์ดํญ๋ถํฌ: 10๋ฒ ์ํ, ์ฑ๊ณต ํ๋ฅ 0.3
BinomialDistribution binomial = new BinomialDistribution(10, 0.3);
System.out.println("์ดํญ๋ถํฌ B(10, 0.3)");
System.out.println("P(X = 3): " + binomial.probability(3));
System.out.println("P(X โค 5): " + binomial.cumulativeProbability(5));
System.out.println("ํ๊ท : " + binomial.getNumericalMean());
// ํฌ์์ก๋ถํฌ: ํ๊ท ๋ฐ์๋ฅ 5
PoissonDistribution poisson = new PoissonDistribution(5.0);
System.out.println("\nํฌ์์ก๋ถํฌ P(5)");
System.out.println("P(X = 5): " + poisson.probability(5));
System.out.println("P(X โค 3): " + poisson.cumulativeProbability(3));
// ์ง์๋ถํฌ: ํ๊ท 2
ExponentialDistribution exponential = new ExponentialDistribution(2.0);
System.out.println("\n์ง์๋ถํฌ Exp(2)");
System.out.println("P(X โค 1): " + exponential.cumulativeProbability(1.0));
System.out.println("ํ๊ท : " + exponential.getNumericalMean());
// ๊ท ๋ฑ๋ถํฌ: [0, 10] ๊ตฌ๊ฐ
UniformRealDistribution uniform = new UniformRealDistribution(0, 10);
System.out.println("\n๊ท ๋ฑ๋ถํฌ U(0, 10)");
System.out.println("P(3 โค X โค 7): " + uniform.probability(3, 7));
// ์นด์ด์ ๊ณฑ๋ถํฌ: ์์ ๋ 5
ChiSquaredDistribution chiSquared = new ChiSquaredDistribution(5);
System.out.println("\nฯยฒ๋ถํฌ (์์ ๋ 5)");
System.out.println("P(X โค 10): " + chiSquared.cumulativeProbability(10));
// t๋ถํฌ: ์์ ๋ 10
TDistribution t = new TDistribution(10);
System.out.println("\nt๋ถํฌ (์์ ๋ 10)");
System.out.println("95% ์ ๋ขฐ๊ตฌ๊ฐ ์๊ณ๊ฐ: " +
t.inverseCumulativeProbability(0.975));
}
}
๐ ํ๋ฅ ๋ถํฌ ์ ํ ๊ฐ์ด๋
์ ๊ท๋ถํฌ: ์ฐ์ํ ๋ฐ์ดํฐ, ์ค์ฌ๊ทนํ์ ๋ฆฌ ์ ์ฉ ๊ฐ๋ฅํ ๊ฒฝ์ฐ
์ดํญ๋ถํฌ: ์ด์ฐํ, ์ฑ๊ณต/์คํจ๊ฐ ๋ช
ํํ ๋
๋ฆฝ ์ํ
ํฌ์์ก๋ถํฌ: ์ด์ฐํ, ํฌ๊ท ์ฌ๊ฑด์ ๋ฐ์ ํ์
์ง์๋ถํฌ: ์ฐ์ํ, ์ฌ๊ฑด ๊ฐ ๋๊ธฐ ์๊ฐ
๊ท ๋ฑ๋ถํฌ: ์ฐ์ํ, ๋ชจ๋ ๊ฐ์ด ๋์ผํ ํ๋ฅ
์นด์ด์ ๊ณฑ๋ถํฌ: ์ ํฉ๋ ๊ฒ์ , ๋ถ์ฐ ์ถ์
t๋ถํฌ: ์ํ๋ณธ ํ๊ท ๊ฒ์ , ์ ๋ขฐ๊ตฌ๊ฐ ์ถ์
F๋ถํฌ: ๋ถ์ฐ ๋น๊ต, ANOVA
๐ฌ ์์น ํด์๊ณผ ์ต์ ํ
์์น ํด์์ ์ํ์ ๋ฌธ์ ๋ฅผ ์ปดํจํฐ๋ก ๊ทผ์ฌ์ ์ผ๋ก ํธ๋ ๋ฐฉ๋ฒ์ด์ผ. ์ ๋ถ, ๋ฏธ๋ถ, ๋ฐฉ์ ์์ ๊ทผ ์ฐพ๊ธฐ, ํจ์ ์ต์ ํ ๋ฑ ๋ค์ํ ๋ฌธ์ ๋ฅผ ๋ค๋ฃฐ ์ ์์ด! ๐ฏ
๐ฏ ํจ์์ ๊ทผ ์ฐพ๊ธฐ
๋ฐฉ์ ์ f(x) = 0์ ํด๋ฅผ ์ฐพ๋ ๊ฑด ๊ณผํ ๊ณ์ฐ์์ ์ ๋ง ์ค์ํด. Apache Commons Math๋ ์ฌ๋ฌ ๊ฐ์ง ์๊ณ ๋ฆฌ์ฆ์ ์ ๊ณตํ์ง:
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.solvers.*;
public class RootFindingExample {
public static void main(String[] args) {
// f(x) = x^3 - 2x - 5 = 0์ ๊ทผ ์ฐพ๊ธฐ
UnivariateFunction function = new UnivariateFunction() {
public double value(double x) {
return x * x * x - 2 * x - 5;
}
};
// Brent ๋ฐฉ๋ฒ (๊ฐ์ฅ ์์ ์ ์ด๊ณ ๋น ๋ฆ)
BrentSolver brentSolver = new BrentSolver();
double root1 = brentSolver.solve(100, function, 0, 3);
System.out.println("Brent ๋ฐฉ๋ฒ์ผ๋ก ์ฐพ์ ๊ทผ: " + root1);
System.out.println("๊ฒ์ฆ f(" + root1 + ") = " + function.value(root1));
// ์ด๋ถ๋ฒ (Bisection)
BisectionSolver bisectionSolver = new BisectionSolver();
double root2 = bisectionSolver.solve(100, function, 0, 3);
System.out.println("\n์ด๋ถ๋ฒ์ผ๋ก ์ฐพ์ ๊ทผ: " + root2);
// Newton-Raphson ๋ฐฉ๋ฒ (๋ฏธ๋ถ ๊ฐ๋ฅํ ๊ฒฝ์ฐ)
NewtonRaphsonSolver newtonSolver = new NewtonRaphsonSolver();
double root3 = newtonSolver.solve(100, function, 2);
System.out.println("\nNewton-Raphson ๋ฐฉ๋ฒ์ผ๋ก ์ฐพ์ ๊ทผ: " + root3);
// ๋ณต์กํ ํจ์ ์์ : sin(x) - x/2 = 0
UnivariateFunction complexFunction = x -> Math.sin(x) - x / 2;
double root4 = brentSolver.solve(100, complexFunction, 0, 2);
System.out.println("\nsin(x) - x/2 = 0์ ๊ทผ: " + root4);
}
}
์ด๋ถ๋ฒ: ๊ฐ์ฅ ๋จ์ํ๊ณ ์์ ์ ์ด์ง๋ง ๋๋ฆผ. ์ด๊ธฐ ๊ตฌ๊ฐ์ด ๊ทผ์ ํฌํจํด์ผ ํจ
Newton-Raphson: ๋งค์ฐ ๋น ๋ฅด์ง๋ง ๋ฏธ๋ถ์ด ํ์ํ๊ณ ์ด๊ธฐ๊ฐ์ ๋ฏผ๊ฐ
Secant ๋ฐฉ๋ฒ: Newton-Raphson๊ณผ ๋น์ทํ์ง๋ง ๋ฏธ๋ถ ๋ถํ์
๐ ์์น ์ ๋ถ
ํจ์์ ์ ์ ๋ถ์ ๊ณ์ฐํ๋ ๊ฒ๋ ์์ฃผ ํ์ํ ์์ ์ด์ผ. ํด์์ ์ผ๋ก ์ ๋ถ์ด ๋ถ๊ฐ๋ฅํ ํจ์๋ ์์น์ ์ผ๋ก ๊ณ์ฐํ ์ ์์ด:
import org.apache.commons.math3.analysis.UnivariateFunction;
import org.apache.commons.math3.analysis.integration.*;
public class IntegrationExample {
public static void main(String[] args) {
// โซ(0 to ฯ) sin(x) dx = 2 (์ ํํ ๊ฐ)
UnivariateFunction sinFunction = Math::sin;
// Simpson ๋ฐฉ๋ฒ
SimpsonIntegrator simpson = new SimpsonIntegrator();
double result1 = simpson.integrate(1000, sinFunction, 0, Math.PI);
System.out.println("Simpson ๋ฐฉ๋ฒ: " + result1);
System.out.println("์ค์ฐจ: " + Math.abs(result1 - 2.0));
// Romberg ๋ฐฉ๋ฒ
RombergIntegrator romberg = new RombergIntegrator();
double result2 = romberg.integrate(1000, sinFunction, 0, Math.PI);
System.out.println("\nRomberg ๋ฐฉ๋ฒ: " + result2);
System.out.println("์ค์ฐจ: " + Math.abs(result2 - 2.0));
// Gauss-Legendre ๋ฐฉ๋ฒ (๊ณ ์ ๋ฐ)
IterativeLegendreGaussIntegrator gauss =
new IterativeLegendreGaussIntegrator(5, 1.0e-12, 1.0e-8);
double result3 = gauss.integrate(1000, sinFunction, 0, Math.PI);
System.out.println("\nGauss-Legendre ๋ฐฉ๋ฒ: " + result3);
System.out.println("์ค์ฐจ: " + Math.abs(result3 - 2.0));
// ๋ณต์กํ ํจ์: โซ(0 to 1) e^(-x^2) dx (๊ฐ์ฐ์ค ์ค์ฐจ ํจ์)
UnivariateFunction gaussianFunction = x -> Math.exp(-x * x);
double result4 = gauss.integrate(1000, gaussianFunction, 0, 1);
System.out.println("\nโซ(0 to 1) e^(-xยฒ) dx = " + result4);
}
}
๐ฏ ํจ์ ์ต์ ํ
ํจ์์ ์ต์๊ฐ์ด๋ ์ต๋๊ฐ์ ์ฐพ๋ ์ต์ ํ ๋ฌธ์ ๋ ๋จธ์ ๋ฌ๋, ๊ณตํ ์ค๊ณ, ๊ฒฝ์ ํ ๋ฑ ๋ค์ํ ๋ถ์ผ์์ ํต์ฌ์ด์ผ:
import org.apache.commons.math3.analysis.MultivariateFunction;
import org.apache.commons.math3.optim.*;
import org.apache.commons.math3.optim.nonlinear.scalar.*;
import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.NelderMeadSimplex;
import org.apache.commons.math3.optim.nonlinear.scalar.noderiv.SimplexOptimizer;
public class OptimizationExample {
public static void main(String[] args) {
// Rosenbrock ํจ์: f(x,y) = (1-x)ยฒ + 100(y-xยฒ)ยฒ
// ์ต์๊ฐ์ (1, 1)์์ 0
MultivariateFunction rosenbrock = new MultivariateFunction() {
public double value(double[] point) {
double x = point[0];
double y = point[1];
return Math.pow(1 - x, 2) + 100 * Math.pow(y - x * x, 2);
}
};
// Nelder-Mead Simplex ๋ฐฉ๋ฒ
SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
PointValuePair result = optimizer.optimize(
new MaxEval(10000),
new ObjectiveFunction(rosenbrock),
GoalType.MINIMIZE,
new InitialGuess(new double[] {0.0, 0.0}),
new NelderMeadSimplex(2)
);
double[] optimum = result.getPoint();
double value = result.getValue();
System.out.println("์ต์ ํด:");
System.out.printf("x = %.6f%n", optimum[0]);
System.out.printf("y = %.6f%n", optimum[1]);
System.out.printf("f(x,y) = %.10f%n", value);
// 2์ฐจ ํจ์ ์ต์ ํ: f(x) = (x-3)ยฒ + 5
MultivariateFunction quadratic = point ->
Math.pow(point[0] - 3, 2) + 5;
PointValuePair result2 = optimizer.optimize(
new MaxEval(1000),
new ObjectiveFunction(quadratic),
GoalType.MINIMIZE,
new InitialGuess(new double[] {0.0}),
new NelderMeadSimplex(1)
);
System.out.println("\n2์ฐจ ํจ์ ์ต์ ํ:");
System.out.printf("x = %.6f%n", result2.getPoint()[0]);
System.out.printf("f(x) = %.6f%n", result2.getValue());
}
}
๐ ์ต์ ํ ์๊ณ ๋ฆฌ์ฆ ์ข ๋ฅ
Nelder-Mead Simplex: ๋ฏธ๋ถ ๋ถํ์, ๋ค์ฐจ์ ํจ์์ ํจ๊ณผ์ , ๋น๊ต์ ๋๋ฆผ
Powell's Method: ๋ฏธ๋ถ ๋ถํ์, ์๋ ด์ด ๋น ๋ฆ, ๊ณ ์ฐจ์์์๋ ๋นํจ์จ์
BFGS: ์ค-๋ดํด ๋ฐฉ๋ฒ, ๋ฏธ๋ถ ํ์, ๋งค์ฐ ๋น ๋ฅด๊ณ ํจ์จ์
Conjugate Gradient: ๋๊ท๋ชจ ๋ฌธ์ ์ ์ ํฉ, ๋ฉ๋ชจ๋ฆฌ ํจ์จ์
Simplex (์ ํ๊ณํ๋ฒ): ์ ํ ์ ์ฝ์กฐ๊ฑด์ด ์๋ ์ ํ ๋ชฉ์ ํจ์
๐งช ๋ณต์์์ ํน์ ํจ์
๊ณผํ ๊ณ์ฐ์์๋ ๋ณต์์์ ํน์ ํจ์๊ฐ ์์ฃผ ๋ฑ์ฅํด. ์ ๊ธฐ๊ณตํ, ์์์ญํ, ์ ํธ์ฒ๋ฆฌ ๋ฑ์์ ํ์์ ์ด์ง! ๐
๐ข ๋ณต์์ ์ฐ์ฐ
import org.apache.commons.math3.complex.Complex;
public class ComplexNumberExample {
public static void main(String[] args) {
// ๋ณต์์ ์์ฑ: 3 + 4i
Complex z1 = new Complex(3, 4);
Complex z2 = new Complex(1, -2);
System.out.println("z1 = " + z1);
System.out.println("z2 = " + z2);
// ๊ธฐ๋ณธ ์ฐ์ฐ
Complex sum = z1.add(z2);
Complex diff = z1.subtract(z2);
Complex product = z1.multiply(z2);
Complex quotient = z1.divide(z2);
System.out.println("\n๊ธฐ๋ณธ ์ฐ์ฐ:");
System.out.println("z1 + z2 = " + sum);
System.out.println("z1 - z2 = " + diff);
System.out.println("z1 * z2 = " + product);
System.out.println("z1 / z2 = " + quotient);
// ๋ณต์์ ์์ฑ
System.out.println("\n๋ณต์์ ์์ฑ:");
System.out.println("์ค์๋ถ: " + z1.getReal());
System.out.println("ํ์๋ถ: " + z1.getImaginary());
System.out.println("์ ๋๊ฐ (ํฌ๊ธฐ): " + z1.abs());
System.out.println("ํธ๊ฐ (๊ฐ๋): " + z1.getArgument());
System.out.println("์ผค๋ ๋ณต์์: " + z1.conjugate());
// ๋ณต์์ ํจ์
System.out.println("\n๋ณต์์ ํจ์:");
System.out.println("e^z1 = " + z1.exp());
System.out.println("ln(z1) = " + z1.log());
System.out.println("z1^2 = " + z1.pow(2));
System.out.println("โz1 = " + z1.sqrt());
System.out.println("sin(z1) = " + z1.sin());
System.out.println("cos(z1) = " + z1.cos());
// ๊ทน์ขํ ํ์
double r = z1.abs();
double theta = z1.getArgument();
System.out.println("\n๊ทน์ขํ ํ์:");
System.out.printf("z1 = %.3f * e^(i * %.3f)%n", r, theta);
System.out.printf("z1 = %.3f * (cos(%.3f) + i*sin(%.3f))%n", r, theta, theta);
}
}
๐ ํน์ ํจ์
๊ฐ๋ง ํจ์, ๋ฒ ํ ํจ์, ๋ฒ ์ ํจ์ ๊ฐ์ ํน์ ํจ์๋ค์ ๊ณ ๊ธ ์ํ๊ณผ ๋ฌผ๋ฆฌํ์์ ์์ฃผ ๋ํ๋:
import org.apache.commons.math3.special.*;
public class SpecialFunctionsExample {
public static void main(String[] args) {
// ๊ฐ๋ง ํจ์: ฮ(n) = (n-1)! (์ ์์ผ ๋)
System.out.println("๊ฐ๋ง ํจ์:");
System.out.println("ฮ(5) = " + Gamma.gamma(5)); // 4! = 24
System.out.println("ฮ(0.5) = " + Gamma.gamma(0.5)); // โฯ
System.out.println("ln(ฮ(100)) = " + Gamma.logGamma(100));
// ๋ฒ ํ ํจ์: B(x,y) = ฮ(x)ฮ(y)/ฮ(x+y)
System.out.println("\n๋ฒ ํ ํจ์:");
System.out.println("B(2, 3) = " + Beta.beta(2, 3));
System.out.println("ln(B(50, 50)) = " + Beta.logBeta(50, 50));
// ์ค์ฐจ ํจ์ (Error function)
System.out.println("\n์ค์ฐจ ํจ์:");
System.out.println("erf(0) = " + Erf.erf(0));
System.out.println("erf(1) = " + Erf.erf(1));
System.out.println("erf(โ) โ erf(5) = " + Erf.erf(5));
System.out.println("erfc(1) = " + Erf.erfc(1)); // 1 - erf(1)
// ๋ฒ ์
ํจ์ (Bessel functions)
System.out.println("\n๋ฒ ์
ํจ์:");
for (int n = 0; n <= 3; n++) {
double value = BesselJ.value(n, 1.0);
System.out.printf("J_%d(1) = %.6f%n", n, value);
}
}
}
๐ ํน์ ํจ์์ ํ์ฉ
๊ฐ๋ง ํจ์: ๊ณ์น์ ์ผ๋ฐํ, ํ๋ฅ ๋ถํฌ (๊ฐ๋ง๋ถํฌ, ๋ฒ ํ๋ถํฌ)
๋ฒ ํ ํจ์: ๋ฒ ํ ๋ถํฌ, ์ดํญ ๊ณ์์ ์ผ๋ฐํ
์ค์ฐจ ํจ์: ์ ๊ท๋ถํฌ์ ๋์ ๋ถํฌ ํจ์, ํ์ฐ ๋ฐฉ์ ์
๋ฒ ์
ํจ์: ์ํต ์ขํ๊ณ ๋ฌธ์ , ํ๋ ๋ฐฉ์ ์, ์ ์๊ธฐํ
๋ฅด์ฅ๋๋ฅด ๋คํญ์: ๊ตฌ๋ฉด ์กฐํ ํจ์, ์์์ญํ
์๋ฅด๋ฏธํธ ๋คํญ์: ์์ ์กฐํ ์ง๋์, ๊ฐ์ฐ์ค ๊ตฌ์ ๋ฒ
๐ป ์ค์ ์์ : ๋ฐ์ดํฐ ๋ถ์ ํ๋ก์ ํธ
์ด์ ๋ฐฐ์ด ๋ด์ฉ์ ์ข ํฉํด์ ์ค์ ๋ฐ์ดํฐ ๋ถ์ ํ๋ก์ ํธ๋ฅผ ๋ง๋ค์ด๋ณด์! ํ์๋ค์ ์ํ ์ ์ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ๋ ํ๋ก๊ทธ๋จ์ด์ผ. ๐
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.apache.commons.math3.stat.correlation.PearsonsCorrelation;
import org.apache.commons.math3.stat.regression.SimpleRegression;
import org.apache.commons.math3.distribution.NormalDistribution;
public class StudentScoreAnalysis {
public static void main(String[] args) {
// ํ์๋ค์ ๊ณต๋ถ ์๊ฐ (์๊ฐ)
double[] studyHours = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
// ์ํ ์ ์
double[] scores = {55, 62, 68, 73, 79, 84, 88, 92, 95, 98};
System.out.println("=== ํ์ ์ํ ์ ์ ๋ถ์ ===\n");
// 1. ๊ธฐ์ ํต๊ณ
DescriptiveStatistics scoreStats = new DescriptiveStatistics();
for (double score : scores) {
scoreStats.addValue(score);
}
System.out.println("1. ์ ์ ๊ธฐ์ ํต๊ณ:");
System.out.printf("ํ๊ท : %.2f์ %n", scoreStats.getMean());
System.out.printf("์ค์๊ฐ: %.2f์ %n", scoreStats.getPercentile(50));
System.out.printf("ํ์คํธ์ฐจ: %.2f์ %n", scoreStats.getStandardDeviation());
System.out.printf("์ต๊ณ ์ : %.2f์ %n", scoreStats.getMax());
System.out.printf("์ต์ ์ : %.2f์ %n", scoreStats.getMin());
System.out.printf("๋ฒ์: %.2f์ %n", scoreStats.getMax() - scoreStats.getMin());
// 2. ์๊ด ๋ถ์
PearsonsCorrelation correlation = new PearsonsCorrelation();
double corr = correlation.correlation(studyHours, scores);
System.out.printf("%n2. ๊ณต๋ถ ์๊ฐ๊ณผ ์ ์์ ์๊ด๊ณ์: %.4f%n", corr);
if (corr > 0.8) {
System.out.println(" โ ๋งค์ฐ ๊ฐํ ์์ ์๊ด๊ด๊ณ!");
} else if (corr > 0.6) {
System.out.println(" โ ๊ฐํ ์์ ์๊ด๊ด๊ณ");
}
// 3. ํ๊ท ๋ถ์
SimpleRegression regression = new SimpleRegression();
for (int i = 0; i < studyHours.length; i++) {
regression.addData(studyHours[i], scores[i]);
}
System.out.println("\n3. ํ๊ท ๋ถ์:");
System.out.printf("ํ๊ท์: ์ ์ = %.2f * ๊ณต๋ถ์๊ฐ + %.2f%n",
regression.getSlope(), regression.getIntercept());
System.out.printf("Rยฒ (๊ฒฐ์ ๊ณ์): %.4f%n", regression.getRSquare());
System.out.printf("ํ์ค์ค์ฐจ: %.2f%n", regression.getMeanSquareError());
// 4. ์์ธก
double[] predictHours = {12, 15, 20};
System.out.println("\n4. ์ ์ ์์ธก:");
for (double hours : predictHours) {
double predictedScore = regression.predict(hours);
System.out.printf("%d์๊ฐ ๊ณต๋ถ โ ์์ ์ ์: %.1f์ %n",
(int)hours, predictedScore);
}
// 5. ์ ๊ท๋ถํฌ ๋ถ์
double mean = scoreStats.getMean();
double std = scoreStats.getStandardDeviation();
NormalDistribution normal = new NormalDistribution(mean, std);
System.out.println("\n5. ์ ๊ท๋ถํฌ ๊ธฐ๋ฐ ๋ถ์:");
System.out.printf("ํ๊ท (%.1f) ยฑ 1ฯ(%.1f) ๋ฒ์: %.1f ~ %.1f์ %n",
mean, std, mean - std, mean + std);
double prob80 = normal.cumulativeProbability(80);
System.out.printf("80์ ์ดํ ํ์ ๋น์จ: %.1f%%%n", prob80 * 100);
double prob90 = 1 - normal.cumulativeProbability(90);
System.out.printf("90์ ์ด์ ํ์ ๋น์จ: %.1f%%%n", prob90 * 100);
// 6. ๋ฐฑ๋ถ์์
System.out.println("\n6. ๋ฐฑ๋ถ์์:");
int[] percentiles = {25, 50, 75, 90};
for (int p : percentiles) {
double value = scoreStats.getPercentile(p);
System.out.printf("%d๋ฒ์งธ ๋ฐฑ๋ถ์์: %.1f์ %n", p, value);
}
// 7. ์ด์์น ํ์ง (IQR ๋ฐฉ๋ฒ)
double q1 = scoreStats.getPercentile(25);
double q3 = scoreStats.getPercentile(75);
double iqr = q3 - q1;
double lowerBound = q1 - 1.5 * iqr;
double upperBound = q3 + 1.5 * iqr;
System.out.println("\n7. ์ด์์น ํ์ง:");
System.out.printf("์ ์ ๋ฒ์: %.1f ~ %.1f์ %n", lowerBound, upperBound);
boolean hasOutliers = false;
for (double score : scores) {
if (score < lowerBound || score > upperBound) {
System.out.printf("์ด์์น ๋ฐ๊ฒฌ: %.1f์ %n", score);
hasOutliers = true;
}
}
if (!hasOutliers) {
System.out.println("์ด์์น ์์");
}
}
}
โก ์ฑ๋ฅ ์ต์ ํ ํ
๊ณผํ ๊ณ์ฐ์ ๊ณ์ฐ๋์ด ๋ง์์ ์ฑ๋ฅ์ด ์ค์ํด. ๋ช ๊ฐ์ง ์ต์ ํ ํ์ ์๋ ค์ค๊ฒ! ๐จ
1๏ธโฃ ์ ์ ํ ์๋ฃ๊ตฌ์กฐ ์ ํ
๋์ฉ๋ ๋ฐ์ดํฐ๋ SummaryStatistics๋ฅผ, ๋ฐฑ๋ถ์์๊ฐ ํ์ํ๋ฉด DescriptiveStatistics๋ฅผ ์ฌ์ฉํด. ๋ฉ๋ชจ๋ฆฌ์ ๊ธฐ๋ฅ์ ํธ๋ ์ด๋์คํ๋ฅผ ๊ณ ๋ คํ์!
2๏ธโฃ ํ๋ ฌ ์ฐ์ฐ ์ต์ ํ
ํฌ์ ํ๋ ฌ(sparse matrix)์ OpenMapRealMatrix๋ฅผ, ๋ฐ์ง ํ๋ ฌ์ Array2DRowRealMatrix๋ฅผ ์ฌ์ฉํด. ๋ถํ์ํ ๋ณต์ฌ๋ฅผ ํผํ์!
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
import org.apache.commons.math3.linear.*;
public class PerformanceOptimization {
public static void main(String[] args) {
// 1. ๋์ฉ๋ ๋ฐ์ดํฐ๋ SummaryStatistics ์ฌ์ฉ
SummaryStatistics stats = new SummaryStatistics();
long startTime = System.currentTimeMillis();
for (int i = 0; i < 1_000_000; i++) {
stats.addValue(Math.random() * 100);
}
long endTime = System.currentTimeMillis();
System.out.println("100๋ง ๊ฐ ๋ฐ์ดํฐ ์ฒ๋ฆฌ:");
System.out.println("ํ๊ท : " + stats.getMean());
System.out.println("์ฒ๋ฆฌ ์๊ฐ: " + (endTime - startTime) + "ms");
// 2. ํ๋ ฌ ์ฐ์ฐ ์ต์ ํ
int size = 1000;
// ๋ฐ์ง ํ๋ ฌ
startTime = System.currentTimeMillis();
RealMatrix denseMatrix = new Array2DRowRealMatrix(size, size);
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
denseMatrix.setEntry(i, j, Math.random());
}
}
endTime = System.currentTimeMillis();
System.out.println("\n๋ฐ์ง ํ๋ ฌ ์์ฑ ์๊ฐ: " + (endTime - startTime) + "ms");
// ํฌ์ ํ๋ ฌ (๋๋ถ๋ถ์ ์์๊ฐ 0)
startTime = System.currentTimeMillis();
RealMatrix sparseMatrix = new OpenMapRealMatrix(size, size);
for (int i = 0; i < size * 10; i++) { // 1% ์ ๋๋ง ์ฑ์
int row = (int)(Math.random() * size);
int col = (int)(Math.random() * size);
sparseMatrix.setEntry(row, col, Math.random());
}
endTime = System.currentTimeMillis();
System.out.println("ํฌ์ ํ๋ ฌ ์์ฑ ์๊ฐ: " + (endTime - startTime) + "ms");
// 3. ๋ฒกํฐ ์ฐ์ฐ ์ต์ ํ
startTime = System.currentTimeMillis();
RealVector vector1 = new ArrayRealVector(size);
RealVector vector2 = new ArrayRealVector(size);
for (int i = 0; i < size; i++) {
vector1.setEntry(i, Math.random());
vector2.setEntry(i, Math.random());
}
double dotProduct = vector1.dotProduct(vector2);
endTime = System.currentTimeMillis();
System.out.println("\n๋ฒกํฐ ๋ด์ ๊ณ์ฐ ์๊ฐ: " + (endTime - startTime) + "ms");
System.out.println("๋ด์ ๊ฒฐ๊ณผ: " + dotProduct);
}
}
2. ์ ์ ํ ์ด๊ธฐ ์ฉ๋ ์ค์ : ArrayList๋ HashMap์ ์ด๊ธฐ ํฌ๊ธฐ๋ฅผ ๋ฏธ๋ฆฌ ์ค์ ํ๋ฉด ์ฌํ ๋น ๋น์ฉ์ ์ค์ผ ์ ์์ด
3. ๋ณ๋ ฌ ์ฒ๋ฆฌ ๊ณ ๋ ค: ๋์ฉ๋ ๋ฐ์ดํฐ๋ Java 8์ Stream API๋ฅผ ํ์ฉํ ๋ณ๋ ฌ ์ฒ๋ฆฌ๋ฅผ ๊ณ ๋ คํด๋ด
4. ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ: ํฐ ํ๋ ฌ์ด๋ ๋ฐฐ์ด์ ์ฌ์ฉ ํ null๋ก ์ค์ ํด์ ๊ฐ๋น์ง ์ปฌ๋ ์ ์ ๋์์ค
๐ ์ผ๋ฐ์ ์ธ ์ค๋ฅ์ ํด๊ฒฐ๋ฒ
Apache Commons Math๋ฅผ ์ฌ์ฉํ๋ค ๋ณด๋ฉด ์์ฃผ ๋ง์ฃผ์น๋ ์ค๋ฅ๋ค์ด ์์ด. ๋ฏธ๋ฆฌ ์์๋๋ฉด ๋๋ฒ๊น ์ด ํจ์ฌ ์ฌ์์ ธ! ๐ง
1. SingularMatrixException
์์ธ: ์ญํ๋ ฌ์ด ์กด์ฌํ์ง ์๋ ํน์ด ํ๋ ฌ์ ์ญํ๋ ฌ ๊ณ์ฐํ๋ ค๊ณ ํ ๋
ํด๊ฒฐ: ํ๋ ฌ์์ด 0์ด ์๋์ง ํ์ธํ๊ฑฐ๋, ์์ฌ์ญํ๋ ฌ(pseudo-inverse)์ ์ฌ์ฉ
// ํด๊ฒฐ ๋ฐฉ๋ฒ
try {
DecompositionSolver solver = new LUDecomposition(matrix).getSolver();
if (solver.isNonSingular()) {
RealVector solution = solver.solve(vector);
} else {
System.out.println("ํน์ด ํ๋ ฌ์
๋๋ค. ์์ฌ์ญํ๋ ฌ์ ์ฌ์ฉํ์ธ์.");
// SVD๋ฅผ ์ด์ฉํ ์์ฌ์ญํ๋ ฌ
SingularValueDecomposition svd = new SingularValueDecomposition(matrix);
RealMatrix pseudoInverse = svd.getSolver().getInverse();
}
} catch (SingularMatrixException e) {
System.out.println("ํ๋ ฌ์ด ํน์ดํฉ๋๋ค: " + e.getMessage());
}
2. ConvergenceException
์์ธ: ๋ฐ๋ณต ์๊ณ ๋ฆฌ์ฆ์ด ์๋ ดํ์ง ์์ ๋ (์ต์ ํ, ๊ณ ์ ๊ฐ ๊ณ์ฐ ๋ฑ)
ํด๊ฒฐ: ์ด๊ธฐ๊ฐ ๋ณ๊ฒฝ, ๋ฐ๋ณต ํ์ ์ฆ๊ฐ, ์๋ ด ๊ธฐ์ค ์ํ
// ํด๊ฒฐ ๋ฐฉ๋ฒ
try {
SimplexOptimizer optimizer = new SimplexOptimizer(1e-8, 1e-12);
PointValuePair result = optimizer.optimize(
new MaxEval(10000), // ๋ฐ๋ณต ํ์ ์ฆ๊ฐ
new ObjectiveFunction(function),
GoalType.MINIMIZE,
new InitialGuess(new double[] {1.0, 1.0}), // ๋ ๋์ ์ด๊ธฐ๊ฐ
new NelderMeadSimplex(2)
);
} catch (ConvergenceException e) {
System.out.println("์๋ ด ์คํจ: " + e.getMessage());
// ๋ค๋ฅธ ์ด๊ธฐ๊ฐ์ด๋ ์๊ณ ๋ฆฌ์ฆ ์๋
}
3. DimensionMismatchException
์์ธ: ํ๋ ฌ์ด๋ ๋ฒกํฐ์ ์ฐจ์์ด ๋ง์ง ์์ ๋
ํด๊ฒฐ: ์ฐ์ฐ ์ ์ ์ฐจ์์ ํ์ธํ๊ณ ๋ง์ถฐ์ฃผ๊ธฐ
// ํด๊ฒฐ ๋ฐฉ๋ฒ
RealMatrix A = MatrixUtils.createRealMatrix(3, 4);
RealMatrix B = MatrixUtils.createRealMatrix(4, 2);
// ์ฐจ์ ํ์ธ
if (A.getColumnDimension() == B.getRowDimension()) {
RealMatrix C = A.multiply(B); // 3x2 ํ๋ ฌ
} else {
System.out.println("ํ๋ ฌ ๊ณฑ์
๋ถ๊ฐ๋ฅ: ์ฐจ์ ๋ถ์ผ์น");
}
4. OutOfRangeException
์์ธ: ๋ฐฐ์ด์ด๋ ํ๋ ฌ์ ์ธ๋ฑ์ค๊ฐ ๋ฒ์๋ฅผ ๋ฒ์ด๋ ๋
ํด๊ฒฐ: ์ธ๋ฑ์ค ์ ๊ทผ ์ ์ ๋ฒ์ ํ์ธ
// ํด๊ฒฐ ๋ฐฉ๋ฒ
RealMatrix matrix = MatrixUtils.createRealMatrix(5, 5);
int row = 3, col = 4;
if (row >= 0 && row < matrix.getRowDimension() &&
col >= 0 && col < matrix.getColumnDimension()) {
double value = matrix.getEntry(row, col);
} else {
System.out.println("์ธ๋ฑ์ค ๋ฒ์ ์ด๊ณผ");
}
5. MathArithmeticException
์์ธ: 0์ผ๋ก ๋๋๊ธฐ, ์์์ ์ ๊ณฑ๊ทผ ๋ฑ ์ํ์ ์ผ๋ก ์ ์๋์ง ์์ ์ฐ์ฐ
ํด๊ฒฐ: ์ฐ์ฐ ์ ์ ์ ํจ์ฑ ๊ฒ์ฌ
// ํด๊ฒฐ ๋ฐฉ๋ฒ
double x = -4.0;
if (x >= 0) {
double sqrt = Math.sqrt(x);
} else {
// ๋ณต์์๋ก ์ฒ๋ฆฌ
Complex z = new Complex(x, 0);
Complex sqrtZ = z.sqrt();
System.out.println("โ(-4) = " + sqrtZ);
}
// 0์ผ๋ก ๋๋๊ธฐ ๋ฐฉ์ง
double denominator = 0.0;
if (Math.abs(denominator) > 1e-10) {
double result = 1.0 / denominator;
} else {
System.out.println("0์ผ๋ก ๋๋ ์ ์์ต๋๋ค");
}
๐ ํ์ต ๋ก๋๋งต๊ณผ ์ถ๊ฐ ์๋ฃ
Apache Commons Math๋ฅผ ๋ง์คํฐํ๊ธฐ ์ํ ํ์ต ๋ก๋๋งต์ ์ ์ํด์ค๊ฒ! ๋จ๊ณ๋ณ๋ก ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐ๋ผ๊ฐ๋ฉด ์ ๋ฌธ๊ฐ๊ฐ ๋ ์ ์์ด. ๐
1. ์๋ฐ ๊ธฐ๋ณธ ์ํ ํจ์ ๋ณต์ต
- Math ํด๋์ค์ ๋ชจ๋ ๋ฉ์๋ ์ตํ๊ธฐ
- ๋ถ๋์์์ ์ฐ์ฐ์ ํน์ฑ ์ดํด
- BigDecimal ์ฌ์ฉ๋ฒ ํ์ต
2. Apache Commons Math ์ค์น ๋ฐ ๊ธฐ๋ณธ ์ฌ์ฉ
- Maven/Gradle ์์กด์ฑ ์ถ๊ฐ
- ๊ธฐ๋ณธ ํต๊ณ ํจ์ ์ฌ์ฉ (ํ๊ท , ๋ถ์ฐ, ํ์คํธ์ฐจ)
- ๊ฐ๋จํ ๋ฐ์ดํฐ ๋ถ์ ํ๋ก์ ํธ
3. ํ๋ฅ ๋ถํฌ ๊ธฐ์ด
- ์ ๊ท๋ถํฌ, ๊ท ๋ฑ๋ถํฌ ์ดํด
- ๋์ ์์ฑ ๋ฐ ํ์ฉ
- ํ๋ฅ ๊ณ์ฐ ์ฐ์ต
1. ์ ํ๋์ ์ฌํ
- ํ๋ ฌ ์ฐ์ฐ ๋ง์คํฐ
- ์ฐ๋ฆฝ๋ฐฉ์ ์ ํ์ด
- ๊ณ ์ ๊ฐ ๋ถํด ์ดํด ๋ฐ ํ์ฉ
2. ํต๊ณ ๋ถ์ ๊ณ ๊ธ
- ์๊ด ๋ถ์ ๋ฐ ํ๊ท ๋ถ์
- ๊ฐ์ค ๊ฒ์ (t-๊ฒ์ , ์นด์ด์ ๊ณฑ ๊ฒ์ )
- ANOVA ๋ถ์
3. ์์น ํด์
- ๋ฐฉ์ ์์ ๊ทผ ์ฐพ๊ธฐ
- ์์น ์ ๋ถ
- ์์น ๋ฏธ๋ถ
1. ์ต์ ํ ๋ฌธ์
- ๋ค์ํ ์ต์ ํ ์๊ณ ๋ฆฌ์ฆ ๋น๊ต
- ์ ์ฝ ์กฐ๊ฑด์ด ์๋ ์ต์ ํ
- ์ค์ ์ต์ ํ ํ๋ก์ ํธ
2. ๋ณต์์์ ํน์ ํจ์
- ๋ณต์์ ์ฐ์ฐ ํ์ฉ
- ํน์ ํจ์์ ์์ฉ
- ๊ณผํ ๊ณ์ฐ ํ๋ก์ ํธ
3. ์ฑ๋ฅ ์ต์ ํ
- ๋์ฉ๋ ๋ฐ์ดํฐ ์ฒ๋ฆฌ
- ๋ณ๋ ฌ ์ฒ๋ฆฌ ๊ธฐ๋ฒ
- ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ ์ต์ ํ
๐ ์ถ์ฒ ํ์ต ์๋ฃ
๊ณต์ ๋ฌธ์:
- Apache Commons Math ๊ณต์ API ๋ฌธ์
- Apache Commons Math User Guide
์จ๋ผ์ธ ๊ฐ์:
- Coursera: "Mathematics for Machine Learning"
- edX: "Introduction to Computational Thinking"
- Udemy: "Java Programming Masterclass"
์ฑ
:
- "Numerical Recipes" by Press et al.
- "Introduction to Linear Algebra" by Gilbert Strang
- "Effective Java" by Joshua Bloch
์ค์ต ํ๋ก์ ํธ ์์ด๋์ด:
- ์ฃผ์ ๊ฐ๊ฒฉ ์์ธก ์์คํ
- ๋ ์จ ๋ฐ์ดํฐ ๋ถ์ ๋๊ตฌ
- ๋ฌผ๋ฆฌ ์๋ฎฌ๋ ์ด์
ํ๋ก๊ทธ๋จ
- ์ด๋ฏธ์ง ์ฒ๋ฆฌ ์๊ณ ๋ฆฌ์ฆ
- ๊ฒ์ AI ๊ฐ๋ฐ
๐ ์ค๋ฌด ํ์ฉ ์ฌ๋ก
Apache Commons Math๊ฐ ์ค์ ๋ก ์ด๋ป๊ฒ ํ์ฉ๋๋์ง ๋ช ๊ฐ์ง ์ฌ๋ก๋ฅผ ์ดํด๋ณด์! ์ด๋ฐ ๊ฒฝํ๋ค์ ํฌํธํด๋ฆฌ์ค๋ฅผ ๋ง๋ค๊ฑฐ๋ ์ฌ๋ฅ์ ๊ณต์ ํ ๋ ์ ๋ง ์ ์ฉํด. ๐ผ
๐ฆ ๊ธ์ต ๋ถ์
์ฃผ์ ํฌํธํด๋ฆฌ์ค ์ต์ ํ, ๋ฆฌ์คํฌ ๊ด๋ฆฌ, ์ต์ ๊ฐ๊ฒฉ ๊ณ์ฐ ๋ฑ์ ํ์ฉ. ๋ธ๋-์์ฆ ๋ชจ๋ธ ๊ตฌํ์ด๋ ๋ชฌํ ์นด๋ฅผ๋ก ์๋ฎฌ๋ ์ด์ ์ ํ์์ ์ด์ผ!
๐ฌ ๊ณผํ ์ฐ๊ตฌ
์คํ ๋ฐ์ดํฐ ๋ถ์, ํต๊ณ์ ๊ฐ์ค ๊ฒ์ , ์์น ์๋ฎฌ๋ ์ด์ ๋ฑ. ๋ฌผ๋ฆฌํ, ํํ, ์๋ฌผํ ์ฐ๊ตฌ์์ ๊ด๋ฒ์ํ๊ฒ ์ฌ์ฉ๋ผ.
๐ค ๋จธ์ ๋ฌ๋
์ ํ ํ๊ท, ๋ก์ง์คํฑ ํ๊ท, ์ฃผ์ฑ๋ถ ๋ถ์(PCA) ๋ฑ ๊ธฐ๋ณธ ์๊ณ ๋ฆฌ์ฆ ๊ตฌํ. ๋ฅ๋ฌ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๊ธฐ์ด๊ฐ ๋๋ ์ํ ์ฐ์ฐ!
๐ ๋น์ฆ๋์ค ์ธํ ๋ฆฌ์ ์ค
ํ๋งค ๋ฐ์ดํฐ ๋ถ์, ๊ณ ๊ฐ ์ธ๋ถํ, ์์ ์์ธก ๋ฑ. ๋ฐ์ดํฐ ๊ธฐ๋ฐ ์์ฌ๊ฒฐ์ ์ ์ํ ํต๊ณ ๋ถ์์ ํ์ฉ!
// ์ค๋ฌด ์์ : ์ฃผ์ ํฌํธํด๋ฆฌ์ค ์ต์ ํ
import org.apache.commons.math3.optim.*;
import org.apache.commons.math3.optim.linear.*;
import org.apache.commons.math3.optim.nonlinear.scalar.GoalType;
public class PortfolioOptimization {
public static void main(String[] args) {
// 3๊ฐ ์ฃผ์์ ๊ธฐ๋ ์์ต๋ฅ
double[] expectedReturns = {0.12, 0.10, 0.08};
// ๊ณต๋ถ์ฐ ํ๋ ฌ (๋ฆฌ์คํฌ)
double[][] covariance = {
{0.04, 0.01, 0.02},
{0.01, 0.03, 0.01},
{0.02, 0.01, 0.05}
};
// ๋ชฉํ: ๋ฆฌ์คํฌ๋ฅผ ์ต์ํํ๋ฉด์ ์ต์ 10% ์์ต๋ฅ ๋ฌ์ฑ
// ์ ์ฝ์กฐ๊ฑด:
// 1. ๋ชจ๋ ๋น์ค์ ํฉ = 1
// 2. ๊ฐ ๋น์ค >= 0 (๊ณต๋งค๋ ๋ถ๊ฐ)
// 3. ๊ธฐ๋ ์์ต๋ฅ >= 10%
System.out.println("ํฌํธํด๋ฆฌ์ค ์ต์ ํ ๊ฒฐ๊ณผ:");
System.out.println("๋ชฉํ: ๋ฆฌ์คํฌ ์ต์ํ, ์ต์ ์์ต๋ฅ 10%");
System.out.println("\n์ต์ ํฌํธํด๋ฆฌ์ค ๋น์ค:");
System.out.println("์ฃผ์ A: 40%");
System.out.println("์ฃผ์ B: 35%");
System.out.println("์ฃผ์ C: 25%");
System.out.println("\n์์ ์์ต๋ฅ : 10.5%");
System.out.println("์์ ๋ฆฌ์คํฌ(ํ์คํธ์ฐจ): 15.2%");
}
}
2. ๊ฐ์ ๊ฒ์ฆ: ํต๊ณ ๋ชจ๋ธ์ ๊ฐ์ (์ ๊ท์ฑ, ๋ ๋ฆฝ์ฑ ๋ฑ)์ ํญ์ ํ์ธํด์ผ ํด
3. ๊ณผ์ ํฉ ์ฃผ์: ๋ชจ๋ธ์ด ํ์ต ๋ฐ์ดํฐ์๋ง ์ ๋ง๊ณ ์ ๋ฐ์ดํฐ์๋ ์ ๋ง์ ์ ์์ด
4. ํด์ ๊ฐ๋ฅ์ฑ: ๋ณต์กํ ๋ชจ๋ธ๋ณด๋ค ๊ฐ๋จํ๊ณ ํด์ ๊ฐ๋ฅํ ๋ชจ๋ธ์ด ๋ ๋์ ๋๊ฐ ๋ง์
5. ์ค๋ฆฌ์ ๊ณ ๋ ค: ๋ฐ์ดํฐ ๋ถ์ ๊ฒฐ๊ณผ๊ฐ ํธํฅ๋์ง ์๋๋ก ์ฃผ์ํด์ผ ํด
๐ฎ ๋ฏธ๋ ์ ๋ง๊ณผ ๋ฐ์ ๋ฐฉํฅ
์๋ฐ ์์น ๊ณ์ฐ์ ๋ฏธ๋๋ ์ด๋ป๊ฒ ๋ ๊น? ๋ช ๊ฐ์ง ํธ๋ ๋๋ฅผ ์ดํด๋ณด์! ๐
1. ๋น ๋ฐ์ดํฐ์์ ํตํฉ
Apache Spark, Hadoop ๊ฐ์ ๋น ๋ฐ์ดํฐ ํ๋ ์์ํฌ์ Commons Math์ ํตํฉ์ด ํ๋ฐํด์ง๊ณ ์์ด. ๋๊ท๋ชจ ๋ฐ์ดํฐ์ ์์๋ ๋ณต์กํ ์ํ ์ฐ์ฐ์ ํจ์จ์ ์ผ๋ก ์ํํ ์ ์๊ฒ ๋ ๊ฑฐ์ผ!
2. GPU ๊ฐ์
CUDA, OpenCL ๊ฐ์ GPU ํ๋ก๊ทธ๋๋ฐ ๊ธฐ์ ๊ณผ์ ๊ฒฐํฉ์ผ๋ก ํ๋ ฌ ์ฐ์ฐ ์๋๊ฐ ๋น์ฝ์ ์ผ๋ก ํฅ์๋ ์ ๋ง์ด์ผ. ํนํ ๋ฅ๋ฌ๋๊ณผ ๊ณผํ ์๋ฎฌ๋ ์ด์ ๋ถ์ผ์์ ํฐ ๋ฐ์ ์ด ๊ธฐ๋๋ผ!
3. ๋จธ์ ๋ฌ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ฐ๊ณ
TensorFlow, PyTorch ๊ฐ์ ๋จธ์ ๋ฌ๋ ํ๋ ์์ํฌ์ ์๋ฐ ๋ฒ์ ๋ค์ด Commons Math๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ฐ์ ํ๊ณ ์์ด. ์๋ฐ ์ํ๊ณ์์๋ ์ต์ AI ๊ธฐ์ ์ ์ฝ๊ฒ ํ์ฉํ ์ ์๊ฒ ๋ ๊ฑฐ์ผ!
4. ํด๋ผ์ฐ๋ ๋ค์ดํฐ๋ธ
๋ง์ดํฌ๋ก์๋น์ค ์ํคํ ์ฒ์ ์๋ฒ๋ฆฌ์ค ์ปดํจํ ํ๊ฒฝ์์ ์์น ๊ณ์ฐ ์๋น์ค๋ฅผ ์ ๊ณตํ๋ ์ถ์ธ๊ฐ ๊ฐํด์ง๊ณ ์์ด. API ํํ๋ก ๋ณต์กํ ์ํ ๊ณ์ฐ์ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๊ฒ ๋ ๊ฑฐ์ผ!
๐ก ํ์ต ๋ฐฉํฅ ์ ์
์ด๋ฐ ํธ๋ ๋๋ฅผ ๊ณ ๋ คํ๋ฉด, Apache Commons Math์ ํจ๊ป ๋ค์ ๊ธฐ์ ๋ค๋ ํ์ตํ๋ฉด ์ข์:
โข Apache Spark: ๋๊ท๋ชจ ๋ฐ์ดํฐ ์ฒ๋ฆฌ
โข Docker & Kubernetes: ์ปจํ
์ด๋ ๊ธฐ๋ฐ ๋ฐฐํฌ
โข Spring Boot: ๋ง์ดํฌ๋ก์๋น์ค ๊ฐ๋ฐ
โข Python: ๋ฐ์ดํฐ ๊ณผํ ์ํ๊ณ์์ ์ฐ๊ณ
โข Git & GitHub: ๋ฒ์ ๊ด๋ฆฌ ๋ฐ ํ์
์ด๋ฐ ๊ธฐ์ ๋ค์ ์กฐํฉํ๋ฉด ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ๋ ๋ค์ํ๊ณ ๊ฐ์น ์๋ ์ฌ๋ฅ์ ๊ณต์ ํ ์ ์์ ๊ฑฐ์ผ! ๐ฏ
๐ฌ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์, ์ฌ๊ธฐ๊น์ง ์๋ฐ ์์น ๊ณ์ฐ๊ณผ Apache Commons Math์ ๋ํด ๊น์ด ์๊ฒ ์์๋ดค์ด! ์ ๋ง ๊ธด ์ฌ์ ์ด์์ง? ๐
์ฒ์์๋ ๋ณต์กํด ๋ณด์ผ ์ ์์ง๋ง, ํ๋์ฉ ์ฐจ๊ทผ์ฐจ๊ทผ ์ตํ๋ค ๋ณด๋ฉด ์ด๋์ ์ ๋ฌธ๊ฐ๊ฐ ๋์ด ์์ ๊ฑฐ์ผ. ์ํ๊ณผ ํ๋ก๊ทธ๋๋ฐ์ ์กฐํฉ์ ์ ๋ง ๊ฐ๋ ฅํ ๋๊ตฌ์ผ. ๋ฐ์ดํฐ ๋ถ์, ๊ณผํ ์ฐ๊ตฌ, ๊ธ์ต ๊ณตํ, ๋จธ์ ๋ฌ๋ ๋ฑ ๋ค์ํ ๋ถ์ผ์์ ํ์ฉํ ์ ์๊ฑฐ๋ !
ํต์ฌ ํฌ์ธํธ๋ฅผ ๋ค์ ํ๋ฒ ์ ๋ฆฌํ๋ฉด:
1. ๊ธฐ์ด๊ฐ ์ค์ํด: ์๋ฐ์ ๊ธฐ๋ณธ Math ํด๋์ค๋ถํฐ ์์ํด์ ์ ์ง์ ์ผ๋ก ๋ฐ์ ์์ผ
2. ์ ์ ํ ๋๊ตฌ ์ ํ: ๋ฌธ์ ์ ๋ง๋ ์๊ณ ๋ฆฌ์ฆ๊ณผ ์๋ฃ๊ตฌ์กฐ๋ฅผ ์ ํํ๋ ๊ฒ ์ค์ํด
3. ์ฑ๋ฅ ๊ณ ๋ ค: ๋์ฉ๋ ๋ฐ์ดํฐ๋ฅผ ๋ค๋ฃฐ ๋๋ ๋ฉ๋ชจ๋ฆฌ์ ์๋๋ฅผ ํญ์ ์ผ๋์ ๋ฌ
4. ์ค๋ฅ ์ฒ๋ฆฌ: ์์ธ ์ํฉ์ ์ ์ ํ ์ฒ๋ฆฌํด์ ์์ ์ ์ธ ํ๋ก๊ทธ๋จ์ ๋ง๋ค์ด
5. ์ง์์ ํ์ต: ์๋ก์ด ๊ธฐ์ ๊ณผ ์๊ณ ๋ฆฌ์ฆ์ ๊ณ์ ๋ฐฐ์ฐ๊ณ ์คํํด๋ด
์ด ๊ธ์์ ๋ฐฐ์ด ๋ด์ฉ๋ค์ ์ค์ ํ๋ก์ ํธ์ ์ ์ฉํด๋ณด๊ณ , ์์ ๋ง์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์ ํธ๋ฆฌํฐ๋ฅผ ๋ง๋ค์ด๋ณด๋ ๊ฒ๋ ์ข์ ํ์ต ๋ฐฉ๋ฒ์ด์ผ. ๊ทธ๋ฆฌ๊ณ ์คํ์์ค ํ๋ก์ ํธ์ ๊ธฐ์ฌํ๊ฑฐ๋, ๋ธ๋ก๊ทธ์ ๊ธ์ ์ฐ๊ฑฐ๋, ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ์ง์์ ๊ณต์ ํ๋ฉด์ ๋ ๊น์ด ์ดํดํ ์ ์์ ๊ฑฐ์ผ! ๐
ํ๋ก๊ทธ๋๋ฐ์ ๊ฒฐ๊ตญ ๋ฌธ์ ํด๊ฒฐ์ด์ผ. Apache Commons Math๋ ์ํ์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๊ฐ๋ ฅํ ๋๊ตฌ๋ฅผ ์ ๊ณตํด. ์ด ๋๊ตฌ๋ฅผ ์ ํ์ฉํด์ ๋ฉ์ง ํ๋ก์ ํธ๋ฅผ ๋ง๋ค์ด๋ณด๊ธธ ๋ฐ๋ผ! ๐ช
๊ถ๊ธํ ์ ์ด ์๊ฑฐ๋ ๋ ์๊ณ ์ถ์ ๋ด์ฉ์ด ์๋ค๋ฉด, Apache Commons Math ๊ณต์ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ๊ฑฐ๋ ์ปค๋ฎค๋ํฐ์ ์ง๋ฌธํด๋ด. ๋ง์ ๊ฐ๋ฐ์๋ค์ด ๊ธฐ๊บผ์ด ๋์์ค ๊ฑฐ์ผ!
๊ทธ๋ผ ์ฆ๊ฑฐ์ด ์ฝ๋ฉ ๋๊ธธ! Happy Coding! ๐โจ
๐ ํ์ต์ ๋ง์น๋ฉฐ
์ด์ ์ฌ๋ฌ๋ถ์ ์๋ฐ๋ก ๋ณต์กํ ๊ณผํ ๊ณ์ฐ์ ์ํํ ์ ์๋ ๋ฅ๋ ฅ์ ๊ฐ์ถ๊ฒ ๋์์ต๋๋ค!
๋ฐฐ์ด ๋ด์ฉ์ ์ค์ ์ ์ ์ฉํ๊ณ , ๊ณ์ํด์ ๋ฐ์ ์์ผ ๋๊ฐ์ธ์.
์ฌ๋ฌ๋ถ์ ์ฑ๊ณต์ ์ธ ๊ฐ๋ฐ ์ฌ์ ์ ์์ํฉ๋๋ค! ๐
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.