問題タブ [gamma-function]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
3 に答える
3771 参照

math - 逆不完全ガンマ関数の単純な近似

いくつかの単純な分析関数f(s、Г)で逆不完全ガンマ関数Г(s、x)をどのように近似できますか?つまり、x = f(s、Г)= 12 * log(123.45 *Г)+Г+ 123.4^sのように記述します。

(少なくともアイデアや参考資料が必要です。)

0 投票する
6 に答える
4635 参照

javascript - 小数を含む数値の階乗を計算する関数を作成する方法は?

JavaScript で 10 進数の階乗 (またはガンマ関数)を計算する関数を作成するにはどうすればよいですか? たとえば、どのように計算できます2.33!か?

0 投票する
1 に答える
886 参照

r - ガンマ関数を含む関数を最適化するための R

ガンマ関数を含む関数を最適化しようとしています。私のデータは打ち切りデータです。私が持っている エラーは次のとおりです:「fn(par、...)のエラー:非関数を適用しようとしています」 Rコードは次のとおりです:

fn(par, ...) のエラー: 非関数を適用しようとしています

よろしくお願いいたします。

0 投票する
1 に答える
1186 参照

python - Python のガンマ関数を使用した累積分布関数

次のような Schechter Luminosity 関数を扱っています。

たとえば、L/Lstar は l です。

の累積分布関数の解析解は、ガンマ関数によって与えられます: N = ノルム係数*ガンマ(a+1, l)。

積分の限界が L から無限大であるため、これは不完全なガンマ関数です。

現在、Python で cdf をプロットしようとしています。私が使用した:

(ここで、l[I] は乱数から作成した配列です)

結果のグラフの合計は 1 で、cdf のように見えます。しかし今、私はそれをランダム化したいです。したがって、cdf = 1 の代わりに、cdf = 乱数を設定します (Python によって一様に生成されます)。ここで、ランダム サンプリングを使用してカウント数と L のヒストグラムをプロットする場合は、ガンマ関数を反転する必要があります。

私の質問は: Python でガンマ関数を反転するにはどうすればよいですか?

これは私が今持っているものです:

コンパイラは文句を言いませんが、ヒストグラムは間違った形です。cdf のランダムにサンプリングされたヒストグラムは、PDF の形状を回復するはずだと思います。

私は何を間違っていますか?どうやら、不完全なガンマ関数の scipy のバージョンは「正則化」されています。つまり、完全なガンマ関数で除算されます。したがって、 gammainc(a+1, u[I])* gamma(a+1) を掛けても、まだ機能しません。

軸は対数スケールです。

助言がありますか?

結論: ランダム サンプリングにより、Schechter 光度関数の cdf のヒストグラムを作成する必要があります。

0 投票する
1 に答える
1805 参照

python - scipy.special.gammaln の精度

問題

私のプログラミングの多くは、scipy.stats の統計関数に関係しています。新しい問題では、ベータ二項分布の pmf を計算する必要がありました。これには分析形式がありますが、scipy.stats には表示されないため、その pmf の関数を自分で定義する必要がありました。私は scipy バージョン 0.12.0 と numpy バ​​ージョン 1.7.0 を使用しています。

統計問題では、n と k の値を通常 0 から 100 の範囲で解こうとしていますが、K と N は 1e9 まで大きくなる可能性があります。私の問題は、この関数が異なる入力に対して同じ値を返すことです。

結果の配列は

Kの値がそれぞれ異なることを考えると、これはかなり奇妙です。配列の 1 番目と 3 番目の値の類似性をよりよく理解するには


関数の精度の非常に簡単なテストは、gammaln1-(ガンマ(N+1)/ガンマ(N))/N です。紙の上で代数を計算すると、結果がちょうど 0 になるので便利です。

質問

gammaln計算できる精度には限界があることは認識していますが、精度が 5 桁変化する N=1e7 付近で何が起こるのでしょうか? この問題を回避する方法についての提案はありますか?

0 投票する
1 に答える
377 参照

math - 平均と分散から分布パラメータを解く方法

次の方程式を解くことで元の質問を解決できるように、OP を更新します。

どこ

ここで、g(j,k) = j / [ k* g1 (1+j, 定数 1/k) - k* g1 (1+j, 定数 2/k) + exp(-定数 2/k) * k^(1 -j) * 定数 2^j - exp(-定数 1/k) * k^(1-j) * 定数 1^j ] 定数 1 >= 0 、定数 2 >
0

k と j の解を見つける必要があります。


制約として積分を使用して数学的最適化モデルを解く必要があります。

どんな助けでも大歓迎です。

0 投票する
1 に答える
1420 参照

statistics - Fast incomplete gamma function

What is a fast way to calculate the incomplete gamma function, or at least a "good" approximation of it, in C++?

Background

What I ultimately need to calculate

Given a number of Bernoulli trails N, with probability p of success, I'm ultimately trying to calculate the probability of obtaining at most k successes, as a function of k. The cumulative binomial distribution F(k,N,p) gives this probability.

The need for speed

I need to calculate a few hundred thousand of these cumulative probabilities per second. Calculating the cumulative binomial distribution by straightforward summation is very computation-intensive for large N. Using the incomplete beta function is a lot better, but still quite computation intensive.

Exploitable constraints

I'm hoping the following constraints from the application domain can help with speeding up the calculation:

  • p < 0.01 (the distribution is always very skew)
  • N > 50

Poisson approximation

After some experimentation in Excel, I've learned that the Poisson approximation is excellent under the above conditions. I.e. B(N,p) at k is almost identical to Pois(Np) at k under the conditions of interest. This means I only need a function of 2 variables, no longer 3.

I understand that the cumulative Poisson distribution can be calculated in terms of the incomplete gamma function, which, judging by the source code in the cephes library, seems to be quite a lot simpler to calculate than the original incomplete beta function one would have had to calculate without the Poisson approximation. But it still isn't very simple and is an iterative numerical calculation. So now I'm looking for a fast way to calculate the incomplete gamma function. I'm wondering whether there isn't a closed-form expression that can approximate it reasonably well.

Required precision

20% relative error is quite acceptable on the integral/probability (considered from every k, in both directions).

I've considered using an interpolated look up table for the Poisson CDF directly, but evenly-spaced domain-points are probably less-than-ideal and the domain would also then have to be restricted to an arbitrary rectangle. An analytic function with quite a number of tweaked parameters is what I'm hoping to find ideally.

0 投票する
2 に答える
357 参照

ruby - ガンマ関数近似

特定の間隔でガンマ関数を近似する 3 パラメーター メソッドを作成しようとしています。近似は、右端点のリーマン和でなければなりません。

ガンマ関数は次の式で与えられます。

したがって、区間 (0, m) での右端のリーマン和近似は次のようになります。

私のコードは次のとおりです。

コードは 3 の近似値を返す必要があります! = 6 ですが、代わりに 0.0 を返します。私が間違っているかもしれないアイデアはありますか?