Commit 40227258 authored by pfreon's avatar pfreon
Browse files

Modification majeures: Inclusion test Fisher sur R2, rajout R2 et AIC...

Modification majeures: Inclusion test Fisher sur R2, rajout R2 et AIC corrigés, correction AIC, format scientifique résultats

 Inclusion test Fisher sur R2 avec tables de fisher.
Rajout R2 corrigé et AIC corrigé.
Correction AIC.
Format  scientifiue pour résultats chiffres trés grands ou très petits.
Changement mineurs sur titres ou entêtes
parent aa8a9ff9
......@@ -82,32 +82,49 @@ public class CadreMain extends JFrame {
initWin();
Global.init();
Global.CadreMain = this;
System.out.println(Global.pfisher(7.5, 2, 9));
readConfig();
InputStream inRegle = CadreMain.class.getResourceAsStream("resources/regles.csv");
if (inRegle == null) {
MsgDialogBox msg = new MsgDialogBox(0, "FATAL ERROR\nFile regles.csv not found", 0, this);
System.exit(0);
}
InputStream inComment = CadreMain.class.getResourceAsStream("resources/Comment.csv");
if (inComment == null) {
MsgDialogBox msg = new MsgDialogBox(0, "FATAL ERROR\nFile Comment.csv not found", 0, this);
System.exit(0);
}
TexteRegles.initScript(inRegle, inComment);
InputStream inRep = CadreMain.class.getResourceAsStream("resources/Arbre_decisions.csv");
if (inRep == null) {
MsgDialogBox msg = new MsgDialogBox(0, "FATAL ERROR\nFile Arbre_decisions.csv not found", 0, this);
System.exit(0);
}
QuestionReponse.initScript(inRep);
InputStream inMod = CadreMain.class.getResourceAsStream("resources/ListeModele.csv");
if (inMod == null) {
MsgDialogBox msg = new MsgDialogBox(0, "FATAL ERROR\nFile ListeModele.csv not found", 0, this);
System.exit(0);
}
RechercheModele.initScript(inMod);
//System.out.println(Global.datafilePath);
InputStream inFisher_p_01 = CadreMain.class.getResourceAsStream("resources/TableFisherSnedecor_p_0.01.csv");
if (inFisher_p_01 == null) {
MsgDialogBox msg = new MsgDialogBox(0, "FATAL ERROR\nFile TableFisherSnedecor_p_0.01.csv not found", 0, this);
System.exit(0);
}
//Global.initScript(inFisher_p_01);
InputStream inFisher_p_05 = CadreMain.class.getResourceAsStream("resources/TableFisherSnedecor_p_0.05.csv");
if (inFisher_p_01 == null) {
MsgDialogBox msg = new MsgDialogBox(0, "FATAL ERROR\nFile TableFisherSnedecor_p_0.05.csv not found", 0, this);
System.exit(0);
}
Global.initScript(inFisher_p_01, inFisher_p_05);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -271,7 +288,7 @@ public class CadreMain extends JFrame {
});
menuPlotThreeVariate.setEnabled(false);
menuPlotThreeVariate.setMnemonic(KeyEvent.VK_T);
menuPlotThreeVariate.setText("Three-variate plots");
menuPlotThreeVariate.setText("CPUE=f() & Y=() plots");
menuPlotThreeVariate.addActionListener(new java.awt.event.ActionListener() {
@Override
......@@ -669,7 +686,7 @@ public class CadreMain extends JFrame {
if (Global.CadreThreeVariatePlots == null) {
Cadre_Plot dlg;
dlg = new Cadre_Plot(Global.variatePlot);
dlg.setTitle("Climprod: Three variates plots");
dlg.setTitle("Climprod: CPUE=f() & Y=() plots");
dlg.setVisible(true);
Global.CadreThreeVariatePlots = dlg;
} else {
......@@ -681,7 +698,7 @@ public class CadreMain extends JFrame {
if (Global.CadreMSPlots == null) {
Cadre_Plot dlg;
dlg = new Cadre_Plot(Global.msyPlot);
dlg.setTitle("Climprod: Msy & MS_E plots");
dlg.setTitle("Climprod: MSY & MSE plots");
dlg.setVisible(true);
Global.CadreMSPlots = dlg;
} else {
......@@ -783,7 +800,7 @@ public class CadreMain extends JFrame {
String faits = "";
DecimalFormat nf = new DecimalFormat(" 0.00");
DecimalFormat nf2= new DecimalFormat(" 0.000000;-0.000000");
Global.Res_Test_Jackknife_Par = new int[Validation.nbre_par]; // Rajout 2020.
Global.Res_Test_Jackknife_Par = new int[4]; // Rajout 2020.
if (Global.nom_fichier != null) {
faits = "Data file path:" + Global.nom_fichier + s + s;
......@@ -838,22 +855,18 @@ public class CadreMain extends JFrame {
}
faits = faits + s;
}
if (Global.validationOk)
{ faits=faits + s + "Parameters Jackknife t-ratio test result";
Validation.getParamResult();
{
Validation.valide_modele();
Validation.getParamResult();
faits=faits + s + "Parameters Jackknife t-ratio test result";
for(int i=0;i<Validation.nbre_par;i++)
{faits=faits + s + " " + Global.param$[i]+ " " + Global.Test_Jackknife_Param$[Global.Res_Test_Jackknife_Par[i]];
//faits=faits + s + " " + Global.param$[i]+ " " + data$[i+1][0]=Global.param$[i]+ " " + Validation.Test_Jackknife_Param$[Validation.Res_Test_Jackknife_Par[i]];
}
{faits=faits + s + " " + Global.param$[i]+ " " + Global.Test_Jackknife_Param$[Global.Res_Test_Jackknife_Par[i]];
}
if (Global.test_jackknife)
{faits = faits + s + "Overall T_Jackknife on parameters: good" + s;}
else {faits = faits + s + "Overall T_Jackknife on parameters: bad" + s;}
faits = faits + s + "Jackknife coefficient of determination R²: " + nf.format(Global.jackknife) + s;
faits = faits + s + "Fisher test of R² for F(" + getNbDataRetenue() + "," + Global.nbre_param +") : "+
Global.pfisher(Global.coeff_determination, getNbDataRetenue(), Global.nbre_param);
faits = faits + s + "Fisher threshold : "+
nf2.format(Global.fF(Global.coeff_determination, getNbDataRetenue(), Global.nbre_param));
faits = faits + s + "Jackknife coefficient of determination R²: " + nf.format(Global.jackknife) + s;
}
}
......
......@@ -175,7 +175,7 @@ public class Cadre_ModeleDirect extends JFrame {
//gridLayout3.setColumns(2);
//gridLayout3.setHgap(5);
jScrollPane4.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(142, 142, 142)), "Validation:Main results"));
jScrollPane4.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(142, 142, 142)), "Validation: Jackknife main results"));
this.getContentPane().add(jPanChoix, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 0, 0, 5), 0, 0));
jPanChoix.add(jPanCmdChoix, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 5), 0, 0));
......@@ -558,6 +558,7 @@ private void displayList(String[] liste) {
Global.recruitment_age = -1;
Global.begin_influence_period = -1;
Global.end_influence_period = -1;
Global.modelisationOk = false;
Global.nb_classes_exploitees = jcboExploitedYears.getSelectedIndex() + 1;
if (jcboRecrutement.isEnabled()) {
......@@ -601,6 +602,8 @@ in the QuestionReponse.java file, cases 17, 52 & 58.
} catch (Exception ee) {
new MsgDialogBox(0, ee.getMessage(), 0, Global.CadreMain);
}
if (Global.begin_influence_period == -1) Global.begin_influence_period = 0; // Change for consistency in loops of models with effect on catchability only
if (Global.end_influence_period == -1) Global.end_influence_period = 0; // Change for consistency in loops of models with effect on catchability only
Global.numero_modele = RechercheModele.getNumero();
Global.typeModele = RechercheModele.getType();
Modele.Estimer();
......
......@@ -19,6 +19,8 @@ public class Configuration {
static String arbrePathName = "";
static String commentPathName = "";
static String modelePathName = "";
static String TableFisher_p_01PathName = "";
static String TableFisher_p_05PathName = "";
static String helpPathName = "";
static String userDir = "";
static String userHome = "";
......@@ -79,6 +81,8 @@ public class Configuration {
arbrePathName = applicationPathName + fileSep + "Arbre_decisions.csv";
commentPathName = applicationPathName + fileSep + "Comment.csv";
modelePathName = applicationPathName + fileSep + "ListeModele.csv";
TableFisher_p_01PathName = applicationPathName + fileSep + "TableFisherSnedecor_p_0.01.csv";
TableFisher_p_05PathName = applicationPathName + fileSep + "TableFisherSnedecor_p_0.05.csv";
helpPathName = applicationPathName + fileSep + "help";
File hd = new File(helpPathName);
hd.mkdir();
......@@ -102,6 +106,8 @@ public class Configuration {
out.println("reglePathName|" + reglePathName);
out.println("arbrePathName|" + arbrePathName);
out.println("modelePathName|" + modelePathName);
out.println("TableFisher_p_0.01PathName|" + TableFisher_p_01PathName);
out.println("TableFisher_p_0.05PathName|" + TableFisher_p_05PathName);
out.println("lastPathSource|" + lastPathSource);
out.println("userDir|" + userDir);
out.println("userHome|" + userHome);
......
......@@ -11,12 +11,13 @@ package fr.ird.climprod;
import javax.swing.JFrame;
import java.util.HashMap;
import org.apache.commons.math3.special.Gamma;
import java.io.InputStream;
import java.util.StringTokenizer;
public class Global {
static final String[] influenceEnv = {"", "abundance", "catchability", "both"};//probl�me du both
static JFrame CadreQuestion; //Une seule instance est permise pour l'instant
static JFrame Cadre_Question;
static JFrame CadreModeleDirect;
static JFrame CadreModele;
static JFrame CadreResultats;
......@@ -57,8 +58,8 @@ public class Global {
static int decreasing_relationship; // Does this plot appear to be decreasing
static int effort_preponderant; // Is the influence of fishing effort on CPUE more important than environmental influence
/**
* ************************************
/*
* *********Réponses aux questions***************************
*/
static int climatic_influence;
static int linear_relationship; // Does this plot look linear
......@@ -83,15 +84,16 @@ public class Global {
static int sous_stock_isole; // Is the sub-stock well isolated, (i.e. with few exchanges) from others
static int stock_deja_effondre; // Did the stock already collapse or exhibit drastic decrease(s) in catches
static int pessimiste; // Do you have any (additional) reason to expect highly unstable behaviour or collapse of the stock
static int cpue_sous_sur_production; // May the stock present large fluctuations in CPUE when overexploited
static double jackknife;
/*
* *********Validation***************************
*/
static double jackknife, fF;
static boolean test_jackknife;
static String [] param$={"a","b","c","d"}; // Rajout 2020.
static String[] Test_Jackknife_Param$={" (good)"," (bad)"}; // Rajout 2020.
static int Res_Test_Jackknife_Param; // Rajout 2020.
static int[] Res_Test_Jackknife_Par = new int[5]; // Rajout 2020. int[] a = new int[1];
static int[] Res_Test_Jackknife_Par = new int[4]; // Rajout 2020. int[] a = new int[1];
static int coeff_determination_instable; // Reasonable jackknife coefficient R2 (>65% recommended), no extreme yearly coefficient, and acceptable MSY graph
static int acceptable_graphs; // Graphs MSY & MSE acceptable
/**
......@@ -117,13 +119,13 @@ public class Global {
static int numero_modele; // Current model
static int nbre_param; // Number of parameters
static double[] val_param; // Value of parameters
static double coeff_determination; //R2
static double critereAIC; //Akeike
static double coeff_determination; // R2
static double corrected_R2; // corrected R2 according to the number of variables
static double critereAIC; // Akaike
static double critereAIC_Corr; // Akaike
static boolean validationOk; // true si Validation ex�cut�e
static boolean modelisationOk; // true si mod�le ajust�
static int Compteur_erreurs_Jackknife; // Rajout 2020.
static int[] Nb_years_lower100; // Rajout 2020.
static int [] Nb_years_greater100; // Rajout 2020.
static String Texte_erreur_jackknife$; // Rajout 2020.
/**
......@@ -131,7 +133,7 @@ public class Global {
*/
//static int[] typePlot = {2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 2, 2,2,2,2,2};
//static Hashtable htPlot=new Hashtable();
static String[] titreG = {"E Time Plot", "V Time Plot", "Y Time Plot", "CPUE Time Plot", "E Distribution", "V Distribution", "Y Distribution", "CPUE Distribution", "Y vs E (unlagged)", "Y vs V (unlagged)", "CPUE vs E (unlagged)", "CPUE vs V (unlagged)", "CPUE versus E (E weighted if relevant)", "CPUE versus V (V lagged if relevant)","E versus V (unlagged)", "Observed and Fitted CPUE (lag effect if relevant)", "Time Plot of residual CPUE (lag effect if relevant)", "Residual CPUE versus E (E weighted if relevant)", "Residual CPUE versus V (V lagged and weighted if relevant)", "a (%) Time Plot (lag effect if relevant)", " b (%) Time Plot (lag effect if relevant)", "c (%) Time Plot (lag effect if relevant)", "d (%) Time Plot (lag effect if relevant)", "Plot R2 (% of %) Time Plot", "Function Y=f(V & E) (lagged if relevant)", "Function Y=f(V & E) (E weighted if relevant)", "Function CPUE=f(V & E)(E weighted if relevant)", "Function CPUE=f(V & E) (E weighted if relevant)", "MSY versus V", "MSE versus V"};
static String[] titreG = {"E Time Plot", "V Time Plot", "Y Time Plot", "CPUE Time Plot", "E Distribution", "V Distribution", "Y Distribution", "CPUE Distribution", "Y vs E (unlagged)", "Y vs V (unlagged)", "CPUE vs E (unlagged)", "CPUE vs V (unlagged)", "CPUE versus E (E weighted if relevant)", "CPUE versus V (V lagged if relevant)","E versus V (unlagged)", "Observed and Fitted CPUE (lag effect if relevant)", "Time Plot of residual CPUE (lag effect if relevant)", "Residual CPUE versus E (E weighted if relevant)", "Residual CPUE versus V (V lagged and weighted if relevant)", "a (%) Time Plot (lag effect if relevant)", " b (%) Time Plot (lag effect if relevant)", "c (%) Time Plot (lag effect if relevant)", "d (%) Time Plot (lag effect if relevant)", "Plot R2 (%) Time Plot", "Function Y=f(V & E) (lagged if relevant)", "Function Y=f(V & E) (E weighted if relevant)", "Function CPUE=f(V & E)(E weighted if relevant)", "Function CPUE=f(V & E) (E weighted if relevant)", "MSY versus V", "MSE versus V"};
static String[] titreSx = {"Year", "Year", "Year", "Year", "Classes", "Classes", "Classes", "Classes", "Effort (E)", "Environment (V)", "Effort (E)", "Environment (V)", "Environment (V)", "Year", "Year", "Effort (E)", "Environment (V)", "Year", "Year", " Year", "Year", "Year", "Weighted effort (E)", "Weighted effort (E)", "Weighted effort (E)", " Weighted effort (E)", "Environment (V)", "Environment (V)"};
static String[] titreSy = {"Effort (E)", "Environment (V)", "Production (Y)", "CPUE ", "Nb", "Nb", "Nb", "Nb", "Production (Y)", "Production (Y)", "CPUE", "CPUE", "CPUE", "CPUE", " Residual", "Residual", "Residual", "a (%)", "b (%)", "c (%)", "d (%)", "R² (%)", "Production (Y)", "Production (Y)", "CPUE", "CPUE", "MSY", "MSE"};
......@@ -257,6 +259,7 @@ public class Global {
nbre_param = 0; // Number of parameters
coeff_determination = 0; //R2
critereAIC = 0;
critereAIC_Corr = 0;
modelisationOk = false;
validationOk = false; // true si Validation ex�cut�e
//bavard=true;
......@@ -268,25 +271,70 @@ public class Global {
public static double gam(double x){
return(Gamma.gamma(x));
}
// Calcul du F de Fisher rajouté par Julien Veyssier
// f(x) = Γ((n1 + n2)/2) / (Γ(n1/2) Γ(n2/2)) (n1/n2)^(n1/2) x^(n1/2 - 1) (1 + (n1/n2) x)^-(n1 + n2)/2 Formule donnée par PF à Julien Veyssier le 21/03/2016
public static double pfisher(double x, double n1, double n2){
//double n1 = 2;
//double n2 = 9;
return(
gam((n1 + n2)/2) /
(gam(n1/2) * gam(n2/2)) *
java.lang.Math.pow( (n1/n2), (n1/2) ) *
java.lang.Math.pow(x, (n1/2) - 1 ) *
java.lang.Math.pow(1 + (n1/n2)* x, -(n1 + n2)/2)
);
}
// Lecture tables de Fisher
// F=(R²(n-p-1)) / (p(1-R²)
// F = (r_tot*(nim-nbre_par-1))/(nbre_par*(1-r_tot))
public static double fF(double R2, double n, double p){
return(
(R2*(n-p-1)) / (p*(1-R2))
);
public static double[][] TableFisher_p_01;
public static double[][] TableFisher_p_05;
private static boolean existFile = false;
public static void initScript(InputStream file, InputStream fileFisher_p_05)
{ // Lecture fichier TableFisherSnedecor_p_0.01.csv
existFile = false;
try {
String[] dataLine;
ReadFileText rft = new ReadFileText(file);
dataLine = rft.getLines();
TableFisher_p_01 = new double[100][4];
if (dataLine != null) //Lecture ok
{
StringTokenizer t = new StringTokenizer(dataLine[0], ";");
if (t.countTokens() != 4) {
throw new OnError("Invalid Fisher's table p 0.01 data file.");
}
for (int i = 0; i < 100; i++) {
StringTokenizer d = new StringTokenizer(dataLine[i], ";");
if (d.countTokens() != 4) {
throw new OnError("Invalid Fisher's table p 0.01 data file.");
}
int k = 0;
while (d.hasMoreTokens()) {
TableFisher_p_01[i][k] = Double.parseDouble(d.nextToken().trim());
k = k + 1;
}
}
}
existFile = true;
ReadFileText rft2 = new ReadFileText(fileFisher_p_05);
dataLine = rft2.getLines();
TableFisher_p_05 = new double[100][4];
if (dataLine != null) //Lecture ok
{
StringTokenizer t = new StringTokenizer(dataLine[0], ";");
if (t.countTokens() != 4) {
throw new OnError("Invalid Fisher's table p 0.05 data file.");
}
for (int i = 0; i < 100; i++) {
StringTokenizer d = new StringTokenizer(dataLine[i], ";");
if (d.countTokens() != 4) {
throw new OnError("Invalid Fisher's table p 0.05 data file.");
}
int k = 0;
while (d.hasMoreTokens()) {
TableFisher_p_05[i][k] = Double.parseDouble(d.nextToken().trim());
k = k + 1;
}
}
}
existFile = true;
}
catch (Exception e) {
MsgDialogBox msg = new MsgDialogBox(0, e.getMessage(), 0, Global.CadreMain);
}
}
public static double fF(double R2, double p, double n){ // Fisher Fcalc; p = nombre de paramètres autres que constante (a en général)
return((R2/p)/((1 - R2) / (n-p-1)));
}
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ package fr.ird.climprod;
import static fr.ird.climprod.Data.getNbDataRetenue;
import static fr.ird.climprod.Data.getNbYears; // Addition 2020.
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.awt.Color;
public class Modele {
......@@ -22,12 +23,13 @@ public class Modele {
static final private double eps = 1.E-8;
static final private double mul = 1.E-3;
static private int nim;
static private int nimTabFish;
static private int nbYears; // Addition 2020.
static private double lambda;
static private int nbre_par;
static private int riter, iter, ritertot;
static private double val_init, val_fin, ecart;
static private double r, sompar, variance_pue, yy, aic;
static private double r, sompar, variance_pue, yy, aic, aic_corr;
static private double[] ptmp;
static private double[][] covar;
......@@ -90,18 +92,25 @@ public class Modele {
}
r = (1. - sompar / variance_pue);
// System.out.println("r = " + r + " nim = " + nim + " nbre_par = " + nbre_par);
Global.corrected_R2 = 1. - (((double)nim - 1.) / ((double)nim - (double)nbre_par)) * (1. - r); // Addition 2020
System.out.println("Global.corrected_R2 = " + Global.corrected_R2 + " r = " + r + " nim = " + nim + " nbre_par = " + nbre_par);
//System.out.println("sompar 3 = " + sompar+" r = " + r);
if (r < 0) {
r = 0;
}
if (r == 0){
message = "R2 is set to zero due to unexpected results in the variances (residual variance or total variance) computation. This is possibly due to poor fitting by the Marquart algorithm.";
message = "R2 is set to zero due to unexpected results in the variances (residual variance or total variance) computation. \nThis is possibly due to poor fitting by the Marquart algorithm.";
MsgDialogBox msg = new MsgDialogBox(0, message, 1, Global.CadreMain);
}
//System.out.println("Variance " + variance_pue);
if (Global.corrected_R2 < 0) {
Global.corrected_R2 = 0;
}
//System.out.println("Variance " + variance_pue);
// System.out.println("Variance r�siduelle " + sompar);
// System.out.println("R� " +r);
aic = AICritere();
aic_corr = AICritereCorr();
Global.nbre_param = nbre_par;
Global.val_param = new double[nbre_par];
// System.out.println( "Apr�s marquard");
......@@ -110,6 +119,7 @@ public class Modele {
}
Global.coeff_determination = r;
Global.critereAIC = aic;
Global.critereAIC_Corr = aic_corr;
// for(int i=0;i<nim;i++)
// System.out.println("********"+res[i]);
calc_residus();
......@@ -820,11 +830,20 @@ public class Modele {
private static double AICritere() {
double sse = somme_residus(par_alors);
return nim * Math.log((sse / (nim + 1.E-15)) + 1.E-15) + 2 * nbre_par + nim;
double sse = somme_residus(par_alors); // Residual deviance
// return nim * Math.log((sse / (nim + 1.E-15)) + 1.E-15) + 2 * nbre_par + nim;
// return nim * Math.log((sse / (double)nim )) + 2 * nbre_par + nim;
// return Math.log(Math.pow(sse, 2.)) + (2. * nbre_par / (double)nim);
System.out.println("variance_pue = " + variance_pue + " sse = " + somme_residus(par_alors) + " nim = " + nim);
return (double)nim * Math.log(sse) + (2. * (double)nbre_par);
}
private static double AICritereCorr() {
double sse = somme_residus(par_alors); // Residual deviance
return (double)nim * Math.log(sse) + (2. * (double)nbre_par) + ((2.* (double)nbre_par * ((double)nbre_par + 1.)) / ((double)nim - (double)nbre_par - 1.));
// Alternative equation (same result) : return (double)nim * Math.log(sse) + (2. * (double)nbre_par) + ((((2.* (double)nbre_par) * (double)nbre_par) + 2 * (double)nbre_par) / ((double)nim - (double)nbre_par - 1.));
}
private static void makePlot() {
/**
* ***************** cpue plot *****************************
......@@ -1016,22 +1035,27 @@ public class Modele {
Donne les principaux r�sultats dans fenetre "Fit a model directly", sous fenetre de gauche "Modelization: Main results, y compris Akaike
*/
public static Object[][] getResult() {
nimTabFish = Data.getNbDataRetenue();
if (nimTabFish > 100) nimTabFish = 100;
if (!Global.modelisationOk) {
return null;
}
String[] param$ = {" a ", " b ", " c ", " d "};
String[] title$ = {"Parameters ", "Actual value ", "Initial value"};
Object[][] data$ = new String[nbre_par + 9][3];
DecimalFormat nf = new DecimalFormat(" 0.000000;-0.000000");
Object[][] data$ = new String[nbre_par + 11][3];
DecimalFormat nf = new DecimalFormat(" 0.0000;-0.0000");
DecimalFormat nf2 = new DecimalFormat(" 0.00;-0.00");
NumberFormat numFormat = new DecimalFormat();
numFormat = new DecimalFormat("0.####E0");
for (int j = 0; j < 3; j++) {
data$[0][j] = title$[j];
}
for (int i = 0; i < nbre_par; i++) {
data$[i + 1][0] = param$[i];
data$[i + 1][1] = nf.format(par_alors[i]); // Valeur paramètre estimé fin Marquart
data$[i + 1][2] = nf.format(par_init[i]); // Valeur initiale du paramètre début Marquart
if ((par_alors[i] < 0.001 && par_alors[i] > 0) || par_alors[i] > 999.999 || par_alors[i] < 1.0E-3) data$[i + 1][1] = numFormat.format(par_alors[i]);
else data$[i + 1][1] = nf.format(par_alors[i]); // Valeur paramètre estimé fin Marquart
if ((par_init[i] < 0.001 && par_init[i] > 0) || par_init[i] > 999.999 || par_init[i] < 1.0E-3) data$[i + 1][2] = numFormat.format(par_init[i]);
else data$[i + 1][2] = nf.format(par_init[i]); // Valeur paramètre estimé fin Marquart
}
data$[nbre_par + 1][0] = "Nb. of data used to fit"; // Dans ce qui suit, la seconde dimension de data$ indique qu'il s'agit soit d'un titre ([0]) soit de la valeur correspondante ([0]). Commentaire 2020.
data$[nbre_par + 1][1] = Integer.toString(nim); // nim = nombre observations
......@@ -1040,20 +1064,36 @@ public class Modele {
data$[nbre_par + 3][0] = "Coefficient of determination R²";
data$[nbre_par + 3][1] = nf2.format(r);
System.out.println("r : "+r+" et globalr : "+Global.coeff_determination);
data$[nbre_par + 4][0] = "Fisher test of R² for F(" + getNbDataRetenue() + "; " + Global.nbre_param +")"; // Donne entre parenthèses les valeurs du nombre d'observation et de paramètres du modèle pour le test de Fisher sur R2
data$[nbre_par + 4][1] = nf.format(Global.pfisher(Global.coeff_determination, getNbDataRetenue(), Global.nbre_param)); // Valeur tirée du tableau à 3D Global.pfisher
data$[nbre_par + 5][0] = "Fisher threshold";
data$[nbre_par + 5][1] = nf.format(Global.fF(Global.coeff_determination, getNbDataRetenue(), Global.nbre_param));
data$[nbre_par + 6][0] = "Akaike's Information Criterion ";
data$[nbre_par + 6][1] = nf.format(aic);
data$[nbre_par + 7][0] = "Variance ";
data$[nbre_par + 7][1] = nf.format(variance_pue);
data$[nbre_par + 8][0] = "Residual Variance ";
data$[nbre_par + 8][1] = nf.format(sompar);
// System.out.println("r : "+r+" et globalr : "+Global.coeff_determination); // r = Global.coeff_determination ligne 111
Global.fF = Global.fF(Global.coeff_determination, (Global.nbre_param - 1), getNbDataRetenue());
//System.out.println("fF Model = " + Global.fF);
data$[nbre_par + 4][0] = "Fisher test on R²: F(" + (Global.nbre_param -1) + "; " + (getNbDataRetenue() - Global.nbre_param) +")"; // Contrairement à p dans fF de Global.java dernière methode, nbre_param inclus la constante (a en général). D'où la soustraction de 1.
// F(x,y) Donne entre parenthèses les valeurs du nombre d'observation et de paramètres du modèle pour le test de Fisher sur R2
if ((Global.fF < 0.001 && Global.fF > 0) || Global.fF> 999.999 || Global.fF < 1.0E-3) data$[nbre_par + 4][1] = numFormat.format(Global.fF);
else data$[nbre_par + 4][1] = nf.format( Global.fF);
data$[nbre_par+5][0]= "Fisher test on R²: p-value";
if (Global.fF < (Global.TableFisher_p_05 [nimTabFish- Global.nbre_param - 1][Global.nbre_param - 1 - 1])) // The last -1 term is here to compensate the fact that table indices start at 0 and not at 1.
data$[nbre_par+5][1]= " >0.05";
else
if (Global.fF >= Global.TableFisher_p_05 [nimTabFish - Global.nbre_param - 1][Global.nbre_param - 1 - 1] && Global.fF < Global.TableFisher_p_01 [nimTabFish - Global.nbre_param - 1][Global.nbre_param - 1 -1])
data$[nbre_par+5][1]= " <0.05";
else
data$[nbre_par+5][1]= " <0.01";
data$[nbre_par + 6][0] = "Corrected R² ";
data$[nbre_par + 6][1] = nf2.format(Global.corrected_R2);
data$[nbre_par + 7][0] = "AIC ";
if (aic < 0.001 && aic > 0) data$[nbre_par +7][1] = numFormat.format(aic);
else data$[nbre_par +7][1] = nf.format(aic);
data$[nbre_par + 8][0] = "Corrected AIC ";
if (aic_corr < 0.001 && aic_corr > 0) data$[nbre_par +8][1] = numFormat.format(aic_corr);
else data$[nbre_par +8][1] = nf.format(aic_corr);
data$[nbre_par + 9][0] = "Variance ";
if (variance_pue < 0.001 && variance_pue > 0) data$[nbre_par +9][1] = numFormat.format(variance_pue);
else data$[nbre_par +9][1] = nf.format(variance_pue);
data$[nbre_par + 10][0] = "Residual Variance ";
if (sompar < 0.001 && sompar > 0) data$[nbre_par +10][1] = numFormat.format(sompar);
else data$[nbre_par +10][1] = nf.format(sompar);
return data$;
......
......@@ -279,12 +279,12 @@ public class QuestionReponse {
break;
case 17:
Global.nb_classes_exploitees = index;
if (Global.nb_classes_exploitees > 5 && Global.nb_classes_exploitees < 9) {
throw new OnError("WARNING! \nA stock with more than 5 significantly exploited year-classes is not ideal for applying \nsurplus production models that make use of the transition prediction approach (past-effort-averaging) of \nFox (1975). This method is used in CLIMPROD to fit data on non-equilibrium conditions. It simulates the \nequilibrium by using a weighted average of fishing effort (E). \nIf interanual variability of E is too large, the results are likely to be uncertain. \nYou can still continue by clickin on the Next(N) button.");
}
if (Global.nb_classes_exploitees > 8) {
if (Global.nb_classes_exploitees > 5 && Global.nb_classes_exploitees < 9) {
throw new OnError("WARNING! \nA stock with more than 5 significantly exploited year-classes is not ideal for applying \nsurplus production models that make use of the transition prediction approach (past-effort-averaging) of \nFox (1975). This method is used in CLIMPROD to fit data on non-equilibrium conditions. It simulates the \nequilibrium by using a weighted average of fishing effort (E). \nIf interanual variability of E is too large, the results are likely to be uncertain. \nYou can still continue by clickin on the Next(N) button.");
}
if (Global.nb_classes_exploitees > 8) {
throw new OnError("WARNING! \nA stock with too many significantly exploited year-classes is not a situation compatible with the use of \nsurplus production models that make use of the transition prediction approach (past-effort-averaging) \nofFox (1975). This method is used in CLIMPROD to fit data on non-equilibrium conditions. It simulate the \nequilibrium by using a weighted average of fishing effort (E). \nIt is recommanded to stop here your research or revise your answer if necessary.");
} Data.init_val();//Pour obtenir la relation en fct du d�calage
} Data.init_val();//Pour obtenir la relation en fct du d�calage
break;
case 18:
Global.relationCPU_E = 0; //Initialisations pour prendre
......@@ -401,7 +401,8 @@ public class QuestionReponse {
Global.begin_influence_period = index - 1;
if (Global.begin_influence_period >= (Global.recruitment_age + Global.nb_classes_exploitees)) {
throw new OnError("If the age at the begining of environmental influence occurs \nafter the age of the last exploited year class \n(that is age at recruitment + number of significantly exploited year classes - 1) \nthen there is no point in using a model incorporating an environmental variable. \nPlease use the 'Previous' button to modify your answer(s)");
}
}
if (Global.begin_influence_period == -1) Global.begin_influence_period = 0; // Change for consistency in loops of models with effect on catchability only
break;
case 53:
case 58:
......@@ -410,7 +411,7 @@ public class QuestionReponse {
throw new OnError("Age at the end of environmental influence must be larger than or equal to \nage at the begining of environmental influence. \nPlease modify your answer(s), using the 'Previous' button when necessary.");
}
if (Global.end_influence_period > (Global.recruitment_age + Global.nb_classes_exploitees - 1)) {
msg = new MsgDialogBox(0, "If the age at the end of environmental influence occurs \nafter the age of the last exploited year class \n(that is age at recruitment + number of significantly exploited year classes - 1) \nthen only its influence on exploited year classes will be taken into account. \nYou can still continue by clickin on the Next(N) button.", 0, Global.Cadre_Question);
msg = new MsgDialogBox(0, "If the age at the end of environmental influence occurs \nafter the age of the last exploited year class \n(that is age at recruitment + number of significantly exploited year classes - 1) \nthen only its influence on exploited year classes will be taken into account. \nYou can still continue by clickin on the Next(N) button.", 0, Global.CadreQuestion);
}
if (Global.recruitment_age >= 0 && Global.begin_influence_period >=0 && Global.end_influence_period < (Global.recruitment_age + Global.nb_classes_exploitees)){
if ((Global.end_influence_period - Global.begin_influence_period) >= 5){
......@@ -422,6 +423,7 @@ public class QuestionReponse {
throw new OnError ("WARNING! \nToo many year classes influenced by the environnement (V). \n\nOwing to a recruitment at age " + Global.recruitment_age + " and " + Global.nb_classes_exploitees + " exploited year classes, and the environmental influence beginning at age " + Global.begin_influence_period + " and ending at age " + Global.end_influence_period + ", \nresults in the need of averaging the environnement effect on " + (Global.recruitment_age + Global.nb_classes_exploitees - Global.begin_influence_period) + " year classes." + "\nYou can still continue by clickin on the Next(N) button.");
}
}
if (Global.end_influence_period == -1) Global.end_influence_period = 0; // Change for consistency in loops of models with effect on catchability only
Data.init_val();
break;
case 95:
......
......@@ -10,12 +10,14 @@
package fr.ird.climprod;
import static fr.ird.climprod.Data.getNbDataRetenue;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.awt.Color;
import java.io.*;
public class Validation {
//public static double[][] stat = new double[10][4]; // Modif 2020
static private int nparmax=4,nv=100; // Modif 2020
static private int nim;
static private int nimTabFish;
static public int jk,nbre_par;
static private int riter,iter,ritertot,maxrit=100;
static private double val_init,val_fin, alpha=4,ecart;
......@@ -241,7 +243,7 @@ public static void valide_modele()
double []f_ms_s=new double[nv];
double []y_ms_m=new double[nv];
double []y_ms_s=new double[nv];
double []vec_y_v=new double[nv];
double []vec_y_v=new double[nv];
double []vec_y_min=new double[nv];
double []vec_y_max=new double[nv];
double []vec_f_v=new double[nv];
......@@ -263,10 +265,7 @@ public static void valide_modele()
//char val[25];
/**************** initialisations ********************/