fix
diff --git a/org.eclipse.stem/core/org.eclipse.stem.solvers.stochastic/src/org/eclipse/stem/solvers/stochastic/impl/StandardStochasticImpl.java b/org.eclipse.stem/core/org.eclipse.stem.solvers.stochastic/src/org/eclipse/stem/solvers/stochastic/impl/StandardStochasticImpl.java index b797054..21a6f8f 100644 --- a/org.eclipse.stem/core/org.eclipse.stem.solvers.stochastic/src/org/eclipse/stem/solvers/stochastic/impl/StandardStochasticImpl.java +++ b/org.eclipse.stem/core/org.eclipse.stem.solvers.stochastic/src/org/eclipse/stem/solvers/stochastic/impl/StandardStochasticImpl.java
@@ -360,9 +360,18 @@ // First find how many people are in the source sourceCount = otherPopulationModelLabelValue.eGetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID()); + int roundedSourceCount = (int)Math.round(sourceCount); + // SED FIX 2019/02/12 + double probability = transitionCount/sourceCount; + if(Double.isInfinite(probability)) + probability = 0; + if(probability > 1.0) + probability = 1.0; + double stochasticMigration = binomialDist.fastPickFromBinomialDist(probability, (int)Math.round(roundedSourceCount)); + // END FIX // Draw stochastically the number of people migrating in - int sumMigration=0; + //int sumMigration=0; if(sourceCount > 0) { // The rest of the labels in the "otherLabels" array are organized in pairs, where the first is the source // disease model label and the second is the target. We draw for each compartment of type Standard stochastically @@ -378,10 +387,14 @@ sourceCount = otherDiseaseModelLabelValue.eGetDouble(ea.getFeatureID()); if(sourceCount > 0) { // Migrate weighting by the size of the compartment - double weightedTransition = transitionCount*(sourceCount/otherDiseaseModelLabelValue.eGetDouble( org.eclipse.stem.diseasemodels.standard.StandardPackage.eINSTANCE.getDiseaseModelLabelValue_PopulationCount().getFeatureID())); - double draw = weightedTransition/sourceCount; - if(draw > 1.0) draw = 1.0; - int iMigrationCount = binomialDist.fastPickFromBinomialDist(draw, (int)Math.round(sourceCount)); + //double weightedTransition = transitionCount*(sourceCount/otherDiseaseModelLabelValue.eGetDouble( org.eclipse.stem.diseasemodels.standard.StandardPackage.eINSTANCE.getDiseaseModelLabelValue_PopulationCount().getFeatureID())); + // SED FIX: + double weightedTransition = stochasticMigration*(sourceCount/otherDiseaseModelLabelValue.eGetDouble( org.eclipse.stem.diseasemodels.standard.StandardPackage.eINSTANCE.getDiseaseModelLabelValue_PopulationCount().getFeatureID())); + //double draw = weightedTransition/sourceCount; + //if(draw > 1.0) draw = 1.0; + //int iMigrationCount = binomialDist.fastPickFromBinomialDist(draw, (int)Math.round(sourceCount)); + // SED FIX: + int iMigrationCount = (int)Math.round(weightedTransition); if(otherDiseaseModelLabelValue.eGetDouble(ea.getFeatureID()) < iMigrationCount) iMigrationCount = (int)Math.floor(otherDiseaseModelLabelValue.eGetDouble(ea.getFeatureID())); // Subtract from the source the number of people migrating out of the state @@ -392,7 +405,8 @@ thisDiseaseModelLabelValue.eSetDouble(ea.getFeatureID(), thisDiseaseModelLabelValue.eGetDouble(ea.getFeatureID())+iMigrationCount); - sumMigration += iMigrationCount; + // SED FIX not needed + //sumMigration += iMigrationCount; } } } @@ -401,15 +415,15 @@ copyCurrentToNext(otherDiseaseModelLabel); } - // Add to the source the number of people migrating in + // Add to the source the number of people migrating in iLabCurrentValue.eSetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID(), - iLabCurrentValue.eGetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID())+sumMigration); + iLabCurrentValue.eGetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID())+stochasticMigration); // Subtract from the target population model label IntegrationLabel targetPopulationLabel = (IntegrationLabel)arrivalsExchange.getOtherLabels().get(0); // First one is population model label; IntegrationLabelValue targetPopulationLabelValue = (IntegrationLabelValue)targetPopulationLabel.getCurrentValue(); targetPopulationLabelValue.eSetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID(), - targetPopulationLabelValue.eGetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID())-sumMigration); + targetPopulationLabelValue.eGetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID())-stochasticMigration); // Since we updated the other label value set the next value copyCurrentToNext(targetPopulationLabel); } @@ -424,8 +438,18 @@ // First find how many people are in the source sourceCount = otherPopulationModelLabelValue.eGetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID()); + // SED FIX 2019/02/12 + roundedSourceCount = (int)Math.round(sourceCount); + probability = transitionCount/sourceCount; + if(Double.isInfinite(probability)) + probability = 0; + if(probability > 1.0) + probability = 1.0; + double stochasticAging = binomialDist.fastPickFromBinomialDist(probability, (int)Math.round(roundedSourceCount)); + // END FIX + // Draw stochastically the number of people aging in - int sumAging=0; + //int sumAging=0; if(sourceCount > 0) { // The rest of the labels in the "otherLabels" array are organized in pairs, where the first is the source // disease model label and the second is the target. We draw for each compartment of type Standard stochastically @@ -441,10 +465,14 @@ sourceCount = otherDiseaseModelLabelValue.eGetDouble(ea.getFeatureID()); if(sourceCount > 0) { // Aging weighting by the size of the compartment - double weightedTransition = transitionCount*(sourceCount/otherDiseaseModelLabelValue.eGetDouble( org.eclipse.stem.diseasemodels.standard.StandardPackage.eINSTANCE.getDiseaseModelLabelValue_PopulationCount().getFeatureID())); - double draw = weightedTransition/sourceCount; - if(draw > 1.0) draw = 1.0; - int iAgingCount = binomialDist.fastPickFromBinomialDist(draw, (int)Math.round(sourceCount)); + // SED FIX + //double weightedTransition = transitionCount*(sourceCount/otherDiseaseModelLabelValue.eGetDouble( org.eclipse.stem.diseasemodels.standard.StandardPackage.eINSTANCE.getDiseaseModelLabelValue_PopulationCount().getFeatureID())); + //double draw = weightedTransition/sourceCount; + //if(draw > 1.0) draw = 1.0; + double weightedTransition = stochasticAging*(sourceCount/otherDiseaseModelLabelValue.eGetDouble( org.eclipse.stem.diseasemodels.standard.StandardPackage.eINSTANCE.getDiseaseModelLabelValue_PopulationCount().getFeatureID())); + + //int iAgingCount = binomialDist.fastPickFromBinomialDist(draw, (int)Math.round(sourceCount)); + int iAgingCount = (int)Math.round(weightedTransition); if(iAgingCount > sourceCount) iAgingCount = (int)Math.floor(sourceCount); // safe, don't age more than available // Subtract from the source the number of people migrating out of the state @@ -454,7 +482,7 @@ thisDiseaseModelLabelValue.eSetDouble(ea.getFeatureID(), thisDiseaseModelLabelValue.eGetDouble(ea.getFeatureID())+iAgingCount); - sumAging += iAgingCount; + //sumAging += iAgingCount; } } @@ -468,13 +496,13 @@ // Add to the source the number of people aging in iLabCurrentValue.eSetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID(), - iLabCurrentValue.eGetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID())+sumAging); + iLabCurrentValue.eGetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID())+stochasticAging); // Subtract from the target population model label IntegrationLabel targetPopulationLabel = (IntegrationLabel)arrivalsExchange.getOtherLabels().get(0); // First one is population model label; IntegrationLabelValue targetPopulationLabelValue = (IntegrationLabelValue)targetPopulationLabel.getCurrentValue(); targetPopulationLabelValue.eSetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID(), - targetPopulationLabelValue.eGetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID())-sumAging); + targetPopulationLabelValue.eGetDouble(StandardPackage.eINSTANCE.getStandardPopulationModelLabelValue_Count().getFeatureID())-stochasticAging); // Since we updated the current value of the other label set the next value // Set the next to the modified current value copyCurrentToNext(targetPopulationLabel);