Commit 954173e9 authored by patrick.lambert's avatar patrick.lambert
Browse files

with computation of mean and standard deviation of spawner lengths

parent 8b47e885
......@@ -28,6 +28,7 @@ import java.util.Map.Entry;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import environment.Basin;
import environment.RIOBasinNetwork;
import environment.RiverBasin;
import environment.Time.Season;
......@@ -49,6 +50,8 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
private int memorySize = 30;
private Season analysisSeason = Season.SPRING;
private transient RiverBasin[] riverBasins;
private transient Map<RiverBasin, QueueMemory<Double>> ageOfFemaleMemories;
private transient Map<RiverBasin, QueueMemory<Double>> ageOfMaleMemories;
private transient Map<RiverBasin, QueueMemory<Double>> ageOfPrimiparousFemaleMemories;
......@@ -62,13 +65,16 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
public void initTransientParameters(Pilot pilot) {
super.initTransientParameters(pilot);
// keep the river basins
riverBasins = ((RIOBasinNetwork) pilot.getAquaticWorld().getEnvironment()).getRiverBasins();
ageOfFemaleMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
ageOfMaleMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
ageOfPrimiparousFemaleMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
ageOfPrimiparousMaleMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
primiparousMemories = new HashMap<RiverBasin, QueueMemory<Double>>();
for (RiverBasin riverBasin : ((RIOBasinNetwork) pilot.getAquaticWorld().getEnvironment()).getRiverBasins()) {
for (RiverBasin riverBasin : riverBasins) {
ageOfFemaleMemories.put(riverBasin, new QueueMemory<>(memorySize));
ageOfMaleMemories.put(riverBasin, new QueueMemory<>(memorySize));
ageOfPrimiparousFemaleMemories.put(riverBasin, new QueueMemory<>(memorySize));
......@@ -177,7 +183,7 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
public double getMeanAgeOfPrimiparousFemale() {
double sum = 0;
double nb = 0;
for (RiverBasin riverBasin : ageOfPrimiparousFemaleMemories.keySet()) {
for (RiverBasin riverBasin : riverBasins) {
if (riverBasin.getSpawnersForFirstTimeMeanAges(Gender.FEMALE).getMeanWithoutZero() > 0.) {
nb++;
sum += riverBasin.getSpawnersForFirstTimeMeanAges(Gender.FEMALE).getMeanWithoutZero();
......@@ -191,7 +197,7 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
public double getMeanLengthOfPrimiparousFemale() {
double sum = 0;
double nb = 0;
for (RiverBasin riverBasin : ageOfPrimiparousFemaleMemories.keySet()) {
for (RiverBasin riverBasin : riverBasins) {
if (riverBasin.getSpawnersForFirstTimeMeanLengths(Gender.FEMALE).getMeanWithoutZero() > 0.) {
nb++;
sum += riverBasin.getSpawnersForFirstTimeMeanLengths(Gender.FEMALE).getMeanWithoutZero();
......@@ -216,6 +222,45 @@ public class AnalyseSpawnerFeatures extends AquaNismsGroupProcess<DiadromousFish
}
public double getMeanLengthOfMatureFish(DiadromousFishGroup group) {
double sumOfLength = 0.;
double numberOfMatureFish = 0.;
for (Basin basin : group.getEnvironment().getBasins()) {
if (basin.getFishs(group) != null) {
for (DiadromousFish fish : basin.getFishs(group)) {
if (fish.isMature()) {
sumOfLength += fish.getAmount() * fish.getLength();
numberOfMatureFish += fish.getAmount();
}
}
}
}
return sumOfLength / numberOfMatureFish;
}
public double getStandardDeviationOfMatureFishLength(DiadromousFishGroup group) {
double standardDeviationOfMatureFishLength = 0.;
double sumOfSquareLength = 0.;
double numberOfMatureFish = 0.;
double meanOfSquareLengthOfMatureFish = 0.;
for (Basin basin : group.getEnvironment().getBasins()) {
if (basin.getFishs(group) != null) {
for (DiadromousFish fish : basin.getFishs(group)) {
if (fish.isMature()) {
sumOfSquareLength += fish.getAmount() * fish.getLength() * fish.getLength();
numberOfMatureFish += fish.getAmount();
}
}
}
meanOfSquareLengthOfMatureFish = sumOfSquareLength / numberOfMatureFish;
double meanLength = getMeanLengthOfMatureFish(group);
standardDeviationOfMatureFishLength = Math.sqrt(meanOfSquareLengthOfMatureFish - meanLength * meanLength);
}
return standardDeviationOfMatureFishLength;
}
public String[][] exportToR() {
int nbBasin = ageOfFemaleMemories.size();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment