Skip to content

Commit

Permalink
Fix bugs in estimating geometric distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdurand committed Sep 12, 2024
1 parent e743d53 commit e8a9fde
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 30 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ TODO list for `StructureAnalysis` to be updated / completed. We target a next of
[ ] Repare `stat_tool` and `sequence_analysis` tests
+ create a new branch for each new development (do not systematically use new_python_api)
+ update tests to be compliant with python 3
+ Fix stat_tool_examples.py, test_distribution_functional.py, test_estimate.py, test_multivariate_mixture_functional.py, test_vector_distance.py
+ matplotlib output to Survival (remove gnuplot)
+ Translate C++ comments
+ let enumerated types be systematically transferred from python to wrappers to C++ by intermediate conversions to int
Expand Down
10 changes: 6 additions & 4 deletions stat_tool/src/cpp/discrete_mixture_algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ void DiscreteMixture::init(const FrequencyDistribution &histo , bool *estimate ,
}

case NEGATIVE_BINOMIAL : {
component[i]->parameter = NEGATIVE_BINOMIAL_PARAMETER;
component[i]->probability = component[i]->parameter / (shift_mean + component[i]->parameter);
component[i]->parameter = 1.;
component[i]->probability = 1. / ((histo.nb_value)+1+shift_mean);
break;
}
}
Expand Down Expand Up @@ -617,9 +617,11 @@ DiscreteMixture* FrequencyDistribution::discrete_mixture_estimation(StatError &e
previous_likelihood = likelihood;
likelihood = mixt->Distribution::likelihood_computation(*this);

if (!mixt->component_order_test()) {
// Commenting: having increasing means does not seem
// to be required in mixtures
/* if (!mixt->component_order_test()) {
likelihood = D_INF;
}
}*/
}
while (((likelihood - previous_likelihood) / -likelihood > DISCRETE_MIXTURE_LIKELIHOOD_DIFF) &&
(j < DISCRETE_MIXTURE_NB_ITER) && (likelihood != D_INF));
Expand Down
2 changes: 1 addition & 1 deletion stat_tool/src/openalea/stat_tool/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def estimate_DiscreteMixture(histo, *args, **kargs):
else:
distributions = list(args)

InfBoundStatus = kargs.get("InfBoundStatus","Free")
InfBoundStatus = kargs.get("InfBoundStatus","Fixed")
DistInfBoundStatus = kargs.get("DistInfBoundStatus", "Free")
NbComponent = kargs.get("NbComponent", "Fixed")

Expand Down
4 changes: 2 additions & 2 deletions stat_tool/test/stat_tool_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from openalea.stat_tool import Compound, Convolution, VarianceAnalysis
from openalea.stat_tool import ContingencyTable

from openalea.sequence_analysis import Sequences
# from openalea.sequence_analysis import Sequences

from openalea.stat_tool import get_shared_data

Expand Down Expand Up @@ -236,7 +236,7 @@
# change of unit for the variable diameter of the annual shoot

marginal2 = ExtractHistogram(seq0, "Value", 2)
print marginal2
print(marginal2)
Plot(Cluster(marginal2, "Information", 0.75))
Plot(Cluster(marginal2, "Information", 0.61))
Plot(Cluster(marginal2, "Step", 10))
Expand Down
48 changes: 27 additions & 21 deletions stat_tool/test/test_compound_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,37 @@

# read data file
def test():
cdist1 = Compound("data/compound1.cd")
Plot(cdist1)

chisto1 = Simulate(cdist1, 200)
Plot(chisto1)

histo30 = ExtractHistogram(chisto1, "Sum")
Plot(histo30)

histo30e = ExtractHistogram(chisto1, "Elementary")
Plot(histo30e)


cdist2 = Estimate(chisto1, "COMPOUND",
ExtractDistribution(cdist1, "Elementary"),
"Sum", MinInfBound=0)

histo31 = ExtractHistogram(ExtractData(cdist2), "Sum")
histo32 = ToHistogram(ExtractDistribution(cdist2, "Sum"))
Plot(histo31, histo32)
# cdist1 = Compound("data/compound1.cd")
# Plot(cdist1)
#
# chisto1 = Simulate(cdist1, 200)
# Plot(chisto1)
#
# histo30 = ExtractHistogram(chisto1, "Sum")
# Plot(histo30)
#
# histo30e = ExtractHistogram(chisto1, "Elementary")
# Plot(histo30e)
#
#
# cdist2 = Estimate(chisto1, "COMPOUND",
# ExtractDistribution(cdist1, "Elementary"),
# "Sum", MinInfBound=0)
#
# histo31 = ExtractHistogram(ExtractData(cdist2), "Sum")
# histo32 = ToHistogram(ExtractDistribution(cdist2, "Sum"))
# Plot(histo31, histo32)

peup1 = Histogram("data/peup1.his")
mixt4 = Estimate(peup1, "MIXTURE", "B", "NB")
histo33 = ToHistogram(ExtractDistribution(mixt4, "Component", 2))
histo34 = Shift(histo33, -11)
try:
histo34 = Shift(histo33, -11)
except Exception:
pass
else:
raise ValueError("Failed to detect bad shift value")
histo34 = Shift(histo33, -4)
Plot(histo34)

cdist3 = Estimate(histo34, "COMPOUND",
Expand Down
7 changes: 5 additions & 2 deletions stat_tool/test/test_vectors_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
from openalea.stat_tool.estimate import Estimate
from openalea.stat_tool.output import Display, Plot

from tools import interface
from tools import runTestClass, robust_path as get_shared_data

def test():
vec10 = Vectors("data/chene_sessile.vec")
vec10 = Vectors(get_shared_data("chene_sessile.vec"))
Plot(vec10)
# plot of the pointwise averages
Plot(Regression(vec10, "MovingAverage", 1, 2, [1]))
Expand Down Expand Up @@ -111,4 +114,4 @@ def test():


if __name__ == "__main__":
test1()
test()

0 comments on commit e8a9fde

Please sign in to comment.