diff --git a/JavaUtils/nbproject/project.properties b/JavaUtils/nbproject/project.properties deleted file mode 100644 index d9a04f2..0000000 --- a/JavaUtils/nbproject/project.properties +++ /dev/null @@ -1,93 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processor.options= -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.modulepath=\ - ${run.modulepath} -debug.test.classpath=\ - ${run.test.classpath} -debug.test.modulepath=\ - ${run.test.modulepath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/JavaUtils.jar -dist.javadoc.dir=${dist.dir}/javadoc -dist.jlink.dir=${dist.dir}/jlink -dist.jlink.output=${dist.jlink.dir}/JavaUtils -excludes= -includes=** -jar.compress=false -javac.classpath= -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.external.vm=true -javac.modulepath= -javac.processormodulepath= -javac.processorpath=\ - ${javac.classpath} -javac.source=11 -javac.target=11 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.modulepath=\ - ${javac.modulepath} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.html5=false -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -# The jlink additional root modules to resolve -jlink.additionalmodules= -# The jlink additional command line parameters -jlink.additionalparam= -jlink.launcher=true -jlink.launcher.name=JavaUtils -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=true -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.modulepath=\ - ${javac.modulepath} -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -run.test.modulepath=\ - ${javac.test.modulepath} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test diff --git a/JavaUtils/src/id/ac/ub/filkom/rendicahya/utils/array/operators/StandardDeviationCalculator.java b/JavaUtils/src/id/ac/ub/filkom/rendicahya/utils/array/operators/StandardDeviationCalculator.java index 898a3ac..0b437b6 100644 --- a/JavaUtils/src/id/ac/ub/filkom/rendicahya/utils/array/operators/StandardDeviationCalculator.java +++ b/JavaUtils/src/id/ac/ub/filkom/rendicahya/utils/array/operators/StandardDeviationCalculator.java @@ -5,4 +5,119 @@ // Input 1: [1, 4, 8, 2, 5] // Output: 2.7386127875258 public class StandardDeviationCalculator implements ArrayToDoubleReducer { -} + + @Override + public double reduce(byte[] input) { + double sum = 0, standardDeviation = 0; + int length = input.length; + + for(double num : input) { + sum += num; + } + + double mean = (sum/length); + + for(double num: input) { + standardDeviation += Math.pow(num - mean, 2); + } + + return Math.sqrt(standardDeviation/length); + } + + @Override + public double reduce(short[] input) { + double sum = 0, standardDeviation = 0; + int length = input.length; + + for(double num : input) { + sum += num; + } + + double mean = (sum/length); + + for(double num: input) { + standardDeviation += Math.pow(num - mean, 2); + } + + return Math.sqrt(standardDeviation/length); + + } + + @Override + public double reduce(int[] input) { + double sum = 0, standardDeviation = 0; + int length = input.length; + + for(double num : input) { + sum += num; + } + + double mean = (sum/length); + + for(double num: input) { + standardDeviation += Math.pow(num - mean, 2); + } + + return Math.sqrt(standardDeviation/length); + + } + + @Override + public double reduce(long[] input) { + double sum = 0, standardDeviation = 0; + int length = input.length; + + for(double num : input) { + sum += num; + } + double mean = (sum/length); + + for(double num: input) { + standardDeviation += Math.pow(num - mean, 2); + } + + return Math.sqrt(standardDeviation/length); + + } + + @Override + public double reduce(float[] input) { + double sum = 0, standardDeviation = 0; + int length = input.length; + + for(double num : input) { + sum += num; + } + + double mean = (sum/length); + + for(double num: input) { + standardDeviation += Math.pow(num - mean, 2); + } + + return Math.sqrt(standardDeviation/length); + + } + + @Override + public double reduce(double[] input) { + double sum = 0, standardDeviation = 0; + int length = input.length; + + for(double num : input) { + sum += num; + } + + double mean = (sum/length); + + for(double num: input) { + standardDeviation += Math.pow(num - mean, 2); + } + + return Math.sqrt(standardDeviation/length); + + } + } + + +