forked from NPM/numass-framework
Update coroutines version
This commit is contained in:
parent
50802232c3
commit
65c83f3524
@ -2,7 +2,7 @@ description = 'dataforge-core'
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'ch.qos.logback:logback-classic:1.2.3'
|
compile 'ch.qos.logback:logback-classic:1.2.3'
|
||||||
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.2'
|
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.5.0'
|
||||||
compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_version
|
compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlin_version
|
||||||
compile group: 'javax.cache', name: 'cache-api', version: '1.1.0'
|
compile group: 'javax.cache', name: 'cache-api', version: '1.1.0'
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,10 @@ dependencies {
|
|||||||
compile project(':dataforge-plots')
|
compile project(':dataforge-plots')
|
||||||
compile project(':dataforge-gui:dataforge-html')
|
compile project(':dataforge-gui:dataforge-html')
|
||||||
compile 'org.controlsfx:controlsfx:8.40.14'
|
compile 'org.controlsfx:controlsfx:8.40.14'
|
||||||
compile "no.tornado:tornadofx:1.7.17"
|
compile "no.tornado:tornadofx:1.7.19"
|
||||||
compile 'no.tornado:tornadofx-controlsfx:0.1.1'
|
compile 'no.tornado:tornadofx-controlsfx:0.1.1'
|
||||||
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.2'
|
compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.10.2'
|
||||||
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-javafx:1.0.1'
|
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-javafx:1.5.0'
|
||||||
|
|
||||||
// optional dependency for JFreeChart
|
// optional dependency for JFreeChart
|
||||||
//compileOnly project(":dataforge-plots:plots-jfc")
|
//compileOnly project(":dataforge-plots:plots-jfc")
|
||||||
|
@ -16,10 +16,9 @@
|
|||||||
|
|
||||||
package hep.dataforge.maths.chain
|
package hep.dataforge.maths.chain
|
||||||
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.channels.ReceiveChannel
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.channels.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.channels.produce
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
@ -48,8 +47,7 @@ interface Chain<out R> : Sequence<R> {
|
|||||||
/**
|
/**
|
||||||
* Chain as a coroutine receive channel
|
* Chain as a coroutine receive channel
|
||||||
*/
|
*/
|
||||||
val channel: ReceiveChannel<R>
|
val flow: Flow<R> get() = flow { while (true) emit(next()) }
|
||||||
get() = GlobalScope.produce { while (true) send(next()) }
|
|
||||||
|
|
||||||
override fun iterator(): Iterator<R> {
|
override fun iterator(): Iterator<R> {
|
||||||
return object : Iterator<R> {
|
return object : Iterator<R> {
|
||||||
@ -77,10 +75,7 @@ interface Chain<out R> : Sequence<R> {
|
|||||||
return parent.fork().map(func)
|
return parent.fork().map(func)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val channel: ReceiveChannel<T>
|
override val flow: Flow<T> get() = parent.flow.map { func.invoke(it) }
|
||||||
get() {
|
|
||||||
return parent.channel.map { func.invoke(it) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@ package hep.dataforge.stat
|
|||||||
|
|
||||||
import hep.dataforge.maths.chain.Chain
|
import hep.dataforge.maths.chain.Chain
|
||||||
import hep.dataforge.maths.chain.SimpleChain
|
import hep.dataforge.maths.chain.SimpleChain
|
||||||
import kotlinx.coroutines.channels.dropWhile
|
import kotlinx.coroutines.flow.dropWhile
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
import org.apache.commons.math3.distribution.MultivariateRealDistribution
|
import org.apache.commons.math3.distribution.MultivariateRealDistribution
|
||||||
import org.apache.commons.math3.distribution.RealDistribution
|
import org.apache.commons.math3.distribution.RealDistribution
|
||||||
import org.apache.commons.math3.random.RandomGenerator
|
import org.apache.commons.math3.random.RandomGenerator
|
||||||
@ -44,10 +45,11 @@ fun <T : Any> rejectingChain(
|
|||||||
proposalDensity: (T) -> Double,
|
proposalDensity: (T) -> Double,
|
||||||
factor: Double = 1.0,
|
factor: Double = 1.0,
|
||||||
generator: RandomGenerator = defaultGenerator,
|
generator: RandomGenerator = defaultGenerator,
|
||||||
targetDensity: (T) -> Double): Chain<T> {
|
targetDensity: (T) -> Double,
|
||||||
|
): Chain<T> {
|
||||||
return SimpleChain {
|
return SimpleChain {
|
||||||
//TODO check if target density higher than proposal density?
|
//TODO check if target density higher than proposal density?
|
||||||
proposal.channel.dropWhile { generator.nextDouble() < targetDensity(it) / proposalDensity(it) / factor }.receive()
|
proposal.flow.dropWhile { generator.nextDouble() < targetDensity(it) / proposalDensity(it) / factor }.first()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +59,7 @@ fun <T : Any> rejectingChain(
|
|||||||
fun RealDistribution.rejectingChain(
|
fun RealDistribution.rejectingChain(
|
||||||
factor: Double = 1.0,
|
factor: Double = 1.0,
|
||||||
generator: RandomGenerator = defaultGenerator,
|
generator: RandomGenerator = defaultGenerator,
|
||||||
targetDensity: (Double) -> Double): Chain<Double> {
|
targetDensity: (Double) -> Double,
|
||||||
|
): Chain<Double> {
|
||||||
return rejectingChain(this.chain, this::density, factor, generator, targetDensity)
|
return rejectingChain(this.chain, this::density, factor, generator, targetDensity)
|
||||||
}
|
}
|
@ -18,6 +18,7 @@ package inr.numass.scripts.models
|
|||||||
|
|
||||||
import hep.dataforge.buildContext
|
import hep.dataforge.buildContext
|
||||||
import hep.dataforge.configure
|
import hep.dataforge.configure
|
||||||
|
import hep.dataforge.fx.FXPlugin
|
||||||
import hep.dataforge.fx.output.FXOutputManager
|
import hep.dataforge.fx.output.FXOutputManager
|
||||||
import hep.dataforge.io.output.stream
|
import hep.dataforge.io.output.stream
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
@ -39,6 +40,7 @@ import inr.numass.data.SpectrumGenerator
|
|||||||
import inr.numass.models.NBkgSpectrum
|
import inr.numass.models.NBkgSpectrum
|
||||||
import inr.numass.models.sterile.SterileNeutrinoSpectrum
|
import inr.numass.models.sterile.SterileNeutrinoSpectrum
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.javafx.JavaFx
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
@ -46,7 +48,7 @@ import kotlin.math.sqrt
|
|||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
|
|
||||||
val context = buildContext("NUMASS", NumassPlugin::class.java, JFreeChartPlugin::class.java) {
|
val context = buildContext("NUMASS", NumassPlugin::class.java, FXPlugin::class.java, JFreeChartPlugin::class.java) {
|
||||||
output = FXOutputManager()
|
output = FXOutputManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,9 +73,9 @@ fun main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(14000.0..18600.0 step 10.0).forEach {
|
// (14000.0..18600.0 step 10.0).forEach {
|
||||||
println("$it\t${spectrum.value(it,params)}")
|
// println("$it\t${spectrum.value(it,params)}")
|
||||||
}
|
// }
|
||||||
|
|
||||||
fun plotSpectrum(name: String, vararg override: Pair<String, Double>): Plot {
|
fun plotSpectrum(name: String, vararg override: Pair<String, Double>): Plot {
|
||||||
val x = (14000.0..18600.0).step(100.0).toList()
|
val x = (14000.0..18600.0).step(100.0).toList()
|
||||||
@ -141,7 +143,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
plots.setType<DataPlot>()
|
plots.setType<DataPlot>()
|
||||||
+plotResidual("trap", "trap" to 0.99)
|
+plotResidual("trap", "trap" to 0.99)
|
||||||
context.launch(Dispatchers.Main) {
|
context.launch(Dispatchers.JavaFx) {
|
||||||
try {
|
try {
|
||||||
+plotFitResidual("trap_fit", "trap" to 0.99)
|
+plotFitResidual("trap_fit", "trap" to 0.99)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
@ -149,7 +151,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
+plotResidual("X", "X" to 0.11)
|
+plotResidual("X", "X" to 0.11)
|
||||||
context.launch(Dispatchers.Main) {
|
context.launch(Dispatchers.JavaFx) {
|
||||||
+plotFitResidual("X_fit", "X" to 0.11)
|
+plotFitResidual("X_fit", "X" to 0.11)
|
||||||
}
|
}
|
||||||
+plotResidual("sterile_1", "U2" to 1e-3)
|
+plotResidual("sterile_1", "U2" to 1e-3)
|
||||||
@ -157,7 +159,7 @@ fun main() {
|
|||||||
+plotFitResidual("sterile_1_fit", "U2" to 1e-3)
|
+plotFitResidual("sterile_1_fit", "U2" to 1e-3)
|
||||||
}
|
}
|
||||||
+plotResidual("sterile_3", "msterile2" to (3000 * 3000).toDouble(), "U2" to 1e-3)
|
+plotResidual("sterile_3", "msterile2" to (3000 * 3000).toDouble(), "U2" to 1e-3)
|
||||||
context.launch(Dispatchers.Main) {
|
context.launch(Dispatchers.JavaFx) {
|
||||||
+plotFitResidual("sterile_3_fit", "msterile2" to (3000 * 3000).toDouble(), "U2" to 1e-3)
|
+plotFitResidual("sterile_3_fit", "msterile2" to (3000 * 3000).toDouble(), "U2" to 1e-3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user