refactor: change to MIT license and reformat codes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# Num4j
|
||||
# Math Toolkit
|
||||
|
||||
`num4j` provides some mathematical algorithms and utilities such as chained high-precision mathematical calculator and percentile statistic algorithm.
|
||||
**Math Toolkit** provides some mathematical algorithms and utilities such as chained high-precision
|
||||
mathematical calculator and percentile statistic algorithm.
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 OnixByte
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import java.net.URI
|
||||
|
||||
plugins {
|
||||
@@ -83,8 +89,8 @@ publishing {
|
||||
}
|
||||
|
||||
scm {
|
||||
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
|
||||
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
|
||||
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
|
||||
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
|
||||
url = projectGithubUrl
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 OnixByte
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.math;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Objects;
|
||||
@@ -87,14 +89,12 @@ import java.util.function.Function;
|
||||
* and may have performance implications for extremely large numbers or complex calculations.
|
||||
*
|
||||
* @author sunzsh
|
||||
* @version 1.1.0
|
||||
* @version 3.0.0
|
||||
* @see BigDecimal
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public final class ChainedCalcUtil {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(ChainedCalcUtil.class);
|
||||
|
||||
/**
|
||||
* Creates a {@code ChainedCalcUtil} instance with the specified initial value.
|
||||
*
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 OnixByte
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.math;
|
||||
|
||||
import com.onixbyte.math.model.QuartileBounds;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,30 +32,30 @@ import java.util.List;
|
||||
* <p>
|
||||
* This class contains static methods to:
|
||||
* <ul>
|
||||
* <li>Calculate a specified percentile from a list of double values using linear interpolation.</li>
|
||||
* <li>Calculate interquartile bounds (Q1, Q3) and the corresponding lower and upper bounds,
|
||||
* which can be used to identify outliers in the dataset.</li>
|
||||
* <li>
|
||||
* Calculate a specified percentile from a list of double values using linear interpolation.
|
||||
* </li>
|
||||
* <li>
|
||||
* Calculate interquartile bounds (Q1, Q3) and the corresponding lower and upper bounds,
|
||||
* which can be used to identify outliers in the dataset.
|
||||
* </li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* This class is final, meaning it cannot be subclassed, and it only contains static methods,
|
||||
* so instances of the class cannot be created.
|
||||
* <h2>Example usage:</h2>
|
||||
* <pre>
|
||||
* {@code
|
||||
* <pre>{@code
|
||||
* List<Double> data = Arrays.asList(1.0, 2.0, 3.0, 4.0, 5.0);
|
||||
* Double percentileValue = PercentileCalculator.calculatePercentile(data, 50.0); // Calculates median
|
||||
* QuartileBounds bounds = PercentileCalculator.calculatePercentileBounds(data); // Calculates IQR bounds
|
||||
* }
|
||||
* </pre>
|
||||
* }</pre>
|
||||
*
|
||||
* @author zihluwang
|
||||
* @version 1.6.5
|
||||
* @version 3.0.0
|
||||
* @since 1.6.5
|
||||
*/
|
||||
public final class PercentileCalculator {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(PercentileCalculator.class);
|
||||
|
||||
/**
|
||||
* Private constructor to prevent instantiation of this utility class.
|
||||
*/
|
||||
@@ -100,18 +103,18 @@ public final class PercentileCalculator {
|
||||
*/
|
||||
public static QuartileBounds calculatePercentileBounds(List<Double> data) {
|
||||
var sorted = data.stream().sorted().toList();
|
||||
var Q1 = calculatePercentile(sorted, 25.);
|
||||
var Q3 = calculatePercentile(sorted, 75.);
|
||||
var q1 = calculatePercentile(sorted, 25.);
|
||||
var q3 = calculatePercentile(sorted, 75.);
|
||||
|
||||
var IQR = Q3 - Q1;
|
||||
var iqr = q3 - q1;
|
||||
|
||||
var lowerBound = Q1 - 1.5 * IQR;
|
||||
var upperBound = Q3 + 1.5 * IQR;
|
||||
var lowerBound = q1 - 1.5 * iqr;
|
||||
var upperBound = q3 + 1.5 * iqr;
|
||||
|
||||
return QuartileBounds.builder()
|
||||
.upperBound(upperBound)
|
||||
.lowerBound(lowerBound)
|
||||
.build();
|
||||
.upperBound(upperBound)
|
||||
.lowerBound(lowerBound)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2024-2025 OnixByte.
|
||||
* Copyright (c) 2024-2025 OnixByte
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.onixbyte.math.model;
|
||||
@@ -26,27 +31,31 @@ package com.onixbyte.math.model;
|
||||
* <p>
|
||||
* Quartile bounds consist of:
|
||||
* <ul>
|
||||
* <li>{@code lowerBound} - The lower bound of the dataset, typically {@code Q1 - 1.5 * IQR}.</li>
|
||||
* <li>{@code upperBound} - The upper bound of the dataset, typically {@code Q3 + 1.5 * IQR}.</li>
|
||||
* <li>
|
||||
* {@code lowerBound} - The lower bound of the dataset, typically {@code Q1 - 1.5 * IQR}.
|
||||
* </li>
|
||||
* <li>
|
||||
* {@code upperBound} - The upper bound of the dataset, typically {@code Q3 + 1.5 * IQR}.
|
||||
* </li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Example usage:
|
||||
* <pre>
|
||||
* <pre>{@code
|
||||
* QuartileBounds bounds = QuartileBounds.builder()
|
||||
* .lowerBound(1.5)
|
||||
* .upperBound(7.5)
|
||||
* .build();
|
||||
* </pre>
|
||||
* .lowerBound(1.5)
|
||||
* .upperBound(7.5)
|
||||
* .build();
|
||||
* }</pre>
|
||||
*
|
||||
* @param upperBound the upper bound of the dataset
|
||||
* @param lowerBound the lower bound of the dataset
|
||||
* @author zihluwang
|
||||
* @version 1.6.5
|
||||
* @version 3.0.0
|
||||
* @since 1.6.5
|
||||
*/
|
||||
public record QuartileBounds(
|
||||
Double upperBound,
|
||||
Double lowerBound
|
||||
Double upperBound,
|
||||
Double lowerBound
|
||||
) {
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,26 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2024-2024 OnixByte.
|
||||
~ Copyright (c) 2024-2025 OnixByte
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
~ of this software and associated documentation files (the "Software"), to deal
|
||||
~ in the Software without restriction, including without limitation the rights
|
||||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
~ copies of the Software, and to permit persons to whom the Software is
|
||||
~ furnished to do so, subject to the following conditions:
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~ The above copyright notice and this permission notice shall be included in all
|
||||
~ copies or substantial portions of the Software.
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
~ SOFTWARE.
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
<property name="COLOURFUL_OUTPUT" value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
|
||||
<property name="STANDARD_OUTPUT" value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
|
||||
<property name="COLOURFUL_OUTPUT"
|
||||
value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
|
||||
<property name="STANDARD_OUTPUT"
|
||||
value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
|
||||
|
||||
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
|
||||
<statusListener class="ch.qos.logback.core.status.NopStatusListener"/>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<pattern>${COLOURFUL_OUTPUT}</pattern>
|
||||
@@ -29,4 +36,4 @@
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user