Commit 0be43823 authored by patrick.lambert's avatar patrick.lambert
Browse files

move methods used in ABC calibration in dedicated processess

parent fd6eea4d
......@@ -37,6 +37,7 @@ import species.DiadromousFishGroup;
/**
*
*/
@Deprecated
public class ComputeStatisticForABCCalibration extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private Double targetedAgeForFemaleSpawnerForFirstTime = 5.5;
......@@ -154,7 +155,21 @@ public class ComputeStatisticForABCCalibration extends AquaNismsGroupProcess<Dia
int obsVal;
double sumLogWherePres = 0.;
double sumLogWhereAbs = 0.;
final double[] probOfNonNulRecruitmentDuringLastYears = rioBasinNetwork.getProbOfNonNulRecruitmentDuringLastYears();
RiverBasin[] riverBasins = rioBasinNetwork.getRiverBasins();
double[] probOfNonNulRecruitmentDuringLastYears = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum() < 1.0) {
probOfNonNulRecruitmentDuringLastYears[i] = 0.001;
} else if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears()
.getSum() > (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size() - 1)) {
probOfNonNulRecruitmentDuringLastYears[i] = 0.999;
} else {
probOfNonNulRecruitmentDuringLastYears[i] = riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum()
/ (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size());
}
}
final String[] riverBasinNames = rioBasinNetwork.getRiverBasinNames();
// TODO very risky since dependinf of basin order
......
......@@ -25,6 +25,7 @@ import species.DiadromousFish;
import species.DiadromousFish.Gender;
import species.DiadromousFishGroup;
@Deprecated
public class TypeTrajectoryCV extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private String fileNameOutput = "summary";
......@@ -35,6 +36,9 @@ public class TypeTrajectoryCV extends AquaNismsGroupProcess<DiadromousFish, Diad
private Double targetedAgeForFemaleSpawnerForFirstTime = 5.5;
private Double targetedAgeForMaleSpawnerForFirstTime = 4.5;
protected double cVthresholdForFinalStates = 5.;
protected double RecruitmentThresholdForFsAndKappa = 50.;
/**
* The minimum number of recruits to consider a basin as populated
*
......@@ -107,17 +111,105 @@ public class TypeTrajectoryCV extends AquaNismsGroupProcess<DiadromousFish, Diad
@Override
public void doProcess(DiadromousFishGroup group) {
// int[] finalStates = group.getEnvironment().getFinalStates();
// int[] finalStatesWithStoch = group.getEnvironment().getFinalStatesWithStochasticity();
int[] finalStatesForKappa = group.getEnvironment().getFinalStatesForKappa();
double[] geoMeanRecOverProdCap = group.getEnvironment().getGeoMeansLastRecsOverProdCaps();
double[] meanLastRec = group.getEnvironment().getMeanLastRecruitments();
double[] meanPercOfAut = group.getEnvironment().getMeanLastPercOfAut();
double[] probOfNonNulRecruitmentDuringLastYears = group.getEnvironment().getProbOfNonNulRecruitmentDuringLastYears();
long[] yearsOfFirstNonNulRep = group.getEnvironment().getYearsOfFirstNonNulRep();
long[] yearsOfLastNulRep = group.getEnvironment().getYearsOfLastNulRep();
RiverBasin[] riverBasins = group.getEnvironment().getRiverBasins();
String[] finalStatesNames = group.getEnvironment().getRiverBasinNames();
double[] finalProbabilityOfPresence = group.getEnvironment().getFinalProbabilityOfPresence();
//// final states
// int[] finalStates = new int[riverBasins.length];
// for (int i = 0; i < riverBasins.length; i++) {
// RiverBasin riverBasin = riverBasins[i];
// double roundedCV = Math.round(riverBasin.getLastRecruitments().getCoefficientVariation() * 10000.) / 100.;
// if (roundedCV == 0.) {
// finalStates[i] = 0;
// } else if (roundedCV < this.cVthresholdForFinalStates) {
// finalStates[i] = 2;
// } else {
// finalStates[i] = 1;
// }
// }
// FinalStatesWithStochasticity
int[] finalStates = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i];
double roundedCV = Math.round(riverBasin.getLastRecruitmentExpectations().getCoefficientVariation() * 10000.) / 100.;
if (roundedCV == 0.) {
finalStates[i] = 0;
} else if (roundedCV < this.cVthresholdForFinalStates) {
finalStates[i] = 2;
} else {
finalStates[i] = 1;
}
}
// Final States For Kappa
int[] finalStatesForKappa = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i];
if (riverBasin.getLastRecruitments().getMean() <= RecruitmentThresholdForFsAndKappa) {
finalStatesForKappa[i] = 0;
} else {
finalStatesForKappa[i] = 1;
}
}
// Mean Last Recruitments
double[] meanLastRec = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
meanLastRec[i] = riverBasins[i].getLastRecruitments().getMean();
}
// Prob Of Non Nul Recruitment During Last Years()
double[] probOfNonNulRecruitmentDuringLastYears = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum() < 1.0) {
probOfNonNulRecruitmentDuringLastYears[i] = 0.001;
} else if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears()
.getSum() > (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size() - 1)) {
probOfNonNulRecruitmentDuringLastYears[i] = 0.999;
} else {
probOfNonNulRecruitmentDuringLastYears[i] = riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum()
/ (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size());
}
}
// Final Probability Of Presence (in 2100)
// for the allis shad case study
double[] finalProbabilityOfPresence = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
finalProbabilityOfPresence[i] = riverBasins[i].getNumberOfNonNulRecruitmentForFinalProbOfPres().getSum()
/ riverBasins[i].getNumberOfNonNulRecruitmentForFinalProbOfPres().size();
}
// mean last recruitment expectations
// double[] meanLastRecruitmentExpectations = new double[riverBasins.length];
// for (int i = 0; i < riverBasins.length; i++) {
// meanLastRecruitmentExpectations[i] = riverBasins[i].getLastRecruitmentExpectations().getMean();
// }
// Geometric Means of Last Recruitment Over Prodution Capacitiess
double[] geoMeanRecOverProdCap = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
geoMeanRecOverProdCap[i] = riverBasins[i].getLastRecsOverProdCaps().getGeometricMean();
}
// mean Last Perc Of Autochtonous { // give the mean of the last % of autochtone spawners
double[] meanPercOfAut = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
meanPercOfAut[i] = riverBasins[i].getLastPercentagesOfAutochtones().getMean();
}
// Years Of First Non Nul Rep
long[] yearsOfFirstNonNulRep = new long[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
yearsOfFirstNonNulRep[i] = riverBasins[i].getYearOfFirstNonNulRep();
}
// Years Of Last Nul Rep()
long[] yearsOfLastNulRep = new long[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
yearsOfLastNulRep[i] = riverBasins[i].getYearOfLastNulRep();
}
// System.out.println(group.getEnvironment().getMeanLastRecruitmentsBV2());
// System.out.println(" nom des bv " + Arrays.deepToString(finalStatesNames) + "final states : " +
......@@ -137,6 +229,7 @@ public class TypeTrajectoryCV extends AquaNismsGroupProcess<DiadromousFish, Diad
// System.out.println(" nom des bv " + Arrays.deepToString(finalStatesNames) + "year of last nul reproduction :
// " + Arrays.toString(yearsOfLastNulRep));
// this.fireChangesToObservers();
if (fileNameOutput != null) {
// create the subdirectorrys if necessary ?
new File(group.getOutputPath() + fileNameOutput).getParentFile().mkdirs();
......@@ -307,9 +400,21 @@ public class TypeTrajectoryCV extends AquaNismsGroupProcess<DiadromousFish, Diad
double sumLogWherePres = 0.;
double sumLogWhereAbs = 0.;
RIOBasinNetwork rioBasinNetwork = group.getEnvironment();
final double[] probOfNonNulRecruitmentDuringLastYears = rioBasinNetwork.getProbOfNonNulRecruitmentDuringLastYears();
final String[] riverBasinNames = rioBasinNetwork.getRiverBasinNames();
RiverBasin[] riverBasins = rioBasinNetwork.getRiverBasins();
double[] probOfNonNulRecruitmentDuringLastYears = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum() < 1.0) {
probOfNonNulRecruitmentDuringLastYears[i] = 0.001;
} else if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears()
.getSum() > (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size() - 1)) {
probOfNonNulRecruitmentDuringLastYears[i] = 0.999;
} else {
probOfNonNulRecruitmentDuringLastYears[i] = riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum()
/ (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size());
}
}
final String[] riverBasinNames = rioBasinNetwork.getRiverBasinNames();
// TODO very risky since dependinf of basin order
for (int i = 0; i < riverBasinNames.length; i++) {
int presence = presences.get(period).get(riverBasinNames[i]);
......
......@@ -13,16 +13,12 @@ public abstract class BasinNetwork extends Environment<Basin, DiadromousFish> {
protected int memorySize; // size of all the queues
protected int memorySizeLongQueue; // size of all longer queues
protected double cVthresholdForFinalStates = 5.;
protected double RecruitmentThresholdForFsAndKappa = 50.;
protected long yearOfTheBegin = 1800;
protected transient double[][] distanceGrid;
protected transient Time time;
@InitTransientParameters
public void initTransientParameters(Pilot pilot) {
time = new Time();
......@@ -47,162 +43,6 @@ public abstract class BasinNetwork extends Environment<Basin, DiadromousFish> {
public abstract String[] getRiverBasinNames();
public int[] getFinalStates() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins();
int[] finalStates = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i];
double roundedCV = Math.round(riverBasin.getLastRecruitments().getCoefficientVariation() * 10000.) / 100.;
if (roundedCV == 0.) {
finalStates[i] = 0;
} else if (roundedCV < this.cVthresholdForFinalStates) {
finalStates[i] = 2;
} else {
finalStates[i] = 1;
}
}
return finalStates;
}
public int[] getFinalStatesWithStochasticity() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins();
int[] finalStates = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i];
double roundedCV = Math.round(riverBasin.getLastRecruitmentExpectations().getCoefficientVariation() * 10000.) / 100.;
if (roundedCV == 0.) {
finalStates[i] = 0;
} else if (roundedCV < this.cVthresholdForFinalStates) {
finalStates[i] = 2;
} else {
finalStates[i] = 1;
}
}
return finalStates;
}
public int[] getFinalStatesForKappa() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins();
int[] finalStatesForKappa = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i];
if (riverBasin.getLastRecruitments().getMean() <= RecruitmentThresholdForFsAndKappa) {
finalStatesForKappa[i] = 0;
} else {
finalStatesForKappa[i] = 1;
}
}
return finalStatesForKappa;
}
public double[] getMeanLastRecruitments() {
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getLastRecruitments().getMean();
}
return data;
}
public double[] getProbOfNonNulRecruitmentDuringLastYears() {
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum() < 1.0) {
data[i] = 0.001;
} else if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears()
.getSum() > (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size() - 1)) {
data[i] = 0.999;
} else {
data[i] = riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum()
/ (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size());
}
}
return data;
}
public double[] getFinalProbabilityOfPresence() { // function computed for obtain probability of presence in 2100
// for the allis shad case study
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getNumberOfNonNulRecruitmentForFinalProbOfPres().getSum()
/ riverBasins[i].getNumberOfNonNulRecruitmentForFinalProbOfPres().size();
}
return data;
}
public double getMeanLastRecruitmentsBV2() {
RiverBasin[] riverBasins = getRiverBasins();
double data = riverBasins[1].getLastRecruitments().getMean();
return data;
}
public double[] getMeanLastRecruitmentExpectations() {
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getLastRecruitmentExpectations().getMean();
}
return data;
}
public double[] getGeoMeansLastRecsOverProdCaps() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins();
double[] geoMeans = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
geoMeans[i] = riverBasins[i].getLastRecsOverProdCaps().getGeometricMean();
}
return geoMeans;
}
public double[] getMeanLastPercOfAut() { // give the mean of the last % of autochtone spawners
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getLastPercentagesOfAutochtones().getMean();
}
return data;
}
public long[] getYearsOfFirstNonNulRep() {
RiverBasin[] riverBasins = getRiverBasins();
long[] data = new long[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getYearOfFirstNonNulRep();
}
return data;
}
public long[] getYearsOfLastNulRep() {
RiverBasin[] riverBasins = getRiverBasins();
long[] data = new long[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getYearOfLastNulRep();
}
return data;
}
/**
* @return the yearOfTheBegin
*/
......
......@@ -26,7 +26,6 @@ public abstract class GridBasinNetwork extends BasinNetwork {
protected transient Time time;
@Override
@InitTransientParameters
public void initTransientParameters(Pilot pilot) {
......@@ -179,174 +178,6 @@ public abstract class GridBasinNetwork extends BasinNetwork {
}
@Override
public int[] getFinalStates() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins();
int[] finalStates = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i];
double roundedCV = Math.round(riverBasin.getLastRecruitments().getCoefficientVariation() * 10000.) / 100.;
if (roundedCV == 0.) {
finalStates[i] = 0;
} else if (roundedCV < this.cVthresholdForFinalStates) {
finalStates[i] = 2;
} else {
finalStates[i] = 1;
}
}
return finalStates;
}
@Override
public int[] getFinalStatesWithStochasticity() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins();
int[] finalStates = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i];
double roundedCV = Math.round(riverBasin.getLastRecruitmentExpectations().getCoefficientVariation() * 10000.) / 100.;
if (roundedCV == 0.) {
finalStates[i] = 0;
} else if (roundedCV < this.cVthresholdForFinalStates) {
finalStates[i] = 2;
} else {
finalStates[i] = 1;
}
}
return finalStates;
}
@Override
public int[] getFinalStatesForKappa() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins();
int[] finalStatesForKappa = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i];
if (riverBasin.getLastRecruitments().getMean() <= RecruitmentThresholdForFsAndKappa) {
finalStatesForKappa[i] = 0;
} else {
finalStatesForKappa[i] = 1;
}
}
return finalStatesForKappa;
}
@Override
public double[] getMeanLastRecruitments() {
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getLastRecruitments().getMean();
}
return data;
}
@Override
public double[] getProbOfNonNulRecruitmentDuringLastYears() {
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum() < 1.0) {
data[i] = 0.001;
} else if (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears()
.getSum() > (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size() - 1)) {
data[i] = 0.999;
} else {
data[i] = riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().getSum()
/ (riverBasins[i].getNumberOfNonNulRecruitmentDuringLastYears().size());
}
}
return data;
}
@Override
public double[] getFinalProbabilityOfPresence() { // function computed for obtain probability of presence in 2100
// for the allis shad case study
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getNumberOfNonNulRecruitmentForFinalProbOfPres().getSum()
/ riverBasins[i].getNumberOfNonNulRecruitmentForFinalProbOfPres().size();
}
return data;
}
@Override
public double getMeanLastRecruitmentsBV2() {
RiverBasin[] riverBasins = getRiverBasins();
double data = riverBasins[1].getLastRecruitments().getMean();
return data;
}
@Override
public double[] getMeanLastRecruitmentExpectations() {
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getLastRecruitmentExpectations().getMean();
}
return data;
}
@Override
public double[] getGeoMeansLastRecsOverProdCaps() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
RiverBasin[] riverBasins = getRiverBasins();
double[] geoMeans = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
geoMeans[i] = riverBasins[i].getLastRecsOverProdCaps().getGeometricMean();
}
return geoMeans;
}
@Override
public double[] getMeanLastPercOfAut() { // give the mean of the last % of autochtone spawners
RiverBasin[] riverBasins = getRiverBasins();
double[] data = new double[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getLastPercentagesOfAutochtones().getMean();
}
return data;
}
@Override
public long[] getYearsOfFirstNonNulRep() {
RiverBasin[] riverBasins = getRiverBasins();
long[] data = new long[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getYearOfFirstNonNulRep();
}
return data;
}
@Override
public long[] getYearsOfLastNulRep() {
RiverBasin[] riverBasins = getRiverBasins();
long[] data = new long[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
data[i] = riverBasins[i].getYearOfLastNulRep();
}
return data;
}
/**
* @return the yearOfTheBegin
*/
......
......@@ -202,172 +202,7 @@ public abstract class RIOBasinNetwork extends BasinNetwork {
return basin;
}
@Deprecated
@Override
public int[] getFinalStates() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
int[] finalStates = new int[riverBasins.length];
for (int i = 0; i < riverBasins.length; i++) {
RiverBasin riverBasin = riverBasins[i];
double roundedCV = Math.round(riverBasin.getLastRecruitments().getCoefficientVariation() * 10000.) / 100.;
if (roundedCV == 0.) {
finalStates[i] = 0;
} else if (roundedCV < this.cVthresholdForFinalStates) {
finalStates[i] = 2;
} else {
finalStates[i] = 1;
}
}
return finalStates;
}
@Override
public int[] getFinalStatesWithStochasticity() {
// TODO ask to Nicolas to be able to use ReflectUtils with arguments
int[] finalStates = new int[riverBasins.length];