Italian Libreria Probability

saslvovc

Member
Licensed User
Longtime User
Salve ragazzi qualcuno sa parlarmi della libreria Probability in particolare della formula di Poisson
come si usa.
 

derez

Expert
Licensed User
Longtime User
9df5c46ed6718f2da9df4662a481a198.png


B4X:
Sub Poisson(k As Int, Lambda As Double)
Dim sum As Double
If (k < 0 ) Then
    dres(0) = -999
    dres(1) = -999
    Return
End If   

dres(1) = Power(Lambda,k)* Power(cE,-Lambda)/ Factorial(k)
sum = 1
For  i = 1 To k
    sum = sum +    Power(Lambda,i)/Factorial(i)
Next
dres(0) = sum * Power(cE,-Lambda)
End Sub
       
Sub InvPoisson(Pp As Double , Lambda As Double) As Int
Dim k, dk,flag,oldflag As Int
k = 10
dk = 8
flag = 1
oldflag = 1
Poisson(k,Lambda)
Do While (dk >= 1)
    If (dres(0) > Pp + 1e-6) Then
        flag = -1
    Else
        flag = 1
    End If
    k = k + flag * dk
    If (k < 1 ) Then k = 0
    If(flag <> oldflag) Then dk = dk/2
    Poisson(k,Lambda)
Loop
If (dres(0) > Pp + 1e-6 ) Then
    Return k-1
Else
    Return k
End If
End Sub
 

derez

Expert
Licensed User
Longtime User
LucaMs - please help with the language, the above is simple - the poisson sub follows the formula, the invpoisson finds it by searching the range and finding the solution that will give the poisson result.
 

saslvovc

Member
Licensed User
Longtime User
grazie a tutti ragazzi dei suggerimenti datomi ho risolto cosi:

Sub Poisson(k As Int, Lambda As Double)

If (k < 0 ) Then
Return
End If

Return Power(Lambda,k)* Power(cE,-Lambda)/ Factorial.Factorial(k)

End Sub
presa dal'esempio di derez e finziona.
---------------------------------------------------------------------------------------
ma il problema riscontrato nella libreria Probability da me installata è questo:


Sub Globals
Dim p As Probability
Private EditText1 As EditText
Private Button1 As Button
End Sub

Sub Button1_Click
EditText1.text= p.Poisson(1,1.80)
End Sub
mi restitusce seguente valore: [D@42ff38c8
volevo usare questa libreria

---------------------------------------------------------------------------------------

l'esempio riportato da derez mi da il seguente errore:

An error has occurred in
sub:main_poisson(java line:418)
java.lang.ArrayIndexOfBound sException: lenghet=1; index=1
continuare?
 

derez

Expert
Licensed User
Longtime User
EditText1.text= p.Poisson(1,1.80)

The problem is that you expect one value to be returned from the function, while it is defined to return an array of two doubles.
You can see this if you press "." after the library object (your P).
upload_2014-11-27_14-46-7.png


In the demo the code is this:
B4X:
Dim qx(2) As Double
....
qx = prob.Poisson(Et1.Text,Et3.Text)
....
Et4.Text = Round2( qx(0), 10)
Et5.Text = Round2( qx(1), 10)
 
Top