Commit aa1604d2 authored by pfreon's avatar pfreon
Browse files

Major changes: addition of t-test of Student on jackknife values of...

Major changes: addition of t-test of Student on jackknife values of parameters, change in the criteria used for validation, comments on results tables regarding R²<0 and vhen all yearly jackknife values are > or < 100%.  Addition of BIC criteria

Plus minor changes (addition of comments in the script, change in format, etc.)
parent 99240dee
......@@ -116,14 +116,20 @@ public class CadreMain extends JFrame {
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);
InputStream inStudent = CadreMain.class.getResourceAsStream("resources/TableStudent.csv");
if (inStudent == null) {
MsgDialogBox msg = new MsgDialogBox(0, "FATAL ERROR\nFile TableStudent.csv not found", 0, this);
System.exit(0);
}
Global.initScript(inFisher_p_01, inFisher_p_05, inStudent);
} catch (Exception e) {
e.printStackTrace();
......@@ -859,15 +865,25 @@ public class CadreMain extends JFrame {
{
Validation.valide_modele();
Validation.getParamResult();
if (Global.coeff_determination == 0.0)
faits=faits + s + "*R² estimate was negative and consequently set to zero.\nThis result is due to a poor fitting by the Marquart algorithm\nand it is commonly observed when the model does not include\nan intercept parameter or when the model includes a non-linear function.\nConsequently the display of the jackknife R² graph is not available." + s;
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]];
}
for(int i=0;i<Validation.nbre_par;i++) {
if (Global.Flag_pb_jackknife[i] != 1)
faits=faits + s + " " + Global.param$[i]+ " " + Global.Test_Jackknife_Param$[Global.Res_Test_Jackknife_Par[i]];
else
faits=faits + s + " " + Global.param$[i]+ "** " + Global.Test_Jackknife_Param$[Global.Res_Test_Jackknife_Par[i]];
}
if (Global.Flag_pb_jackknife_Tot != 0) faits=faits + s + Global.message2$;
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;
if(Global.jackknife != 0.00)
faits = faits + s + "Jackknife coefficient of determination R²: " + nf.format(Global.jackknife) + s;
else {
faits = faits + s + "Jackknife coefficient of determination R²***: " + nf.format(Global.jackknife) + s;
faits=faits+s+"***Jackknife R² estimate was negative and consequently set to zero.\nThis result is due to a poor fitting by the Marquart algorithm\nand it is commonly observed when the model does not include\nan intercept parameter or when the model includes a non-linear function.\nConsequently the display of the jackknife R² graph is not available.";
}
}
}
......
......@@ -110,13 +110,16 @@ public class Cadre_Faits extends JFrame {
}
if(Global.validationOk)
{
faits=faits+s+"Jackknife coefficient of determination R²: " +Global.jackknife+s;
if(Global.jackknife != 0.00)
faits=faits+s+"Jackknife coefficient of determination R²: " + Global.jackknife+s;
else
faits=faits+s+"Jackknife coefficient of determination R²***: " + Global.jackknife+s;
faits=faits+s+"***Jackknife R² estimate was negative and consequently set to zero.\nThis result is due to poor fitting by the Marquart algorithm\nand it is commonly observed when the model does not include\nan intercept parameter or when the model includes a non-linear function.\nConsequently the display of the jackknife R² graph is not available.";
if(Global.test_jackknife)
faits=faits+"T_Jackknife: good"+s;
else
faits=faits+"T_Jackknife: bad"+s;
}
}
......
......@@ -456,7 +456,7 @@ public class Cadre_Question extends JFrame
dlgSp.setVisible(false);
dlgSp = null;
}
new MsgDialogBox(0, "The model is validated. \nYou can use this model for prediction \nand display result tables through the 'Modelization' menu. ", 1, this.parent);
new MsgDialogBox(0, "The model is validated. \nYou can use this model for prediction, \ndisplay result tables through the 'Modelization' menu \nand built a folder containing .html and .jpg files of the history \nof all results (graphs & tables) and answers to question \nthrough the 'File' menu.", 1, this.parent);
QuestionReponse.reset();
this.dispose();
......
/**
* Titre : Climprod<p>
* Classe statique qui regroupe l'ensemble des variables globales avec en
* commentaire les questions correspondantes lorsque relevant.
* Donne les titres de certains graphiques et les appelle.
* Calcul du test de Fisher/**
* Titre : Climprod<p>
* Classe statique qui regroupe l'ensemble des variables globales avec en
* commentaire les questions correspondantes lorsque relevant.
......@@ -89,11 +94,13 @@ public class Global {
* *********Validation***************************
*/
static double jackknife, fF;
static String fFsignif$;
static String fFsignif$;
static String message2$ ="";
static int Flag_pb_jackknife_Tot;
static int[] Flag_pb_jackknife=new int[4];
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 String[] Test_Jackknife_Param$={" (p<0.01)"," (p<0.05)"," (p>0.05)"," na"}; // Rajout 2020.
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
......@@ -123,7 +130,8 @@ public class Global {
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 double critereAIC_Corr; // Akaike corrigé
static double critereBIC;
static boolean validationOk; // true si Validation ex�cut�e
static boolean modelisationOk; // true si mod�le ajust�
static int Compteur_erreurs_Jackknife; // Rajout 2020.
......@@ -134,7 +142,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)", "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[] 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)", "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"};
......@@ -273,12 +281,13 @@ public class Global {
return(Gamma.gamma(x));
}
// Lecture tables de Fisher
// Lecture tables de Fisher et Student
public static double[][] TableFisher_p_01;
public static double[][] TableFisher_p_05;
public static double[][] TableFisher_p_05;
public static double[][] TableStudent;
private static boolean existFile = false;
public static void initScript(InputStream file, InputStream fileFisher_p_05)
public static void initScript(InputStream file, InputStream fileFisher_p_05, InputStream fileStudent)
{ // Lecture fichier TableFisherSnedecor_p_0.01.csv
existFile = false;
try {
......@@ -329,6 +338,30 @@ public class Global {
}
}
existFile = true;
ReadFileText rft3 = new ReadFileText(fileStudent); // First column = p<0.05; second p<0.01
dataLine = rft3.getLines();
TableStudent = new double[50][2];
if (dataLine != null) //Lecture ok
{
StringTokenizer t = new StringTokenizer(dataLine[0], ";");
if (t.countTokens() != 2) {
throw new OnError("Invalid Student's table data file.");
}
for (int i = 0; i < 50; i++) {
StringTokenizer d = new StringTokenizer(dataLine[i], ";");
if (d.countTokens() != 2) {
throw new OnError("Invalid Student's table data file.");
}
int k = 0;
while (d.hasMoreTokens()) {
TableStudent[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);
......
......@@ -3,7 +3,7 @@
* Appelle et lance les graphiques serie, bivariees et histogramme pour réponse à questions graphiques
* au debut des questions du menu "Select the appropriate model and fit it".
* Lances ces graphiques
* Ajuste un modèle par l'algorithme de Marquart
* Ajuste un modèle par l'algorithme de Marquart par la méthode marquart() quis se trouve dans Validation.java
*
*/
package fr.ird.climprod;
......@@ -29,7 +29,7 @@ public class Modele {
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, aic_corr;
static private double r,sompar, variance_pue, yy, aic, aic_corr, bic;
static private double[] ptmp;
static private double[][] covar;
......@@ -57,8 +57,8 @@ public class Modele {
Data.init_val();
nim = Data.getNbDataRetenue();
f = Data.getF();
v = Data.getV();
f = Data.getF(); // f = effort (moyenne pondérée si nécessaire)
v = Data.getV(); // v = environnement
vbar = Data.getVbar();
pue = Data.getPue();
res = new double[nim];
......@@ -100,7 +100,7 @@ public class Modele {
r = 0;
}
if (r == 0){
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.";
message = "R² estimate was negative and consequently set to zero.\nThis result is due to poor fitting by the Marquart algorithm\nand it is commonly observed when the model does not include\nan intercept parameter or when the model includes a non-linear function.";
MsgDialogBox msg = new MsgDialogBox(0, message, 1, Global.CadreMain);
}
if (Global.corrected_R2 < 0) {
......@@ -111,6 +111,7 @@ public class Modele {
// System.out.println("R� " +r);
aic = AICritere();
aic_corr = AICritereCorr();
bic = BICCritere();
Global.nbre_param = nbre_par;
Global.val_param = new double[nbre_par];
// System.out.println( "Apr�s marquard");
......@@ -120,6 +121,7 @@ public class Modele {
Global.coeff_determination = r;
Global.critereAIC = aic;
Global.critereAIC_Corr = aic_corr;
Global.critereBIC = bic;
// for(int i=0;i<nim;i++)
// System.out.println("********"+res[i]);
calc_residus();
......@@ -152,7 +154,7 @@ public class Modele {
}
}
private static void calcul_val_init() {
private static void calcul_val_init() { // Fixation ou Calcul des valeurs initiales pour algo Marquart
int l, k;
double tmp;
......@@ -163,7 +165,7 @@ public class Modele {
nbre_par = 2; // Modèle Schaefer CPUE=a+b.E. Commentaire 2020
for (k = 0; k < nim; k++) {
ptmp[0] = 1;
ptmp[1] = f[k];
ptmp[1] = f[k]; // f = effort
yy = pue[k];
itercov();
}
......@@ -272,7 +274,7 @@ public class Modele {
}
inverse_gauss();
break;
case 10:
case 10: //CPUE=a+b.V+c.V^2+d.E
nbre_par = 4;
for (k = 0; k < nim; k++) {
ptmp[0] = 1;
......@@ -582,7 +584,6 @@ public class Modele {
for (j = 0; j < nbre_par; j++) {
covpy[j] += ptmp[j] * yy;
}
}
private static void inverse_gauss() {
......@@ -830,12 +831,12 @@ public class Modele {
private static double AICritere() {
double sse = somme_residus(par_alors); // Residual deviance
double sse = somme_residus(par_alors); // Residual deviance ou somme des carrés résiduels
// 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);
return (double)nim * Math.log(sse/(double)nim) + (2. * (double)nbre_par); //valable si les erreurs sont distribuées normalement. Sinon −2 * log(vraissemblance) + 2 k où k est le nb de paramètres
}
private static double AICritereCorr() {
......@@ -843,7 +844,10 @@ public class Modele {
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 double BICCritere() { // Bayesian Information Criterion
double sse = somme_residus(par_alors); // Residual deviance ou somme des carrés résiduels
return (double)nim * Math.log(sse) + (Math.log(nim) * (double)nbre_par); //valable si les erreurs sont distribuées normalement. )
}
private static void makePlot() {
/**
* ***************** cpue plot *****************************
......@@ -1042,7 +1046,7 @@ public class Modele {
}
String[] param$ = {" a ", " b ", " c ", " d "};
String[] title$ = {"Parameters ", "Actual value ", "Initial value"};
Object[][] data$ = new String[nbre_par + 11][3];
Object[][] data$ = new String[nbre_par + 12][3];
DecimalFormat nf = new DecimalFormat(" 0.0000;-0.0000");
DecimalFormat nf2 = new DecimalFormat(" 0.00;-0.00");
NumberFormat numFormat = new DecimalFormat();
......@@ -1052,53 +1056,60 @@ public class Modele {
}
for (int i = 0; i < nbre_par; i++) {
data$[i + 1][0] = param$[i];
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]);
if ((par_alors[i] < 0.001 && par_alors[i] > 0) || par_alors[i] > 999.999 || (par_alors[i] > -1.0E-3 && par_alors[i]<0)|| par_alors[i] < -999.999) 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]);
if ((par_init[i] < 0.001 && par_init[i] > 0) || par_init[i] > 999.999 || (par_init[i] > -1.0E-3 && par_init[i]<0)|| par_init[i] < -999.999) 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
data$[nbre_par + 2][0] = "Nb. of degrees of freedom";
data$[nbre_par + 2][1] = Integer.toString(nim - nbre_par);
data$[nbre_par + 3][0] = "Coefficient of determination R²";
if (r != 0.0)
data$[nbre_par + 3][0] = "Coefficient of determination R²";
else
data$[nbre_par + 3][0] = "Coefficient of determination R²"; // Rajout 2020.
data$[nbre_par + 3][1] = nf2.format(r);
// 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.
data$[nbre_par + 4][0] = "Fisher test : 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);
if ((Global.fF < 0.001 && Global.fF > 0) || Global.fF> 999.999) 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";
data$[nbre_par+5][0]= "Fisher test: F 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";
Global.fFsignif$ = ", p>0.05";
Global.fFsignif$ = ", p>0.05"; // Do not use p>0.05 because this is not compatible with the path of the html graph file.
}
else
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";
data$[nbre_par+5][1]= ", <0.05";
Global.fFsignif$ = ", p<0.05";
}
else
else {
data$[nbre_par+5][1]= " <0.01";
Global.fFsignif$ = ", p<0.01";
Global.fFsignif$ = ", p<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);
if ((aic < 0.001 && aic > 0) || aic > 999.999 || (aic > -1.0E-3 && aic < 0)|| aic < -999.999) 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);
if ((aic_corr < 0.001 && aic_corr > 0) || aic_corr > 999.999 || (aic_corr > -1.0E-3 && aic_corr < 0)|| aic_corr < -999.999) data$[nbre_par +8][1] = numFormat.format(aic_corr);
else data$[nbre_par +8][1] = nf.format(aic_corr);
data$[nbre_par + 9][0] = "BIC ";
if ((bic < 0.001 && bic > 0) || bic > 999.999 || (bic > -1.0E-3 && bic < 0)|| bic < -999.999) data$[nbre_par +9][1] = numFormat.format(bic);
else data$[nbre_par +9][1] = nf.format(bic);
data$[nbre_par + 10][0] = "Variance ";
if ((variance_pue < 0.001 && variance_pue > 0)|| variance_pue > 999.999) data$[nbre_par +9][1] = numFormat.format(variance_pue);
else data$[nbre_par +10][1] = nf.format(variance_pue);
data$[nbre_par + 11][0] = "Residual Variance ";
if ((sompar < 0.001 && sompar > 0) || sompar > 999.999) data$[nbre_par +11][1] = numFormat.format(sompar);
else data$[nbre_par +11][1] = nf.format(sompar);
return data$;
......
......@@ -11,7 +11,7 @@ import java.io.InputStream;
public class RechercheModele { //Variables dans fichier ListeModele.csv:
private static int nbData=0;
private static int[] ordre; //Ordre de slection des modles lors de la recherche
private static int[] ordre; //Ordre de sélection des modèles lors de la recherche
private static String [] equation; //Equation litterale
private static String [] help; //Fichier d'aide associ�
private static int [] type; //Type de modèle: Effort = 1 Climat = 2 Mixte = 3
......
......@@ -355,7 +355,7 @@ for (int i=0;i<s.length;i++)
return max;
}
static public double[] Extremas(double [] s){ // Utilisé pour analyser données brutes.
static public double[] Extremas(double [] s){ // Utilisé pour analyser données brutes et dans Validation.java.
double[] ext=new double[2];
ext[0]=s[0];
ext[1]=s[0];
......
......@@ -99,7 +99,6 @@ public static void loadRegles(int number)
{
indexEnCours=Integer.parseInt((String)htNum.get(Integer.toString(numEnCours)));
//System.out.println("indexEnCours dans TexteRegles.java = " + indexEnCours);
if (indexEnCours == 56) indexEnCours = 18; // Patch 2020 pour empêcher plantage sur lignes suivantes.
scriptEnCours=script[indexEnCours];
itemEnCours=new String[item[indexEnCours].length];
for (int i=0;i<itemEnCours.length;i++)
......@@ -139,7 +138,7 @@ public static void initRegles()
@return boolean true si règle vraie.
IMPOSSIBLE DE PRESENTER MESSAGE DE WARNING (lu dans Comments.csv) DANS FENETRE QUESTION SI:
1) Pas de règle associée (ex: décision n°5;
2)¨result (boléen) = true;
2) result (boléen) = true;
3) si décision aboutit sur -1 (on a alors un message d'arrêt de la procedure de sélection STOP).
Seule solution trouvée (uniquement lorsque result != true): rajouter un if et donner ici le commentaire.
*/
......@@ -166,17 +165,23 @@ public static boolean isTrue(){
break;
case 42:
result = (Global.changement_exploitation!=2);
if(Global.changement_exploitation==3)
commentaireEnCours="It is compulsory to know the answer to this question. \nPlease have a look at the help file using the 'Help (H)' button \nif necessary";
break;
case 43:
result = (Global.unite_standardisee!=1);
if(Global.unite_standardisee==3)
commentaireEnCours="It is compulsory to know the answer to this question. \nPlease have a look at the help file using the 'Help (H)' button \nif necessary";
break;
case 44:
result = (Global.effet_delais_abundance_negligeable!=1);
if(Global.effet_delais_abundance_negligeable==3)
commentaireEnCours="It is compulsory to know the answer to this question. \nPlease have a look at the help file using the 'Help (H)' button \nif necessary";
break;
case 46:
result = (Global.stock_unique!=1 && Global.metapopulation!=1); // Changement de nom variable. Modif. 2020
if(!result){
commentaireEnCours="Metapopulations are special cases that difficult the application of any kind of population dynamics model. \nAccording to the level connectivity between sub-stocks, modelization might be borderline or not recommended as you will see \nafter answering the next question.";
commentaireEnCours="Metapopulations are special cases that difficult the application of any kind of population dynamics model. \nAccording to the level connectivity between sub-stocks, modelization might be borderline or not recommended \nas you will see after answering the next question.";
}
break;
case 45:
......@@ -192,11 +197,11 @@ public static boolean isTrue(){
result = (Global.under_and_over_exploited!=1);// Avant Global.under_and_over_exploited!=1 && Global.under_and_optimaly==1). Modif 2020.
break;
case 49:
result = (Global.under_and_optimaly!=1); // Avant (Global.under_and_over_exploited!=1 && Global.under_and_optimaly!=1). Modif 2020.
result = (Global.under_and_optimaly==2); // Avant (Global.under_and_over_exploited!=1 && Global.under_and_optimaly!=1). Modif 2020.
if(!result){
commentaireEnCours="Your can still go on but your case is a borderline one. Model results will be uncertain (particularly maximum production that could be underestimated) owing to the lack of exploitation above MSY/MSE levels.";
commentaireEnCours="Your can still go on but your case is a borderline one. Model results will be uncertain \n(particularly maximum production that could be underestimated) owing to \nthe lack of exploitation above MSY/MSE levels.";
}
break;
break;
case 37:
result = (Global.statistiques_anormales==1);
break;
......@@ -213,10 +218,10 @@ public static boolean isTrue(){
result = (Global.effort_increasing==1);
break;
case 40:
result = (Global.independance==1);
result = (Global.independance==1);
break;
case 48:
result = (Global.effort_preponderant==1 && Global.decreasing_relationship==2);
result = (Global.effort_preponderant==1 && Global.decreasing_relationship==2);
break;
case 10:
//System.out.println(Global.relationCPU_E+" "+Global.pessimiste+" "+Global.stock_deja_effondre+" "+Global.lifespan+" "+Global.fecondite_faible);
......@@ -484,9 +489,9 @@ public static boolean isTrue(){
if(result)
commentaireEnCours="From the current rule the model " + RechercheModele.getEquation()+ " is convenient.";
break;
case 2:
/* case 2:
result=(Global.test_jackknife==false);
System.out.println("La valeur de test_jackknife est "+Global.test_jackknife);
//System.out.println("La valeur de test_jackknife est "+Global.test_jackknife);
if(result){
commentaireEnCours="The Student's test on jackknife is not acceptable.\nAt least one of the regression coefficients is not significant as you can see in the jackknife plots.\nFrom the current rule the model " + RechercheModele.getEquation()+ " is not validated";
if (Global.CadreJackniffePlots == null)
......@@ -503,9 +508,9 @@ public static boolean isTrue(){
else
commentaireEnCours="The Student's test on jackknife regression coefficients is acceptable";
commentaireEnCours=commentaireEnCours+"\n\nDue to usual autocorrelation in time series and non independance between CPUE and E, \nconventional statistics are usually provide too optimistic results";
break;
case 1:
result=( Global.coeff_determination_instable!=1);
break;*/
case 1:
result=(Global.coeff_determination_instable!=1);
if(result)
commentaireEnCours="From the current rule the model " + RechercheModele.getEquation()+ " is not validated";
break;
......@@ -532,7 +537,7 @@ public static boolean isTrue(){
if (result && commentaireEnCours.equals(""))
{ commentaireEnCours=(String)htComment.get(Integer.toString(numEnCours));
// System.out.println("On teste la règle (dans TexteRegles.java ligne 529) " + numEnCours + " elle est "+ result );
if (commentaireEnCours == null) commentaireEnCours = "";
if (commentaireEnCours == null) commentaireEnCours = ""; // Patch 2020 pour empêcher plantage écriture questions/réponses dans fichier html
}
return result;
}
......
......@@ -18,6 +18,7 @@ public class Validation {
static private int nparmax=4,nv=100; // Modif 2020
static private int nim;
static private int nimTabFish;
static private int nimTabStudent;
static public int jk,nbre_par;
static private int riter,iter,ritertot,maxrit=100;
static private double val_init,val_fin, alpha=4,ecart;
......@@ -45,7 +46,7 @@ public class Validation {
static private double[][] pseudo=new double [61][nparmax+1];
static private double[] val_v=new double[4];
static private double[] moyenne_pseudo=new double[nparmax+2];
static private double[][] covar_pseudo=new double[nparmax+1][nparmax+1];
static private double[][] covar_pseudo=new double[nparmax+1][nparmax+1]; // Matrice de covariance des paramètres
static private double[] ecart_pseudo=new double[nparmax+2];
static private double []f_ms_m=new double[nv];
......@@ -67,6 +68,9 @@ static private double []vec_y_min2=new double[nv];
static private double []vec_y_max2=new double[nv];
/***************************************
* Algorithme de Marquart
****************************************/
private static void marquardt()
{
......@@ -164,6 +168,10 @@ private static void marquardt()
}
}
/****************************************************
* calcul_derivee_hess()
****************************************************/
private static void calcul_derivee_hess()
{
int i,j,n;
......@@ -236,6 +244,7 @@ public static void valide_modele()
//int nv=50;
double var_tot, sdc_tot, sdc_jk;
double f_ms,y_ms,vmin,vmax,vv,ecartv;
String message = "";
Global.Res_Test_Jackknife_Par = new int[4]; // Rajout 2020.
double[] pue_c,pue_j;
......@@ -310,14 +319,14 @@ public static void valide_modele()
calc_var_jk();
marquardt();
pue_c[jk] = EquationModele.fonction_modele(f[jk],v[jk],vbar[jk],par_init);
pue_j[jk] = EquationModele.fonction_modele(f[jk],v[jk],vbar[jk],par_alors);
sdc_jk += (pue[jk]-pue_j[jk])*(pue[jk]-pue_j[jk]);
for(i=0;i<nbre_par;i++) jkn[jk][i+1]=par_alors[i];//ici
pue_c[jk] = EquationModele.fonction_modele(f[jk],v[jk],vbar[jk],par_init); // par_init = valeur initiale paramètre dans Marquart
pue_j[jk] = EquationModele.fonction_modele(f[jk],v[jk],vbar[jk],par_alors); // par_alors = valeur finale paramètre dans Marquart
sdc_jk += (pue[jk]-pue_j[jk])*(pue[jk]-pue_j[jk]); // Somme des carrés des écarts
for(i=0;i<nbre_par;i++) jkn[jk][i+1]=par_alors[i];// jkn[nim][nbre_par] = valeur du paramètre après retrait de l'année nim.
val_fin = somme_residus_jk(par_alors);
jkn[jk][0] = 1 - (val_fin/variance_pue);//pour r
jkn[jk][0] = 1 - (val_fin/variance_pue); // pour r2
for(i=0;i<nbre_par;i++)
pseudo[jk][i]= nim*par_init[i]-(nim-1)*par_alors[i];//ici
pseudo[jk][i]= nim*par_init[i]-(nim-1)*par_alors[i]; // ici. PF pseudo-valeurs = différence entre valeurs paramétres avec ou sans retrait d'une année, pondérée par le nb total d'années dans le modèle.
vv = val_v[2];
if((Global.numero_modele > 5) || (Global.numero_modele < 2)) // Exclus les modèles CPUE = f(V) Commentaire 2020
for(iv=0;iv<nv;iv++){
......@@ -351,37 +360,49 @@ public static void valide_modele()
/**************** calculs des pseudo-valeurs *********************/
for(i=0;i<nbre_par;i++) {
moyenne_pseudo[i] = 0.0;//ici
for(jk=0;jk<nim;jk++)
moyenne_pseudo[i] += pseudo[jk][i]; //ici 2
moyenne_pseudo[i] /= (double)nim;//ici