Compare commits

..

No commits in common. "fc0393436f1e9698370099b0e9d03fc53ceb85cf" and "2fe04040c6316912969eeef5cbfe1ca799aef736" have entirely different histories.

13 changed files with 108 additions and 94 deletions

View File

@ -6,7 +6,7 @@ plugins {
id("org.jetbrains.kotlinx.kover") version "0.7.6"
}
val attributesVersion by extra("0.2.0")
val attributesVersion by extra("0.1.0")
allprojects {
repositories {

View File

@ -17,4 +17,4 @@ own `MemoryBuffer.create()` factory).
## Buffer performance
One should avoid using default boxing buffer wherever it is possible. Try to use primitive buffers or memory buffers
instead.
instead .

View File

@ -68,9 +68,6 @@ public operator fun ShapeND.component3(): Int = get(2)
*/
public fun ShapeND.toArray(): IntArray = array.copyOf()
/**
* Provide internal content of [ShapeND]. Must not be modified.
*/
@UnsafeKMathAPI
public fun ShapeND.asArray(): IntArray = array

View File

@ -19,7 +19,7 @@ import space.kscience.kmath.structures.indices
* [GaussLegendreRuleFactory].
* * [IntegrationRange]—the univariate range of integration. By default, uses `0..1` interval.
* * [IntegrandMaxCalls]—the maximum number of function calls during integration. For non-iterative rules, always
* use the maximum number of points. By default, uses 10 points.
* use the maximum number of points. By default, uses 10 points.
* * [UnivariateIntegrandRanges]—set of ranges and number of points per range. Defaults to given
* [IntegrationRange] and [IntegrandMaxCalls].
*/

View File

@ -38,9 +38,9 @@ class MinuitParameter {
* @param name a [String] object.
* @param val a double.
*/
constructor(num: Int, name: String, value: Double) {
constructor(num: Int, name: String, `val`: Double) {
theNum = num
theValue = value
theValue = `val`
theConst = true
theName = name
}
@ -53,9 +53,9 @@ class MinuitParameter {
* @param val a double.
* @param err a double.
*/
constructor(num: Int, name: String, value: Double, err: Double) {
constructor(num: Int, name: String, `val`: Double, err: Double) {
theNum = num
theValue = value
theValue = `val`
theError = err
theName = name
}
@ -70,9 +70,9 @@ class MinuitParameter {
* @param min a double.
* @param max a double.
*/
constructor(num: Int, name: String, value: Double, err: Double, min: Double, max: Double) {
constructor(num: Int, name: String, `val`: Double, err: Double, min: Double, max: Double) {
theNum = num
theValue = value
theValue = `val`
theError = err
theLoLimit = min
theUpLimit = max
@ -288,8 +288,8 @@ class MinuitParameter {
*
* @param val a double.
*/
fun setValue(value: Double) {
theValue = value
fun setValue(`val`: Double) {
theValue = `val`
}
/**

View File

@ -77,8 +77,8 @@ abstract class MnApplication {
* @param val a double.
* @param name a [String] object.
*/
fun add(name: String, value: Double, err: Double) {
theState.add(name, value, err)
fun add(name: String, `val`: Double, err: Double) {
theState.add(name, `val`, err)
}
/**
@ -90,8 +90,8 @@ abstract class MnApplication {
* @param val a double.
* @param err a double.
*/
fun add(name: String, value: Double, err: Double, low: Double, up: Double) {
theState.add(name, value, err, low, up)
fun add(name: String, `val`: Double, err: Double, low: Double, up: Double) {
theState.add(name, `val`, err, low, up)
}
/**
@ -100,8 +100,8 @@ abstract class MnApplication {
* @param name a [String] object.
* @param val a double.
*/
fun add(name: String, value: Double) {
theState.add(name, value)
fun add(name: String, `val`: Double) {
theState.add(name, `val`)
}
/**
@ -471,8 +471,8 @@ abstract class MnApplication {
* @param index a int.
* @param val a double.
*/
fun setValue(index: Int, value: Double) {
theState.setValue(index, value)
fun setValue(index: Int, `val`: Double) {
theState.setValue(index, `val`)
}
/**
@ -482,8 +482,8 @@ abstract class MnApplication {
* @param name a [String] object.
* @param val a double.
*/
fun setValue(name: String?, value: Double) {
theState.setValue(name, value)
fun setValue(name: String?, `val`: Double) {
theState.setValue(name, `val`)
}
/**

View File

@ -106,8 +106,8 @@ class MnMinos(fcn: MultiFunction?, min: FunctionMinimum?, stra: MnStrategy?) {
val para = intArrayOf(par)
val upar: MnUserParameterState = theMinimum!!.userState().copy()
val err: Double = upar.error(par)
val value: Double = upar.value(par) - err
val xmid = doubleArrayOf(value)
val `val`: Double = upar.value(par) - err
val xmid = doubleArrayOf(`val`)
val xdir = doubleArrayOf(-err)
val ind: Int = upar.intOfExt(par)
val m: MnAlgebraicSymMatrix = theMinimum!!.error().matrix()
@ -121,7 +121,7 @@ class MnMinos(fcn: MultiFunction?, min: FunctionMinimum?, stra: MnStrategy?) {
upar.setValue(ext, upar.value(ext) - xdev)
}
upar.fix(par)
upar.setValue(par, value)
upar.setValue(par, `val`)
val toler = 0.1
val cross = MnFunctionCross(theFCN, upar, theMinimum!!.fval(), theStrategy, errDef)
val aopt: MnCross = cross.cross(para, xmid, xdir, toler, maxcalls)
@ -330,8 +330,8 @@ class MnMinos(fcn: MultiFunction?, min: FunctionMinimum?, stra: MnStrategy?) {
val para = intArrayOf(par)
val upar: MnUserParameterState = theMinimum!!.userState().copy()
val err: Double = upar.error(par)
val value: Double = upar.value(par) + err
val xmid = doubleArrayOf(value)
val `val`: Double = upar.value(par) + err
val xmid = doubleArrayOf(`val`)
val xdir = doubleArrayOf(err)
val ind: Int = upar.intOfExt(par)
val m: MnAlgebraicSymMatrix = theMinimum!!.error().matrix()
@ -345,7 +345,7 @@ class MnMinos(fcn: MultiFunction?, min: FunctionMinimum?, stra: MnStrategy?) {
upar.setValue(ext, upar.value(ext) + xdev)
}
upar.fix(par)
upar.setValue(par, value)
upar.setValue(par, `val`)
val toler = 0.1
val cross = MnFunctionCross(theFCN, upar, theMinimum!!.fval(), theStrategy, errDef)
val aopt: MnCross = cross.cross(para, xmid, xdir, toler, maxcalls)

View File

@ -52,9 +52,17 @@ internal class MnSeedGenerator : MinimumSeedGenerator {
val delta: Double = hgrd.getSecond().getEntry(i)
if (abs(calculated - provided) > delta) {
MINUITPlugin.logStatic(
"""gradient discrepancy of external parameter "%d" (internal parameter "%d") too large. Expected: "%f", provided: "%f"""",
""
+ "gradient discrepancy of external parameter \"%d\" "
+ "(internal parameter \"%d\") too large. Expected: \"%f\", provided: \"%f\"",
st.getTransformation().extOfInt(i), i, provided, calculated
)
//
// MINUITPlugin.logStatic("gradient discrepancy of external parameter "
// + st.getTransformation().extOfInt(i)
// + " (internal parameter " + i + ") too large.");
// good = false;
}
}
if (!good) {
@ -76,7 +84,10 @@ internal class MnSeedGenerator : MinimumSeedGenerator {
dcovar = 0.0
} else {
for (i in 0 until n) {
mat[i, i] = if (abs(dgrad.getGradientDerivative().getEntry(i)) > prec.eps2()
mat[i, i] = if (abs(
dgrad.getGradientDerivative()
.getEntry(i)
) > prec.eps2()
) 1.0 / dgrad.getGradientDerivative().getEntry(i) else 1.0
}
}

View File

@ -235,9 +235,9 @@ class MnUserParameterState {
* @param val a double.
* @param name a [String] object.
*/
fun add(name: String, value: Double, err: Double) {
theParameters.add(name, value, err)
theIntParameters.add(value)
fun add(name: String, `val`: Double, err: Double) {
theParameters.add(name, `val`, err)
theIntParameters.add(`val`)
theCovarianceValid = false
theGCCValid = false
theValid = true
@ -252,10 +252,10 @@ class MnUserParameterState {
* @param err a double.
* @param up a double.
*/
fun add(name: String, value: Double, err: Double, low: Double, up: Double) {
theParameters.add(name, value, err, low, up)
fun add(name: String, `val`: Double, err: Double, low: Double, up: Double) {
theParameters.add(name, `val`, err, low, up)
theCovarianceValid = false
theIntParameters.add(ext2int(index(name), value))
theIntParameters.add(ext2int(index(name), `val`))
theGCCValid = false
theValid = true
}
@ -266,8 +266,8 @@ class MnUserParameterState {
* @param name a [String] object.
* @param val a double.
*/
fun add(name: String, value: Double) {
theParameters.add(name, value)
fun add(name: String, `val`: Double) {
theParameters.add(name, `val`)
theValid = true
}
@ -331,8 +331,8 @@ class MnUserParameterState {
return theParameters.errors()
}
fun ext2int(i: Int, value: Double): Double {
return theParameters.trafo().ext2int(i, value)
fun ext2int(i: Int, `val`: Double): Double {
return theParameters.trafo().ext2int(i, `val`)
}
/**
@ -426,8 +426,8 @@ class MnUserParameterState {
}
// transformation internal <-> external
fun int2ext(i: Int, value: Double): Double {
return theParameters.trafo().int2ext(i, value)
fun int2ext(i: Int, `val`: Double): Double {
return theParameters.trafo().int2ext(i, `val`)
}
fun intCovariance(): MnUserCovariance {
@ -700,14 +700,14 @@ class MnUserParameterState {
* @param e a int.
* @param val a double.
*/
fun setValue(e: Int, value: Double) {
theParameters.setValue(e, value)
fun setValue(e: Int, `val`: Double) {
theParameters.setValue(e, `val`)
if (!parameter(e).isFixed() && !parameter(e).isConst()) {
val i = intOfExt(e)
if (parameter(e).hasLimits()) {
theIntParameters[i] = ext2int(e, value)
theIntParameters[i] = ext2int(e, `val`)
} else {
theIntParameters[i] = value
theIntParameters[i] = `val`
}
}
}
@ -719,8 +719,8 @@ class MnUserParameterState {
* @param name a [String] object.
* @param val a double.
*/
fun setValue(name: String?, value: Double) {
setValue(index(name), value)
fun setValue(name: String?, `val`: Double) {
setValue(index(name), `val`)
}
/** {@inheritDoc} */

View File

@ -65,8 +65,8 @@ class MnUserParameters {
* @param val a double.
* @param name a [String] object.
*/
fun add(name: String, value: Double, err: Double) {
theTransformation.add(name, value, err)
fun add(name: String, `val`: Double, err: Double) {
theTransformation.add(name, `val`, err)
}
/**
@ -78,8 +78,8 @@ class MnUserParameters {
* @param val a double.
* @param err a double.
*/
fun add(name: String, value: Double, err: Double, low: Double, up: Double) {
theTransformation.add(name, value, err, low, up)
fun add(name: String, `val`: Double, err: Double, low: Double, up: Double) {
theTransformation.add(name, `val`, err, low, up)
}
/**
@ -88,8 +88,8 @@ class MnUserParameters {
* @param name a [String] object.
* @param val a double.
*/
fun add(name: String, value: Double) {
theTransformation.add(name, value)
fun add(name: String, `val`: Double) {
theTransformation.add(name, `val`)
}
/**
@ -344,8 +344,8 @@ class MnUserParameters {
* @param index a int.
* @param val a double.
*/
fun setValue(index: Int, value: Double) {
theTransformation.setValue(index, value)
fun setValue(index: Int, `val`: Double) {
theTransformation.setValue(index, `val`)
}
/**
@ -355,8 +355,8 @@ class MnUserParameters {
* @param name a [String] object.
* @param val a double.
*/
fun setValue(name: String?, value: Double) {
theTransformation.setValue(name, value)
fun setValue(name: String?, `val`: Double) {
theTransformation.setValue(name, `val`)
}
/** {@inheritDoc} */

View File

@ -64,12 +64,12 @@ class MnUserTransformation {
* @param err
* @param val
*/
fun add(name: String, value: Double, err: Double) {
fun add(name: String, `val`: Double, err: Double) {
require(!nameMap.containsKey(name)) { "duplicate name: $name" }
nameMap[name] = theParameters.size
theExtOfInt.add(theParameters.size)
theCache.add(value)
theParameters.add(MinuitParameter(theParameters.size, name, value, err))
theCache.add(`val`)
theParameters.add(MinuitParameter(theParameters.size, name, `val`, err))
}
/**
@ -77,12 +77,12 @@ class MnUserTransformation {
* @param up
* @param low
*/
fun add(name: String, value: Double, err: Double, low: Double, up: Double) {
fun add(name: String, `val`: Double, err: Double, low: Double, up: Double) {
require(!nameMap.containsKey(name)) { "duplicate name: $name" }
nameMap[name] = theParameters.size
theExtOfInt.add(theParameters.size)
theCache.add(value)
theParameters.add(MinuitParameter(theParameters.size, name, value, err, low, up))
theCache.add(`val`)
theParameters.add(MinuitParameter(theParameters.size, name, `val`, err, low, up))
}
/**
@ -90,11 +90,11 @@ class MnUserTransformation {
* @param name
* @param val
*/
fun add(name: String, value: Double) {
fun add(name: String, `val`: Double) {
require(!nameMap.containsKey(name)) { "duplicate name: $name" }
nameMap[name] = theParameters.size
theCache.add(value)
theParameters.add(MinuitParameter(theParameters.size, name, value))
theCache.add(`val`)
theParameters.add(MinuitParameter(theParameters.size, name, `val`))
}
/**
@ -107,20 +107,20 @@ class MnUserTransformation {
return MnUserTransformation(this)
}
fun dInt2Ext(i: Int, value: Double): Double {
fun dInt2Ext(i: Int, `val`: Double): Double {
var dd = 1.0
val parm: MinuitParameter = theParameters[theExtOfInt[i]]
if (parm.hasLimits()) {
dd = if (parm.hasUpperLimit() && parm.hasLowerLimit()) {
theDoubleLimTrafo.dInt2Ext(
value,
`val`,
parm.upperLimit(),
parm.lowerLimit()
)
} else if (parm.hasUpperLimit() && !parm.hasLowerLimit()) {
theUpperLimTrafo.dInt2Ext(value, parm.upperLimit())
theUpperLimTrafo.dInt2Ext(`val`, parm.upperLimit())
} else {
theLowerLimTrafo.dInt2Ext(value, parm.lowerLimit())
theLowerLimTrafo.dInt2Ext(`val`, parm.lowerLimit())
}
}
return dd
@ -143,30 +143,30 @@ class MnUserTransformation {
return result
}
fun ext2int(i: Int, value: Double): Double {
fun ext2int(i: Int, `val`: Double): Double {
val parm: MinuitParameter = theParameters[i]
return if (parm.hasLimits()) {
if (parm.hasUpperLimit() && parm.hasLowerLimit()) {
theDoubleLimTrafo.ext2int(
value,
`val`,
parm.upperLimit(),
parm.lowerLimit(),
precision()
)
} else if (parm.hasUpperLimit() && !parm.hasLowerLimit()) {
theUpperLimTrafo.ext2int(
value,
`val`,
parm.upperLimit(),
precision()
)
} else {
theLowerLimTrafo.ext2int(
value,
`val`,
parm.lowerLimit(),
precision()
)
}
} else value
} else `val`
}
fun extOfInt(internal: Int): Int {
@ -200,21 +200,21 @@ class MnUserTransformation {
return nameMap[name]!!
}
fun int2ext(i: Int, value: Double): Double {
fun int2ext(i: Int, `val`: Double): Double {
val parm: MinuitParameter = theParameters[theExtOfInt[i]]
return if (parm.hasLimits()) {
if (parm.hasUpperLimit() && parm.hasLowerLimit()) {
theDoubleLimTrafo.int2ext(
value,
`val`,
parm.upperLimit(),
parm.lowerLimit()
)
} else if (parm.hasUpperLimit() && !parm.hasLowerLimit()) {
theUpperLimTrafo.int2ext(value, parm.upperLimit())
theUpperLimTrafo.int2ext(`val`, parm.upperLimit())
} else {
theLowerLimTrafo.int2ext(value, parm.lowerLimit())
theLowerLimTrafo.int2ext(`val`, parm.lowerLimit())
}
} else value
} else `val`
}
fun int2extCovariance(vec: RealVector, cov: MnAlgebraicSymMatrix): MnUserCovariance {
@ -235,13 +235,13 @@ class MnUserTransformation {
return result
}
fun int2extError(i: Int, value: Double, err: Double): Double {
fun int2extError(i: Int, `val`: Double, err: Double): Double {
var dx = err
val parm: MinuitParameter = theParameters[theExtOfInt[i]]
if (parm.hasLimits()) {
val ui = int2ext(i, value)
var du1 = int2ext(i, value + dx) - ui
val du2 = int2ext(i, value - dx) - ui
val ui = int2ext(i, `val`)
var du1 = int2ext(i, `val` + dx) - ui
val du2 = int2ext(i, `val` - dx) - ui
if (parm.hasUpperLimit() && parm.hasLowerLimit()) {
if (dx > 1.0) {
du1 = parm.upperLimit() - parm.lowerLimit()
@ -354,13 +354,13 @@ class MnUserTransformation {
setUpperLimit(index(name), up)
}
fun setValue(index: Int, value: Double) {
theParameters[index].setValue(value)
theCache[index] = value
fun setValue(index: Int, `val`: Double) {
theParameters[index].setValue(`val`)
theCache[index] = `val`
}
fun setValue(name: String?, value: Double) {
setValue(index(name), value)
fun setValue(name: String?, `val`: Double) {
setValue(index(name), `val`)
}
fun transform(pstates: RealVector): ArrayRealVector {

View File

@ -71,7 +71,10 @@ internal object NegativeG2LineSearch {
} while (iter++ < 2 * n && iterate)
val mat = MnAlgebraicSymMatrix(n)
for (i in 0 until n) {
mat[i, i] = if (abs(dgrad.getGradientDerivative().getEntry(i)) > prec.eps2()
mat[i, i] = if (abs(
dgrad.getGradientDerivative()
.getEntry(i)
) > prec.eps2()
) 1.0 / dgrad.getGradientDerivative().getEntry(i) else 1.0
}
val err = MinimumError(mat, 1.0)

View File

@ -41,7 +41,10 @@ internal class SimplexSeedGenerator : MinimumSeedGenerator {
val mat = MnAlgebraicSymMatrix(n)
val dcovar = 1.0
for (i in 0 until n) {
mat[i, i] = if (abs(dgrad.getGradientDerivative().getEntry(i)) > prec.eps2()
mat[i, i] = if (abs(
dgrad.getGradientDerivative()
.getEntry(i)
) > prec.eps2()
) 1.0 / dgrad.getGradientDerivative().getEntry(i) else 1.0
}
val err = MinimumError(mat, dcovar)