わかった、
丸め誤差の問題に遭遇しました。リストを行ごとにいくつかの数字で読み取るJavaプログラムがあります。プログラムでは、このリストが浮動小数点数 (どのタイプの浮動小数点数ですか? 単精度だと思います) で、合計 S が .999 から 1.001 の間 (つまり、.999 <= S <= 1.001) である必要があります。次に例を示します。
from numpy import array, linalg
def Normalize(X):
NumpyX = array(X)
Norm = linalg.norm(NumpyX)
Normalize = NumpyX/Norm
return Normalize
def FileMaker(FilePointer,Vector)
for i in Vector:
FilePointer.write('%f\n'%i)
return
#sum(SubstitutionPoints) does not add to 1
SubstitutionPoints =[0.00606508512067950,0.00675296642376962,0.00688999694872917,0.00580692396866418,0.00680583604896024,0.00609061670962565,0.00585881991631447,0.00577148570812953,0.00600882981888663,0.00618499536435559,0.00650767341787896,0.00670521809234427,0.00699374780209504,0.00841141135948587,0.00830145870238677,0.00879477131238090,0.00918627324146331,0.00958946761973615,0.01032404247887830,0.01093417870737930,0.01188202458790520,0.01261860720648550,0.01355451051017660,0.01473818756656830,0.01623978223562570,0.01811682034513980,0.01990010225231130,0.02154250858435480,0.02418185925226890,0.02583490296173980,0.02844212438633430,0.03194935989118780,0.03534228607419560,0.03971366519834600,0.04548573525944540,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660,0.05190994307855660]
NormedSP = Normalize(SubstitutionPoints)
SubFile = open('Sub.txt','w')
FileMaker(SubFile,NormedSP)
SubFile.close()
Python は単精度浮動小数点数を使用しないため、Java プログラム (metasim) がエラーを返すため、作成されたファイルが Java プログラムで問題を引き起こしているのではないかと心配しています。
Simulating files:
[BorreliaBurgdorferiB31_CP32-3.fasta]
java.lang.Exception: Substitution rates don't sum to 1.0.
!!! FAILED !!!
残念ながら、「Java 実行可能ファイル」であるため、Java プログラムをデバッグできません。私の唯一の選択肢は、正しい情報を提供することです。
任意の提案/ヘルプをいただければ幸いです。
編集
float32() を試すといういくつかの提案から、正規化メソッドを次のように修正しました。
def Normalize(self,X):
Total = sum(X)
NumpyX = array([float32(i) for i in X])
Norm = linalg.norm(NumpyX,ord=1)
Normalize = NumpyX/Norm
return Normalize
私はそれが単精度浮動小数点数の問題であることを疑い始めています。
出力が切り捨てられ、エラーが発生していますか?