optimization

This commit is contained in:
Sabina 2023-10-03 14:58:16 +03:00
parent 5fcff41db6
commit f67157b953
2 changed files with 40 additions and 26 deletions

View File

@ -20,7 +20,7 @@ import kotlin.math.*
* @author [Alexander Nozik](mailto:altavir@gmail.com) * @author [Alexander Nozik](mailto:altavir@gmail.com)
*/ */
public class NumassTransmission( public class NumassTransmission(
public val trapFunc: Kernel = defaultTrapping, public val trapFunc: Kernel = trapFunction,
// private val adjustX: Boolean = false, // private val adjustX: Boolean = false,
) : DifferentiableKernel { ) : DifferentiableKernel {
// private val trapFunc: Kernel = if (meta.hasValue("trapping")) { // private val trapFunc: Kernel = if (meta.hasValue("trapping")) {
@ -80,8 +80,8 @@ public class NumassTransmission(
//trapping part //trapping part
// //
//val trap = (arguments[trap] ?: 1.0) * trapFunc(ei, ef, arguments) val trap = (arguments[trap] ?: 1.0) * trapFunc(ei, ef, arguments)
val trap = 0.0 //val trap = 0.0
return loss + trap return loss + trap
} }
@ -136,6 +136,7 @@ public class NumassTransmission(
} }
private fun getCachedSpectrum(order: Int): Function1D<Double> { private fun getCachedSpectrum(order: Int): Function1D<Double> {
//println("-------------------ORDER $order ------------------------")
return when { return when {
order <= 0 -> error("Non-positive loss cache order") order <= 0 -> error("Non-positive loss cache order")
order == 1 -> singleScatterFunction order == 1 -> singleScatterFunction

View File

@ -27,8 +27,8 @@ fun parse(filename: String): XYErrorColumnarData<Double, Double, Double> {
val array = it.split("\t").map { it.toDouble() } val array = it.split("\t").map { it.toDouble() }
x.add(array[0]) x.add(array[0])
y.add(array[1]) y.add(array[1])
//errors.add(array[2]) errors.add(array[2])
errors.add(1.0) //errors.add(array[1] / 100)
} }
return XYErrorColumnarData.of( return XYErrorColumnarData.of(
x.asBuffer(), x.asBuffer(),
@ -41,16 +41,16 @@ fun parse(filename: String): XYErrorColumnarData<Double, Double, Double> {
suspend fun main() { suspend fun main() {
val spectrum: NBkgSpectrum = SterileNeutrinoSpectrum( val spectrum: NBkgSpectrum = SterileNeutrinoSpectrum(
// fss = FSS.default, // fss = FSS.default,
transmission = NumassTransmission(NumassTransmission.trapFunction), transmission = NumassTransmission(NumassTransmission.trapFunction),
resolution = NumassResolution(1.7e-4) // resolution = NumassResolution(1.7e-4)
).withNBkg() ).withNBkg()
val args: Map<Symbol, Double> = mapOf( val args: Map<Symbol, Double> = mapOf(
NBkgSpectrum.norm to 319034.0, NBkgSpectrum.norm to 8.84e8,
NBkgSpectrum.bkg to 0.029, NBkgSpectrum.bkg to -1.702,
NumassBeta.mnu2 to 0.0, NumassBeta.mnu2 to 0.0,
NumassBeta.e0 to 18575.0, NumassBeta.e0 to 18572.0,
NumassBeta.msterile2 to 1000.0.pow(2), NumassBeta.msterile2 to 0.0.pow(2),
NumassBeta.u2 to 1e-2, NumassBeta.u2 to 1e-2,
NumassTransmission.thickness to 0.3, NumassTransmission.thickness to 0.3,
NumassTransmission.trap to 1.0 NumassTransmission.trap to 1.0
@ -64,40 +64,41 @@ suspend fun main() {
// //
// val strategy = (12000.0..19000.0 step 100.0).asSequence().associateWith { timePerPoint } // val strategy = (12000.0..19000.0 step 100.0).asSequence().associateWith { timePerPoint }
val data = parse("/home/sabina/Numass/Fit/tr5wobkg") val data = parse("/home/sabina/Numass/Fit/Data/03.10.2023")
//val fit: XYFit = data.fitWith( val fit: XYFit = data.fitWith(
// optimizer = QowOptimizer, optimizer = QowOptimizer,
// modelExpression = spectrum, modelExpression = spectrum,
// startingPoint = args, startingPoint = args,
// OptimizationParameters(NBkgSpectrum.norm, NBkgSpectrum.bkg), OptimizationParameters(NumassBeta.e0, NBkgSpectrum.norm, NBkgSpectrum.bkg),
// OptimizationIterations(20) OptimizationIterations(20)
//) )
//println("Chi squared/dof: ${fit.chiSquaredOrNull}/${fit.dof}") //println("Chi squared/dof: ${fit.chiSquaredOrNull}/${fit.dof}")
Plotly.page { Plotly.page {
plot { plot {
/* scatter {
scatter {
name = "Data" name = "Data"
mode = ScatterMode.markers mode = ScatterMode.markers
x.buffer = data.x x.buffer = data.x
y.buffer = data.y y.buffer = data.y
}*/ }
scatter { scatter {
name = "Initial" name = "Initial"
mode = ScatterMode.lines mode = ScatterMode.lines
x.buffer = 12000.0..18600.0 step 50.0 x.buffer = 12000.0..18600.0 step 50.0
y.numbers = x.doubles.map { spectrum(it, args) } y.numbers = x.doubles.map { spectrum(it, args + fit.resultPoint) }
File("/home/sabina/Numass/Fit/output").printWriter().use { out -> File("/home/sabina/Numass/Fit/trap1").printWriter().use { out ->
y.numbers.forEach { y.numbers.forEach {
out.println(it) out.println(it)
} }
} }
} }
} scatter {
/* scatter {
name = "Fit" name = "Fit"
mode = ScatterMode.lines mode = ScatterMode.lines
x.buffer = 12000.0..18600.0 step 10.0 x.buffer = 12000.0..18600.0 step 10.0
@ -125,6 +126,18 @@ suspend fun main() {
} }
name = "Res histo" name = "Res histo"
} }
}*/ }
plot {
scatter {
name = "Residuals_lines"
mode = ScatterMode.lines
x.buffer = data.x
y.numbers = data.indices.map {
val value = spectrum(data.x[it], args + fit.resultPoint)
val dif = data.y[it] - value
dif / data.yErr[it]
}
}
}
}.makeFile() }.makeFile()
} }