diff --git a/.space.kts b/.space.kts index c9500e967..e4d7522e3 100644 --- a/.space.kts +++ b/.space.kts @@ -1,3 +1,3 @@ -job("Build") { - gradlew("openjdk:11", "build") +job("Build and run tests") { + gradlew("amazoncorretto:17-alpine", "build") } \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index ec67eaa54..40ae9f210 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ allprojects { } group = "space.kscience" - version = "0.3.1-dev-RC" + version = "0.3.1" } subprojects { diff --git a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt index 8ad7f7293..c56583fa8 100644 --- a/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt +++ b/kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt @@ -19,9 +19,9 @@ import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC +import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.linear.* import space.kscience.kmath.linear.Matrix -import space.kscience.kmath.UnstableKMathAPI import space.kscience.kmath.nd.StructureFeature import space.kscience.kmath.operations.DoubleField import space.kscience.kmath.operations.FloatField diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt index ca3537005..ae814254b 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/NormalDistribution.kt @@ -6,6 +6,7 @@ package space.kscience.kmath.distributions import space.kscience.kmath.chains.Chain +import space.kscience.kmath.operations.DoubleField.pow import space.kscience.kmath.random.RandomGenerator import space.kscience.kmath.samplers.GaussianSampler import space.kscience.kmath.samplers.InternalErf @@ -34,8 +35,23 @@ public class NormalDistribution(public val sampler: GaussianSampler) : Distribut } } - private companion object { + public companion object { private val SQRT2 = sqrt(2.0) + + /** + * Zelen & Severo approximation for the standard normal CDF. + * The error upper boundary by 7.5 * 10e-8. + */ + public fun zSNormalCDF(x: Double): Double { + val t = 1 / (1 + 0.2316419 * abs(x)) + val sum = 0.319381530 * t - + 0.356563782 * t.pow(2) + + 1.781477937 * t.pow(3) - + 1.821255978 * t.pow(4) + + 1.330274429 * t.pow(5) + val temp = sum * exp(-abs(x).pow(2) / 2) / (2 * PI).pow(0.5) + return if (x >= 0) 1 - temp else temp + } } } diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/zSNormalCdf.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/zSNormalCdf.kt deleted file mode 100644 index adfbbc9cd..000000000 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/distributions/zSNormalCdf.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2018-2023 KMath contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package space.kscience.kmath.distributions - -import space.kscience.kmath.operations.DoubleField.pow -import kotlin.math.PI -import kotlin.math.absoluteValue -import kotlin.math.exp - - -/** - * Zelen & Severo approximation for the standard normal CDF. - * The error is bounded by 7.5 * 10e-8. - * */ -public fun zSNormalCDF(x: Double): Double { - - val t = 1 / (1 + 0.2316419 * x.absoluteValue) - val summ = 0.319381530*t - 0.356563782*t.pow(2) + 1.781477937*t.pow(3) - 1.821255978*t.pow(4) + 1.330274429*t.pow(5) - val temp = summ * exp(-x.absoluteValue.pow(2) / 2) / (2 * PI).pow(0.5) - return if (x >= 0) 1 - temp else temp -} \ No newline at end of file diff --git a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/VarianceRatioTest.kt b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/VarianceRatioTest.kt index 6a2f5e426..4becb3413 100644 --- a/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/VarianceRatioTest.kt +++ b/kmath-stat/src/commonMain/kotlin/space/kscience/kmath/series/VarianceRatioTest.kt @@ -5,7 +5,7 @@ package space.kscience.kmath.series -import space.kscience.kmath.distributions.zSNormalCDF +import space.kscience.kmath.distributions.NormalDistribution import space.kscience.kmath.operations.DoubleField.pow import space.kscience.kmath.operations.fold import kotlin.math.absoluteValue @@ -14,8 +14,12 @@ import kotlin.math.absoluteValue /** * Container class for Variance Ratio Test result: * ratio itself, corresponding Z-score, also it's p-value - * **/ -public data class VarianceRatioTestResult(val varianceRatio: Double=1.0, val zScore: Double=0.0, val pValue: Double=0.5) + */ +public data class VarianceRatioTestResult( + val varianceRatio: Double = 1.0, + val zScore: Double = 0.0, + val pValue: Double = 0.5, +) /** @@ -23,11 +27,17 @@ public data class VarianceRatioTestResult(val varianceRatio: Double=1.0, val zSc * under Homoscedastic or Heteroscedstic assumptions * with two-sided p-value test * https://ssrn.com/abstract=346975 - * **/ -public fun SeriesAlgebra.varianceRatioTest(series: Series, shift: Int, homoscedastic: Boolean=true): VarianceRatioTestResult { + * + * @author https://github.com/mrFendel + */ +public fun SeriesAlgebra.varianceRatioTest( + series: Series, + shift: Int, + homoscedastic: Boolean = true, +): VarianceRatioTestResult { - require(shift > 1) {"Shift must be greater than one"} - require(shift < series.size) {"Shift must be smaller than sample size"} + require(shift > 1) { "Shift must be greater than one" } + require(shift < series.size) { "Shift must be smaller than sample size" } val sum = { x: Double, y: Double -> x + y } @@ -46,7 +56,7 @@ public fun SeriesAlgebra.varianceRatioTest(series: Series.varianceRatioTest(series: Series