問題タブ [scipy-optimize-minimize]

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 投票する
0 に答える
415 参照

python - SciPy Optimization for one and two variables

I'm writing this program where I have to do a bunch of optimizations. Some with only 1 variable, some with 2. At first I was using the basinhopping algorithm from the scipy.optimize library, but I figured that the normal minimize algorithm should do the job. The basinhopping optimization was working, more or less, but it was extremely time-consuming. Now, I'm using the normal minimize optimization and I've already figured out how to do it for 1 variable. The code for this is given below. I'm using the COBYLA method here, since this one seems to be the only one working. (Nelder-Mead and Powell also work, but sometimes they give back a negative x, which I can't have. And since both of these methods are unconstrained, I can't use them). Hence my first question: what is the difference between all the methods and why do some of the methods converge for my function and others don't?

The code that I use for the optimization for 2 variables is quite identical to the one for 1 variable, but somehow it gives me the wrong results. Does this have to do with the method I'm using? Or what could be the problem here?

For the sake of completeness, below is my code for the calculate_score function. I was maybe thinking to calculate the gradient of this function, so that given this gradient the BFGS or L-BFGS-B methods would work, but I'm not quite sure how to do this.

In short, what I would like to know is:

  • Was it a good idea to switch from basinhopping to minimize? (I just thought basinhopping was extremely slow)
  • Is the method COBYLA I'm using the best one for this specific case?
  • Why is my result for 1 variable correct, while my result for 2 variables isn't?
0 投票する
0 に答える
113 参照

python - pandas データ フレーム引数で scipy を使用した最適化

関数を最適化しようとしています。ただし、この関数は pandas データ フレームを引数として取ります。したがって、コードを実行すると、次のエラーが発生します。

TypeError: 'DataFrame' オブジェクトは可変であるため、ハッシュできません

私の評価関数:

価格は pandas データ フレームです。

これを最適化するにはどうすればよいですか?また、もう 1 つの質問は、私の最適化関数には初期推測の配列も渡す必要があるということです。args パラメータを設定するとき、どうすればそれを説明できますか?

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

optimization - scipy 最適化を使用して要素ごとの制約を使用してパラメーター行列を解く

私は比較的単純な最適化の問題を抱えていますが、scipy に特に精通しておらず、必要な制約を適用する方法を理解できません。私の目的関数は、10 要素ベクトルyxの間の絶対距離を最小化することです。ここで、xは 10x3 パラメーター行列pの加重行合計です。

パラメータ行列pに次の制約を追加する必要があります。

  1. pの各要素、ただし >=0 および <=1 である
  2. pの各列の合計は1 でなければなりません
  3. pの各行の合計は1 を超えてはなりません

私は他の SO の質問に基づいて制約を実装しようとしましたが、それを完全には理解していないことも、それが生成するエラーも認めていません。

このコードを実行すると、次のエラー メッセージが表示されます。

AxisError: 軸 1 は次元 1 の配列の範囲外です

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