本文整理汇总了Scala中org.apache.commons.math3.distribution.NormalDistribution类的典型用法代码示例。如果您正苦于以下问题:Scala NormalDistribution类的具体用法?Scala NormalDistribution怎么用?Scala NormalDistribution使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NormalDistribution类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Distr
//设置package包名称以及导入依赖的类
package Survival
object Distr {
import org.apache.commons.math3.distribution.{NormalDistribution}
import math.{log,exp,Pi}
private val N01 = new NormalDistribution(0,1)
trait ErrorDistribution {
def logpdf(z: Double): Double
def surv(z: Double): Double
}
object Normal extends ErrorDistribution {
def logpdf(z: Double) = -(log(2.0*Pi) + z*z)/2.0
def surv(z: Double) = 1-N01.cumulativeProbability(z)
}
object Logistic extends ErrorDistribution {
def logpdf(z: Double) = -z -2.0*log(1.0+exp(-z))
def surv(z: Double) = 1/(exp(z) + 1)
}
object ExtremeValue extends ErrorDistribution {
// Wikipedia
//def logpdf(z: Double) = -z-exp(-z)
//def surv(z: Double) = 1-exp(-exp(-z))
// R and Stats community
def logpdf(z: Double) = z - exp(z)
def surv(z: Double) = exp(-exp(z))
}
trait TimeDistribution {
val errDistr: ErrorDistribution
def logpdf(t: Double, mu: Double, s: Double) = {
assert(t > 0 && s > 0, "t,s should be > 0")
errDistr.logpdf((log(t)-mu)/s) - log(t*s)
}
def logSurv(t: Double, mu: Double, s: Double) = {
assert(t > 0 && s > 0, "t,s should be > 0")
//log(1-errDistr.cdf((log(t)-mu)/s))
log(errDistr.surv((log(t)-mu)/s))
}
}
object LogNormal extends TimeDistribution { val errDistr = Normal }
object LogLogistic extends TimeDistribution { val errDistr = Logistic }
object Weibull extends TimeDistribution { val errDistr = ExtremeValue }
}
开发者ID:luiarthur,项目名称:SurvivalScala,代码行数:50,代码来源:Distr.scala
注:本文中的org.apache.commons.math3.distribution.NormalDistribution类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论