翻阅了 官方 tutorial.
与 Python 比较
new
相当于在 Python 中显式地调用__init__
方法.import
好像没有 Python 灵活, 比如a.b.c
, 只能导入 fully qualified name (一个具体的类) 或者一个库下所有的类, 而不能像 Python 一样from a import b
然后再用b.c
.- 没有默认参数 (可以用函数重载实现), 没有位置参数 (传参感觉不方便读 raw text?).
- 方法命名习惯用动词开头, camelCase.
- “only public methods are allowed to be called on class instance.” Why subclass in another package cannot access a protected method?
线性回归系数检验
Apache Commons Math 库的线性回归类没有直接实现各种假设检验. 考虑线性回归 (满足一般假设)
y=Xβ+ε,ε∼N(0,σ2I).其中 X 是 n×p 设计矩阵 (第一列全为 1), β 是 p×1 参数向量. 检验估计参数 ˆβ 的每一项,
H0:β1=⋯=βp−1=0,其中 β0 为截距. 由于
ˆβ∼Np(β,σ2(X′X)−1),如果 βi=0 成立, 则 t-统计量
τi=ˆβi√ci,i√u′u/(n−p)∼tn−p,其中 ci,i 表示 (X′X)−1 的第 i 行第 i 列, 残差 u=y−Xˆβ (右下角这一坨是 ˆσ), 符号 tn−p 表示自由度为 n−p 的 t 分布. 最后 2P(Z>|τi|) 则为第 i 项对应的 p-value, 其中随机变量 Z∼tn−p.
实现见 这里, 其中
- 在
TDistribution
构造函数中显式传入rng=null
避免创建随机数生成器; - 用了 Apache 的 FastMath: Faster, more accurate, portable alternative to Math and StrictMath for large scale computation.;
- 用函数重载实现了类似默认参数的效果, 避免重复计算 beta;
- Javadoc 的写法参考了 Apache Commons Math 官方文档风格.
其他
Python 可以用 JPype 调 jar 包, 但是一个 已知缺陷 是
Because of lack of JVM support, you cannot shutdown the JVM and then restart it. Nor can you start more than one copy of the JVM.
Gitalking ...