Compare commits
2 Commits
08.04.06-F
...
cbc5dc9e49
| Author | SHA1 | Date | |
|---|---|---|---|
| cbc5dc9e49 | |||
| 8e75323e99 |
@@ -1,15 +1,20 @@
|
|||||||
package ecoparasite;
|
package ecoparasite;
|
||||||
|
|
||||||
|
import ecoparasite.completion.Completion;
|
||||||
import ecoparasite.input.InputFactory;
|
import ecoparasite.input.InputFactory;
|
||||||
import ecoparasite.input.InputFileException;
|
import ecoparasite.input.InputFileException;
|
||||||
import ecoparasite.input.RawData;
|
import ecoparasite.input.RawData;
|
||||||
import ecoparasite.input.RawDataOverflow;
|
import ecoparasite.input.RawDataOverflow;
|
||||||
|
import ecoparasite.nettoyage.Nettoyage;
|
||||||
|
import ecoparasite.poisson.Poisson;
|
||||||
import ecoparasite.population.Population;
|
import ecoparasite.population.Population;
|
||||||
import ecoparasite.population.PopulationArgInterval;
|
import ecoparasite.population.PopulationArgInterval;
|
||||||
import ecoparasite.population.PopulationArgs;
|
import ecoparasite.population.PopulationArgs;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class LectureEval {
|
public class LectureEval {
|
||||||
|
|
||||||
@@ -90,6 +95,28 @@ public class LectureEval {
|
|||||||
System.out.println(p);
|
System.out.println(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Complétion de la masse.
|
||||||
|
Function<Population,Double> getWeight = population -> {
|
||||||
|
return population.getTotal().getWidth() != null ? population.getTotal().getWidth().transformToDouble() : null;
|
||||||
|
};
|
||||||
|
BiConsumer<Population,Double> setWeight = (population, aDouble) -> {
|
||||||
|
population.getTotal().setWidth(new PopulationArgInterval(aDouble,aDouble));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Complétion de la masse.
|
||||||
|
pop = Completion.completeColumnsMoyenne(pop, getWeight, setWeight);
|
||||||
|
System.out.println("---");
|
||||||
|
for( Population p: pop){
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nettoyage de la masse.
|
||||||
|
pop = Nettoyage.nettoieColumnsMoyenne(pop, getWeight, setWeight, false);
|
||||||
|
System.out.println("---");
|
||||||
|
for( Population p: pop){
|
||||||
|
System.out.println(p);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,17 +15,18 @@ import java.util.function.Function;
|
|||||||
public class Nettoyage {
|
public class Nettoyage {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de remplacer les valeurs inexistantes d'un paramètre d'un HashSet par la moyenne des autres valeurs (non nulles).
|
* Permet de remplacer les valeurs abérrantes d'un paramètre d'un HashSet par la moyenne des autres valeurs (non nulles).
|
||||||
* Exemple d'utilisation : T = Poisson, V = Double, getValue = Poisson::getInfestation, setValue = Poisson::setInfestation.
|
* Exemple d'utilisation : T = Poisson, V = Double, getValue = Poisson::getInfestation, setValue = Poisson::setInfestation.
|
||||||
*
|
*
|
||||||
* @param list La liste de données cobaye.
|
* @param list La liste de données cobaye.
|
||||||
* @param getValue La fonction (Getter) qui permet d'obtenir la valeur que l'on veut vérifier
|
* @param getValue La fonction (Getter) qui permet d'obtenir la valeur que l'on veut vérifier
|
||||||
* @param setValue La fonction (Setter) qui permet de remplacer la valeur si null.
|
* @param setValue La fonction (Setter) qui permet de remplacer la valeur si null.
|
||||||
|
* @param allowNegative Savoir si une valeur négative est forcément aberrant.
|
||||||
* @return Le HashSet avec les valeurs remplacés.
|
* @return Le HashSet avec les valeurs remplacés.
|
||||||
* @param <T> Le type de données cobaye. Exemple : Poisson, Population
|
* @param <T> Le type de données cobaye. Exemple : Poisson, Population
|
||||||
* @param <V> Le type de la donnée à vérifier, doit être un Wrapper Number. Exemple : Double.
|
* @param <V> Le type de la donnée à vérifier, doit être un Wrapper Number. Exemple : Double.
|
||||||
*/
|
*/
|
||||||
public static <T,V extends Number> HashSet<T> nettoieColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue ){
|
public static <T,V extends Number> HashSet<T> nettoieColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue, boolean allowNegative ){
|
||||||
|
|
||||||
Double mean = Completion.calculateMean(list, getValue);
|
Double mean = Completion.calculateMean(list, getValue);
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ public class Nettoyage {
|
|||||||
Double IQR = thirdQuart - firstQuart;
|
Double IQR = thirdQuart - firstQuart;
|
||||||
|
|
||||||
for(T item : list){
|
for(T item : list){
|
||||||
if( getValue.apply(item).doubleValue() < firstQuart - (IQR * 1.5) || getValue.apply(item).doubleValue() > thirdQuart + (IQR * 1.5)){
|
if( getValue.apply(item).doubleValue() < firstQuart - (IQR * 1.5) || getValue.apply(item).doubleValue() > thirdQuart + (IQR * 1.5) || ( !allowNegative && getValue.apply(item).doubleValue() < 0 ) ){
|
||||||
setValue.accept( item, (V) mean);
|
setValue.accept( item, (V) mean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,5 +53,20 @@ public class Nettoyage {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Polymorphisme de la fonction précédente. Autorise les valeurs abérrantes à être négative.
|
||||||
|
* @param list
|
||||||
|
* @param getValue
|
||||||
|
* @param setValue
|
||||||
|
* @return
|
||||||
|
* @param <T>
|
||||||
|
* @param <V>
|
||||||
|
*
|
||||||
|
* @see Nettoyage::nettoieColumnsMoyenne
|
||||||
|
*/
|
||||||
|
public static <T,V extends Number> HashSet<T> nettoieColumnsMoyenne(HashSet<T> list, Function<T,V> getValue, BiConsumer<T,V> setValue){
|
||||||
|
return nettoieColumnsMoyenne(list, getValue, setValue, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,10 +187,10 @@ public class PopulationArgs {
|
|||||||
return String.format( "Année: %d, N: %d, Length: %f, Width: %f, Prevalence: %f, IC: %f, Intensity: %f, Abondance: %f, Zone: %s",
|
return String.format( "Année: %d, N: %d, Length: %f, Width: %f, Prevalence: %f, IC: %f, Intensity: %f, Abondance: %f, Zone: %s",
|
||||||
this.year,
|
this.year,
|
||||||
this.number,
|
this.number,
|
||||||
this.length != null ? this.length.transformToDouble() : 0.0,
|
this.length != null ? this.length.transformToDouble() : null,
|
||||||
this.width != null ? this.width.transformToDouble() : 0.0,
|
this.width != null ? this.width.transformToDouble() : null,
|
||||||
this.prevalence != null ? this.prevalence.transformToDouble() : 0.0,
|
this.prevalence != null ? this.prevalence.transformToDouble() : null,
|
||||||
this.ic != null ? this.ic.transformToDouble() : 0.0,
|
this.ic != null ? this.ic.transformToDouble() : null,
|
||||||
this.intensity,
|
this.intensity,
|
||||||
this.abondance,
|
this.abondance,
|
||||||
this.zone
|
this.zone
|
||||||
|
|||||||
Reference in New Issue
Block a user