Isis-fish-data-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- 322 discussions
10 Apr '14
Author: echatellier
Date: 2014-04-10 18:44:50 +0200 (Thu, 10 Apr 2014)
New Revision: 315
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/315
Log:
Mise ?\195?\160 jour dans la gestion des ouverture/fermeture et nettoyage des sessions
Modified:
branches/4.2.2/sensitivityanalysis/DOptimal.java
branches/4.2.2/sensitivityanalysis/Fast.java
branches/4.2.2/sensitivityanalysis/Morris.java
branches/4.2.2/sensitivityanalysis/OptimumLHS.java
branches/4.2.2/sensitivityanalysis/RandomLHS.java
branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java
branches/4.2.2/sensitivityanalysis/RegularFractions.java
branches/4.2.2/sensitivityanalysis/Sobol.java
Modified: branches/4.2.2/sensitivityanalysis/DOptimal.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/DOptimal.java 2014-04-10 14:19:27 UTC (rev 314)
+++ branches/4.2.2/sensitivityanalysis/DOptimal.java 2014-04-10 16:44:50 UTC (rev 315)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -32,7 +32,6 @@
import org.apache.commons.lang.StringUtils;
import org.nuiton.j2r.REngine;
import org.nuiton.j2r.RException;
-import org.nuiton.j2r.RProxy;
import org.nuiton.j2r.types.RDataFrame;
import java.io.File;
@@ -77,12 +76,8 @@
int factorsNb = factors.size();
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
engine.voidEval("library(AlgDesign)");
//Create a list of the factors under the form factor1=factor1,...
@@ -211,7 +206,7 @@
Map<Object, Object> values = discDomain.getValues();
int count=0;
Collection<Object> collecValues = values.values();
- for (Object value:collecValues){
+ for (Object value:collecValues) {
if (count!=0){
parameters += ",";
}
@@ -236,11 +231,8 @@
"\"nomModel\")<-\"isis-fish-externe-R\"");
engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
+ closeEngine(engine, outputDirectory, false);
-
} catch (RException eee) {
throw new SensitivityException("Can't generate scenarios", eee);
}
@@ -254,22 +246,16 @@
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
//Get back the factors number
int factorNumber = (Integer)engine.eval("dim(x$design)[2]");
SimulationParameter param = simulationStorages.get(0).getParameter();
int sensitivityNumber = param.getSensitivityExport().size();
- SimulationStorage firstStorage = simulationStorages.get(0);
+ String firstStorageName = outputDirectory.getName().replaceAll("-", "");
- String firstStorageName = firstStorage.getName().replaceAll("-", "");
-
for (int k = 0; k < sensitivityNumber; k++) {
SensitivityExport sensitivityExport =
@@ -318,7 +304,7 @@
*Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
*/
-//Compute Sum of Squares and Sensitivity indices
+ //Compute Sum of Squares and Sensitivity indices
engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
@@ -373,23 +359,8 @@
}
- //Rename R objects for saving purpose
- renameObjects(engine, firstStorageName);
+ closeEngine(engine, outputDirectory);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(firstStorageName)){
- engine.remove(object);
- }
- }
-
- //Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
} catch (Exception e) {
throw new SensitivityException("Can't evaluate results", e);
}
Modified: branches/4.2.2/sensitivityanalysis/Fast.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/Fast.java 2014-04-10 14:19:27 UTC (rev 314)
+++ branches/4.2.2/sensitivityanalysis/Fast.java 2014-04-10 16:44:50 UTC (rev 315)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -28,7 +28,6 @@
import fr.ifremer.isisfish.simulator.sensitivity.*;
import org.nuiton.j2r.REngine;
import org.nuiton.j2r.RException;
-import org.nuiton.j2r.RProxy;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.export.SensitivityExport;
@@ -102,12 +101,8 @@
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- engine.clearSession();
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
// Load sensitivity package into R (if package already loaded,
// nothing happens.
engine.voidEval("library(sensitivity)");
@@ -156,10 +151,6 @@
engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
// Setting up the scenarios.
for (int j = 0; j < nbExperiments; j++) {
Scenario experimentScenario = new Scenario();
@@ -171,6 +162,8 @@
thisExperimentScenarios.add(experimentScenario);
thisExperiment.setScenarios(thisExperimentScenarios);
}
+
+ closeEngine(engine, outputDirectory, false);
} catch (RException eee) {
throw new SensitivityException("Can't generate scenarios", eee);
}
@@ -182,20 +175,13 @@
public void analyzeResult(List<SimulationStorage> simulationStorages,
File outputDirectory) throws SensitivityException {
- SimulationStorage storage = simulationStorages.get(0);
- String simulationName = storage.getName().replaceAll("-", "");
+ String simulationName = outputDirectory.getName().replaceAll("-", "");
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
+ // for export
engine.setwd(outputDirectory);
// Call R
@@ -284,21 +270,9 @@
simulationName + "." + name));
}
+
+ closeEngine(engine, outputDirectory);
- //Rename R objects for saving purpose
- renameObjects(engine, simulationName);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
} catch (Exception e) {
throw new SensitivityException("Can't evaluate results", e);
}
Modified: branches/4.2.2/sensitivityanalysis/Morris.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/Morris.java 2014-04-10 14:19:27 UTC (rev 314)
+++ branches/4.2.2/sensitivityanalysis/Morris.java 2014-04-10 16:44:50 UTC (rev 315)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -123,17 +123,9 @@
rCall = editRInstruction(rCall);
}
- REngine engine;
-
try {
- engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
// Load sensitivity package into R (if package already loaded,
// nothing happens.
engine.voidEval("library(sensitivity)");
@@ -200,10 +192,6 @@
"\"isis-fish-externe-R\"");
engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
// Setting up the scenarios.
List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
for (int j = 0; j < nbExperiments; j++) {
@@ -216,6 +204,8 @@
thisExperimentScenarios.add(experimentScenario);
thisExperiment.setScenarios(thisExperimentScenarios);
}
+
+ closeEngine(engine, outputDirectory, false);
} catch (RException eee) {
throw new SensitivityException("Can't generate scenarios", eee);
@@ -229,20 +219,11 @@
public void analyzeResult(List<SimulationStorage> simulationStorages,
File outputDirectory) throws SensitivityException {
- SimulationStorage storage = simulationStorages.get(0);
- String simulationName = storage.getName().replaceAll("-", "");
+ String simulationName = outputDirectory.getName().replaceAll("-", "");
- REngine engine = null;
-
try {
- engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
// Call R
// Load sensitivity package into R (if package already loaded,
// nothing happens.
@@ -331,20 +312,8 @@
}
- //Rename R objects for saving purpose
- renameObjects(engine,simulationName);
+ closeEngine(engine, outputDirectory);
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
} catch (Exception e) {
throw new SensitivityException("Can't evaluate results", e);
}
Modified: branches/4.2.2/sensitivityanalysis/OptimumLHS.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/OptimumLHS.java 2014-04-10 14:19:27 UTC (rev 314)
+++ branches/4.2.2/sensitivityanalysis/OptimumLHS.java 2014-04-10 16:44:50 UTC (rev 315)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -26,7 +26,6 @@
import java.util.List;
import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RProxy;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.export.SensitivityExport;
@@ -69,10 +68,10 @@
}
@Override
- public SensitivityScenarios compute(DesignPlan plan, File outputdirectory)
+ public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
throws SensitivityException {
- setIsisFactorsR(plan, outputdirectory);
+ setIsisFactorsR(plan, outputDirectory);
int factorNumber = plan.getFactors().size();
List<Factor> factors = plan.getFactors();
@@ -84,15 +83,8 @@
checkAllFactorContinuous(factors);
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- //Clear session
- engine.clearSession();
-
- //Set working directory to get Isis R session
- engine.loadRData(outputdirectory.getParentFile(),
- outputdirectory.getName());
-
//Load the lhs library
engine.voidEval("library(lhs)");
@@ -200,12 +192,8 @@
engine.voidEval(rInstruction);
- // Save Isis R session
- engine.saveRData(outputdirectory.getParentFile(),
- outputdirectory.getName());
+ closeEngine(engine, outputDirectory, false);
- engine.terminate();
-
} catch (Exception e) {
throw new SensitivityException("Can't generate scenarios", e);
}
@@ -219,20 +207,12 @@
//The first storage to get the name and parameters all along the method
SimulationStorage storage = simulationStorages.get(0);
+ String simulationName = outputDirectory.getName().replaceAll("-", "");
- String simulationName = storage.getName().replaceAll("-", "");
-
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
engine.voidEval("factors<-data.frame(x)");
engine.voidEval("names(factors)<-factornames");
@@ -349,18 +329,8 @@
}
- //Rename R objects for saving purpose
- renameObjects(engine, simulationName);
+ closeEngine(engine, outputDirectory);
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- engine.terminate();
-
} catch (Exception e) {
throw new SensitivityException("Can't evaluate results", e);
}
Modified: branches/4.2.2/sensitivityanalysis/RandomLHS.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/RandomLHS.java 2014-04-10 14:19:27 UTC (rev 314)
+++ branches/4.2.2/sensitivityanalysis/RandomLHS.java 2014-04-10 16:44:50 UTC (rev 315)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -28,7 +28,6 @@
import fr.ifremer.isisfish.export.SensitivityExport;
import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RProxy;
import org.nuiton.j2r.types.RDataFrame;
import fr.ifremer.isisfish.datastore.SimulationStorage;
@@ -81,15 +80,8 @@
try {
- REngine engine = new RProxy(); //The R engine
+ REngine engine = openEngine(outputDirectory);
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
//Load the lhs library
engine.voidEval("library(lhs)");
@@ -190,16 +182,13 @@
engine.voidEval(rInstruction);
// Clean RData
- for (Factor factor:factors) {
- engine.remove(factor.getName().replaceAll(" ", ""));
+ for (Factor factor : factors) {
+ String factorName = factor.getName().replaceAll(" ", "");
+ engine.remove(factorName);
}
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
+ closeEngine(engine, outputDirectory, false);
- engine.terminate();
-
} catch (Exception e) {
throw new SensitivityException("Can't generate scenarios", e);
}
@@ -212,22 +201,14 @@
File outputDirectory) throws SensitivityException {
SimulationStorage simulationStorage1 = simulationStorages.get(0);
- String simName = simulationStorage1.getName();
- String simulationName = simName.replaceAll("-", "");
+ String simulationName = outputDirectory.getName().replaceAll("-", "");
SimulationParameter param = simulationStorage1.getParameter();
int sensitivityNumber = param.getSensitivityExport().size();
//List<SensitivityExport> export = param.getSensitivityExport();
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
engine.voidEval("factors<-data.frame(x)");
//Get back the factors number
@@ -339,26 +320,10 @@
"isis.methodAnalyse";
engine.voidEval(String.format(renameIsisMethodAnalyse,
simulationName + "." + name));
-
}
- //Rename R objects for saving purpose
- renameObjects(engine, simulationName);
+ closeEngine(engine, outputDirectory);
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
} catch (Exception e) {
throw new SensitivityException("Can't evaluate results", e);
}
Modified: branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java 2014-04-10 14:19:27 UTC (rev 314)
+++ branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java 2014-04-10 16:44:50 UTC (rev 315)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -32,7 +32,6 @@
import org.apache.commons.lang.StringUtils;
import org.nuiton.j2r.REngine;
import org.nuiton.j2r.RException;
-import org.nuiton.j2r.RProxy;
import org.nuiton.j2r.types.RDataFrame;
import java.io.File;
@@ -77,7 +76,7 @@
int factorsNb = factors.size();
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
//Get Isis R session
engine.loadRData(outputDirectory.getParentFile(),
@@ -213,11 +212,8 @@
"\"nomModel\")<-\"isis-fish-externe-R\"");
engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
+ closeEngine(engine, outputDirectory, false);
-
} catch (RException eee) {
throw new SensitivityException("Can't generate scenarios", eee);
}
@@ -231,22 +227,16 @@
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
//Get back the factors number
int factorNumber = (Integer)engine.eval("dim(x)[2]");
SimulationParameter param = simulationStorages.get(0).getParameter();
int sensitivityNumber = param.getSensitivityExport().size();
- SimulationStorage firstStorage = simulationStorages.get(0);
+ String firstStorageName = outputDirectory.getName().replaceAll("-", "");
- String firstStorageName = firstStorage.getName().replaceAll("-", "");
-
for (int k = 0; k < sensitivityNumber; k++) {
SensitivityExport sensitivityExport =
@@ -344,22 +334,8 @@
}
- //Rename R objects for saving purpose
- renameObjects(engine, firstStorageName);
+ closeEngine(engine, outputDirectory);
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(firstStorageName)){
- engine.remove(object);
- }
- }
-
- //Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
} catch (Exception e) {
throw new SensitivityException("Can't evaluate results", e);
}
Modified: branches/4.2.2/sensitivityanalysis/RegularFractions.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/RegularFractions.java 2014-04-10 14:19:27 UTC (rev 314)
+++ branches/4.2.2/sensitivityanalysis/RegularFractions.java 2014-04-10 16:44:50 UTC (rev 315)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2014 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -28,7 +28,6 @@
import fr.ifremer.isisfish.export.SensitivityExport;
import org.nuiton.j2r.REngine;
import org.nuiton.j2r.RException;
-import org.nuiton.j2r.RProxy;
import org.nuiton.j2r.types.RDataFrame;
import fr.ifremer.isisfish.datastore.SimulationStorage;
@@ -97,7 +96,7 @@
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
//Clear session
engine.clearSession();
@@ -204,12 +203,8 @@
engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
+ closeEngine(engine, outputDirectory, false);
- engine.terminate();
-
} catch (RException eee) {
throw new SensitivityException("Can't generate scenarios", eee);
}
@@ -226,19 +221,12 @@
SimulationParameter param = firstStorage.getParameter();
List<SensitivityExport> exports = param.getSensitivityExport();
int sensitivityNumber = exports.size();
- String simulationName = firstStorage.getName().replaceAll("-", "");
+ String simulationName = outputDirectory.getName().replaceAll("-", "");
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
//Get back the factors number
int factorNumber = (Integer) engine.eval("dim(data)[2]");
@@ -347,22 +335,8 @@
}
- //Rename R objects for saving purpose
- renameObjects(engine,simulationName);
+ closeEngine(engine, outputDirectory);
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
} catch (Exception eee) {
throw new SensitivityException("Can't evaluate results", eee);
}
Modified: branches/4.2.2/sensitivityanalysis/Sobol.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/Sobol.java 2014-04-10 14:19:27 UTC (rev 314)
+++ branches/4.2.2/sensitivityanalysis/Sobol.java 2014-04-10 16:44:50 UTC (rev 315)
@@ -29,7 +29,6 @@
import fr.ifremer.isisfish.simulator.sensitivity.*;
import org.apache.commons.lang3.StringUtils;
import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RProxy;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.simulator.SimulationParameter;
@@ -68,10 +67,10 @@
}
@Override
- public SensitivityScenarios compute(DesignPlan plan, File outputdirectory)
+ public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
throws SensitivityException {
- setIsisFactorsR(plan, outputdirectory);
+ setIsisFactorsR(plan, outputDirectory);
RDataFrame dataFrame;
int nbExperiments;
@@ -90,15 +89,8 @@
}
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputdirectory.getParentFile(),
- outputdirectory.getName());
-
engine.voidEval("library(sensitivity)");
String x = "<-data.frame(matrix(c(";
@@ -156,11 +148,7 @@
engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
- // Save Isis R session
- engine.saveRData(outputdirectory.getParentFile(),
- outputdirectory.getName());
-
- // Setting up the scenarios.
+ // Setting up the scenarios.
for (int j = 0; j < nbExperiments; j++) {
Scenario experimentScenario = new Scenario();
for (int i = 0; i < factorNumber; i++) {
@@ -171,11 +159,13 @@
}
thisExperimentScenarios.add(experimentScenario);
}
+
+ closeEngine(engine, outputDirectory, false);
} catch (Exception e) {
- throw new SensitivityException("Can't generate scenarios", e);}
+ throw new SensitivityException("Can't generate scenarios", e);
+ }
-
thisExperiment.setScenarios(thisExperimentScenarios);
return thisExperiment;
@@ -188,19 +178,12 @@
SimulationStorage firstStorage = simulationStorages.get(0);
SimulationParameter param = firstStorage.getParameter();
int sensitivityNumber = param.getSensitivityExport().size();
- String simulationName = firstStorage.getName().replaceAll("-", "");
+ String simulationName = outputDirectory.getName().replaceAll("-", "");
try {
- REngine engine = new RProxy();
+ REngine engine = openEngine(outputDirectory);
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
// Call R
// Load sensitivity package into R (if package already loaded,
// nothing happens.
@@ -291,19 +274,7 @@
}
- //Rename R objects for saving purpose
- renameObjects(engine, simulationName);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
+ closeEngine(engine, outputDirectory);
} catch (Exception e) {
throw new SensitivityException("Can't evaluate results", e);
}
1
0
Author: echatellier
Date: 2014-04-10 16:19:27 +0200 (Thu, 10 Apr 2014)
New Revision: 314
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/314
Log:
Fix javadoc
Modified:
branches/4.2.2/scripts/RuleUtil.java
branches/4.2.2/scripts/SiMatrix.java
Modified: branches/4.2.2/scripts/RuleUtil.java
===================================================================
--- branches/4.2.2/scripts/RuleUtil.java 2013-12-01 22:05:23 UTC (rev 313)
+++ branches/4.2.2/scripts/RuleUtil.java 2014-04-10 14:19:27 UTC (rev 314)
@@ -52,7 +52,7 @@
/**
* @param context le context de simulation
* @param species l'espece sur lequel on souhaite le total
- * @param date la date pour laquel on veut le calcul, cet argument est
+ * @param step le pas de temps pour lequel on veut le calcul, cet argument est
* passe seulement pour que le cache ne retourne pas toujours la meme valeur
* @return total catch in tons
*/
Modified: branches/4.2.2/scripts/SiMatrix.java
===================================================================
--- branches/4.2.2/scripts/SiMatrix.java 2013-12-01 22:05:23 UTC (rev 313)
+++ branches/4.2.2/scripts/SiMatrix.java 2014-04-10 14:19:27 UTC (rev 314)
@@ -101,13 +101,9 @@
}
/**
- *
* @param context
- * Simulation context
- * @param db
- * TopiaContext with transaction opened. You must used this
- * TopiaContext and not used
- * SimulationContext.getSimulationStorage().getStorage()
+ * Simulation context transaction opened. You must used this
+ * TopiaContext and not used SimulationContext.getSimulationStorage().getStorage()
* @throws TopiaException
*/
public SiMatrix(SimulationContext context) throws TopiaException {
@@ -1080,8 +1076,8 @@
/**
*
- * @param setOfVessels
- * @param zone
+ * @param sov
+ * @param zoneMetier
* @return
*/
protected double travelTimePerTrip(SetOfVessels sov,
1
0
Build failed in Jenkins: isis-fish-data-nightly #1
by admin+ci-codelutin.com@codelutin.com 17 Feb '14
by admin+ci-codelutin.com@codelutin.com 17 Feb '14
17 Feb '14
See <http://ci.codelutin.com/jenkins/job/isis-fish-data-nightly/1/>
------------------------------------------
[...truncated 1429 lines...]
<div id="members">
<ul>
<li><a href="http://www.easter-eggs.com/">Easter-eggs</a></li>
<li><a href="http://www.codelutin.com/">Code Lutin</a></li>
<li><a href="http://www.entrouvert.com/">Entr'ouvert</a></li>
<li><a href="http://www.ldd.fr/">Les Développements Durables</a></li>
<li><a href="http://www.nereide.fr">Néréide</a></li>
<li><a href="http://www.syloe.com/">Syloé</a></li>
<li><a href="http://www.labor-liber.com/">labor-liber</a></li>
<li><a href="http://www.cliss21.com/">Cliss XXI</a></li>
<li><a href="http://www.silecs.info/">SILECS</a></li>
<li><a href="http://www.libricks.fr/">Libricks</a></li>
<li><a href="http://azae.net/">Azaé</a></li>
<li><a href="http://www.scil.coop">SCIL</a></li>
<li><a href="https://www.cadoles.com/">Cadoles</a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="warpperhome" class="clearfix">
<div class="menu">
<div class="rightmenu">
<ul>
<li class="level1"><div class="li"> <a href="/accueil" class="wikilink1" title="accueil">Accueil</a></div>
</li>
<li class="level1"><div class="li"> <a href="/nos_metiers" class="wikilink1" title="nos_metiers">Nos métiers</a></div>
</li>
<li class="level1"><div class="li"> <a href="/nos_valeurs" class="wikilink1" title="nos_valeurs">Nos valeurs</a></div>
</li>
<li class="level1"><div class="li"> <a href="/references" class="wikilink1" title="references"> Nos références</a></div>
</li>
<li class="level1"><div class="li"> <a href="/le_laboratoire" class="wikilink1" title="le_laboratoire">Le laboratoire</a></div>
</li>
<li class="level1"><div class="li"> <a href="/contact" class="wikilink1" title="contact">Contact</a></div>
</li>
</ul>
</div>
</div>
<div id="warpper2">
<div class="maincontent">
<div class="margin">
<!-- wikipage start -->
<div class="page_left">
<h1 class="sectionedit1"><a name="cette_page_n_existe_pas_encore" id="cette_page_n_existe_pas_encore">Cette page n'existe pas encore</a></h1>
<div class="level1">
<p>
Vous avez suivi un lien vers une page qui n'existe pas encore. Si vos droits sont suffisants, vous pouvez utiliser le bouton ou le lien « Créer cette page ».
</p>
</div>
</div>
<div class="right_sidebar">
<div class="main_sidebar sidebar_box">
<h1 class="sectionedit1"><a name="sb_right_actualites" id="sb_right_actualites">Actualités</a></h1>
<div class="level1">
<p>
<div class="news">
</p>
<ul class="rss"><li><div class="li"><a href="http://www.codelutin.com/blog:news:salon_de_l_agriculture_2014" class="urlextern" title="http://www.codelutin.com/blog:news:salon_de_l_agriculture_2014" rel="nofollow">Salon de l'Agriculture 2014</a> (2014/02/03 14:56)<div class="detail"><div>
<p>
L'application Agrosyst, développée par Code Lutin, sera présentée lors du salon de l'agriculture 2014 par l'INRA lors de son colloque intitulé “Conception et adoption de systèmes de production agricole à hautes performances”. La présentation aura lieu le mardi 25 février à partir de 16h30.
</p>
<p>
Agrosyst est un système d'information permettant à l'INRA d'identifier les pratiques culturales innovantes permettant de maintenir des rendements élevés tout en diminuant de 50% l'utilisation de produits phytosanitaires. Toutes les composantes des systèmes de culture y sont répertoriés afin de pouvoir comparer les différentes pratiques et mettre en évidence les plus efficaces.
</p>
<p>
Vous pouvez assister à la présentation en vous inscrivant sur <a href="https://colloque.inra.fr/sia2014_agricultureperformante" title="https://colloque.inra.fr/sia2014_agricultureperformante" rel="nofollow">le site de l'organisation</a>
</p>
</div></div></div></li><li><div class="li"><a href="http://www.codelutin.com/blog:news:bonne_annee_2014" class="urlextern" title="http://www.codelutin.com/blog:news:bonne_annee_2014" rel="nofollow">Bonne année 2014</a> (2014/01/13 10:25)<div class="detail"><div>
<p>
En ce début d'année 2014, toute l'équipe Code Lutin vous souhaite ses meilleurs vœux.
</p>
<p>
Que cette année à venir soit pour vous pleine de promesses et de succès, tant professionnels que personnels.
</p>
</div></div></div></li><li><div class="li"><a href="http://www.codelutin.com/blog:news:balle_de_match" class="urlextern" title="http://www.codelutin.com/blog:news:balle_de_match" rel="nofollow">Balle de match</a> (2013/11/18 17:22)<div class="detail"><div>
<p>
Code Lutin était partenaire du match de championnat de France Nationale 2 de Rink Hockey du Nantes ARH ce samedi 16 Novembre. L'équipe du NARH recevait le leader du championnat, le Biarritz OL. Le match s'est terminé par une défaite du NARH sur le score de 6-5. Les bleu et blanc n'ont pas démerité puisqu'ils s'inclinent sur un but a 50 secondes de la fin du match.
</p>
<p>
Code Lutin a offert la balle de match et plusieurs balles distribuées aux spectateurs durant la rencontre.
</p>
<p>
Le NARH est actuellement 3ème du classement et possède la meilleure défense du championnat.
</p>
</div></div></div></li></ul>
<p>
</div>
</p>
</div>
<!-- EDIT1 SECTION "Actualités" [1-197] -->
<h1 class="sectionedit2"><a name="sb_right_articles_techniques" id="sb_right_articles_techniques">Articles techniques</a></h1>
<div class="level1">
<p>
<div class="article">
</p>
<ul class="rss"></ul>
<p>
</div>
</p>
<p>
<a href="http://www.codelutin.com/blogtech" class="urlextern" title="http://www.codelutin.com/blogtech" rel="nofollow">Tous les articles</a>
</p>
</div>
<!-- EDIT2 SECTION "Articles techniques" [198-454] -->
<h1 class="sectionedit3"><a name="sb_right_actualites_des_forges" id="sb_right_actualites_des_forges">Actualités des forges</a></h1>
<div class="level1">
<p>
<div class="article">
<div class="actutitle clearfix">
<h3>Code Lutin</h3>
</div>
</p>
<ul class="rss"><li><div class="li"><a href="http://forge.codelutin.com/news/259" class="urlextern" title="http://forge.codelutin.com/news/259" rel="nofollow">Tutti - Tutti 3.1.3 released</a> (2014/02/13 17:04)</div></li><li><div class="li"><a href="http://forge.codelutin.com/news/256" class="urlextern" title="http://forge.codelutin.com/news/256" rel="nofollow">Tutti - Tutti 3.1.1 released</a> (2014/02/04 13:32)</div></li><li><div class="li"><a href="http://forge.codelutin.com/news/254" class="urlextern" title="http://forge.codelutin.com/news/254" rel="nofollow">Tutti - Tutti 3.1 released</a> (2014/01/30 20:19)</div></li></ul>
<p>
</div>
</p>
<p>
<div class="article">
<div class="actutitle clearfix">
<h3>Chorem</h3>
</div>
</p>
<ul class="rss"><li><div class="li"><a href="http://www.chorem.org/news/58" class="urlextern" title="http://www.chorem.org/news/58" rel="nofollow">Pollen - Pollen 1.5.5 released</a> (2013/12/23 15:16)</div></li><li><div class="li"><a href="http://www.chorem.org/news/57" class="urlextern" title="http://www.chorem.org/news/57" rel="nofollow">jTimer - jTimer 1.4.3 released</a> (2013/09/27 07:50)</div></li><li><div class="li"><a href="http://www.chorem.org/news/56" class="urlextern" title="http://www.chorem.org/news/56" rel="nofollow">Bow - bow 1.2 released</a> (2013/09/25 05:32)</div></li></ul>
<p>
</div>
</p>
<p>
<div class="article">
<div class="actutitle clearfix">
<h3>Nuiton</h3>
</div>
</p>
<ul class="rss"><li><div class="li"><a href="http://www.nuiton.org/news/529" class="urlextern" title="http://www.nuiton.org/news/529" rel="nofollow">nuiton-maven-report-plugin - Nuiton Maven reports plugin 3.0-rc-1 released</a> (2014/02/13 17:43)</div></li><li><div class="li"><a href="http://www.nuiton.org/news/528" class="urlextern" title="http://www.nuiton.org/news/528" rel="nofollow">jaxx - JAXX 2.8.1 released</a> (2014/02/12 18:27)</div></li><li><div class="li"><a href="http://www.nuiton.org/news/526" class="urlextern" title="http://www.nuiton.org/news/526" rel="nofollow">nuiton-validator - Nuiton Validator 3.0-rc-1 released</a> (2014/02/12 18:04)</div></li></ul>
<p>
</div>
</p>
</div>
<!-- EDIT3 SECTION "Actualités des forges" [455-] -->
</div>
</div>
<!-- wikipage stop -->
</div>
</div>
</div>
<div class="footer">
<ul>
<li class="level1"><div class="li"> <a href="/tarifs" class="wikilink1" title="tarifs">Tarifs</a></div>
</li>
<li class="level1"><div class="li"> <a href="/remerciement" class="wikilink1" title="remerciement"> Remerciements</a></div>
</li>
<li class="level1"><div class="li"> <a href="/offres_de_stage" class="wikilink1" title="offres_de_stage"> Offres de stage</a></div>
</li>
<li class="level1"><div class="li"> <a href="/equipe_de_lutins" class="wikilink1" title="equipe_de_lutins"> Les lutins</a></div>
</li>
</ul>
</div>
<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.codelutin.com/" : "http://piwik.codelutin.com/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://piwik.codelutin.com/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tag -->
</body>
</html>
does not support Maven 3
at org.codehaus.mojo.sonar.SonarMojo.checkVersionRequirements(SonarMojo.java:126)
at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:107)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Sonar analysis completed: FAILURE
Build step 'Sonar' changed build result to FAILURE
Build step 'Sonar' marked build as failure
1
1
r313 - in branches/4.2.2: exports rules scripts sensitivityanalysis sensitivityexports simulationplans simulators
by echatellier@users.forge.codelutin.com 01 Dec '13
by echatellier@users.forge.codelutin.com 01 Dec '13
01 Dec '13
Author: echatellier
Date: 2013-12-01 23:05:23 +0100 (Sun, 01 Dec 2013)
New Revision: 313
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/313
Log:
Format and correct some codes
Modified:
branches/4.2.2/exports/Abundances.java
branches/4.2.2/exports/Biomasses.java
branches/4.2.2/exports/CapturesNombre.java
branches/4.2.2/exports/CapturesNombreStrategies.java
branches/4.2.2/exports/CapturesPoids.java
branches/4.2.2/exports/CapturesPoidsStrategies.java
branches/4.2.2/exports/CellsDefinition.java
branches/4.2.2/exports/EffortsMetier.java
branches/4.2.2/exports/MetierZone.java
branches/4.2.2/exports/NonActivite.java
branches/4.2.2/exports/OwnerMargin.java
branches/4.2.2/exports/RegionDefinition.java
branches/4.2.2/exports/RejetsNombre.java
branches/4.2.2/exports/RejetsPoids.java
branches/4.2.2/exports/VesselMargin.java
branches/4.2.2/exports/ZonesDefinition.java
branches/4.2.2/rules/Cantonnement.java
branches/4.2.2/rules/CantonnementPreSimu.java
branches/4.2.2/rules/ChangementParamControlablePresimu.java
branches/4.2.2/rules/EffortReduction.java
branches/4.2.2/rules/GraviteVPUE1.java
branches/4.2.2/rules/InterdictionEngin.java
branches/4.2.2/rules/InterdictionEnginPreSimu.java
branches/4.2.2/rules/TACpoids.java
branches/4.2.2/rules/TailleMin.java
branches/4.2.2/rules/TotalClosure.java
branches/4.2.2/scripts/GravityModel.java
branches/4.2.2/scripts/MinimisationUtil.java
branches/4.2.2/scripts/ObjectiveFunction.java
branches/4.2.2/scripts/ObjectiveFunctionBaranov.java
branches/4.2.2/scripts/ResultName.java
branches/4.2.2/scripts/RuleUtil.java
branches/4.2.2/scripts/SiMatrix.java
branches/4.2.2/sensitivityanalysis/DOptimal.java
branches/4.2.2/sensitivityanalysis/Fast.java
branches/4.2.2/sensitivityanalysis/Morris.java
branches/4.2.2/sensitivityanalysis/OptimumLHS.java
branches/4.2.2/sensitivityanalysis/RandomLHS.java
branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java
branches/4.2.2/sensitivityanalysis/RegularFractions.java
branches/4.2.2/sensitivityanalysis/Sobol.java
branches/4.2.2/sensitivityexports/SensitivityBiomassReferenceY9.java
branches/4.2.2/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java
branches/4.2.2/sensitivityexports/SensitivityBiomassRelativeY6.java
branches/4.2.2/sensitivityexports/SensitivityBiomassY3.java
branches/4.2.2/sensitivityexports/SensitivityCatchWeightReferenceY7.java
branches/4.2.2/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java
branches/4.2.2/sensitivityexports/SensitivityCatchWeightRelativeY4.java
branches/4.2.2/sensitivityexports/SensitivityCatchWeightY1.java
branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java
branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java
branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java
branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassY2.java
branches/4.2.2/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java
branches/4.2.2/simulationplans/SimulationNumberRestriction.java
branches/4.2.2/simulators/DefaultSimulator.java
branches/4.2.2/simulators/SimulatorEffortByCell.java
Modified: branches/4.2.2/exports/Abundances.java
===================================================================
--- branches/4.2.2/exports/Abundances.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/Abundances.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -37,7 +37,7 @@
import fr.ifremer.isisfish.datastore.SimulationStorage;
/**
- * Abundance.java
+ * Abundances.java
*
* Created: 1 septembre 2006
*
@@ -52,8 +52,8 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(Abundances.class);
- protected String [] necessaryResult = {
- ResultName.MATRIX_ABUNDANCE
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_ABUNDANCE
};
@Override
@@ -80,15 +80,15 @@
public void export(SimulationStorage simulation, Writer out) throws Exception {
for (Population pop : simulation.getParameter().getPopulations()) {
MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_ABUNDANCE);
- for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
- Object [] sems = i.getSemanticsCoordinates();
- TimeStep step = (TimeStep)sems[0];
- PopulationGroup group = (PopulationGroup)sems[1];
- Zone zone = (Zone)sems[2];
+ Object[] sems = i.getSemanticsCoordinates();
+ TimeStep step = (TimeStep) sems[0];
+ PopulationGroup group = (PopulationGroup) sems[1];
+ Zone zone = (Zone) sems[2];
double val = i.getValue();
- out.write(pop.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ step.getStep() +";"+ val +"\n");
+ out.write(pop.getName() + ";" + group.getId() + ";" + zone.getName() + ";" + step.getStep() + ";" + val + "\n");
}
}
}
Modified: branches/4.2.2/exports/Biomasses.java
===================================================================
--- branches/4.2.2/exports/Biomasses.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/Biomasses.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -53,8 +53,8 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(Biomasses.class);
- protected String [] necessaryResult = {
- ResultName.MATRIX_BIOMASS
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_BIOMASS
};
@Override
@@ -81,15 +81,15 @@
public void export(SimulationStorage simulation, Writer out) throws Exception {
for (Population pop : simulation.getParameter().getPopulations()) {
MatrixND mat = simulation.getResultStorage().getMatrix(pop, ResultName.MATRIX_BIOMASS);
- for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
- Object [] sems = i.getSemanticsCoordinates();
- TimeStep step = (TimeStep)sems[0];
- PopulationGroup group = (PopulationGroup)sems[1];
- Zone zone = (Zone)sems[2];
-
+ Object[] sems = i.getSemanticsCoordinates();
+ TimeStep step = (TimeStep) sems[0];
+ PopulationGroup group = (PopulationGroup) sems[1];
+ Zone zone = (Zone) sems[2];
+
double val = i.getValue();
- out.write(pop.getName() +";"+ group.getId() +";"+ zone.getName() +";"+ step.getStep() +";"+ val +"\n");
+ out.write(pop.getName() + ";" + group.getId() + ";" + zone.getName() + ";" + step.getStep() + ";" + val + "\n");
}
}
}
Modified: branches/4.2.2/exports/CapturesNombre.java
===================================================================
--- branches/4.2.2/exports/CapturesNombre.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/CapturesNombre.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -54,7 +54,9 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(CapturesNombre.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP
+ };
@Override
public String[] getNecessaryResult() {
@@ -82,8 +84,7 @@
TimeStep lastStep = simulation.getResultStorage().getLastStep();
for (Population pop : simulation.getParameter().getPopulations()) {
- for (TimeStep step = new TimeStep(0); !step.after(lastStep); step = step
- .next()) {
+ for (TimeStep step = new TimeStep(0); !step.after(lastStep); step = step.next()) {
MatrixND mat = simulation.getResultStorage().getMatrix(step,
pop, ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP);
if (mat != null) { // can be null if simulation is stopped before last year simulation
Modified: branches/4.2.2/exports/CapturesNombreStrategies.java
===================================================================
--- branches/4.2.2/exports/CapturesNombreStrategies.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/CapturesNombreStrategies.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -55,7 +55,9 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(CapturesNombreStrategies.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP
+ };
@Override
public String[] getNecessaryResult() {
@@ -78,8 +80,7 @@
}
@Override
- public void export(SimulationStorage simulation, Writer out)
- throws Exception {
+ public void export(SimulationStorage simulation, Writer out) throws Exception {
TimeStep lastStep = simulation.getResultStorage().getLastStep();
for (Population pop : simulation.getParameter().getPopulations()) {
Modified: branches/4.2.2/exports/CapturesPoids.java
===================================================================
--- branches/4.2.2/exports/CapturesPoids.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/CapturesPoids.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -54,7 +54,9 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(CapturesPoids.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP
+ };
@Override
public String[] getNecessaryResult() {
Modified: branches/4.2.2/exports/CapturesPoidsStrategies.java
===================================================================
--- branches/4.2.2/exports/CapturesPoidsStrategies.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/CapturesPoidsStrategies.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -55,7 +55,9 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(CapturesPoidsStrategies.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP
+ };
@Override
public String[] getNecessaryResult() {
Modified: branches/4.2.2/exports/CellsDefinition.java
===================================================================
--- branches/4.2.2/exports/CellsDefinition.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/CellsDefinition.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -50,11 +50,11 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(CellsDefinition.class);
- public String [] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ protected String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
};
@Override
Modified: branches/4.2.2/exports/EffortsMetier.java
===================================================================
--- branches/4.2.2/exports/EffortsMetier.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/EffortsMetier.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -54,7 +54,7 @@
static private Log log = LogFactory.getLog(EffortsMetier.class);
protected String [] necessaryResult = {
- ResultName.MATRIX_EFFORT_PER_STRATEGY_MET
+ ResultName.MATRIX_EFFORT_PER_STRATEGY_MET
};
@Override
@@ -80,7 +80,7 @@
@Override
public void export(SimulationStorage simulation, Writer out) throws Exception {
MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_EFFORT_PER_STRATEGY_MET);
- for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
Object [] sems = i.getSemanticsCoordinates();
TimeStep step = (TimeStep)sems[0];
Modified: branches/4.2.2/exports/MetierZone.java
===================================================================
--- branches/4.2.2/exports/MetierZone.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/MetierZone.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -51,8 +51,8 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(MetierZone.class);
- public String [] necessaryResult = {
- ResultName.MATRIX_METIER_ZONE,
+ protected String [] necessaryResult = {
+ ResultName.MATRIX_METIER_ZONE,
};
@Override
@@ -82,7 +82,7 @@
for (TimeStep step = new TimeStep(0); !step.after(lastStep); step = step.next() ) {
MatrixND mat = simulation.getResultStorage().getMatrix(step, ResultName.MATRIX_METIER_ZONE);
if (mat != null) { // can be null if simulation is stopped before last year simulation
- for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
if (i.getValue() == 1) {
Object metier = i.getSemanticsCoordinates()[0];
Modified: branches/4.2.2/exports/NonActivite.java
===================================================================
--- branches/4.2.2/exports/NonActivite.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/NonActivite.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -54,7 +54,7 @@
static private Log log = LogFactory.getLog(NonActivite.class);
protected String [] necessaryResult = {
- ResultName.MATRIX_NO_ACTIVITY
+ ResultName.MATRIX_NO_ACTIVITY
};
@Override
@@ -80,7 +80,7 @@
@Override
public void export(SimulationStorage simulation, Writer out) throws Exception {
MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_NO_ACTIVITY);
- for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
Object [] sems = i.getSemanticsCoordinates();
TimeStep step = (TimeStep)sems[0];
Modified: branches/4.2.2/exports/OwnerMargin.java
===================================================================
--- branches/4.2.2/exports/OwnerMargin.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/OwnerMargin.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -54,7 +54,7 @@
static private Log log = LogFactory.getLog(OwnerMargin.class);
protected String [] necessaryResult = {
- ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL
+ ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL
};
@Override
@@ -80,9 +80,9 @@
@Override
public void export(SimulationStorage simulation, Writer out) throws Exception {
MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL);
- for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
- Object [] sems = i.getSemanticsCoordinates();
+ Object[] sems = i.getSemanticsCoordinates();
TimeStep step = (TimeStep)sems[0];
Strategy str = (Strategy)sems[1];
Modified: branches/4.2.2/exports/RegionDefinition.java
===================================================================
--- branches/4.2.2/exports/RegionDefinition.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/RegionDefinition.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -49,11 +49,11 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(RegionDefinition.class);
- public String [] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ protected String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
};
@Override
Modified: branches/4.2.2/exports/RejetsNombre.java
===================================================================
--- branches/4.2.2/exports/RejetsNombre.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/RejetsNombre.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -54,7 +54,9 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(RejetsNombre.class);
- protected String[] necessaryResult = { ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP
+ };
@Override
public String[] getNecessaryResult() {
Modified: branches/4.2.2/exports/RejetsPoids.java
===================================================================
--- branches/4.2.2/exports/RejetsPoids.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/RejetsPoids.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -54,8 +54,8 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(RejetsPoids.class);
- protected String[] necessaryResult = { ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP
-
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP
};
@Override
Modified: branches/4.2.2/exports/VesselMargin.java
===================================================================
--- branches/4.2.2/exports/VesselMargin.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/VesselMargin.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -54,7 +54,7 @@
static private Log log = LogFactory.getLog(VesselMargin.class);
protected String [] necessaryResult = {
- ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL
+ ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL
};
@Override
@@ -80,7 +80,7 @@
@Override
public void export(SimulationStorage simulation, Writer out) throws Exception {
MatrixND mat = simulation.getResultStorage().getMatrix(ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL);
- for (MatrixIterator i=mat.iterator(); i.hasNext();) {
+ for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
Object [] sems = i.getSemanticsCoordinates();
TimeStep step = (TimeStep)sems[0];
Modified: branches/4.2.2/exports/ZonesDefinition.java
===================================================================
--- branches/4.2.2/exports/ZonesDefinition.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/exports/ZonesDefinition.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -51,11 +51,11 @@
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory.getLog(ZonesDefinition.class);
- public String [] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ protected String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
};
@Override
Modified: branches/4.2.2/rules/Cantonnement.java
===================================================================
--- branches/4.2.2/rules/Cantonnement.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/rules/Cantonnement.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -50,6 +50,8 @@
/**
* Cantonnement.java
*
+ * Remplace aussi Cantonnement Engin
+ *
* Created: 30 novembre 2006
*
* @author anonymous <anonymous(a)labs.libre-entreprise.org>
@@ -58,10 +60,6 @@
* Last update: $Date: 2007-11-02 17:41:41 $
* by : $Author: bpoussin $
*/
-
-/**
- * Remplace aussi Cantonnement Engin
- */
public class Cantonnement extends AbstractRule {
/** to use log facility, just put in your code: log.info("..."); */
@@ -80,12 +78,12 @@
@Doc(value="End month")
public Month param_endMonth = Month.DECEMBER;
- public String [] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
- ResultName.MATRIX_NO_ACTIVITY,
+ protected String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ ResultName.MATRIX_NO_ACTIVITY,
};
@Override
@@ -126,7 +124,7 @@
public boolean condition(SimulationContext context, TimeStep step, Metier metier) throws Exception {
if (step.before(param_beginStep)) {
return false;
- } else if(step.after(param_endStep)) {
+ } else if (step.after(param_endStep)) {
return false;
}
@@ -204,7 +202,7 @@
zoneCantonnement.addAllCell(tmpCells);
i.remove();
}
- List<Zone> newZone = new ArrayList<Zone>();
+ List<Zone> newZone = new ArrayList<>();
newZone.add(zoneCantonnement);
infoMetier.setZone(newZone);
} else {
@@ -219,10 +217,10 @@
metierMon.addforbiddenMetier(metier);
List<Strategy> strategies = siMatrix.getStrategies(step);
- for(Strategy str : strategies){
+ for (Strategy str : strategies) {
StrategyMonthInfo info = str.getStrategyMonthInfo(step.getMonth());
double prop = info.getProportionMetier(metier);
- if (prop != 0){
+ if (prop != 0) {
noActivity.setValue(str , metier, prop);
info.setProportionMetier(metier, 0);
}
Modified: branches/4.2.2/rules/CantonnementPreSimu.java
===================================================================
--- branches/4.2.2/rules/CantonnementPreSimu.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/rules/CantonnementPreSimu.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -73,15 +73,15 @@
@Doc(value="End month")
public Month param_endMonth = Month.DECEMBER;
- protected Map<Month, MatrixND> tableNonActivite = new HashMap<Month, MatrixND>();
+ protected Map<Month, MatrixND> tableNonActivite = new HashMap<>();
protected boolean affectNonActivite = false;
- public String [] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
- ResultName.MATRIX_NO_ACTIVITY,
+ protected String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ ResultName.MATRIX_NO_ACTIVITY,
};
@Override
@@ -107,7 +107,8 @@
if (effort != null){
for (Month month : chomageMonth) {
StrategyMonthInfo InfoMois = strategy.getStrategyMonthInfo(month);
-//this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite, listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
+ // this.p.tableNonActivite=Regle_action_lib.reportNonActivite(this.p.tableNonActivite,
+ // listestrategies.get(i), metier, mois, InfoMois.getProportionMetier(metier));
log.info("debut reportNonActivite");
// on regarde si on a déjà une entrée pour le mois courant
@@ -160,16 +161,16 @@
else {
log.info("l engin du métier est bien concerné");
List<MetierSeasonInfo> saisons = metier.getMetierSeasonInfo();
- for (MetierSeasonInfo saisonmetier: saisons){
+ for (MetierSeasonInfo saisonmetier : saisons){
int inter = siMatrix.nbCellInter(saisonmetier.getZone(), param_zone);
- if (inter != 0){
+ if (inter != 0) {
List<Cell> MailleMetier = siMatrix.getCells(saisonmetier.getZone());
// les mailles qui reste dans la zone metier
- List<Cell> newCellMetier = new ArrayList<Cell>(MailleMetier);
+ List<Cell> newCellMetier = new ArrayList<>(MailleMetier);
newCellMetier.removeAll(maillefermee);
- List<Month> saison=saisonmetier.getMonths();
+ List<Month> saison = saisonmetier.getMonths();
if (saison.containsAll(SaisonFermee)){
log.info("il y a bien intersection entre la zone métier et le cantonnement pour la saison "+saison.toString());
// calcule de la zone restante:
Modified: branches/4.2.2/rules/ChangementParamControlablePresimu.java
===================================================================
--- branches/4.2.2/rules/ChangementParamControlablePresimu.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/rules/ChangementParamControlablePresimu.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -77,11 +77,11 @@
@Doc(value="New param controlable value")
public String param_newParamValue = "80";
- public String [] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ protected String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
};
@Override
Modified: branches/4.2.2/rules/EffortReduction.java
===================================================================
--- branches/4.2.2/rules/EffortReduction.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/rules/EffortReduction.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -57,9 +57,13 @@
@Doc("Pourcentage de reduction d effort applique.")
public double param_PercentReduction = 0.5;
- boolean first = true;
+ protected boolean first = true;
- protected String[] necessaryResult = {};
+ protected String[] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ };
/**
* @return the necessaryResult
Modified: branches/4.2.2/rules/GraviteVPUE1.java
===================================================================
--- branches/4.2.2/rules/GraviteVPUE1.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/rules/GraviteVPUE1.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -59,21 +59,20 @@
static private Log log = LogFactory.getLog(GraviteVPUE1.class);
/** stocke la somme des prop initiales [str x month] */
- private MatrixND SommePropInitial = null;
- /** stocke par strat*met, la dernière attractivite pour chaque mois [str x met x month] */
+ protected MatrixND SommePropInitial = null;
/** permet de stocker les CPUE nominales [str x met] */
- private MatrixND valuePerUnitOfEffort = null;
+ protected MatrixND valuePerUnitOfEffort = null;
- public String[] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
- ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
- //ResultName.MATRIX_EFFORT_PER_STRATEGY_MET,
- ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET, // garder la ,
+ // Booleen permettant que ne boucler que sur un seul metier dans la preaction :
+ protected boolean first = true;
+ protected String[] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET
};
@Override
@@ -146,7 +145,6 @@
SommePropInitial.setValue(str, info.getMonth(), somme);
}
}
-
}
/**
@@ -164,8 +162,6 @@
return step.getYear() > 0;
}
- // Booleen permettant que ne boucler que sur un seul metier dans la preaction :
- boolean first = true;
/**
* Si la condition est vrai alors cette action est executee avant le pas
Modified: branches/4.2.2/rules/InterdictionEngin.java
===================================================================
--- branches/4.2.2/rules/InterdictionEngin.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/rules/InterdictionEngin.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -71,11 +71,11 @@
@Doc(value="do the doc of param endMonth")
public Month param_endMonth = Month.DECEMBER;
- public String [] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ protected String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
};
@Override
@@ -167,7 +167,7 @@
// 1er cas:l'effort est reporte sur un metier de la meme strategie,
// n'ayant pas l'espece comme capture principale et pechant avec le meme engin
- List<EffortDescription> MetiersPossibles = new ArrayList<EffortDescription>(Strat.getSetOfVessels().getPossibleMetiers());
+ List<EffortDescription> MetiersPossibles = new ArrayList<>(Strat.getSetOfVessels().getPossibleMetiers());
// on verifie que les metiers sont bien pratiques au mois courant,
// qu'ils n'ont pas le meme engin et qu'ils ne sont pas
@@ -184,7 +184,7 @@
// on repartit maintenant l'effort entre les differents metiers
// possibles dans la meme strategie si un metier possible existe bien
- if (MetiersPossibles.size() != 0){
+ if (MetiersPossibles.size() != 0) {
int NbMetier=MetiersPossibles.size();
for (EffortDescription effort : MetiersPossibles) {
Metier met = effort.getPossibleMetiers();
@@ -203,7 +203,7 @@
siMatrix.getMetiers(step));
matNonActivite.setValue(Strat, metier,
StratMonthInfo.getProportionMetier(metier));
- StratMonthInfo.setProportionMetier(metier,0);
+ StratMonthInfo.setProportionMetier(metier, 0);
}
}
Modified: branches/4.2.2/rules/InterdictionEnginPreSimu.java
===================================================================
--- branches/4.2.2/rules/InterdictionEnginPreSimu.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/rules/InterdictionEnginPreSimu.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -70,14 +70,14 @@
@Doc(value="do the doc of param endMonth")
public Month param_endMonth = Month.DECEMBER;
- protected Map<Month, MatrixND> tableNonActivite = new HashMap<Month, MatrixND>();
+ protected Map<Month, MatrixND> tableNonActivite = new HashMap<>();
protected boolean affectNonActivite = false;
- public String [] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ protected String [] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
};
@Override
@@ -207,7 +207,7 @@
@Override
public void preAction(SimulationContext context, TimeStep step, Metier metier) throws Exception {
// on ne doit le faire qu'une seul fois quelque soit le nombre de metier
- affectNonActivite=true;
+ affectNonActivite = true;
MatrixND mat = tableNonActivite.get(step.getMonth());
MetierMonitor metierMon = context.getMetierMonitor();
@@ -215,8 +215,7 @@
if (noActivity == null) {
metierMon.setNoActivity(step, mat.copy());
- }
- else {
+ } else {
noActivity = noActivity.add(mat);
}
// fin
Modified: branches/4.2.2/rules/TACpoids.java
===================================================================
--- branches/4.2.2/rules/TACpoids.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/rules/TACpoids.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -87,13 +87,13 @@
@Doc("TAC in tons")
public double param_tacInTons = 900;
- boolean affectation = false;
+ protected boolean affectation = false;
protected String[] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
};
/**
Modified: branches/4.2.2/rules/TailleMin.java
===================================================================
--- branches/4.2.2/rules/TailleMin.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/rules/TailleMin.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin, Stéphanie Mahevas, Chatellier Eric
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin, Stéphanie Mahevas, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -79,7 +79,7 @@
protected boolean affectation = true;
- public String[] necessaryResult = {
+ protected String[] necessaryResult = {
// put here all necessary result for this rule
// example:
// ResultName.MATRIX_BIOMASS,
Modified: branches/4.2.2/rules/TotalClosure.java
===================================================================
--- branches/4.2.2/rules/TotalClosure.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/rules/TotalClosure.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -57,8 +57,8 @@
public Month param_beginMonth = Month.JANUARY;
public Month param_endMonth = Month.JANUARY;
- public String[] necessaryResult = {
- ResultName.MATRIX_NO_ACTIVITY
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_NO_ACTIVITY
};
@Override
@@ -77,6 +77,7 @@
*/
@Override
public void init(SimulationContext context) throws Exception {
+
}
/**
Modified: branches/4.2.2/scripts/GravityModel.java
===================================================================
--- branches/4.2.2/scripts/GravityModel.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/scripts/GravityModel.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
+ * Copyright (C) 2006 - 2013 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/scripts/MinimisationUtil.java
===================================================================
--- branches/4.2.2/scripts/MinimisationUtil.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/scripts/MinimisationUtil.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2012 Ifremer, CodeLutin, Chatellier Eric
+ * Copyright (C) 2012, 2013 Ifremer, CodeLutin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/scripts/ObjectiveFunction.java
===================================================================
--- branches/4.2.2/scripts/ObjectiveFunction.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/scripts/ObjectiveFunction.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -1,6 +1,9 @@
/*
- * Copyright (C) 2012 lgasche
- *
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2012, 2013 Ifremer, CodeLutin, lgasche
+ * %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
@@ -14,6 +17,7 @@
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
*/
package scripts;
Modified: branches/4.2.2/scripts/ObjectiveFunctionBaranov.java
===================================================================
--- branches/4.2.2/scripts/ObjectiveFunctionBaranov.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/scripts/ObjectiveFunctionBaranov.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -1,6 +1,9 @@
/*
- * Copyright (C) 2012 lgasche
- *
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2012, 2013 Ifremer, CodeLutin, lgasche
+ * %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
@@ -14,6 +17,7 @@
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
*/
package scripts;
Modified: branches/4.2.2/scripts/ResultName.java
===================================================================
--- branches/4.2.2/scripts/ResultName.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/scripts/ResultName.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin
+ * Copyright (C) 2006 - 2013 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/scripts/RuleUtil.java
===================================================================
--- branches/4.2.2/scripts/RuleUtil.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/scripts/RuleUtil.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, CodeLutin, Chatellier Eric
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/scripts/SiMatrix.java
===================================================================
--- branches/4.2.2/scripts/SiMatrix.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/scripts/SiMatrix.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2011 Ifremer, Code Lutin, Benjamin Poussin
+ * Copyright (C) 2006 - 2013 Ifremer, Code Lutin, Benjamin Poussin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -1493,12 +1493,6 @@
return result;
}
- ///////////////////////////////////////////////////////////////////////////
- //
- //
- //
- ///////////////////////////////////////////////////////////////////////////
-
/**
* @param step
* @return
@@ -1526,12 +1520,6 @@
return result;
}
- ///////////////////////////////////////////////////////////////////////////
- //
- //
- //
- ///////////////////////////////////////////////////////////////////////////
-
/**
*
*
@@ -1556,11 +1544,6 @@
return result;
}
- ///////////////////////////////////////////////////////////////////////////
- //
- //
- //
- ///////////////////////////////////////////////////////////////////////////
public MatrixND matrixEffortNominalPerStrategyMet(TimeStep step) throws TopiaException {
List<Strategy> strategies = getStrategies(step);
@@ -1614,7 +1597,7 @@
MatrixND catchPerStrategy = null;
- for (TimeStep loopstep = new TimeStep(step.getYear() * 12); loopstep.beforeOrEquals(step); loopstep=loopstep.next()){
+ for (TimeStep loopstep = new TimeStep(step.getYear() * 12); loopstep.beforeOrEquals(step); loopstep=loopstep.next()) {
// On fait cette boucle pour contourner les aspects de cache qui font que les resultats ne sont pas recuperes
//s'ils ont deja ete calcules une fois (meme s'ils ont change depuis)
// beforeOrEquals sert a bien prendre Decembre aussi
Modified: branches/4.2.2/sensitivityanalysis/DOptimal.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/DOptimal.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityanalysis/DOptimal.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/sensitivityanalysis/Fast.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/Fast.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityanalysis/Fast.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -24,10 +24,8 @@
import java.io.File;
import java.util.List;
-import java.util.Map;
import fr.ifremer.isisfish.simulator.sensitivity.*;
-import org.apache.commons.lang3.StringUtils;
import org.nuiton.j2r.REngine;
import org.nuiton.j2r.RException;
import org.nuiton.j2r.RProxy;
@@ -35,8 +33,6 @@
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.export.SensitivityExport;
import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
import fr.ifremer.isisfish.util.Doc;
import org.nuiton.j2r.types.RDataFrame;
Modified: branches/4.2.2/sensitivityanalysis/Morris.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/Morris.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityanalysis/Morris.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/sensitivityanalysis/OptimumLHS.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/OptimumLHS.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityanalysis/OptimumLHS.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -37,7 +37,6 @@
import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
import fr.ifremer.isisfish.util.Doc;
import org.nuiton.j2r.types.RDataFrame;
Modified: branches/4.2.2/sensitivityanalysis/RandomLHS.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/RandomLHS.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityanalysis/RandomLHS.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -39,7 +39,6 @@
import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
import fr.ifremer.isisfish.util.Doc;
/**
Modified: branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/sensitivityanalysis/RegularFractions.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/RegularFractions.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityanalysis/RegularFractions.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -35,13 +35,10 @@
import fr.ifremer.isisfish.simulator.SimulationParameter;
import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
-import fr.ifremer.isisfish.simulator.sensitivity.Domain;
import fr.ifremer.isisfish.simulator.sensitivity.Factor;
import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
import fr.ifremer.isisfish.util.Doc;
public class RegularFractions extends AbstractSensitivityAnalysis {
Modified: branches/4.2.2/sensitivityanalysis/Sobol.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/Sobol.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityanalysis/Sobol.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -24,7 +24,6 @@
import java.io.File;
import java.util.List;
-import java.util.Map;
import fr.ifremer.isisfish.export.SensitivityExport;
import fr.ifremer.isisfish.simulator.sensitivity.*;
@@ -34,7 +33,6 @@
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
import fr.ifremer.isisfish.util.Doc;
import org.nuiton.j2r.types.RDataFrame;
Modified: branches/4.2.2/sensitivityexports/SensitivityBiomassReferenceY9.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivityBiomassReferenceY9.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivityBiomassReferenceY9.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/sensitivityexports/SensitivityBiomassRelativeY6.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivityBiomassRelativeY6.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivityBiomassRelativeY6.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/sensitivityexports/SensitivityBiomassY3.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivityBiomassY3.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivityBiomassY3.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/sensitivityexports/SensitivityCatchWeightReferenceY7.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivityCatchWeightReferenceY7.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivityCatchWeightReferenceY7.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -39,14 +39,15 @@
import fr.ifremer.isisfish.types.TimeStep;
import fr.ifremer.isisfish.util.Doc;
-public class SensitivityCatchWeightRelativeReferenceY10 implements
- SensitivityExport {
+public class SensitivityCatchWeightRelativeReferenceY10 implements SensitivityExport {
/** to use log facility, just put in your code: log.info("..."); */
static private Log log = LogFactory
.getLog(SensitivityCatchWeightRelativeReferenceY10.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP
+ };
@Doc("Population")
public Population param_pop;
Modified: branches/4.2.2/sensitivityexports/SensitivityCatchWeightRelativeY4.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivityCatchWeightRelativeY4.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivityCatchWeightRelativeY4.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -43,7 +43,9 @@
static private Log log = LogFactory
.getLog(SensitivityCatchWeightRelativeY4.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP
+ };
@Doc("Population")
public Population param_pop;
Modified: branches/4.2.2/sensitivityexports/SensitivityCatchWeightY1.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivityCatchWeightY1.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivityCatchWeightY1.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -43,7 +43,9 @@
static private Log log = LogFactory
.getLog(SensitivityCatchWeightY1.class);
- protected String[] necessaryResult = { ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP
+ };
@Doc("Population")
public Population param_pop;
Modified: branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -50,13 +50,15 @@
static private Log log = LogFactory
.getLog(SensitivitySpawningBiomassReferenceY8.class);
- protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_BIOMASS
+ };
@Doc("Population")
public Population param_pop;
@Doc("URL of the Biomasses.csv reference export file")
- public String param_referenceBiomassCSV ="";
+ public String param_referenceBiomassCSV = "";
@Override
public void export(SimulationStorage simulation, Writer out)
Modified: branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -57,7 +57,7 @@
public Population param_pop;
@Doc("URL of the Biomasses.csv reference export file")
- public String param_referenceBiomassCSV ="";
+ public String param_referenceBiomassCSV = "";
@Override
public void export(SimulationStorage simulation, Writer out)
Modified: branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -45,7 +45,9 @@
static private Log log = LogFactory
.getLog(SensitivitySpawningBiomassRelativeY5.class);
- protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_BIOMASS
+ };
@Doc("Population")
public Population param_pop;
Modified: branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassY2.java
===================================================================
--- branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassY2.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/sensitivityexports/SensitivitySpawningBiomassY2.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -45,7 +45,9 @@
static private Log log = LogFactory
.getLog(SensitivitySpawningBiomassY2.class);
- protected String[] necessaryResult = { ResultName.MATRIX_BIOMASS };
+ protected String[] necessaryResult = {
+ ResultName.MATRIX_BIOMASS
+ };
@Doc("Population")
public Population param_pop;
Modified: branches/4.2.2/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java
===================================================================
--- branches/4.2.2/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2007 - 2011 Ifremer, CodeLutin, Sigrid Lehuta
+ * Copyright (C) 2007 - 2013 Ifremer, CodeLutin, Sigrid Lehuta
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -110,7 +110,7 @@
//*** write the name of the simulated matrix that contains the data corresponding
// to your observations (here MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP)
- public String[] necessaryResult = {
+ protected String[] necessaryResult = {
ResultName.MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP
};
Modified: branches/4.2.2/simulationplans/SimulationNumberRestriction.java
===================================================================
--- branches/4.2.2/simulationplans/SimulationNumberRestriction.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/simulationplans/SimulationNumberRestriction.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2011 Ifremer, CodeLutin
+ * Copyright (C) 2006 - 2013 Ifremer, CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -49,11 +49,11 @@
@Doc(value = "do the doc of param max")
public int param_max = 10;
- public String[] necessaryResult = {
- // put here all necessary result for this rule
- // example:
- // ResultName.MATRIX_BIOMASS,
- // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
+ protected String[] necessaryResult = {
+ // put here all necessary result for this rule
+ // example:
+ // ResultName.MATRIX_BIOMASS,
+ // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,
};
@Override
Modified: branches/4.2.2/simulators/DefaultSimulator.java
===================================================================
--- branches/4.2.2/simulators/DefaultSimulator.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/simulators/DefaultSimulator.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin, Chatellier Eric
+ * Copyright (C) 2006 - 2013 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
Modified: branches/4.2.2/simulators/SimulatorEffortByCell.java
===================================================================
--- branches/4.2.2/simulators/SimulatorEffortByCell.java 2013-11-28 09:19:52 UTC (rev 312)
+++ branches/4.2.2/simulators/SimulatorEffortByCell.java 2013-12-01 22:05:23 UTC (rev 313)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Benjamin Poussin
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Benjamin Poussin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
1
0
Author: echatellier
Date: 2013-11-28 10:19:52 +0100 (Thu, 28 Nov 2013)
New Revision: 312
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/312
Log:
Update deps.
Build with java7.
Modified:
branches/4.2.2/pom.xml
Modified: branches/4.2.2/pom.xml
===================================================================
--- branches/4.2.2/pom.xml 2013-11-28 09:19:27 UTC (rev 311)
+++ branches/4.2.2/pom.xml 2013-11-28 09:19:52 UTC (rev 312)
@@ -14,7 +14,7 @@
<packaging>jar</packaging>
<!--Version -->
- <version>4.2.2</version>
+ <version>4.3.0</version>
<!--Description -->
<description>Data for Isis-fish</description>
@@ -36,10 +36,10 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
- <version>2.5.1</version>
+ <version>3.1</version>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
+ <source>1.7</source>
+ <target>1.7</target>
<excludes>
<exclude>**/simulations/**</exclude>
<exclude>**/formules/**</exclude>
@@ -74,7 +74,7 @@
<dependency>
<groupId>fr.ifremer</groupId>
<artifactId>isis-fish</artifactId>
- <version>4.2.2.0-SNAPSHOT</version>
+ <version>4.3.0.0-beta1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
1
0
28 Nov '13
Author: echatellier
Date: 2013-11-28 10:19:27 +0100 (Thu, 28 Nov 2013)
New Revision: 311
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/311
Log:
Update AS scripts
Modified:
branches/4.2.2/sensitivityanalysis/DOptimal.java
branches/4.2.2/sensitivityanalysis/Fast.java
branches/4.2.2/sensitivityanalysis/Morris.java
branches/4.2.2/sensitivityanalysis/OptimumLHS.java
branches/4.2.2/sensitivityanalysis/RandomLHS.java
branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java
branches/4.2.2/sensitivityanalysis/RegularFractions.java
branches/4.2.2/sensitivityanalysis/Sobol.java
Modified: branches/4.2.2/sensitivityanalysis/DOptimal.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/DOptimal.java 2013-11-08 10:22:14 UTC (rev 310)
+++ branches/4.2.2/sensitivityanalysis/DOptimal.java 2013-11-28 09:19:27 UTC (rev 311)
@@ -109,16 +109,15 @@
if (domain instanceof ContinuousDomain) {
ContinuousDomain contDomain = (ContinuousDomain) domain;
int card = factor.getCardinality();
- Double min = contDomain.getCalculatorMinBound();
- Double max = contDomain.getCalculatorMaxBound();
-
- for (int i = 0; i < card; i++) {
- //add the ith value
- vector += (min + (i * (max - min) / (card - 1))) + ",";
- }
+// Double min = contDomain.getCalculatorMinBound();
+// Double max = contDomain.getCalculatorMaxBound();
+//
+// for (int i = 0; i < card; i++) {
+// //add the ith value
+// vector += (min + (i * (max - min) / (card - 1))) + ",";
+// }
} else {
- Map<Object, Object> values = ((DiscreteDomain) domain).getValues();
- int nbValues = values.size();
+ int nbValues = ((DiscreteDomain) domain).getValuesCount();
for (int i = 0; i < nbValues; i++) {
vector += "as.integer(" + i + "),";
}
@@ -202,9 +201,9 @@
if (domain instanceof ContinuousDomain){
ContinuousDomain contDomain = (ContinuousDomain)domain;
distribution += "\"qunif\"";
- parameters += "\"[" + contDomain.getMinBound()
- + ";" + contDomain.getMaxBound()
- + "]\"";
+// parameters += "\"[" + contDomain.getMinBound()
+// + ";" + contDomain.getMaxBound()
+// + "]\"";
} else {
DiscreteDomain discDomain = (DiscreteDomain)domain;
distribution += "\"discrete\"";
Modified: branches/4.2.2/sensitivityanalysis/Fast.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/Fast.java 2013-11-08 10:22:14 UTC (rev 310)
+++ branches/4.2.2/sensitivityanalysis/Fast.java 2013-11-28 09:19:27 UTC (rev 311)
@@ -24,8 +24,10 @@
import java.io.File;
import java.util.List;
+import java.util.Map;
import fr.ifremer.isisfish.simulator.sensitivity.*;
+import org.apache.commons.lang3.StringUtils;
import org.nuiton.j2r.REngine;
import org.nuiton.j2r.RException;
import org.nuiton.j2r.RProxy;
@@ -35,8 +37,6 @@
import fr.ifremer.isisfish.simulator.SimulationParameter;
import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain;
import fr.ifremer.isisfish.util.Doc;
import org.nuiton.j2r.types.RDataFrame;
@@ -44,9 +44,9 @@
* Implementation of Fast method using R.
*
* @author jcouteau
- * @version $Revision: 89 $
+ * @version $Revision: 3842 $
*
- * Last update : $Date: 2009-03-25 13:45:16 +0100 (mer., 25 mars 2009) $ By :
+ * Last update : $Date: 2013-11-22 18:52:48 +0100 (ven., 22 nov. 2013) $ By :
* $Author: jcouteau $
*/
public class Fast extends AbstractSensitivityAnalysis {
@@ -87,14 +87,9 @@
SensitivityScenarios thisExperiment = new SensitivityScenarios();
List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
- //Test all factors, if one is discrete, return null
- for (int i = 0; i < factorNumber; i++) {
- if (factors.get(i).getDomain() instanceof DiscreteDomain) {
- throw new SensitivityException(factors.get(i).getName() +
- " has a discrete domain, this is not acceptable for fast " +
- "method.");
- }
- }
+ // only run with continuous
+ checkAllFactorContinuous(factors);
+
String rInstruction = "a<-fast99(" +
"model=NULL," +
"factors=%s, " +
@@ -145,33 +140,8 @@
nbExperiments = (Integer)engine.eval("dim(a$X)[1]");
- String factorDistribution = "isis.factor.distribution<-data.frame(" +
- "NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
+ engine.voidEval(getIsisFactorDistribution(factors));
- // Creating the vectors.
- String distribution = "";
- String parameters = "";
- String factorNames = "";
-
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = factors.get(i);
- ContinuousDomain domain = (ContinuousDomain) factor.getDomain();
- if (i != 0) {
- distribution += ",";
- parameters += ",";
- factorNames += ",";
- }
-
- distribution += "\"qunif\"";
- parameters += "\"[" + domain.getMinBound() + ";" +
- domain.getMaxBound() + "]\"";
- factorNames += "\"" + factor.getName() + "\"";
- }
- engine.voidEval(String.format(factorDistribution, factorNames,
- distribution, parameters));
-
engine.voidEval("call<-a$call");
@@ -199,18 +169,7 @@
Scenario experimentScenario = new Scenario();
for (int i = 0; i < factorNumber; i++) {
Factor factor = plan.getFactors().get(i);
- Domain domain = factor.getDomain();
- if ((domain instanceof MatrixContinuousDomain)
- || (domain instanceof EquationContinuousDomain)) {
- factor.setValueForIdentifier(dataFrame.get(i,j));
- } else {
- ContinuousDomain continuousDomain = (ContinuousDomain)domain;
- Double min = continuousDomain.getCalculatorMinBound();
- Double max = continuousDomain.getCalculatorMaxBound();
- Double dFValue = (Double)dataFrame.get(i,j);
- Double value = min + (max - min) * dFValue;
- factor.setValueForIdentifier(value);
- }
+ factor.setValueForIdentifier(dataFrame.get(i,j));
experimentScenario.addFactor(factor);
}
thisExperimentScenarios.add(experimentScenario);
Modified: branches/4.2.2/sensitivityanalysis/Morris.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/Morris.java 2013-11-08 10:22:14 UTC (rev 310)
+++ branches/4.2.2/sensitivityanalysis/Morris.java 2013-11-28 09:19:27 UTC (rev 311)
@@ -25,14 +25,10 @@
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.export.SensitivityExport;
import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
-import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
-import fr.ifremer.isisfish.simulator.sensitivity.Factor;
-import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
+import fr.ifremer.isisfish.simulator.sensitivity.*;
import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
import fr.ifremer.isisfish.util.Doc;
+import org.apache.commons.lang3.StringUtils;
import org.nuiton.j2r.REngine;
import org.nuiton.j2r.RException;
import org.nuiton.j2r.RProxy;
@@ -40,6 +36,7 @@
import java.io.File;
import java.util.List;
+import java.util.Map;
/**
* Implementation of Morris method using R.
@@ -87,7 +84,7 @@
param_r = 4;
}
- testNoDiscrete(factors);
+ checkAllUniformDistribution(factors);
// Creating the vectors.
String factorNames = "";
@@ -97,7 +94,6 @@
String bsup = "";
for (int i = 0; i < factorNumber; i++) {
Factor factor = factors.get(i);
- ContinuousDomain domain = (ContinuousDomain) factor.getDomain();
if (i != 0) {
factorNames += ",";
levels += ",";
@@ -112,9 +108,8 @@
gridJump += factor.getCardinality() / 2;
- binf += domain.getCalculatorMinBound();
-
- bsup += domain.getCalculatorMaxBound();
+ binf += 0;
+ bsup += 1;
}
String rInstruction = "a<-morris(model=NULL,factors=c(%s),r=%s," +
@@ -128,7 +123,7 @@
rCall = editRInstruction(rCall);
}
- REngine engine = null;
+ REngine engine;
try {
engine = new RProxy();
@@ -178,9 +173,17 @@
parameters += ",";
}
- distribution += "\"qunif\"";
- parameters += "\"[" + domain.getMinBound() + ";" +
- domain.getMaxBound() + "]\"";
+ Distribution r_distribution = domain.getDistribution();
+
+ distribution += "\""+ r_distribution.getInstruction() +"\"";
+ parameters += "\"[";
+
+ for (Map.Entry<String,Object> param:domain.getDistributionParameters().entrySet()){
+ parameters += param.getKey() + "=" + param.getValue() + ";";
+ }
+
+ parameters = StringUtils.removeEnd(parameters,";");
+ parameters += "]\"";
}
engine.voidEval(String.format(factorDistribution, factorNames,
distribution, parameters));
Modified: branches/4.2.2/sensitivityanalysis/OptimumLHS.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/OptimumLHS.java 2013-11-08 10:22:14 UTC (rev 310)
+++ branches/4.2.2/sensitivityanalysis/OptimumLHS.java 2013-11-28 09:19:27 UTC (rev 311)
@@ -45,7 +45,7 @@
* Implementation of Optimum Latin Hypercube method using R.
*
* @author jcouteau
- * @version $Revision: 1.0 $
+ * @version $Revision: 3842 $
*/
public class OptimumLHS extends AbstractSensitivityAnalysis {
@@ -82,7 +82,7 @@
List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
//Test all factors, if one is discrete, return null
- testNoDiscrete(factors);
+ checkAllFactorContinuous(factors);
try {
REngine engine = new RProxy();
@@ -126,34 +126,7 @@
thisExperiment.setScenarios(thisExperimentScenarios);
}
- String isisFactorDistribution = "isis.factor.distribution<-" +
- "data.frame(" +
- "NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
-
- String distribution = "";
- String parameters = "";
- String factorNames = "";
-
- for (int i = 0; i < factors.size(); i++) {
- Factor tempFactor = factors.get(i);
- ContinuousDomain domain = (ContinuousDomain) tempFactor.getDomain();
- if (i != 0) {
- distribution += ",";
- factorNames += ",";
- parameters += ",";
- }
-
- factorNames += "\"" + factors.get(i).getName() + "\"";
- distribution += "\"qunif\"";
- //add [min;max] to parameters
- parameters += "\"[" + domain.getMinBound() + ";" +
- domain.getMaxBound() + "]\"";
- }
-
- engine.voidEval(String.format(isisFactorDistribution, factorNames,
- distribution, parameters));
+ engine.voidEval(getIsisFactorDistribution(factors));
engine.voidEval("call<-" + "\"x<-optimumLHS("
+ "n=" + param_simulationNumber
Modified: branches/4.2.2/sensitivityanalysis/RandomLHS.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/RandomLHS.java 2013-11-08 10:22:14 UTC (rev 310)
+++ branches/4.2.2/sensitivityanalysis/RandomLHS.java 2013-11-28 09:19:27 UTC (rev 311)
@@ -46,7 +46,7 @@
* Implementation of Random Latin Hypercube method using R.
*
* @author jcouteau
- * @version $Revision: 1.0 $
+ * @version $Revision: 3842 $
*/
public class RandomLHS extends AbstractSensitivityAnalysis {
@@ -78,7 +78,7 @@
List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios(); //The list of scenarios
List<Factor> factors = plan.getFactors(); //The factors
- testNoDiscrete(factors);
+ checkAllFactorContinuous(factors);
try {
@@ -122,35 +122,8 @@
thisExperiment.setScenarios(thisExperimentScenarios);
}
- String isisFactorDistribution = "isis.factor.distribution<-" +
- "data.frame(" +
- "NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
+ engine.voidEval(getIsisFactorDistribution(factors));
- String distribution = "";
- String parameters = "";
- String factorNames = "";
-
-
- //Create the strings for the isis.MethodExp instruction
- for (int i = 0; i < factors.size(); i++) {
- ContinuousDomain domain = (ContinuousDomain)factors.get(i).getDomain();
- if (i != 0) {
- distribution += ","; //the distribution
- factorNames += ","; //the factor names
- parameters += ","; //the parameters
- }
-
- factorNames += "\"" + factors.get(i).getName() + "\"";
- distribution += "\"qunif\""; //all distributions are qunif
- double min = domain.getCalculatorMinBound();
- double max = domain.getCalculatorMaxBound();
- parameters += "\"[" + min + ";" + max + "]\"";
- }
- engine.voidEval(String.format(isisFactorDistribution, factorNames,
- distribution, parameters));
-
engine.voidEval("call<-" + "\"x<-randomLHS("
+ param_simulationNumber + "," + factorNumber + ")\"");
Modified: branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java 2013-11-08 10:22:14 UTC (rev 310)
+++ branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java 2013-11-28 09:19:27 UTC (rev 311)
@@ -100,20 +100,19 @@
Domain domain = factor.getDomain();
if (domain instanceof ContinuousDomain) {
- ContinuousDomain contDomain = (ContinuousDomain) domain;
- int card = factor.getCardinality();
- Double min = contDomain.getCalculatorMinBound();
- Double max = contDomain.getCalculatorMaxBound();
-
- for (int i = 0; i < card; i++) {
- //add the ith value
- vector += (min + (i * (max - min) / (card - 1))) + ",";
- }
+// ContinuousDomain contDomain = (ContinuousDomain) domain;
+// int card = factor.getCardinality();
+// Double min = contDomain.getCalculatorMinBound();
+// Double max = contDomain.getCalculatorMaxBound();
+//
+// for (int i = 0; i < card; i++) {
+// //add the ith value
+// vector += (min + (i * (max - min) / (card - 1))) + ",";
+// }
}
if (domain instanceof DiscreteDomain) {
- Map<Object, Object> values = ((DiscreteDomain) domain).getValues();
- int nbValues = values.size();
+ int nbValues = ((DiscreteDomain) domain).getValuesCount();
for (int i = 0; i < nbValues; i++) {
vector += "as.integer(" + i + "),";
}
@@ -178,9 +177,9 @@
if (domain instanceof ContinuousDomain){
ContinuousDomain contDomain = (ContinuousDomain)domain;
distribution += "\"qunif\"";
- parameters += "\"[" + contDomain.getMinBound()
- + ";" + contDomain.getMaxBound()
- + "]\"";
+// parameters += "\"[" + contDomain.getMinBound()
+// + ";" + contDomain.getMaxBound()
+// + "]\"";
} else {
DiscreteDomain discDomain = (DiscreteDomain)domain;
distribution += "\"discrete\"";
Modified: branches/4.2.2/sensitivityanalysis/RegularFractions.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/RegularFractions.java 2013-11-08 10:22:14 UTC (rev 310)
+++ branches/4.2.2/sensitivityanalysis/RegularFractions.java 2013-11-28 09:19:27 UTC (rev 311)
@@ -42,8 +42,6 @@
import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain;
import fr.ifremer.isisfish.util.Doc;
public class RegularFractions extends AbstractSensitivityAnalysis {
@@ -89,20 +87,15 @@
String factorNames = "";
//Test all factors, if one is discrete, return null
+ checkAllFactorContinuous(factors);
+
//Create a string with all factors names
for (int i = 0; i < factorNumber; i++) {
- Domain domain = factors.get(i).getDomain();
if (i != 0) {
factorNames += ",";
}
factorNames += "\"" + factors.get(i).getName() + "\"";
-
- if (domain instanceof DiscreteDomain) {
- throw new SensitivityException(factors.get(i).getName() +
- " has a discrete domain, this is not acceptable for " +
- "this method.");
- }
}
try {
@@ -157,18 +150,7 @@
Scenario experimentScenario = new Scenario();
for (int i = 0; i < factors.size(); i++) {
Factor factor = plan.getFactors().get(i);
- Domain domain = factor.getDomain();
- Double dFValue = (Double)dataFrame.get(i,j);
- if ((domain instanceof MatrixContinuousDomain)
- || (domain instanceof EquationContinuousDomain)) {
- factor.setValueForIdentifier(dFValue);
- } else {
- ContinuousDomain contDomain = (ContinuousDomain)domain;
- Double max = contDomain.getCalculatorMaxBound();
- Double min = contDomain.getCalculatorMinBound();
- Double value = min + (max - min) * dFValue / (param_p - 1);
- factor.setValueForIdentifier(value);
- }
+ factor.setValueForIdentifier(dataFrame.get(i,j));
experimentScenario.addFactor(factor);
}
thisExperimentScenarios.add(experimentScenario);
@@ -207,7 +189,7 @@
}
engine.voidEval(dataframe);
- engine.voidEval("isis.factor.distribution<-c(0.0)");
+ engine.voidEval(getIsisFactorDistribution(factors));
engine.voidEval("isis.MethodExp<-list(" +
"\"isis.factors\"=isis.factors," +
Modified: branches/4.2.2/sensitivityanalysis/Sobol.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/Sobol.java 2013-11-08 10:22:14 UTC (rev 310)
+++ branches/4.2.2/sensitivityanalysis/Sobol.java 2013-11-28 09:19:27 UTC (rev 311)
@@ -24,20 +24,16 @@
import java.io.File;
import java.util.List;
+import java.util.Map;
import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.simulator.sensitivity.*;
+import org.apache.commons.lang3.StringUtils;
import org.nuiton.j2r.REngine;
import org.nuiton.j2r.RProxy;
import fr.ifremer.isisfish.datastore.SimulationStorage;
import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
-import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
-import fr.ifremer.isisfish.simulator.sensitivity.Domain;
-import fr.ifremer.isisfish.simulator.sensitivity.Factor;
-import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
import fr.ifremer.isisfish.util.Doc;
import org.nuiton.j2r.types.RDataFrame;
@@ -46,9 +42,9 @@
* Implementation of Sobol method using R.
*
* @author jcouteau
- * @version $Revision: 89 $
+ * @version $Revision: 3842 $
*
- * Last update : $Date: 2009-03-25 13:45:16 +0100 (mer., 25 mars 2009) $ By :
+ * Last update : $Date: 2013-11-22 18:52:48 +0100 (ven., 22 nov. 2013) $ By :
* $Author: jcouteau $
*/
public class Sobol extends AbstractSensitivityAnalysis {
@@ -86,7 +82,7 @@
SensitivityScenarios thisExperiment = new SensitivityScenarios();
List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
- testNoDiscrete(factors);
+ checkAllFactorContinuous(factors);
String rInstruction = "a<-sobol2002(model=NULL,X1=X1,X2=X2,nboot=%s)";
String rCall = String.format(rInstruction, param_nboot);
@@ -107,11 +103,19 @@
engine.voidEval("library(sensitivity)");
- engine.voidEval("X1<-data.frame(matrix(runif(" + factorNumber + "*"
- + param_n + "),nrow=" + param_n + "))");
- engine.voidEval("X2<-data.frame(matrix(runif(" + factorNumber + "*"
- + param_n + "),nrow=" + param_n + "))");
+ String x = "<-data.frame(matrix(c(";
+ for (int i = 0; i < factorNumber; i++) {
+ x += "runif("+param_n+"),";
+ }
+
+ x = StringUtils.removeEnd(x, ",");
+
+ x+="),nrow="+param_n+"))";
+
+ engine.voidEval("X1"+x);
+ engine.voidEval("X2"+x);
+
engine.voidEval(rCall);
// Creating the factors vector.
@@ -135,36 +139,8 @@
nbExperiments = dataFrame.dim()[0];
- String isisFactorDistribution = "isis.factor.distribution<-" +
- "data.frame(NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
+ engine.voidEval(getIsisFactorDistribution(factors));
- // Creating the vectors.
- String distribution = "";
- String parameters = "";
- String factorNames = "";
-
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = factors.get(i);
- Domain domain = factor.getDomain();
- if (i != 0) {
- distribution += ",";
- parameters += ",";
- factorNames += ",";
- }
-
- distribution += "\"qunif\"";
- ContinuousDomain continuousDomain = (ContinuousDomain) domain;
- double min = continuousDomain.getCalculatorMinBound();
- double max = continuousDomain.getCalculatorMaxBound();
- parameters += "\"[" + min + ";" + max + "]\"";
- factorNames += "\"" + factor.getName() + "\"";
- }
-
- engine.voidEval(String.format(isisFactorDistribution, factorNames,
- distribution, parameters));
-
engine.voidEval("call<-a$call");
engine.voidEval("isis.MethodExp<-list(" +
1
0
Author: echatellier
Date: 2013-11-08 11:22:14 +0100 (Fri, 08 Nov 2013)
New Revision: 310
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/310
Log:
AJout d'un commentaire sur un resultat
Modified:
trunk/scripts/ResultName.java
Modified: trunk/scripts/ResultName.java
===================================================================
--- trunk/scripts/ResultName.java 2013-11-07 14:21:30 UTC (rev 309)
+++ trunk/scripts/ResultName.java 2013-11-08 10:22:14 UTC (rev 310)
@@ -136,6 +136,9 @@
* Dimension 3 : Metier
* Dimension 4 : Group
* Dimension 5 : Zone
+ *
+ * N'est calculé que si l'effort est calculé par cellule et non par zone.
+ * @see SimulatorEffortByCell
*/
@Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZoneMet")
static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET = n_("matrixCatchWeightPerStrategyMetPerZoneMet");
1
0
Author: echatellier
Date: 2013-11-07 15:21:30 +0100 (Thu, 07 Nov 2013)
New Revision: 309
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/309
Log:
AJout d'un commentaire sur un resultat
Modified:
trunk/scripts/ResultName.java
trunk/simulators/SimulatorEffortByCell.java
Modified: trunk/scripts/ResultName.java
===================================================================
--- trunk/scripts/ResultName.java 2013-11-02 10:38:07 UTC (rev 308)
+++ trunk/scripts/ResultName.java 2013-11-07 14:21:30 UTC (rev 309)
@@ -111,6 +111,9 @@
* Dimension 3 : Metier
* Dimension 4 : Group
* Dimension 5 : Zone
+ *
+ * N'est calculé que si l'effort est calculé par cellule et non par zone.
+ * @see SimulatorEffortByCell
*/
@Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZoneMet")
static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET = n_("matrixCatchPerStrategyMetPerZoneMet");
Modified: trunk/simulators/SimulatorEffortByCell.java
===================================================================
--- trunk/simulators/SimulatorEffortByCell.java 2013-11-02 10:38:07 UTC (rev 308)
+++ trunk/simulators/SimulatorEffortByCell.java 2013-11-07 14:21:30 UTC (rev 309)
@@ -2,7 +2,7 @@
* #%L
* IsisFish data
* %%
- * Copyright (C) 2009 - 2011 Ifremer, Code Lutin, Benjamin Poussin
+ * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Benjamin Poussin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
@@ -31,7 +31,7 @@
/**
* Simulateur qui fixe la valeur de effortByCell a true pour force
- * l'utilisation des calcules par cellule plutot que par zone.
+ * l'utilisation des calculs par cellule plutot que par zone.
*
* @author poussin
*/
1
0
Author: echatellier
Date: 2013-11-02 11:38:07 +0100 (Sat, 02 Nov 2013)
New Revision: 308
Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/308
Log:
Remove old branches
Removed:
branches/3.2/
branches/4.0.1/
branches/4.1/
1
0
07 Nov '12
Author: echatellier
Date: 2012-11-07 15:18:20 +0100 (Wed, 07 Nov 2012)
New Revision: 307
Url: http://forge.codelutin.com/repositories/revision/isis-fish-data/307
Log:
Rename sensitivy scripts with prefix
Added:
branches/4.2.2/sensitivityanalysis/DOptimal.java
branches/4.2.2/sensitivityanalysis/Fast.java
branches/4.2.2/sensitivityanalysis/Morris.java
branches/4.2.2/sensitivityanalysis/OptimumLHS.java
branches/4.2.2/sensitivityanalysis/RandomLHS.java
branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java
branches/4.2.2/sensitivityanalysis/RegularFractions.java
branches/4.2.2/sensitivityanalysis/Sobol.java
Removed:
branches/4.2.2/sensitivityanalysis/SensitivityCalculatorJavaExpandGrid.java
branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRDOptimal.java
branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRExpandGrid.java
branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRFast.java
branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRFrF2.java
branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRMorris.java
branches/4.2.2/sensitivityanalysis/SensitivityCalculatorROptimumLHS.java
branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRRandomLHS.java
branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRSobol.java
branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRegularFractions.java
Copied: branches/4.2.2/sensitivityanalysis/DOptimal.java (from rev 305, branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRDOptimal.java)
===================================================================
--- branches/4.2.2/sensitivityanalysis/DOptimal.java (rev 0)
+++ branches/4.2.2/sensitivityanalysis/DOptimal.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -0,0 +1,405 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+package sensitivityanalysis;
+
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.simulator.sensitivity.*;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
+import fr.ifremer.isisfish.util.Doc;
+import org.apache.commons.lang.StringUtils;
+import org.nuiton.j2r.REngine;
+import org.nuiton.j2r.RException;
+import org.nuiton.j2r.RProxy;
+import org.nuiton.j2r.types.RDataFrame;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * User: couteau
+ * Date: 14 janv. 2010
+ * Time: 11:58:09
+ */
+public class DOptimal extends AbstractSensitivityAnalysis {
+
+ @Doc("True to be able to modify the code sent to R")
+ public boolean param_modifR = false;
+
+ @Doc("Order")
+ public int param_order=1;
+
+ /**
+ * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
+ * continue.
+ *
+ * @return <tt>true</tt> s'il sait la gerer
+ */
+ @Override
+ public boolean canManageCardinality() {
+ return false;
+ }
+
+ @Override
+ public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
+ throws SensitivityException {
+
+ SensitivityScenarios thisExperiment = new SensitivityScenarios();
+
+ setIsisFactorsR(plan, outputDirectory);
+
+ //extract the factors from the design plan
+ List<Factor> factors = plan.getFactors();
+ int factorsNb = factors.size();
+
+ try {
+ REngine engine = new RProxy();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ engine.voidEval("library(AlgDesign)");
+
+ //Create a list of the factors under the form factor1=factor1,...
+ String factorsNames = "";
+
+ //Create a list of the factors under the form factor1,factor2,...
+ String factorNames = "";
+
+ //Create a list of the factors under the form factor1+factor2+...
+ String factorPlus="";
+
+ //create the factors vectors
+ for (Factor factor : factors) {
+ //The factor values vector
+ String factorName = factor.getName().replaceAll(" ", "");
+ factorsNames += factorName + "=" + factorName + ",";
+ factorNames += factorName + ",";
+ factorPlus += factorName + "+";
+
+ String vector = factorName + "<-c(";
+
+ Domain domain = factor.getDomain();
+
+ if (domain instanceof ContinuousDomain) {
+ ContinuousDomain contDomain = (ContinuousDomain) domain;
+ int card = factor.getCardinality();
+ Double min = contDomain.getCalculatorMinBound();
+ Double max = contDomain.getCalculatorMaxBound();
+
+ for (int i = 0; i < card; i++) {
+ //add the ith value
+ vector += (min + (i * (max - min) / (card - 1))) + ",";
+ }
+ } else {
+ Map<Object, Object> values = ((DiscreteDomain) domain).getValues();
+ int nbValues = values.size();
+ for (int i = 0; i < nbValues; i++) {
+ vector += "as.integer(" + i + "),";
+ }
+ }
+
+ vector = vector.substring(0, vector.length() - 1);
+
+ vector += ")";
+
+ engine.voidEval(vector);
+
+
+ }
+
+ factorsNames = factorsNames.substring(0,factorsNames.length()-1);
+ factorNames = factorNames.substring(0,factorNames.length()-1);
+ factorPlus = factorPlus.substring(0,factorPlus.length()-1);
+
+
+ //X<-expand.grid(vector=???,weight=???)
+ String expandGrid = "expandgrid<-expand.grid(%s)";
+
+
+
+ String rCall = String.format(expandGrid,factorsNames);
+
+ engine.voidEval(rCall);
+
+ if (param_order ==1 ){
+ rCall = "x<-optFederov(~(%s),data=expandgrid, " +
+ "approximate =FALSE, center=F, criterion = \"D\"," +
+ "nRepeats=10)";
+ } else {
+ rCall = "x<-optFederov(~(%s)^"+param_order+",data=expandgrid, " +
+ "approximate =FALSE, center=F, criterion = \"D\"," +
+ "nRepeats=10)";
+ }
+
+ rCall = String.format(rCall,factorPlus);
+
+ if (param_modifR) {
+ rCall = editRInstruction(rCall);
+ }
+
+ engine.voidEval("runif(1)");
+
+ engine.voidEval(rCall);
+
+ engine.eval("expPlan<-as.data.frame(x$design)");
+ RDataFrame dataFrame = (RDataFrame)engine.eval("expPlan");
+ dataFrame.setVariable("expPlan");
+ int nbExperiments = (Integer)engine.eval("dim(x$design)[1]");
+
+ List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
+ for (int j = 0; j < nbExperiments; j++) {
+ Scenario experimentScenario = new Scenario();
+ for (int i = 0; i < factorsNb; i++) {
+ Factor factor = factors.get(i);
+ factor.setValueForIdentifier(dataFrame.get(i, j));
+ experimentScenario.addFactor(factor);
+ }
+ thisExperimentScenarios.add(experimentScenario);
+ thisExperiment.setScenarios(thisExperimentScenarios);
+ }
+
+
+ String factorDistribution = "isis.factor.distribution<-data.frame(" +
+ "NomFacteur=c(%s)," +
+ "NomDistribution=c(%s)," +
+ "ParametreDistribution=c(%s))";
+
+ String distribution = "";
+ String parameters = "";
+
+ for (int i = 0; i < factorsNb; i++) {
+ Domain domain = factors.get(i).getDomain();
+ if (i != 0) {
+ distribution += ",";
+ parameters += ",";
+ }
+ if (domain instanceof ContinuousDomain){
+ ContinuousDomain contDomain = (ContinuousDomain)domain;
+ distribution += "\"qunif\"";
+ parameters += "\"[" + contDomain.getMinBound()
+ + ";" + contDomain.getMaxBound()
+ + "]\"";
+ } else {
+ DiscreteDomain discDomain = (DiscreteDomain)domain;
+ distribution += "\"discrete\"";
+ parameters+="\"[";
+ Map<Object, Object> values = discDomain.getValues();
+ int count=0;
+ Collection<Object> collecValues = values.values();
+ for (Object value:collecValues){
+ if (count!=0){
+ parameters += ",";
+ }
+ parameters += StringUtils.replace(value.toString(), "\"", "\\\"") ;
+ count++;
+ }
+ parameters+="]\"";
+ }
+ }
+ engine.voidEval(String.format(factorDistribution, factorNames,
+ distribution, parameters));
+
+ engine.voidEval("call<-\"" + rCall + "\"");
+ engine.voidEval("isis.MethodExp<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"call\"=call)");
+ engine.voidEval("attr(isis.MethodExp," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine.voidEval("isis.simule<-x$design");
+ engine.voidEval("attr(isis.simule," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+
+ } catch (RException eee) {
+ throw new SensitivityException("Can't generate scenarios", eee);
+ }
+
+ return thisExperiment;
+ }
+
+ @Override
+ public void analyzeResult(List<SimulationStorage> simulationStorages,
+ File outputDirectory) throws SensitivityException {
+
+ try {
+
+ REngine engine = new RProxy();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ //Get back the factors number
+ int factorNumber = (Integer)engine.eval("dim(x$design)[2]");
+
+ SimulationParameter param = simulationStorages.get(0).getParameter();
+ int sensitivityNumber = param.getSensitivityExport().size();
+
+ SimulationStorage firstStorage = simulationStorages.get(0);
+
+ String firstStorageName = firstStorage.getName().replaceAll("-", "");
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ SensitivityExport sensitivityExport =
+ param.getSensitivityExport().get(k);
+
+ String name = sensitivityExport.getExportFilename();
+
+ String rInstruction = createImportInstruction(sensitivityExport,
+ simulationStorages);
+
+ // Send the simulation results
+ engine.voidEval(rInstruction);
+
+ //Put results in isis.simule
+ engine.voidEval("isis.simule<-data.frame(isis.simule,"
+ + name + ")");
+
+ //Create the dataforaov data.frame
+ String dataFrame = "dataforaov<-data.frame(x$design,"
+ + name + "=" + name + ")";
+ engine.voidEval(dataFrame);
+
+ //Call aov()
+ String aovCall = "aovresult<-aov(" + name + "~(";
+ for (int j = 0; j < factorNumber; j++) {
+ if (j < (factorNumber - 1)) {
+ aovCall = aovCall
+ + engine.eval("names(x$design)[" + (j + 1) + "]")
+ + "+";
+ } else {
+ aovCall = aovCall
+ + engine.eval("names(x$design)[" + (j + 1) + "]")
+ + ")";
+ if(param_order>1){
+ aovCall+="^" + param_order + ",data=dataforaov)";
+ }else{
+ aovCall+=",data=dataforaov)";
+ }
+ }
+ }
+ engine.voidEval(aovCall);
+
+ /*Export the results
+ *Export format is csv, data separated by ','
+ *Results Export name is sensitivityExportName_Results.csv
+ *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
+ */
+
+//Compute Sum of Squares and Sensitivity indices
+ engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
+ engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
+ engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
+
+ //Create a data.frame to export sensitivity important results in one file.
+ engine.voidEval("exportsensitivity<-data.frame(" +
+ "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
+ "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
+ engine.voidEval("names(exportsensitivity)<-c(" +
+ "\"Sum Of Squares\"," +
+ "\"Sensitivity indices\")");
+ engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
+
+
+ //Set dataforaov names
+ engine.voidEval("resultsnames<-c(names(x$design),\"Result\")");
+ engine.voidEval("names(dataforaov)<-resultsnames");
+
+
+ /*Set the export directory
+ *Export directory is the first simulation export directory.
+ */
+ engine.setwd(outputDirectory);
+
+ //Save the results with the scenarios.
+ engine.voidEval("write.csv(dataforaov,\""
+ + param.getSensitivityExport().get(k)
+
+ .getExportFilename() + "_Results.csv\")");
+
+ //Save the sensitivity indices
+ engine.voidEval("write.csv(exportsensitivity,\""
+ + param.getSensitivityExport().get(k)
+ .getExportFilename()
+ + "_SensitivityIndices.csv\")");
+ //FIXME export through java to enable export when using Rserve (when distant Rserve).
+
+ //creating isis.methodAnalyse
+ engine.voidEval("isis.methodAnalyse<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"isis.simule\"=isis.simule," +
+ "\"call_method\"=\"" + aovCall + "\"," +
+ "\"analysis_result\"=list(aovresult,IndSensibilite))");
+
+ engine.voidEval("attr(isis.methodAnalyse," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-isis.methodAnalyse";
+ engine.voidEval(String.format(renameIsisMethodAnalyse,
+ firstStorageName + "." + name));
+
+ }
+
+ //Rename R objects for saving purpose
+ renameObjects(engine, firstStorageName);
+
+
+ //Clean temporary R objects
+ for (String object:engine.ls()) {
+ if (!object.startsWith(firstStorageName)){
+ engine.remove(object);
+ }
+ }
+
+ //Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ engine.terminate();
+
+ } catch (Exception e) {
+ throw new SensitivityException("Can't evaluate results", e);
+ }
+
+ }
+
+ @Override
+ public String getDescription() {
+ return "Implementation of D optimal method method using R, needs" +
+ "AlgDesign package to work";
+ }
+}
Copied: branches/4.2.2/sensitivityanalysis/Fast.java (from rev 305, branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRFast.java)
===================================================================
--- branches/4.2.2/sensitivityanalysis/Fast.java (rev 0)
+++ branches/4.2.2/sensitivityanalysis/Fast.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -0,0 +1,358 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+package sensitivityanalysis;
+
+import java.io.File;
+import java.util.List;
+
+import fr.ifremer.isisfish.simulator.sensitivity.*;
+import org.nuiton.j2r.REngine;
+import org.nuiton.j2r.RException;
+import org.nuiton.j2r.RProxy;
+
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain;
+import fr.ifremer.isisfish.util.Doc;
+import org.nuiton.j2r.types.RDataFrame;
+
+/**
+ * Implementation of Fast method using R.
+ *
+ * @author jcouteau
+ * @version $Revision: 89 $
+ *
+ * Last update : $Date: 2009-03-25 13:45:16 +0100 (mer., 25 mars 2009) $ By :
+ * $Author: jcouteau $
+ */
+public class Fast extends AbstractSensitivityAnalysis {
+
+ @Doc("an integer giving the sample size, i.e. the length of the " +
+ "discretization of the s-space (see Cukier et al.). (default=20)")
+ public int param_n = 20;
+
+ @Doc("an integer specifying the interference parameter, i.e. the number " +
+ "of harmonics to sum in the Fourier series decomposition (see Cukier et " +
+ "al.). (default=6)")
+ public int param_M = 6;
+
+ @Doc("True to be able to modify the code sent to R")
+ public boolean param_modifR = false;
+
+ /**
+ * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
+ * continue.
+ *
+ * @return <tt>true</tt> s'il sait la gerer
+ */
+ @Override
+ public boolean canManageCardinality() {
+ return true;
+ }
+
+ @Override
+ public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
+ throws SensitivityException {
+
+ setIsisFactorsR(plan, outputDirectory);
+
+ RDataFrame dataFrame;
+ int nbExperiments;
+ int factorNumber = plan.getFactors().size();
+ List<Factor> factors = plan.getFactors();
+ SensitivityScenarios thisExperiment = new SensitivityScenarios();
+ List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
+
+ //Test all factors, if one is discrete, return null
+ for (int i = 0; i < factorNumber; i++) {
+ if (factors.get(i).getDomain() instanceof DiscreteDomain) {
+ throw new SensitivityException(factors.get(i).getName() +
+ " has a discrete domain, this is not acceptable for fast " +
+ "method.");
+ }
+ }
+ String rInstruction = "a<-fast99(" +
+ "model=NULL," +
+ "factors=%s, " +
+ "n=%s, " +
+ "M=%s, " +
+ "q = \"qunif\", " +
+ "q.arg=list(min=0,max=1))";
+ String rCall = String.format(rInstruction, factors.size(), param_n,
+ param_M);
+
+ if (param_modifR) {
+ rCall = editRInstruction(rCall);
+ }
+
+ try {
+
+ REngine engine = new RProxy();
+
+ engine.clearSession();
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ // Load sensitivity package into R (if package already loaded,
+ // nothing happens.
+ engine.voidEval("library(sensitivity)");
+
+ // Run sensitivity analysis
+ engine.voidEval(rCall);
+
+ // Creating the factors vector.
+ rInstruction = "factornames<-c(";
+ for (int i = 0; i < factorNumber; i++) {
+ String factorName = factors.get(i).getName();
+ if (i != (factorNumber - 1)) {
+ rInstruction += "\"" + factorName + "\",";
+ } else {
+ rInstruction += "\"" + factorName + "\"";
+ }
+ }
+
+ rInstruction += ")";
+
+ engine.voidEval(rInstruction);
+
+ // Get back experiment plan
+ dataFrame = (RDataFrame) engine.eval("a$X");
+ dataFrame.setVariable("a$X");
+
+ nbExperiments = (Integer)engine.eval("dim(a$X)[1]");
+
+ String factorDistribution = "isis.factor.distribution<-data.frame(" +
+ "NomFacteur=c(%s)," +
+ "NomDistribution=c(%s)," +
+ "ParametreDistribution=c(%s))";
+
+ // Creating the vectors.
+ String distribution = "";
+ String parameters = "";
+ String factorNames = "";
+
+ for (int i = 0; i < factorNumber; i++) {
+ Factor factor = factors.get(i);
+ ContinuousDomain domain = (ContinuousDomain) factor.getDomain();
+ if (i != 0) {
+ distribution += ",";
+ parameters += ",";
+ factorNames += ",";
+ }
+
+ distribution += "\"qunif\"";
+ parameters += "\"[" + domain.getMinBound() + ";" +
+ domain.getMaxBound() + "]\"";
+ factorNames += "\"" + factor.getName() + "\"";
+ }
+ engine.voidEval(String.format(factorDistribution, factorNames,
+ distribution, parameters));
+
+ engine.voidEval("call<-a$call");
+
+
+ engine.voidEval("isis.MethodExp<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"call\"=call)");
+
+ engine.voidEval("attr(isis.MethodExp,\"nomModel\")<-" +
+ "\"isis-fish-externe-R\"");
+
+ engine.voidEval("isis.simule<-data.frame(a$X)");
+
+ engine.voidEval("attr(isis.simule,\"nomModel\")<-" +
+ "\"isis-fish-externe-R\"");
+
+ engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ // Setting up the scenarios.
+ for (int j = 0; j < nbExperiments; j++) {
+ Scenario experimentScenario = new Scenario();
+ for (int i = 0; i < factorNumber; i++) {
+ Factor factor = plan.getFactors().get(i);
+ Domain domain = factor.getDomain();
+ if ((domain instanceof MatrixContinuousDomain)
+ || (domain instanceof EquationContinuousDomain)) {
+ factor.setValueForIdentifier(dataFrame.get(i,j));
+ } else {
+ ContinuousDomain continuousDomain = (ContinuousDomain)domain;
+ Double min = continuousDomain.getCalculatorMinBound();
+ Double max = continuousDomain.getCalculatorMaxBound();
+ Double dFValue = (Double)dataFrame.get(i,j);
+ Double value = min + (max - min) * dFValue;
+ factor.setValueForIdentifier(value);
+ }
+ experimentScenario.addFactor(factor);
+ }
+ thisExperimentScenarios.add(experimentScenario);
+ thisExperiment.setScenarios(thisExperimentScenarios);
+ }
+ } catch (RException eee) {
+ throw new SensitivityException("Can't generate scenarios", eee);
+ }
+ return thisExperiment;
+
+ }
+
+ @Override
+ public void analyzeResult(List<SimulationStorage> simulationStorages,
+ File outputDirectory) throws SensitivityException {
+
+ SimulationStorage storage = simulationStorages.get(0);
+ String simulationName = storage.getName().replaceAll("-", "");
+
+ try {
+
+ REngine engine = new RProxy();
+
+ //Clear session
+ engine.clearSession();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ engine.setwd(outputDirectory);
+
+ // Call R
+ // Load sensitivity package into R (if package already loaded,
+ // nothing happens.
+ engine.voidEval("library(sensitivity)");
+
+ SimulationParameter param = simulationStorages.get(0).getParameter();
+
+ int sensitivityNumber = param.getSensitivityExport().size();
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ SensitivityExport sensitivityExport =
+ param.getSensitivityExport().get(k);
+
+ String rInstruction = createImportInstruction(sensitivityExport,
+ simulationStorages);
+
+ // Send the simulation results
+ engine.voidEval(rInstruction);
+
+ //Put results in isis.simule
+ engine.voidEval("isis.simule<-data.frame(isis.simule," +
+ sensitivityExport.getExportFilename() + ")");
+ }
+
+ //adding attribute to isis.Simule
+ engine.voidEval("attr(isis.simule,\"nomModel\")<-" +
+ "\"isis-fish-externe-R\"");
+ engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ // Creates the R expression to import results in R
+ String name = param.getSensitivityExport().get(k)
+ .getExportFilename();
+
+ //Compute results
+ engine.voidEval("tell(a,y=" + name + ")");
+
+ engine.voidEval("names(a$V)<-factornames");
+ engine.voidEval("names(a$X)<-factornames");
+ engine.voidEval("names(a$D1)<-factornames");
+ engine.voidEval("names(a$Dt)<-factornames");
+
+ //creating isis.methodAnalyse
+ engine.voidEval("isis.methodAnalyse<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"isis.simule\"=isis.simule," +
+ "call_method=\"tell(a,y=" + name + ")" + "\"," +
+ "\"analysis_result\"=a)");
+
+ //setting isis.methodAnalyse attributes
+ engine.voidEval("attr(isis.methodAnalyse,\"nomModel\")<-" +
+ "\"isis-fish-externe-R\")");
+
+ //Create the data.frame of scenarios and results for export purpose
+ engine.voidEval("dfresults<-data.frame(a$X,a$y)");
+
+ //Set working directory
+ engine.setwd(outputDirectory);
+
+ //Export V
+ engine.voidEval("write.csv(a$V,\"" + name + "_V.csv\")");
+
+ //Export D1
+ engine.voidEval("write.csv(a$D1,\"" + name + "_D1.csv\")");
+
+ //Export Dt
+ engine.voidEval("write.csv(a$Dt,\"" + name + "_Dt.csv\")");
+ //Set dfresults names
+ engine.voidEval("resultsnames<-c(factornames,\"Result\")");
+ engine.voidEval("names(dfresults)<-resultsnames");
+
+ //Export results
+ engine.voidEval("write.csv(dfresults,\"" + name +
+ "_Results.csv\")");
+ //FIXME export through java to enable export when using Rserve
+
+ String renameIsisMethodAnalyse = "%s.isis.methodAnalyse" +
+ "<-isis.methodAnalyse";
+
+ engine.voidEval(String.format(renameIsisMethodAnalyse,
+ simulationName + "." + name));
+
+ }
+
+ //Rename R objects for saving purpose
+ renameObjects(engine, simulationName);
+
+ //Clean temporary R objects
+ for (String object:engine.ls()) {
+ if (!object.startsWith(simulationName)){
+ engine.remove(object);
+ }
+ }
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ } catch (Exception e) {
+ throw new SensitivityException("Can't evaluate results", e);
+ }
+ }
+
+ @Override
+ public String getDescription() {
+ return "Implementation of FAST method using R (needs the sensitivity " +
+ "package to work)";
+ }
+
+}
Copied: branches/4.2.2/sensitivityanalysis/Morris.java (from rev 305, branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRMorris.java)
===================================================================
--- branches/4.2.2/sensitivityanalysis/Morris.java (rev 0)
+++ branches/4.2.2/sensitivityanalysis/Morris.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -0,0 +1,357 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+package sensitivityanalysis;
+
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
+import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
+import fr.ifremer.isisfish.simulator.sensitivity.Factor;
+import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
+import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
+import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
+import fr.ifremer.isisfish.util.Doc;
+import org.nuiton.j2r.REngine;
+import org.nuiton.j2r.RException;
+import org.nuiton.j2r.RProxy;
+import org.nuiton.j2r.types.RDataFrame;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Implementation of Morris method using R.
+ *
+ * @author jcouteau
+ * @version $Revision$
+ *
+ * Last update : $Date$ By :
+ * $Author$
+ */
+public class Morris extends AbstractSensitivityAnalysis {
+
+ @Doc("Integer giving the number of repetitions of the design, i.e. the number of elementary effect computed per factor. (Default value : 4)")
+ public int param_r = 4;
+
+ @Doc("True to be able to modify the code sent to R")
+ public boolean param_modifR = false;
+
+ /**
+ * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
+ * continus.
+ *
+ * @return {@code true} s'il sait la gerer
+ */
+ @Override
+ public boolean canManageCardinality() {
+ return false;
+ }
+
+ @Override
+ public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
+ throws SensitivityException {
+
+ setIsisFactorsR(plan, outputDirectory);
+
+ RDataFrame dataFrame;
+ int nbExperiments;
+ int factorNumber = plan.getFactors().size();
+
+ SensitivityScenarios thisExperiment = new SensitivityScenarios();
+
+ List<Factor> factors = plan.getFactors();
+
+ if (param_r == 0) {
+ param_r = 4;
+ }
+
+ testNoDiscrete(factors);
+
+ // Creating the vectors.
+ String factorNames = "";
+ String levels = "";
+ String gridJump = "";
+ String binf = "";
+ String bsup = "";
+ for (int i = 0; i < factorNumber; i++) {
+ Factor factor = factors.get(i);
+ ContinuousDomain domain = (ContinuousDomain) factor.getDomain();
+ if (i != 0) {
+ factorNames += ",";
+ levels += ",";
+ gridJump += ",";
+ binf += ",";
+ bsup += ",";
+ }
+
+ factorNames += "\"" + factor.getName() + "\"";
+
+ levels += factor.getCardinality();
+
+ gridJump += factor.getCardinality() / 2;
+
+ binf += domain.getCalculatorMinBound();
+
+ bsup += domain.getCalculatorMaxBound();
+ }
+
+ String rInstruction = "a<-morris(model=NULL,factors=c(%s),r=%s," +
+ "design=list(type=\"oat\",levels=c(%s),grid.jump=c(%s))," +
+ "binf=c(%s),bsup=c(%s))";
+
+ String rCall = String.format(rInstruction, factorNames, param_r,
+ levels, gridJump, binf, bsup);
+
+ if (param_modifR) {
+ rCall = editRInstruction(rCall);
+ }
+
+ REngine engine = null;
+
+ try {
+ engine = new RProxy();
+
+ engine.clearSession();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ // Load sensitivity package into R (if package already loaded,
+ // nothing happens.
+ engine.voidEval("library(sensitivity)");
+
+ // Run sensitivity analysis
+ engine.voidEval(rCall);
+
+ // Creating the factors vector.
+ rInstruction = "factornames<-c(%s)";
+ rCall = String.format(rInstruction, factorNames);
+
+ engine.voidEval(rCall);
+
+ // Set output directory
+ engine.setwd(outputDirectory);
+
+ // Get back experiment plan
+ engine.eval("expPlan<-as.data.frame(a$X)");
+ dataFrame = (RDataFrame) engine.eval("expPlan");
+ dataFrame.setVariable("expPlan");
+
+ nbExperiments = (Integer)engine.eval("dim(expPlan)[1]");
+
+ String factorDistribution = "isis.factor.distribution<-data.frame(" +
+ "NomFacteur=c(%s)," +
+ "NomDistribution=c(%s)," +
+ "ParametreDistribution=c(%s))";
+
+ String distribution = "";
+ String parameters = "";
+
+ for (int i = 0; i < factorNumber; i++) {
+ Factor factor = factors.get(i);
+ ContinuousDomain domain = (ContinuousDomain) factor.getDomain();
+ if (i != 0) {
+ distribution += ",";
+ parameters += ",";
+ }
+
+ distribution += "\"qunif\"";
+ parameters += "\"[" + domain.getMinBound() + ";" +
+ domain.getMaxBound() + "]\"";
+ }
+ engine.voidEval(String.format(factorDistribution, factorNames,
+ distribution, parameters));
+
+ engine.voidEval("call<-a$call");
+ engine.voidEval("isis.MethodExp<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"call\"=call)");
+ engine.voidEval("attr(isis.MethodExp,\"nomModel\")<-" +
+ "\"isis-fish-externe-R\"");
+ engine.voidEval("isis.simule<-data.frame(expPlan)");
+ engine.voidEval("attr(isis.simule,\"nomModel\")<-" +
+ "\"isis-fish-externe-R\"");
+ engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ // Setting up the scenarios.
+ List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
+ for (int j = 0; j < nbExperiments; j++) {
+ Scenario experimentScenario = new Scenario();
+ for (int i = 0; i < factorNumber; i++) {
+ Factor factor = factors.get(i);
+ factor.setValueForIdentifier(dataFrame.get(i, j));
+ experimentScenario.addFactor(factor);
+ }
+ thisExperimentScenarios.add(experimentScenario);
+ thisExperiment.setScenarios(thisExperimentScenarios);
+ }
+
+ } catch (RException eee) {
+ throw new SensitivityException("Can't generate scenarios", eee);
+ }
+
+ return thisExperiment;
+
+ }
+
+ @Override
+ public void analyzeResult(List<SimulationStorage> simulationStorages,
+ File outputDirectory) throws SensitivityException {
+
+ SimulationStorage storage = simulationStorages.get(0);
+ String simulationName = storage.getName().replaceAll("-", "");
+
+ REngine engine = null;
+
+ try {
+ engine = new RProxy();
+
+ engine.clearSession();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ // Call R
+ // Load sensitivity package into R (if package already loaded,
+ // nothing happens.
+ engine.voidEval("library(sensitivity)");
+
+ //Set the working directory (for exports)
+ engine.setwd(outputDirectory);
+
+ SimulationParameter param = simulationStorages.get(0)
+ .getParameter();
+ int sensitivityNumber = param.getSensitivityExport().size();
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ SensitivityExport sensitivityExport =
+ param.getSensitivityExport().get(k);
+
+ String rInstruction = createImportInstruction(sensitivityExport,
+ simulationStorages);
+
+ // Send the simulation results
+ engine.voidEval(rInstruction);
+
+ //Put results in isis.simule
+ engine.voidEval("isis.simule<-data.frame(isis.simule," +
+ sensitivityExport.getExportFilename() + ")");
+ }
+
+ //adding attribute to isis.Simule
+ engine.voidEval("attr(isis.simule,\"nomModel\")<-" +
+ "\"isis-fish-externe-R\"");
+
+ engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ // Creates the R expression to import results in R
+ String name = param.getSensitivityExport().get(k)
+ .getExportFilename();
+
+ //Compute results
+ engine.voidEval("tell(a,y=" + name + ")");
+
+ //creating isis.methodAnalyse
+ engine.voidEval("isis.methodAnalyse<-list(" +
+ //"\"isis.factors\"=isis.factors," +
+ //"\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"isis.simule\"=isis.simule," +
+ "\"call_method\"=\"tell(a,y=" + name + ")" + "\"," +
+ "\"analysis_result\"=a)");
+
+ //setting isis.methodAnalyse attributes
+ engine.voidEval("attr(isis.methodAnalyse,\"nomModel\")<-" +
+ "\"isis-fish-externe-R\"");
+
+ // Get back the sensitivity results, mu, mu star and sigma.
+ engine.voidEval("mu<-apply(a$ee, 2, mean)");
+ engine.voidEval("mu.star <- apply(a$ee, 2, function(a) mean(abs(a)))");
+ engine.voidEval("sigma <- apply(a$ee, 2, sd)");
+
+ //Create the data.frame of sensitivity indices for export purpose
+ engine.voidEval("df<-data.frame(mu,mu.star,sigma)");
+ engine.voidEval("row.names(df)<-factornames");
+
+ //Create the data.frame of scenarios and results for export purpose
+ engine.voidEval("dfresults<-data.frame(a$X," + name + ")");
+
+ //Set dfresults names
+ engine.voidEval("resultsnames<-c(factornames,\"Result\")");
+ engine.voidEval("names(dfresults)<-resultsnames");
+
+ //Export sensitivity indices
+ engine.voidEval("write.csv(df," +
+ "\"" + name + "_SensitivityIndices.csv\")");
+
+ //Export results
+ engine.voidEval("write.csv(dfresults," +
+ "\"" + name + "_Results.csv\")");
+ //FIXME export through java to enable export when using Rserve
+
+ String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-" +
+ "isis.methodAnalyse";
+
+ engine.voidEval(String.format(renameIsisMethodAnalyse,
+ simulationName + "." + name));
+
+ }
+
+ //Rename R objects for saving purpose
+ renameObjects(engine,simulationName);
+
+ //Clean temporary R objects
+ for (String object:engine.ls()) {
+ if (!object.startsWith(simulationName)){
+ engine.remove(object);
+ }
+ }
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ } catch (Exception e) {
+ throw new SensitivityException("Can't evaluate results", e);
+ }
+
+ }
+
+ @Override
+ public String getDescription() {
+ return "Implementation of Morris method using R (needs the sensitivity" +
+ " package to work)";
+ }
+
+}
Copied: branches/4.2.2/sensitivityanalysis/OptimumLHS.java (from rev 305, branches/4.2.2/sensitivityanalysis/SensitivityCalculatorROptimumLHS.java)
===================================================================
--- branches/4.2.2/sensitivityanalysis/OptimumLHS.java (rev 0)
+++ branches/4.2.2/sensitivityanalysis/OptimumLHS.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -0,0 +1,404 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+package sensitivityanalysis;
+
+import java.io.File;
+import java.util.List;
+
+import org.nuiton.j2r.REngine;
+import org.nuiton.j2r.RProxy;
+
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
+import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
+import fr.ifremer.isisfish.simulator.sensitivity.Factor;
+import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
+import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
+import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
+import fr.ifremer.isisfish.util.Doc;
+import org.nuiton.j2r.types.RDataFrame;
+
+/**
+ * Implementation of Optimum Latin Hypercube method using R.
+ *
+ * @author jcouteau
+ * @version $Revision: 1.0 $
+ */
+public class OptimumLHS extends AbstractSensitivityAnalysis {
+
+ @Doc("Number of simulations (default=10)")
+ public int param_simulationNumber = 10;
+ @Doc("The maximum number of times the Columnwise Pairwise algorithm is applied to all the columns(default=2).")
+ public int param_MaxSweeps = 2;
+ @Doc("The optimal stopping criterion (between 0 and 1) (default=0.1).")
+ public double param_eps = 0.1;
+ @Doc("True to be able to modify the code sent to R")
+ public boolean param_modifR = false;
+
+ /**
+ * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
+ * continue.
+ *
+ * @return <tt>true</tt> s'il sait la gerer
+ */
+ @Override
+ public boolean canManageCardinality() {
+ return true;
+ }
+
+ @Override
+ public SensitivityScenarios compute(DesignPlan plan, File outputdirectory)
+ throws SensitivityException {
+
+ setIsisFactorsR(plan, outputdirectory);
+
+ int factorNumber = plan.getFactors().size();
+ List<Factor> factors = plan.getFactors();
+ RDataFrame dataFrame;
+ SensitivityScenarios thisExperiment = new SensitivityScenarios();
+ List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
+
+ //Test all factors, if one is discrete, return null
+ testNoDiscrete(factors);
+
+ try {
+ REngine engine = new RProxy();
+
+ //Clear session
+ engine.clearSession();
+
+ //Set working directory to get Isis R session
+ engine.loadRData(outputdirectory.getParentFile(),
+ outputdirectory.getName());
+
+ //Load the lhs library
+ engine.voidEval("library(lhs)");
+
+ String rInstruction = "x<-optimumLHS(n=%s,k=%s,maxSweeps=%s,eps=%s)";
+
+ String rCall = String.format(rInstruction, param_simulationNumber,
+ factorNumber, param_MaxSweeps, param_eps);
+
+ if (param_modifR) {
+ rCall = editRInstruction(rCall);
+ }
+
+ //Create the scenarios
+ engine.voidEval(rCall);
+
+ // Get back experiment plan
+ engine.eval("expPlan<-as.data.frame(x)");
+ dataFrame = (RDataFrame)engine.eval("expPlan");
+ dataFrame.setVariable("expPlan");
+
+ // Setting up the scenarios.
+ for (int j = 0; j < param_simulationNumber; j++) {
+ Scenario experimentScenario = new Scenario();
+ for (int i = 0; i < factorNumber; i++) {
+ Factor factor = plan.getFactors().get(i);
+ factor.setValueForIdentifier(dataFrame.get(i, j));
+ experimentScenario.addFactor(factor);
+ }
+ thisExperimentScenarios.add(experimentScenario);
+ thisExperiment.setScenarios(thisExperimentScenarios);
+ }
+
+ String isisFactorDistribution = "isis.factor.distribution<-" +
+ "data.frame(" +
+ "NomFacteur=c(%s)," +
+ "NomDistribution=c(%s)," +
+ "ParametreDistribution=c(%s))";
+
+ String distribution = "";
+ String parameters = "";
+ String factorNames = "";
+
+ for (int i = 0; i < factors.size(); i++) {
+ Factor tempFactor = factors.get(i);
+ ContinuousDomain domain = (ContinuousDomain) tempFactor.getDomain();
+ if (i != 0) {
+ distribution += ",";
+ factorNames += ",";
+ parameters += ",";
+ }
+
+ factorNames += "\"" + factors.get(i).getName() + "\"";
+ distribution += "\"qunif\"";
+ //add [min;max] to parameters
+ parameters += "\"[" + domain.getMinBound() + ";" +
+ domain.getMaxBound() + "]\"";
+ }
+
+ engine.voidEval(String.format(isisFactorDistribution, factorNames,
+ distribution, parameters));
+
+ engine.voidEval("call<-" + "\"x<-optimumLHS("
+ + "n=" + param_simulationNumber
+ + ",k=" + factorNumber
+ + ",maxSweeps=" + param_MaxSweeps
+ + ",eps=" + param_eps + ")\"");
+
+ engine.voidEval("isis.MethodExp<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"call\"=call)");
+
+ engine.voidEval("attr(isis.MethodExp," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ engine.voidEval("isis.simule<-data.frame(x)");
+
+ engine.voidEval("attr(isis.simule," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
+
+ String data = "data<-data.frame(";
+
+ //Create the factors vectors and the dataFrame instruction
+ for (int j = 0; j < factors.size(); j++) {
+ //The factor values vector
+ String vector;
+ //Get back the factor
+ Scenario scenario = thisExperimentScenarios.get(0);
+ Factor factor = scenario.getFactors().get(j);
+ String factorName = factor.getName().replaceAll(" ", "");
+
+ vector = factorName + "<-c(";
+ for (int i = 0; i < param_simulationNumber; i++) {
+ //Get back the displayed value the factor
+ Scenario tempScenario = thisExperimentScenarios.get(i);
+ Factor tempFactor = tempScenario.getFactors().get(j);
+ Object value = tempFactor.getDisplayedValue();
+
+ if (i < (param_simulationNumber - 1)) {
+ vector = vector + value + ",";
+ } else {
+ vector += value;
+ }
+
+ }
+ vector += ")";
+ engine.voidEval(vector);
+
+ if (j < factors.size() - 1) {
+ data += factorName + "=factor(" + factorName + "),";
+ } else {
+ data += factorName + "=factor(" + factorName + "))";
+ }
+ }
+ engine.voidEval(data);
+
+ // Creating the factors vector.
+ rInstruction = "factornames<-c(";
+ for (int i = 0; i < factorNumber; i++) {
+ if (i != (factorNumber - 1)) {
+ rInstruction = rInstruction + "\""
+ + factors.get(i).getName() + "\",";
+ } else {
+ rInstruction = rInstruction + "\""
+ + factors.get(i).getName() + "\"";
+ }
+ }
+
+ rInstruction += ")";
+
+ engine.voidEval(rInstruction);
+
+ // Save Isis R session
+ engine.saveRData(outputdirectory.getParentFile(),
+ outputdirectory.getName());
+
+ engine.terminate();
+
+ } catch (Exception e) {
+ throw new SensitivityException("Can't generate scenarios", e);
+ }
+
+ return thisExperiment;
+ }
+
+ @Override
+ public void analyzeResult(List<SimulationStorage> simulationStorages,
+ File outputDirectory) throws SensitivityException {
+
+ //The first storage to get the name and parameters all along the method
+ SimulationStorage storage = simulationStorages.get(0);
+
+ String simulationName = storage.getName().replaceAll("-", "");
+
+ try {
+
+ REngine engine = new RProxy();
+
+ //Clear session
+ engine.clearSession();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ engine.voidEval("factors<-data.frame(x)");
+ engine.voidEval("names(factors)<-factornames");
+
+ //Get back the factors number
+ int factorNumber = (Integer) engine.eval("length(factors[1,])");
+ //Get back the simulation number
+ param_simulationNumber = (Integer) (engine.eval("length(factors[,1])"));
+
+ SimulationParameter param = storage.getParameter();
+ int sensitivityNumber = param.getSensitivityExport().size();
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ SensitivityExport sensitivityExport =
+ param.getSensitivityExport().get(k);
+
+ String rInstruction = createImportInstruction(sensitivityExport,
+ simulationStorages);
+
+ // Send the simulation results
+ engine.voidEval(rInstruction);
+
+ //Put results in isis.simule
+ engine.voidEval("isis.simule<-data.frame(isis.simule," +
+ sensitivityExport.getExportFilename() + ")");
+ }
+
+ //adding attribute to isis.Simule
+ engine.voidEval("attr(isis.simule," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ // Creates the R expression to import results in R
+ SensitivityExport export = param.getSensitivityExport().get(k);
+ String name = export.getExportFilename();
+
+ //Create the dataforaov data.frame
+ String dataframe = "dataforaov<-data.frame(factors," +
+ name + "=" + name + ")";
+ engine.voidEval(dataframe);
+
+ //Call aov()
+ String aovCall = "aovresult<-aov(" + name + "~";
+ for (int j = 0; j < factorNumber; j++) {
+
+ String factorName = (String) engine.eval("names(factors)[" + (j + 1) + "]");
+ factorName = factorName.replaceAll(" ", ".");
+
+ if (j < (factorNumber - 1)) {
+ aovCall += factorName +
+ "+";
+ } else {
+ aovCall += factorName + ",data=dataforaov)";
+ }
+ }
+ engine.voidEval(aovCall);
+
+ /*Export the results
+ *Export format is csv, data separated by ','
+ *Results Export name is sensitivityExportName_Results.csv
+ *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
+ */
+
+ //Compute Sum of Squares and Sensitivity indices
+ engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
+ engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
+ engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
+
+ //Create a data.frame to export sensitivity important results in one file.
+ engine.voidEval("exportsensitivity<-data.frame(" +
+ "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
+ "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
+ engine.voidEval("names(exportsensitivity)<-c(" +
+ "\"Sum Of Squares\"," +
+ "\"Sensitivity indices\")");
+ engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
+
+
+ //Set dataforaov names
+ engine.voidEval("names(dataforaov)<-c(factornames,\"Result\")");
+
+ /*Set the export directory
+ *Export directory is the first simulation export directory.
+ */
+ engine.setwd(outputDirectory);
+
+ //Save the results with the scenarios.
+ engine.voidEval("write.csv(dataforaov,\"" +
+ name + "_Results.csv\")");
+
+ //Save the sensitivity indices
+ engine.voidEval("write.csv(exportsensitivity,\"" +
+ name + "_SensitivityIndices.csv\")");
+ //FIXME export through java to enable export when using Rserve (when distant Rserve).
+
+ //creating isis.methodAnalyse
+ engine.voidEval("isis.methodAnalyse<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"isis.simule\"=isis.simule," +
+ "call_method=\"" + aovCall + "\""+
+ ",\"analysis_result\"=list(aovresult,IndSensibilite))");
+
+ engine.voidEval("attr(isis.methodAnalyse," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-" +
+ "isis.methodAnalyse";
+
+ engine.voidEval(String.format(renameIsisMethodAnalyse,
+ simulationName + "." + name));
+
+ }
+
+ //Rename R objects for saving purpose
+ renameObjects(engine, simulationName);
+
+ //Clean temporary R objects
+ for (String object:engine.ls()) {
+ if (!object.startsWith(simulationName)){
+ engine.remove(object);
+ }
+ }
+
+ engine.terminate();
+
+ } catch (Exception e) {
+ throw new SensitivityException("Can't evaluate results", e);
+ }
+
+ }
+
+ @Override
+ public String getDescription() {
+ return "Implementation of Random Latin Hypercube method method " +
+ "using R (needs 'lhs' package to work)";
+ }
+
+}
Copied: branches/4.2.2/sensitivityanalysis/RandomLHS.java (from rev 305, branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRRandomLHS.java)
===================================================================
--- branches/4.2.2/sensitivityanalysis/RandomLHS.java (rev 0)
+++ branches/4.2.2/sensitivityanalysis/RandomLHS.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -0,0 +1,402 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+package sensitivityanalysis;
+
+import java.io.File;
+import java.lang.String;
+import java.util.List;
+
+import fr.ifremer.isisfish.export.SensitivityExport;
+import org.nuiton.j2r.REngine;
+import org.nuiton.j2r.RProxy;
+import org.nuiton.j2r.types.RDataFrame;
+
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
+import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
+import fr.ifremer.isisfish.simulator.sensitivity.Factor;
+import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
+import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
+import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
+import fr.ifremer.isisfish.util.Doc;
+
+/**
+ * Implementation of Random Latin Hypercube method using R.
+ *
+ * @author jcouteau
+ * @version $Revision: 1.0 $
+ */
+public class RandomLHS extends AbstractSensitivityAnalysis {
+
+ @Doc("Simulation number (default=10)")
+ public int param_simulationNumber = 10;
+ @Doc("True to be able to modify the code sent to R")
+ public boolean param_modifR = false;
+
+ /**
+ * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
+ * continue.
+ *
+ * @return <tt>true</tt> s'il sait la gerer
+ */
+ @Override
+ public boolean canManageCardinality() {
+ return true;
+ }
+
+ @Override
+ public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
+ throws SensitivityException {
+
+ setIsisFactorsR(plan, outputDirectory);
+
+ int factorNumber = plan.getFactors().size();
+ RDataFrame dataFrame; //The dataframe to get back the scenarios from R
+ SensitivityScenarios thisExperiment = new SensitivityScenarios(); //The experiment we will build
+ List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios(); //The list of scenarios
+ List<Factor> factors = plan.getFactors(); //The factors
+
+ testNoDiscrete(factors);
+
+ try {
+
+ REngine engine = new RProxy(); //The R engine
+
+ //Clear session
+ engine.clearSession();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ //Load the lhs library
+ engine.voidEval("library(lhs)");
+
+ //Create the scenarios
+ String rInstruction = "x<-randomLHS(%s,%s)";
+ String rCall = String.format(rInstruction, param_simulationNumber,
+ factorNumber);
+
+ if (param_modifR) {
+ rCall = editRInstruction(rCall);
+ }
+
+ engine.voidEval(rCall);
+
+ // Get back experiment plan
+ engine.eval("expPlan<-as.data.frame(x)");
+ dataFrame = (RDataFrame)engine.eval("expPlan");
+ dataFrame.setVariable("expPlan");
+
+ // Setting up the scenarios.
+ for (int j = 0; j < param_simulationNumber; j++) {
+ Scenario experimentScenario = new Scenario();
+ for (int i = 0; i < factorNumber; i++) {
+ Factor factor = plan.getFactors().get(i); //The factor we are setting
+ factor.setValueForIdentifier(dataFrame.get(i,j));
+ experimentScenario.addFactor(factor);
+ }
+ thisExperimentScenarios.add(experimentScenario);
+ thisExperiment.setScenarios(thisExperimentScenarios);
+ }
+
+ String isisFactorDistribution = "isis.factor.distribution<-" +
+ "data.frame(" +
+ "NomFacteur=c(%s)," +
+ "NomDistribution=c(%s)," +
+ "ParametreDistribution=c(%s))";
+
+ String distribution = "";
+ String parameters = "";
+ String factorNames = "";
+
+
+ //Create the strings for the isis.MethodExp instruction
+ for (int i = 0; i < factors.size(); i++) {
+ ContinuousDomain domain = (ContinuousDomain)factors.get(i).getDomain();
+ if (i != 0) {
+ distribution += ","; //the distribution
+ factorNames += ","; //the factor names
+ parameters += ","; //the parameters
+ }
+
+ factorNames += "\"" + factors.get(i).getName() + "\"";
+ distribution += "\"qunif\""; //all distributions are qunif
+ double min = domain.getCalculatorMinBound();
+ double max = domain.getCalculatorMaxBound();
+ parameters += "\"[" + min + ";" + max + "]\"";
+ }
+ engine.voidEval(String.format(isisFactorDistribution, factorNames,
+ distribution, parameters));
+
+ engine.voidEval("call<-" + "\"x<-randomLHS("
+ + param_simulationNumber + "," + factorNumber + ")\"");
+
+ engine.voidEval("isis.MethodExp<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"call\"=call)");
+
+ engine.voidEval("attr(isis.MethodExp," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ engine.voidEval("isis.simule<-data.frame(x)");
+ engine.voidEval("attr(isis.simule," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
+
+ String data = "data<-data.frame(";
+
+ //Create the factors vectors and the dataFrame instruction
+ for (int j = 0; j < factors.size(); j++) {
+ Scenario firstScenario = thisExperimentScenarios.get(0);
+ Factor factor = firstScenario.getFactors().get(j);
+ String factorName = factor.getName().replaceAll(" ", "");
+
+ //the vector of the factor values
+ //read all the values one by one from the already created
+ //scenarios.
+ String vector = factorName + "<-c(";
+ for (int i = 0; i < param_simulationNumber; i++) {
+ Scenario scenario = thisExperimentScenarios.get(i);
+ List<Factor> factorList = scenario.getFactors();
+ Factor factor1 = factorList.get(j);
+ if (i < (param_simulationNumber - 1)) {
+ vector += factor1.getDisplayedValue() + ",";
+ } else {
+ vector += factor1.getDisplayedValue();
+ }
+
+ }
+ vector = vector + ")";
+ engine.voidEval(vector);
+
+ //add factor1=factor(factor1) for each factor...
+ if (j < factors.size() - 1) {
+ data += factorName + "=factor(" + factorName + "),";
+ } else {
+ data += factorName + "=factor(" + factorName + "))";
+ }
+
+ }
+ engine.voidEval(data);
+
+ // Creating the factors vector.
+ rInstruction = "factornames<-c(";
+ for (int i = 0; i < factorNumber; i++) {
+ if (i != (factorNumber - 1)) {
+ rInstruction = rInstruction + "\""
+ + factors.get(i).getName() + "\",";
+ } else {
+ rInstruction = rInstruction + "\""
+ + factors.get(i).getName() + "\"";
+ }
+ }
+ rInstruction += ")";
+ engine.voidEval(rInstruction);
+
+ // Clean RData
+ for (Factor factor:factors) {
+ engine.remove(factor.getName().replaceAll(" ", ""));
+ }
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ engine.terminate();
+
+ } catch (Exception e) {
+ throw new SensitivityException("Can't generate scenarios", e);
+ }
+
+ return thisExperiment;
+ }
+
+ @Override
+ public void analyzeResult(List<SimulationStorage> simulationStorages,
+ File outputDirectory) throws SensitivityException {
+
+ SimulationStorage simulationStorage1 = simulationStorages.get(0);
+ String simName = simulationStorage1.getName();
+ String simulationName = simName.replaceAll("-", "");
+ SimulationParameter param = simulationStorage1.getParameter();
+ int sensitivityNumber = param.getSensitivityExport().size();
+ //List<SensitivityExport> export = param.getSensitivityExport();
+
+ try {
+ REngine engine = new RProxy();
+
+ //Clear session
+ engine.clearSession();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ engine.voidEval("factors<-data.frame(x)");
+
+ //Get back the factors number
+ int factorNumber = (Integer) engine.eval("length(factors)");
+
+ //Get back the simulation number
+ param_simulationNumber = (Integer) (engine.eval("length(factors[,1])"));
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ SensitivityExport sensitivityExport =
+ param.getSensitivityExport().get(k);
+
+ String rInstruction = createImportInstruction(sensitivityExport,
+ simulationStorages);
+
+ // Send the simulation results
+ engine.voidEval(rInstruction);
+
+ //Put results in isis.simule
+ engine.voidEval("isis.simule<-data.frame(isis.simule," +
+ sensitivityExport.getExportFilename() + ")");
+ }
+
+ //adding attribute to isis.Simule
+ engine.voidEval("attr(isis.simule," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ // Creates the R expression to import results in R
+ String name = param.getSensitivityExport().get(k)
+ .getExportFilename();
+
+ //Create the dataforaov data.frame
+ String dataframe = "dataforaov<-data.frame(factors," + name
+ + "=" + name + ")";
+ engine.voidEval(dataframe);
+
+ //Call aov()
+ String aovCall = "aovresult<-aov(" + name + "~";
+ for (int j = 0; j < factorNumber; j++) {
+
+ if (j < (factorNumber - 1)) {
+ aovCall += engine.eval("names(factors)[" + (j + 1) + "]")
+ + "+";
+ } else {
+ aovCall += engine.eval("names(factors)[" + (j + 1) + "]")
+ + ",data=dataforaov)";
+ }
+ }
+ engine.voidEval(aovCall);
+
+ /*Export the results
+ *Export format is csv, data separated by ','
+ *Results Export name is sensitivityExportName_Results.csv
+ *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
+ */
+
+ //Compute Sum of Squares and Sensitivity indices
+ engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
+ engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
+ engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
+
+ //Create a data.frame to export sensitivity important results in one file.
+ engine.voidEval("exportsensitivity<-data.frame(" +
+ "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
+ "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
+ engine.voidEval("names(exportsensitivity)<-c(" +
+ "\"Sum Of Squares\"," +
+ "\"Sensitivity indices\")");
+ engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
+
+
+ //Set dataforaov names
+ engine.voidEval("resultsnames<-c(factornames,\"Result\")");
+ engine.voidEval("names(dataforaov)<-resultsnames");
+
+ /*Set the export directory
+ *Export directory is the first simulation export directory.
+ */
+ engine.setwd(outputDirectory);
+
+ //Save the results with the scenarios.
+ engine.voidEval("write.csv(dataforaov,\"" +
+ param.getSensitivityExport().get(k).getExportFilename() +
+ "_Results.csv\")");
+
+ //Save the sensitivity indices
+ engine.voidEval("write.csv(exportsensitivity,\"" +
+ param.getSensitivityExport().get(k).getExportFilename() +
+ "_SensitivityIndices.csv\")");
+ //FIXME export through java to enable export when using Rserve (when distant Rserve).
+
+ //creating isis.methodAnalyse
+ engine.voidEval("isis.methodAnalyse<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"isis.simule\"=isis.simule," +
+ "call_method=\"" + aovCall + "\"," +
+ "\"analysis_result\"=list(aovresult,IndSensibilite))");
+
+ engine.voidEval("attr(isis.methodAnalyse," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-" +
+ "isis.methodAnalyse";
+ engine.voidEval(String.format(renameIsisMethodAnalyse,
+ simulationName + "." + name));
+
+ }
+
+ //Rename R objects for saving purpose
+ renameObjects(engine, simulationName);
+
+ //Clean temporary R objects
+ for (String object:engine.ls()) {
+ if (!object.startsWith(simulationName)){
+ engine.remove(object);
+ }
+ }
+
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ engine.terminate();
+
+ } catch (Exception e) {
+ throw new SensitivityException("Can't evaluate results", e);
+ }
+
+ }
+
+ @Override
+ public String getDescription() {
+ return "Implementation of Random Latin Hypercube method method using" +
+ " R needs the 'lhs' package to work)";
+ }
+
+}
Copied: branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java (from rev 305, branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRExpandGrid.java)
===================================================================
--- branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java (rev 0)
+++ branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -0,0 +1,374 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+package sensitivityanalysis;
+
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.export.SensitivityExport;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.simulator.sensitivity.*;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
+import fr.ifremer.isisfish.util.Doc;
+import org.apache.commons.lang.StringUtils;
+import org.nuiton.j2r.REngine;
+import org.nuiton.j2r.RException;
+import org.nuiton.j2r.RProxy;
+import org.nuiton.j2r.types.RDataFrame;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * User: couteau
+ * Date: 6 janv. 2010
+ * Time: 14:31:09
+ */
+public class RegularExpandGrid extends AbstractSensitivityAnalysis {
+
+ @Doc("Interaction order")
+ public int param_order = 2;
+
+ @Doc("True to be able to modify the code sent to R")
+ public boolean param_modifR = false;
+
+ /**
+ * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
+ * continue.
+ *
+ * @return <tt>true</tt> s'il sait la gerer
+ */
+ @Override
+ public boolean canManageCardinality() {
+ return false;
+ }
+
+ @Override
+ public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
+ throws SensitivityException {
+
+ SensitivityScenarios thisExperiment = new SensitivityScenarios();
+
+ setIsisFactorsR(plan, outputDirectory);
+
+ //extract the factors from the design plan
+ List<Factor> factors = plan.getFactors();
+ int factorsNb = factors.size();
+
+ try {
+ REngine engine = new RProxy();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ //Create a list of the factors under the form factor1=factor1,...
+ String factorsNames = "";
+
+ //Create a list of the factors under the form factor1,factor2,...
+ String factorNames = "";
+
+ //create the factors vectors
+ for (Factor factor : factors) {
+ //The factor values vector
+ String factorName = factor.getName().replaceAll(" ", "");
+ factorsNames += factorName + "=" + factorName + ",";
+ factorNames += factorName + ",";
+ String vector = factorName + "<-c(";
+
+ Domain domain = factor.getDomain();
+
+ if (domain instanceof ContinuousDomain) {
+ ContinuousDomain contDomain = (ContinuousDomain) domain;
+ int card = factor.getCardinality();
+ Double min = contDomain.getCalculatorMinBound();
+ Double max = contDomain.getCalculatorMaxBound();
+
+ for (int i = 0; i < card; i++) {
+ //add the ith value
+ vector += (min + (i * (max - min) / (card - 1))) + ",";
+ }
+ }
+
+ if (domain instanceof DiscreteDomain) {
+ Map<Object, Object> values = ((DiscreteDomain) domain).getValues();
+ int nbValues = values.size();
+ for (int i = 0; i < nbValues; i++) {
+ vector += "as.integer(" + i + "),";
+ }
+ }
+
+ vector = vector.substring(0, vector.length() - 1);
+
+ vector += ")";
+
+ engine.voidEval(vector);
+
+
+ }
+
+ factorsNames = factorsNames.substring(0,factorsNames.length()-1);
+ factorNames = factorNames.substring(0,factorNames.length()-1);
+
+
+ //X<-expand.grid(vector=???,weight=???)
+ String expandGrid = "x<-expand.grid(%s)";
+
+ String rCall = String.format(expandGrid,factorsNames);
+
+ if (param_modifR) {
+ rCall = editRInstruction(rCall);
+ }
+
+ engine.voidEval(rCall);
+
+ engine.eval("expPlan<-as.data.frame(x)");
+ RDataFrame dataFrame = (RDataFrame)engine.eval("expPlan");
+ dataFrame.setVariable("expPlan");
+ int nbExperiments = (Integer)engine.eval("dim(x)[1]");
+
+ List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
+ for (int j = 0; j < nbExperiments; j++) {
+ Scenario experimentScenario = new Scenario();
+ for (int i = 0; i < factorsNb; i++) {
+ Factor factor = factors.get(i);
+ factor.setValueForIdentifier(dataFrame.get(i, j));
+ experimentScenario.addFactor(factor);
+ }
+ thisExperimentScenarios.add(experimentScenario);
+ thisExperiment.setScenarios(thisExperimentScenarios);
+ }
+
+
+ String factorDistribution = "isis.factor.distribution<-data.frame(" +
+ "NomFacteur=c(%s)," +
+ "NomDistribution=c(%s)," +
+ "ParametreDistribution=c(%s))";
+
+ String distribution = "";
+ String parameters = "";
+
+ for (int i = 0; i < factorsNb; i++) {
+ Domain domain = factors.get(i).getDomain();
+ if (i != 0) {
+ distribution += ",";
+ parameters += ",";
+ }
+ if (domain instanceof ContinuousDomain){
+ ContinuousDomain contDomain = (ContinuousDomain)domain;
+ distribution += "\"qunif\"";
+ parameters += "\"[" + contDomain.getMinBound()
+ + ";" + contDomain.getMaxBound()
+ + "]\"";
+ } else {
+ DiscreteDomain discDomain = (DiscreteDomain)domain;
+ distribution += "\"discrete\"";
+ parameters+="\"[";
+ Map<Object, Object> values = discDomain.getValues();
+ int count=0;
+ Collection<Object> collecValues = values.values();
+ for (Object value:collecValues){
+ if (count!=0){
+ parameters += ",";
+ }
+ parameters += StringUtils.replace(value.toString(), "\"", "\\\"") ;
+ count++;
+ }
+ parameters+="]\"";
+ }
+ }
+ engine.voidEval(String.format(factorDistribution, factorNames,
+ distribution, parameters));
+
+ engine.voidEval("call<-\"" +
+ String.format(expandGrid,factorsNames) + "\"");
+ engine.voidEval("isis.MethodExp<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"call\"=call)");
+ engine.voidEval("attr(isis.MethodExp," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine.voidEval("isis.simule<-x");
+ engine.voidEval("attr(isis.simule," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+ engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+
+ } catch (RException eee) {
+ throw new SensitivityException("Can't generate scenarios", eee);
+ }
+
+ return thisExperiment;
+ }
+
+ @Override
+ public void analyzeResult(List<SimulationStorage> simulationStorages,
+ File outputDirectory) throws SensitivityException {
+
+ try {
+
+ REngine engine = new RProxy();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ //Get back the factors number
+ int factorNumber = (Integer)engine.eval("dim(x)[2]");
+
+ SimulationParameter param = simulationStorages.get(0).getParameter();
+ int sensitivityNumber = param.getSensitivityExport().size();
+
+ SimulationStorage firstStorage = simulationStorages.get(0);
+
+ String firstStorageName = firstStorage.getName().replaceAll("-", "");
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ SensitivityExport sensitivityExport =
+ param.getSensitivityExport().get(k);
+
+ String name = sensitivityExport.getExportFilename();
+
+ String rInstruction = createImportInstruction(sensitivityExport,
+ simulationStorages);
+
+ // Send the simulation results
+ engine.voidEval(rInstruction);
+
+ //Put results in isis.simule
+ engine.voidEval("isis.simule<-data.frame(isis.simule,"
+ + name + ")");
+
+ //Create the dataforaov data.frame
+ String dataFrame = "dataforaov<-data.frame(x,"
+ + name + "=" + name + ")";
+ engine.voidEval(dataFrame);
+
+ //Call aov()
+ String aovCall = "aovresult<-aov(" + name + "~(";
+ for (int j = 0; j < factorNumber; j++) {
+ if (j < (factorNumber - 1)) {
+ aovCall = aovCall
+ + engine.eval("names(x)[" + (j + 1) + "]")
+ + "+";
+ } else {
+ aovCall = aovCall
+ + engine.eval("names(x)[" + (j + 1) + "]")
+ + ")";
+ if(param_order>1){
+ aovCall+="^" + param_order + ",data=dataforaov)";
+ }else{
+ aovCall+=",data=dataforaov)";
+ }
+ }
+ }
+ engine.voidEval(aovCall);
+
+ /*Export the results
+ *Export format is csv, data separated by ','
+ *Results Export name is sensitivityExportName_Results.csv
+ *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
+ */
+
+ //Compute Sum of Squares and Sensitivity indices
+ engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
+ engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
+ engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
+
+ //Create a data.frame to export sensitivity important results in one file.
+ engine.voidEval("exportsensitivity<-data.frame(" +
+ "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
+ "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
+ engine.voidEval("names(exportsensitivity)<-c(" +
+ "\"Sum Of Squares\"," +
+ "\"Sensitivity indices\")");
+ engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
+
+ /*Set the export directory
+ *Export directory is the first simulation export directory.
+ */
+ engine.setwd(outputDirectory);
+
+ //Save the results with the scenarios.
+ engine.voidEval("write.csv(dataforaov,\""
+ + param.getSensitivityExport().get(k)
+
+ .getExportFilename() + "_Results.csv\")");
+
+ //Save the sensitivity indices
+ engine.voidEval("write.csv(exportsensitivity,\""
+ + param.getSensitivityExport().get(k)
+ .getExportFilename()
+ + "_SensitivityIndices.csv\")");
+ //FIXME export through java to enable export when using Rserve (when distant Rserve).
+
+ //creating isis.methodAnalyse
+ engine.voidEval("isis.methodAnalyse<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"isis.simule\"=isis.simule," +
+ "\"call_method\"=\"" + aovCall + "\"," +
+ "\"analysis_result\"=list(aovresult,IndSensibilite))");
+
+ engine.voidEval("attr(isis.methodAnalyse," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-isis.methodAnalyse";
+ engine.voidEval(String.format(renameIsisMethodAnalyse,
+ firstStorageName + "." + name));
+
+ }
+
+ //Rename R objects for saving purpose
+ renameObjects(engine, firstStorageName);
+
+ //Clean temporary R objects
+ for (String object:engine.ls()) {
+ if (!object.startsWith(firstStorageName)){
+ engine.remove(object);
+ }
+ }
+
+ //Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ engine.terminate();
+
+ } catch (Exception e) {
+ throw new SensitivityException("Can't evaluate results", e);
+ }
+
+ }
+
+ @Override
+ public String getDescription() {
+ return "Implementation of Expand Grid method using R";
+ }
+}
Copied: branches/4.2.2/sensitivityanalysis/RegularFractions.java (from rev 305, branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRegularFractions.java)
===================================================================
--- branches/4.2.2/sensitivityanalysis/RegularFractions.java (rev 0)
+++ branches/4.2.2/sensitivityanalysis/RegularFractions.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -0,0 +1,398 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+package sensitivityanalysis;
+
+import java.io.File;
+import java.util.List;
+
+import fr.ifremer.isisfish.export.SensitivityExport;
+import org.nuiton.j2r.REngine;
+import org.nuiton.j2r.RException;
+import org.nuiton.j2r.RProxy;
+import org.nuiton.j2r.types.RDataFrame;
+
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
+import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
+import fr.ifremer.isisfish.simulator.sensitivity.Domain;
+import fr.ifremer.isisfish.simulator.sensitivity.Factor;
+import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
+import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
+import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain;
+import fr.ifremer.isisfish.util.Doc;
+
+public class RegularFractions extends AbstractSensitivityAnalysis {
+
+ @Doc("the path of the directory where the R function is stored (do not indicate the RegularFractions.R file name)")
+ public String param_pathToFunction = "";
+
+ @Doc("unique prime number of levels of all input and unit factors")
+ public int param_p = 2;
+
+ @Doc("number of unit factors (so that there are N=p^r units)")
+ public int param_r = 2;
+
+ @Doc("resolution of the fraction")
+ public int param_resolution = 2;
+
+ @Doc("True to be able to modify the code sent to R")
+ public boolean param_modifR = false;
+
+ /**
+ * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
+ * continue.
+ *
+ * @return <tt>true</tt> s'il sait la gerer
+ */
+ @Override
+ public boolean canManageCardinality() {
+ return true;
+ }
+
+ @Override
+ public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
+ throws SensitivityException {
+
+ setIsisFactorsR(plan, outputDirectory);
+
+ RDataFrame dataFrame;
+ int factorNumber = plan.getFactors().size();
+ List<Factor> factors = plan.getFactors();
+ SensitivityScenarios thisExperiment = new SensitivityScenarios();
+ List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
+
+ String factorNames = "";
+
+ //Test all factors, if one is discrete, return null
+ //Create a string with all factors names
+ for (int i = 0; i < factorNumber; i++) {
+ Domain domain = factors.get(i).getDomain();
+ if (i != 0) {
+ factorNames += ",";
+ }
+
+ factorNames += "\"" + factors.get(i).getName() + "\"";
+
+ if (domain instanceof DiscreteDomain) {
+ throw new SensitivityException(factors.get(i).getName() +
+ " has a discrete domain, this is not acceptable for " +
+ "this method.");
+ }
+ }
+
+ try {
+
+ REngine engine = new RProxy();
+
+ //Clear session
+ engine.clearSession();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ //Set the working directory (to import the R function)
+ engine.setwd(new File(param_pathToFunction));
+
+ //Import the function
+ engine.voidEval("source(\"regularfractions.R\")");
+
+ //Create the instruction
+ String rInstruction = "x<-regular.fraction(%s,%s,%s,%s)";
+ String rCall = String.format(rInstruction, factors.size(), param_p,
+ param_r, param_resolution);
+
+ if (param_modifR) {
+ rCall = editRInstruction(rCall);
+ }
+
+ // Run function
+ engine.voidEval(rCall);
+
+ // Run function
+ engine.voidEval("call<-\"" + rCall + "\"");
+
+ // Creating the factors vector.
+ rInstruction = "factornames<-c(%s)";
+ rCall = String.format(rInstruction, factorNames);
+
+ engine.voidEval(rCall);
+
+
+ // Get back experiment plan
+ engine.eval("expPlan<-as.data.frame(x[[1]])");
+ dataFrame = (RDataFrame)engine.eval("expPlan");
+ dataFrame.setVariable("expPlan");
+
+ //Get back the simulation number
+ int simulationNumber = (Integer) engine.eval("length(x[[1]][,1])");
+
+ // Setting up the scenarios.
+ for (int j = 0; j < simulationNumber; j++) {
+ Scenario experimentScenario = new Scenario();
+ for (int i = 0; i < factors.size(); i++) {
+ Factor factor = plan.getFactors().get(i);
+ Domain domain = factor.getDomain();
+ Double dFValue = (Double)dataFrame.get(i,j);
+ if ((domain instanceof MatrixContinuousDomain)
+ || (domain instanceof EquationContinuousDomain)) {
+ factor.setValueForIdentifier(dFValue);
+ } else {
+ ContinuousDomain contDomain = (ContinuousDomain)domain;
+ Double max = contDomain.getCalculatorMaxBound();
+ Double min = contDomain.getCalculatorMinBound();
+ Double value = min + (max - min) * dFValue / (param_p - 1);
+ factor.setValueForIdentifier(value);
+ }
+ experimentScenario.addFactor(factor);
+ }
+ thisExperimentScenarios.add(experimentScenario);
+ thisExperiment.setScenarios(thisExperimentScenarios);
+ }
+
+ String dataframe = "data<-data.frame(";
+
+ //Create the factors vectors and the dataframe instruction
+ for (int j = 0; j < factorNumber; j++) {
+ Factor factor = factors.get(j);
+ String factorName = factor.getName().replaceAll(" ", "");
+
+ String vector = factorName + "<-c(";
+ for (int i = 0; i < simulationNumber; i++) {
+ Scenario scenario = thisExperimentScenarios.get(i);
+ List<Factor> newFactors = scenario.getFactors();
+ Factor factor1 = newFactors.get(j);
+
+ if (i < (simulationNumber - 1)) {
+ vector += factor1.getDisplayedValue() + ",";
+ } else {
+ vector += factor1.getDisplayedValue();
+ }
+
+ }
+ vector = vector + ")";
+ engine.voidEval(vector);
+
+ if (j < factorNumber - 1) {
+ dataframe += factorName + "=factor(" + factorName + "),";
+ } else {
+ dataframe += factorName + "=factor(" + factorName + "))";
+ }
+
+ }
+ engine.voidEval(dataframe);
+
+ engine.voidEval("isis.factor.distribution<-c(0.0)");
+
+ engine.voidEval("isis.MethodExp<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"call\"=call)");
+
+ engine.voidEval("attr(isis.MethodExp," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ //Create isis.Simule
+ engine.voidEval("isis.simule<-data.frame(data)");
+
+ engine.voidEval("attr(isis.simule," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ engine.terminate();
+
+ } catch (RException eee) {
+ throw new SensitivityException("Can't generate scenarios", eee);
+ }
+
+ return thisExperiment;
+
+ }
+
+ @Override
+ public void analyzeResult(List<SimulationStorage> simulationStorages,
+ File outputDirectory) throws SensitivityException {
+
+ SimulationStorage firstStorage = simulationStorages.get(0);
+ SimulationParameter param = firstStorage.getParameter();
+ List<SensitivityExport> exports = param.getSensitivityExport();
+ int sensitivityNumber = exports.size();
+ String simulationName = firstStorage.getName().replaceAll("-", "");
+
+ try {
+
+ REngine engine = new RProxy();
+
+ //Clear session
+ engine.clearSession();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ //Get back the factors number
+ int factorNumber = (Integer) engine.eval("dim(data)[2]");
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ SensitivityExport sensitivityExport =
+ param.getSensitivityExport().get(k);
+
+ String rInstruction = createImportInstruction(sensitivityExport,
+ simulationStorages);
+
+ // Send the simulation results
+ engine.voidEval(rInstruction);
+
+ //Put results in isis.simule
+ engine.voidEval("isis.simule<-data.frame(isis.simule," +
+ sensitivityExport.getExportFilename() + ")");
+ }
+
+ //adding attribute to isis.Simule
+ engine.voidEval("attr(isis.simule," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ for (SensitivityExport export : exports) {
+
+ String name = export.getExportFilename();
+
+ //Create the dataforaov data.frame
+ String dataFrame = "dataforaov<-data.frame(data," +
+ name + "=" + name + ")";
+ engine.voidEval(dataFrame);
+
+ //Call aov()
+ String aovCall = "aovresult<-aov(" + name + "~(";
+ for (int j = 0; j < factorNumber; j++) {
+
+ if (j < (factorNumber - 1)) {
+ aovCall = aovCall
+ + engine.eval("names(data)[" + (j + 1) + "]")
+ + "+";
+ } else {
+ aovCall = aovCall
+ + engine.eval("names(data)[" + (j + 1) + "]")
+ + ")";
+ if (param_resolution <= 4) {
+ aovCall += ",data=dataforaov)";
+ } else {
+ aovCall += "^2,data=dataforaov)";
+ }
+ }
+ }
+ engine.voidEval(aovCall);
+
+ /*Export the results
+ *Export format is csv, data separated by ','
+ *Results Export name is sensitivityExportName_Results.csv
+ *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
+ */
+
+ //Compute Sum of Squares and Sensitivity indices
+ engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
+ engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
+ engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
+
+ //Create a data.frame to export sensitivity important results in one file.
+ engine.voidEval("exportsensitivity<-data.frame(" +
+ "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
+ "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
+ engine.voidEval("names(exportsensitivity)<-c(" +
+ "\"Sum Of Squares\"," +
+ "\"Sensitivity indices\")");
+ engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
+
+ //Set dataforaov names
+ engine.voidEval("resultsnames<-c(factornames,\"Result\")");
+ engine.voidEval("names(dataforaov)<-resultsnames");
+
+ /*Set the export directory
+ *Export directory is the first simulation export directory.
+ */
+ engine.setwd(outputDirectory);
+
+ //Save the results with the scenarios.
+ engine.voidEval("write.csv(dataforaov,\"" + name +
+ "_Results.csv\")");
+
+ //Save the sensitivity indices
+ engine.voidEval("write.csv(exportsensitivity,\"" + name +
+ "_SensitivityIndices.csv\")");
+ //FIXME export through java to enable export when using Rserve (when distant Rserve).
+
+ //creating isis.methodAnalyse
+ engine.voidEval("isis.methodAnalyse<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"isis.simule\"=isis.simule," +
+ "\"call_method\"=\"" + aovCall + "\"," +
+ "\"analysis_result\"=list(aovresult,IndSensibilite))");
+
+ engine.voidEval("attr(isis.methodAnalyse," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-isis.methodAnalyse";
+ engine.voidEval(String.format(renameIsisMethodAnalyse,
+ simulationName + "." + name));
+
+ }
+
+ //Rename R objects for saving purpose
+ renameObjects(engine,simulationName);
+
+ //Clean temporary R objects
+ for (String object:engine.ls()) {
+ if (!object.startsWith(simulationName)){
+ engine.remove(object);
+ }
+ }
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ engine.terminate();
+
+ } catch (Exception eee) {
+ throw new SensitivityException("Can't evaluate results", eee);
+ }
+
+ }
+
+ @Override
+ public String getDescription() {
+ return "Implementation of Regular fractions method using R";
+ }
+
+}
Deleted: branches/4.2.2/sensitivityanalysis/SensitivityCalculatorJavaExpandGrid.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/SensitivityCalculatorJavaExpandGrid.java 2012-11-06 10:23:44 UTC (rev 306)
+++ branches/4.2.2/sensitivityanalysis/SensitivityCalculatorJavaExpandGrid.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -1,393 +0,0 @@
-/*
- * #%L
- * IsisFish data
- * %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package sensitivityanalysis;
-
-import java.io.File;
-import java.util.List;
-
-import fr.ifremer.isisfish.export.SensitivityExport;
-import fr.ifremer.isisfish.simulator.sensitivity.*;
-import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RProxy;
-
-import fr.ifremer.isisfish.datastore.SimulationStorage;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain;
-import fr.ifremer.isisfish.util.Doc;
-
-/**
- * Implementation of ExpandGrid method using Java
- *
- * @author jcouteau
- * @version $Revision: 1.0 $
- *
- */
-public class SensitivityCalculatorJavaExpandGrid extends
- AbstractSensitivityAnalysis {
-
- @Doc("Interaction order")
- public int param_order = 2;
-
- /**
- * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
- * continue.
- *
- * @return <tt>true</tt> s'il sait la gerer
- */
- @Override
- public boolean canManageCardinality() {
- return false;
- }
-
- @Override
- public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
- throws SensitivityException {
-
- setIsisFactorsR(plan, outputDirectory);
-
- int k = 1; //number of sensitivity scenarios (initialization)
- int factorNumber = plan.getFactors().size(); //number of factors
- List<Factor> factors = plan.getFactors(); //list of factors
-
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = factors.get(i);
- Domain domain = factor.getDomain();
-
- //calculate the number of scenarios
- if (domain instanceof ContinuousDomain) {
- if (factor.getCardinality() != 0) {
- k = k * factor.getCardinality();
- }
- } else if (domain instanceof DiscreteDomain) {
- DiscreteDomain discreteDomain = (DiscreteDomain)domain;
- if (discreteDomain.getValues().size() != 0) {
- k = k * discreteDomain.getValues().size();
- }
- }
- }
-
- SensitivityScenarios thisExperiment = new SensitivityScenarios();
- List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
-
- for (int i = 0; i < k; i++) {
- int result = 0; //used for the euclidian division
- int rest = i; //used for the euclidian division
- Scenario experimentScenario = new Scenario();
- for (int j = 0; j < factorNumber; j++) {
- Factor factor = factors.get(j);
- Domain domain = factor.getDomain();
- if (domain instanceof ContinuousDomain) {
- ContinuousDomain continuousDomain = (ContinuousDomain)domain;
- Double max = continuousDomain.getCalculatorMaxBound();
- Double min = continuousDomain.getCalculatorMinBound();
- int card = factor.getCardinality();
-
- //Do the euclidian division
- result = (int) Math.floor(rest / card);
- rest = rest - (card * result);
-
- //Calculate the value of the factor
- Double value = min + ((max - min) / (card - 1) * rest);
- if ((domain instanceof MatrixContinuousDomain)
- || (domain instanceof EquationContinuousDomain)) {
- factor.setValueForIdentifier(value);
- } else {
- factor.setValueForIdentifier(value);
- }
- }
- if (factor.getDomain() instanceof DiscreteDomain) {
- DiscreteDomain discreteDomain = (DiscreteDomain)domain;
- int card = discreteDomain.getValues().size();
-
- //Do the euclidian division
- result = (int) Math.floor(rest / card);
- rest = rest - (card * result);
-
- //Select the value of the factor
- factor.setValueForIdentifier(rest);
- }
- rest = result;
- experimentScenario.addFactor(factor);
- }
- thisExperimentScenarios.add(experimentScenario);
-
- }
- thisExperiment.setScenarios(thisExperimentScenarios);
-
- thisExperimentScenarios = thisExperiment.getScenarios();
-
- /*
- * Call R to save the data for result analysis
- */
- int scenariosNumber = thisExperimentScenarios.size();
-
- try {
-
- REngine engine = new RProxy();
-
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- String dataframe = "data<-data.frame(";
-
- //Create the factors vectors and the dataframe instruction
- for (int j = 0; j < factorNumber; j++) {
-
- Factor factor = factors.get(j);
- String factorName = factor.getName().replaceAll(" ", "");
-
- //String vector = "factor" + j + "<-c(";
- String vector = factorName + "<-c(";
- for (int i = 0; i < scenariosNumber; i++) {
- Scenario scenario = thisExperimentScenarios.get(i);
- List<Factor> newFactors = scenario.getFactors();
- Factor factor1 = newFactors.get(j);
-
- if (i < (scenariosNumber - 1)) {
- vector += factor1.getDisplayedValue() + ",";
- } else {
- vector += factor1.getDisplayedValue();
- }
-
- }
- vector = vector + ")";
- engine.voidEval(vector);
-
- if (j < factorNumber - 1) {
- dataframe += factorName + "=factor(" + factorName + "),";
- } else {
- dataframe += factorName + "=factor(" + factorName + "))";
- }
-
- }
- engine.voidEval(dataframe);
-
- // Creating the factors vector.
- String rInstruction = "factornames<-c(";
- for (int i = 0; i < factorNumber; i++) {
- if (i != (factorNumber - 1)) {
- rInstruction = rInstruction + "\""
- + factors.get(i).getName() + "\",";
- } else {
- rInstruction = rInstruction + "\""
- + factors.get(i).getName() + "\"";
- }
- }
-
- rInstruction += ")";
-
- engine.voidEval(rInstruction);
-
- //Create the isis.factor.distribution
- engine.voidEval("isis.factor.distribution<-c(0.0)");
-
- //Create isis.MethodExp
- engine.voidEval("isis.MethodExp<-list(" +
- "isis.factors," +
- "isis.factor.distribution," +
- "call_method=\"isis-fish-externeR\")");
-
- engine.voidEval("attr(isis.MethodExp," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- //Create isis.Simule
- engine.voidEval("isis.simule<-data.frame(data)");
-
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
- } catch (Exception e) {
- throw new SensitivityException("Can't generate scenarios", e);
- }
-
- return thisExperiment;
- }
-
- @Override
- public void analyzeResult(List<SimulationStorage> simulationStorages,
- File outputdirectory) throws SensitivityException {
-
- SimulationStorage firstStorage = simulationStorages.get(0);
- String simulationName = firstStorage.getName().replaceAll("-", "");
- SimulationParameter param = firstStorage.getParameter();
- int sensitivityNumber = param.getSensitivityExport().size();
-
- try {
-
- REngine engine = new RProxy();
-
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputdirectory.getParentFile(),
- outputdirectory.getName());
-
- //Get back the factors number
- int factorNumber = (Integer)engine.eval("dim(data)[2]");
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- SensitivityExport sensitivityExport =
- param.getSensitivityExport().get(k);
-
- String name = sensitivityExport.getExportFilename();
-
- String rInstruction = createImportInstruction(sensitivityExport,
- simulationStorages);
-
- // Send the simulation results
- engine.voidEval(rInstruction);
-
- //Put results in isis.simule
- engine.voidEval("isis.simule<-data.frame(isis.simule,"
- + name + ")");
-
- //Create the dataforaov data.frame
- String dataframe = "dataforaov<-data.frame(data," +
- name + "=" + name + ")";
- engine.voidEval(dataframe);
-
- //Call aov()
- String aovCall = "aovresult<-aov(" + name + "~(";
- for (int j = 0; j < factorNumber; j++) {
- if (j < (factorNumber - 1)) {
- aovCall = aovCall +
- engine.eval("names(data)[" + (j + 1) + "]") +
- "+";
- } else {
- aovCall = aovCall +
- engine.eval("names(data)[" + (j + 1) + "]") +
- ")";
- if(param_order>1){
- aovCall+="^" + param_order + ",data=dataforaov)";
- }else{
- aovCall+=",data=dataforaov)";
- }
- }
- }
- engine.voidEval(aovCall);
-
- /*Export the results
- *Export format is csv, data separated by ','
- *Results Export name is sensitivityExportName_Results.csv
- *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
- */
-
- //Compute Sum of Squares and Sensitivity indices
- engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
- engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
- engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
-
- //Create a data.frame to export sensitivity important results in one file.
- engine.voidEval("exportsensitivity<-data.frame(" +
- "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
- "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
- engine.voidEval("names(exportsensitivity)<-c(" +
- "\"Sum Of Squares\"," +
- "\"Sensitivity indices\")");
- engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
-
-
- //Set dataforaov names
- engine.voidEval("resultsnames<-c(" +
- "factornames," +
- "\"Result\")");
- engine.voidEval("names(dataforaov)<-resultsnames");
-
- /*Set the export directory
- *Export directory is the first simulation export directory.
- */
- engine.setwd(outputdirectory);
-
- //Save the results with the scenarios.
- engine.voidEval("write.csv(dataforaov,\""
- + param.getSensitivityExport().get(k).getExportFilename() + "_Results.csv\")");
-
- //Save the sensitivity indices
- engine.voidEval("write.csv(exportsensitivity,\""
- + param.getSensitivityExport().get(k).getExportFilename()
- + "_SensitivityIndices.csv\")");
- //FIXME export through java to enable export when using Rserve (when distant Rserve).
-
- //creating isis.methodAnalyse
- engine.voidEval("isis.methodAnalyse<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"isis.simule\"=isis.simule," +
- "call_method=\"" + aovCall + "\"," +
- "\"analysis_result\"=list(aovresult,IndSensibilite))");
-
- engine.voidEval("attr(isis.methodAnalyse," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-" +
- "isis.methodAnalyse";
- engine.voidEval(String.format(renameIsisMethodAnalyse,
- simulationName + "." + name));
-
- }
-
- //Rename R objects for saving purpose
- renameObjects(engine,simulationName);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- // Save Isis R session
- engine.saveRData(outputdirectory.getParentFile(),
- outputdirectory.getName());
-
- engine.terminate();
-
- } catch (Exception e) {
- throw new SensitivityException("Can't evaluate results", e);
- }
-
- }
-
- @Override
- public String getDescription() {
- return "Implementation of Expand Grid method using Java";
- }
-
-}
Deleted: branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRDOptimal.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRDOptimal.java 2012-11-06 10:23:44 UTC (rev 306)
+++ branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRDOptimal.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -1,406 +0,0 @@
-/*
- * #%L
- * IsisFish data
- * %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package sensitivityanalysis;
-
-import fr.ifremer.isisfish.datastore.SimulationStorage;
-import fr.ifremer.isisfish.export.SensitivityExport;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.*;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
-import fr.ifremer.isisfish.util.Doc;
-import org.apache.commons.lang.StringUtils;
-import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RException;
-import org.nuiton.j2r.RProxy;
-import org.nuiton.j2r.types.RDataFrame;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * User: couteau
- * Date: 14 janv. 2010
- * Time: 11:58:09
- */
-public class SensitivityCalculatorRDOptimal
- extends AbstractSensitivityAnalysis {
-
- @Doc("True to be able to modify the code sent to R")
- public boolean param_modifR = false;
-
- @Doc("Order")
- public int param_order=1;
-
- /**
- * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
- * continue.
- *
- * @return <tt>true</tt> s'il sait la gerer
- */
- @Override
- public boolean canManageCardinality() {
- return false;
- }
-
- @Override
- public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
- throws SensitivityException {
-
- SensitivityScenarios thisExperiment = new SensitivityScenarios();
-
- setIsisFactorsR(plan, outputDirectory);
-
- //extract the factors from the design plan
- List<Factor> factors = plan.getFactors();
- int factorsNb = factors.size();
-
- try {
- REngine engine = new RProxy();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.voidEval("library(AlgDesign)");
-
- //Create a list of the factors under the form factor1=factor1,...
- String factorsNames = "";
-
- //Create a list of the factors under the form factor1,factor2,...
- String factorNames = "";
-
- //Create a list of the factors under the form factor1+factor2+...
- String factorPlus="";
-
- //create the factors vectors
- for (Factor factor : factors) {
- //The factor values vector
- String factorName = factor.getName().replaceAll(" ", "");
- factorsNames += factorName + "=" + factorName + ",";
- factorNames += factorName + ",";
- factorPlus += factorName + "+";
-
- String vector = factorName + "<-c(";
-
- Domain domain = factor.getDomain();
-
- if (domain instanceof ContinuousDomain) {
- ContinuousDomain contDomain = (ContinuousDomain) domain;
- int card = factor.getCardinality();
- Double min = contDomain.getCalculatorMinBound();
- Double max = contDomain.getCalculatorMaxBound();
-
- for (int i = 0; i < card; i++) {
- //add the ith value
- vector += (min + (i * (max - min) / (card - 1))) + ",";
- }
- } else {
- Map<Object, Object> values = ((DiscreteDomain) domain).getValues();
- int nbValues = values.size();
- for (int i = 0; i < nbValues; i++) {
- vector += "as.integer(" + i + "),";
- }
- }
-
- vector = vector.substring(0, vector.length() - 1);
-
- vector += ")";
-
- engine.voidEval(vector);
-
-
- }
-
- factorsNames = factorsNames.substring(0,factorsNames.length()-1);
- factorNames = factorNames.substring(0,factorNames.length()-1);
- factorPlus = factorPlus.substring(0,factorPlus.length()-1);
-
-
- //X<-expand.grid(vector=???,weight=???)
- String expandGrid = "expandgrid<-expand.grid(%s)";
-
-
-
- String rCall = String.format(expandGrid,factorsNames);
-
- engine.voidEval(rCall);
-
- if (param_order ==1 ){
- rCall = "x<-optFederov(~(%s),data=expandgrid, " +
- "approximate =FALSE, center=F, criterion = \"D\"," +
- "nRepeats=10)";
- } else {
- rCall = "x<-optFederov(~(%s)^"+param_order+",data=expandgrid, " +
- "approximate =FALSE, center=F, criterion = \"D\"," +
- "nRepeats=10)";
- }
-
- rCall = String.format(rCall,factorPlus);
-
- if (param_modifR) {
- rCall = editRInstruction(rCall);
- }
-
- engine.voidEval("runif(1)");
-
- engine.voidEval(rCall);
-
- engine.eval("expPlan<-as.data.frame(x$design)");
- RDataFrame dataFrame = (RDataFrame)engine.eval("expPlan");
- dataFrame.setVariable("expPlan");
- int nbExperiments = (Integer)engine.eval("dim(x$design)[1]");
-
- List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
- for (int j = 0; j < nbExperiments; j++) {
- Scenario experimentScenario = new Scenario();
- for (int i = 0; i < factorsNb; i++) {
- Factor factor = factors.get(i);
- factor.setValueForIdentifier(dataFrame.get(i, j));
- experimentScenario.addFactor(factor);
- }
- thisExperimentScenarios.add(experimentScenario);
- thisExperiment.setScenarios(thisExperimentScenarios);
- }
-
-
- String factorDistribution = "isis.factor.distribution<-data.frame(" +
- "NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
-
- String distribution = "";
- String parameters = "";
-
- for (int i = 0; i < factorsNb; i++) {
- Domain domain = factors.get(i).getDomain();
- if (i != 0) {
- distribution += ",";
- parameters += ",";
- }
- if (domain instanceof ContinuousDomain){
- ContinuousDomain contDomain = (ContinuousDomain)domain;
- distribution += "\"qunif\"";
- parameters += "\"[" + contDomain.getMinBound()
- + ";" + contDomain.getMaxBound()
- + "]\"";
- } else {
- DiscreteDomain discDomain = (DiscreteDomain)domain;
- distribution += "\"discrete\"";
- parameters+="\"[";
- Map<Object, Object> values = discDomain.getValues();
- int count=0;
- Collection<Object> collecValues = values.values();
- for (Object value:collecValues){
- if (count!=0){
- parameters += ",";
- }
- parameters += StringUtils.replace(value.toString(), "\"", "\\\"") ;
- count++;
- }
- parameters+="]\"";
- }
- }
- engine.voidEval(String.format(factorDistribution, factorNames,
- distribution, parameters));
-
- engine.voidEval("call<-\"" + rCall + "\"");
- engine.voidEval("isis.MethodExp<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"call\"=call)");
- engine.voidEval("attr(isis.MethodExp," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
- engine.voidEval("isis.simule<-x$design");
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
- engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
-
- } catch (RException eee) {
- throw new SensitivityException("Can't generate scenarios", eee);
- }
-
- return thisExperiment;
- }
-
- @Override
- public void analyzeResult(List<SimulationStorage> simulationStorages,
- File outputDirectory) throws SensitivityException {
-
- try {
-
- REngine engine = new RProxy();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- //Get back the factors number
- int factorNumber = (Integer)engine.eval("dim(x$design)[2]");
-
- SimulationParameter param = simulationStorages.get(0).getParameter();
- int sensitivityNumber = param.getSensitivityExport().size();
-
- SimulationStorage firstStorage = simulationStorages.get(0);
-
- String firstStorageName = firstStorage.getName().replaceAll("-", "");
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- SensitivityExport sensitivityExport =
- param.getSensitivityExport().get(k);
-
- String name = sensitivityExport.getExportFilename();
-
- String rInstruction = createImportInstruction(sensitivityExport,
- simulationStorages);
-
- // Send the simulation results
- engine.voidEval(rInstruction);
-
- //Put results in isis.simule
- engine.voidEval("isis.simule<-data.frame(isis.simule,"
- + name + ")");
-
- //Create the dataforaov data.frame
- String dataFrame = "dataforaov<-data.frame(x$design,"
- + name + "=" + name + ")";
- engine.voidEval(dataFrame);
-
- //Call aov()
- String aovCall = "aovresult<-aov(" + name + "~(";
- for (int j = 0; j < factorNumber; j++) {
- if (j < (factorNumber - 1)) {
- aovCall = aovCall
- + engine.eval("names(x$design)[" + (j + 1) + "]")
- + "+";
- } else {
- aovCall = aovCall
- + engine.eval("names(x$design)[" + (j + 1) + "]")
- + ")";
- if(param_order>1){
- aovCall+="^" + param_order + ",data=dataforaov)";
- }else{
- aovCall+=",data=dataforaov)";
- }
- }
- }
- engine.voidEval(aovCall);
-
- /*Export the results
- *Export format is csv, data separated by ','
- *Results Export name is sensitivityExportName_Results.csv
- *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
- */
-
-//Compute Sum of Squares and Sensitivity indices
- engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
- engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
- engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
-
- //Create a data.frame to export sensitivity important results in one file.
- engine.voidEval("exportsensitivity<-data.frame(" +
- "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
- "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
- engine.voidEval("names(exportsensitivity)<-c(" +
- "\"Sum Of Squares\"," +
- "\"Sensitivity indices\")");
- engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
-
-
- //Set dataforaov names
- engine.voidEval("resultsnames<-c(names(x$design),\"Result\")");
- engine.voidEval("names(dataforaov)<-resultsnames");
-
-
- /*Set the export directory
- *Export directory is the first simulation export directory.
- */
- engine.setwd(outputDirectory);
-
- //Save the results with the scenarios.
- engine.voidEval("write.csv(dataforaov,\""
- + param.getSensitivityExport().get(k)
-
- .getExportFilename() + "_Results.csv\")");
-
- //Save the sensitivity indices
- engine.voidEval("write.csv(exportsensitivity,\""
- + param.getSensitivityExport().get(k)
- .getExportFilename()
- + "_SensitivityIndices.csv\")");
- //FIXME export through java to enable export when using Rserve (when distant Rserve).
-
- //creating isis.methodAnalyse
- engine.voidEval("isis.methodAnalyse<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"isis.simule\"=isis.simule," +
- "\"call_method\"=\"" + aovCall + "\"," +
- "\"analysis_result\"=list(aovresult,IndSensibilite))");
-
- engine.voidEval("attr(isis.methodAnalyse," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-isis.methodAnalyse";
- engine.voidEval(String.format(renameIsisMethodAnalyse,
- firstStorageName + "." + name));
-
- }
-
- //Rename R objects for saving purpose
- renameObjects(engine, firstStorageName);
-
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(firstStorageName)){
- engine.remove(object);
- }
- }
-
- //Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
- } catch (Exception e) {
- throw new SensitivityException("Can't evaluate results", e);
- }
-
- }
-
- @Override
- public String getDescription() {
- return "Implementation of D optimal method method using R, needs" +
- "AlgDesign package to work";
- }
-}
Deleted: branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRExpandGrid.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRExpandGrid.java 2012-11-06 10:23:44 UTC (rev 306)
+++ branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRExpandGrid.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -1,375 +0,0 @@
-/*
- * #%L
- * IsisFish data
- * %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package sensitivityanalysis;
-
-import fr.ifremer.isisfish.datastore.SimulationStorage;
-import fr.ifremer.isisfish.export.SensitivityExport;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.*;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
-import fr.ifremer.isisfish.util.Doc;
-import org.apache.commons.lang.StringUtils;
-import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RException;
-import org.nuiton.j2r.RProxy;
-import org.nuiton.j2r.types.RDataFrame;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * User: couteau
- * Date: 6 janv. 2010
- * Time: 14:31:09
- */
-public class SensitivityCalculatorRExpandGrid
- extends AbstractSensitivityAnalysis {
-
- @Doc("Interaction order")
- public int param_order = 2;
-
- @Doc("True to be able to modify the code sent to R")
- public boolean param_modifR = false;
-
- /**
- * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
- * continue.
- *
- * @return <tt>true</tt> s'il sait la gerer
- */
- @Override
- public boolean canManageCardinality() {
- return false;
- }
-
- @Override
- public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
- throws SensitivityException {
-
- SensitivityScenarios thisExperiment = new SensitivityScenarios();
-
- setIsisFactorsR(plan, outputDirectory);
-
- //extract the factors from the design plan
- List<Factor> factors = plan.getFactors();
- int factorsNb = factors.size();
-
- try {
- REngine engine = new RProxy();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- //Create a list of the factors under the form factor1=factor1,...
- String factorsNames = "";
-
- //Create a list of the factors under the form factor1,factor2,...
- String factorNames = "";
-
- //create the factors vectors
- for (Factor factor : factors) {
- //The factor values vector
- String factorName = factor.getName().replaceAll(" ", "");
- factorsNames += factorName + "=" + factorName + ",";
- factorNames += factorName + ",";
- String vector = factorName + "<-c(";
-
- Domain domain = factor.getDomain();
-
- if (domain instanceof ContinuousDomain) {
- ContinuousDomain contDomain = (ContinuousDomain) domain;
- int card = factor.getCardinality();
- Double min = contDomain.getCalculatorMinBound();
- Double max = contDomain.getCalculatorMaxBound();
-
- for (int i = 0; i < card; i++) {
- //add the ith value
- vector += (min + (i * (max - min) / (card - 1))) + ",";
- }
- }
-
- if (domain instanceof DiscreteDomain) {
- Map<Object, Object> values = ((DiscreteDomain) domain).getValues();
- int nbValues = values.size();
- for (int i = 0; i < nbValues; i++) {
- vector += "as.integer(" + i + "),";
- }
- }
-
- vector = vector.substring(0, vector.length() - 1);
-
- vector += ")";
-
- engine.voidEval(vector);
-
-
- }
-
- factorsNames = factorsNames.substring(0,factorsNames.length()-1);
- factorNames = factorNames.substring(0,factorNames.length()-1);
-
-
- //X<-expand.grid(vector=???,weight=???)
- String expandGrid = "x<-expand.grid(%s)";
-
- String rCall = String.format(expandGrid,factorsNames);
-
- if (param_modifR) {
- rCall = editRInstruction(rCall);
- }
-
- engine.voidEval(rCall);
-
- engine.eval("expPlan<-as.data.frame(x)");
- RDataFrame dataFrame = (RDataFrame)engine.eval("expPlan");
- dataFrame.setVariable("expPlan");
- int nbExperiments = (Integer)engine.eval("dim(x)[1]");
-
- List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
- for (int j = 0; j < nbExperiments; j++) {
- Scenario experimentScenario = new Scenario();
- for (int i = 0; i < factorsNb; i++) {
- Factor factor = factors.get(i);
- factor.setValueForIdentifier(dataFrame.get(i, j));
- experimentScenario.addFactor(factor);
- }
- thisExperimentScenarios.add(experimentScenario);
- thisExperiment.setScenarios(thisExperimentScenarios);
- }
-
-
- String factorDistribution = "isis.factor.distribution<-data.frame(" +
- "NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
-
- String distribution = "";
- String parameters = "";
-
- for (int i = 0; i < factorsNb; i++) {
- Domain domain = factors.get(i).getDomain();
- if (i != 0) {
- distribution += ",";
- parameters += ",";
- }
- if (domain instanceof ContinuousDomain){
- ContinuousDomain contDomain = (ContinuousDomain)domain;
- distribution += "\"qunif\"";
- parameters += "\"[" + contDomain.getMinBound()
- + ";" + contDomain.getMaxBound()
- + "]\"";
- } else {
- DiscreteDomain discDomain = (DiscreteDomain)domain;
- distribution += "\"discrete\"";
- parameters+="\"[";
- Map<Object, Object> values = discDomain.getValues();
- int count=0;
- Collection<Object> collecValues = values.values();
- for (Object value:collecValues){
- if (count!=0){
- parameters += ",";
- }
- parameters += StringUtils.replace(value.toString(), "\"", "\\\"") ;
- count++;
- }
- parameters+="]\"";
- }
- }
- engine.voidEval(String.format(factorDistribution, factorNames,
- distribution, parameters));
-
- engine.voidEval("call<-\"" +
- String.format(expandGrid,factorsNames) + "\"");
- engine.voidEval("isis.MethodExp<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"call\"=call)");
- engine.voidEval("attr(isis.MethodExp," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
- engine.voidEval("isis.simule<-x");
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
- engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
-
- } catch (RException eee) {
- throw new SensitivityException("Can't generate scenarios", eee);
- }
-
- return thisExperiment;
- }
-
- @Override
- public void analyzeResult(List<SimulationStorage> simulationStorages,
- File outputDirectory) throws SensitivityException {
-
- try {
-
- REngine engine = new RProxy();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- //Get back the factors number
- int factorNumber = (Integer)engine.eval("dim(x)[2]");
-
- SimulationParameter param = simulationStorages.get(0).getParameter();
- int sensitivityNumber = param.getSensitivityExport().size();
-
- SimulationStorage firstStorage = simulationStorages.get(0);
-
- String firstStorageName = firstStorage.getName().replaceAll("-", "");
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- SensitivityExport sensitivityExport =
- param.getSensitivityExport().get(k);
-
- String name = sensitivityExport.getExportFilename();
-
- String rInstruction = createImportInstruction(sensitivityExport,
- simulationStorages);
-
- // Send the simulation results
- engine.voidEval(rInstruction);
-
- //Put results in isis.simule
- engine.voidEval("isis.simule<-data.frame(isis.simule,"
- + name + ")");
-
- //Create the dataforaov data.frame
- String dataFrame = "dataforaov<-data.frame(x,"
- + name + "=" + name + ")";
- engine.voidEval(dataFrame);
-
- //Call aov()
- String aovCall = "aovresult<-aov(" + name + "~(";
- for (int j = 0; j < factorNumber; j++) {
- if (j < (factorNumber - 1)) {
- aovCall = aovCall
- + engine.eval("names(x)[" + (j + 1) + "]")
- + "+";
- } else {
- aovCall = aovCall
- + engine.eval("names(x)[" + (j + 1) + "]")
- + ")";
- if(param_order>1){
- aovCall+="^" + param_order + ",data=dataforaov)";
- }else{
- aovCall+=",data=dataforaov)";
- }
- }
- }
- engine.voidEval(aovCall);
-
- /*Export the results
- *Export format is csv, data separated by ','
- *Results Export name is sensitivityExportName_Results.csv
- *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
- */
-
- //Compute Sum of Squares and Sensitivity indices
- engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
- engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
- engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
-
- //Create a data.frame to export sensitivity important results in one file.
- engine.voidEval("exportsensitivity<-data.frame(" +
- "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
- "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
- engine.voidEval("names(exportsensitivity)<-c(" +
- "\"Sum Of Squares\"," +
- "\"Sensitivity indices\")");
- engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
-
- /*Set the export directory
- *Export directory is the first simulation export directory.
- */
- engine.setwd(outputDirectory);
-
- //Save the results with the scenarios.
- engine.voidEval("write.csv(dataforaov,\""
- + param.getSensitivityExport().get(k)
-
- .getExportFilename() + "_Results.csv\")");
-
- //Save the sensitivity indices
- engine.voidEval("write.csv(exportsensitivity,\""
- + param.getSensitivityExport().get(k)
- .getExportFilename()
- + "_SensitivityIndices.csv\")");
- //FIXME export through java to enable export when using Rserve (when distant Rserve).
-
- //creating isis.methodAnalyse
- engine.voidEval("isis.methodAnalyse<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"isis.simule\"=isis.simule," +
- "\"call_method\"=\"" + aovCall + "\"," +
- "\"analysis_result\"=list(aovresult,IndSensibilite))");
-
- engine.voidEval("attr(isis.methodAnalyse," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-isis.methodAnalyse";
- engine.voidEval(String.format(renameIsisMethodAnalyse,
- firstStorageName + "." + name));
-
- }
-
- //Rename R objects for saving purpose
- renameObjects(engine, firstStorageName);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(firstStorageName)){
- engine.remove(object);
- }
- }
-
- //Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
- } catch (Exception e) {
- throw new SensitivityException("Can't evaluate results", e);
- }
-
- }
-
- @Override
- public String getDescription() {
- return "Implementation of Expand Grid method using R";
- }
-}
Deleted: branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRFast.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRFast.java 2012-11-06 10:23:44 UTC (rev 306)
+++ branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRFast.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -1,358 +0,0 @@
-/*
- * #%L
- * IsisFish data
- * %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package sensitivityanalysis;
-
-import java.io.File;
-import java.util.List;
-
-import fr.ifremer.isisfish.simulator.sensitivity.*;
-import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RException;
-import org.nuiton.j2r.RProxy;
-
-import fr.ifremer.isisfish.datastore.SimulationStorage;
-import fr.ifremer.isisfish.export.SensitivityExport;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain;
-import fr.ifremer.isisfish.util.Doc;
-import org.nuiton.j2r.types.RDataFrame;
-
-/**
- * Implementation of Fast method using R.
- *
- * @author jcouteau
- * @version $Revision: 89 $
- *
- * Last update : $Date: 2009-03-25 13:45:16 +0100 (mer., 25 mars 2009) $ By :
- * $Author: jcouteau $
- */
-public class SensitivityCalculatorRFast extends AbstractSensitivityAnalysis {
-
- @Doc("an integer giving the sample size, i.e. the length of the " +
- "discretization of the s-space (see Cukier et al.). (default=20)")
- public int param_n = 20;
-
- @Doc("an integer specifying the interference parameter, i.e. the number " +
- "of harmonics to sum in the Fourier series decomposition (see Cukier et " +
- "al.). (default=6)")
- public int param_M = 6;
-
- @Doc("True to be able to modify the code sent to R")
- public boolean param_modifR = false;
-
- /**
- * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
- * continue.
- *
- * @return <tt>true</tt> s'il sait la gerer
- */
- @Override
- public boolean canManageCardinality() {
- return true;
- }
-
- @Override
- public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
- throws SensitivityException {
-
- setIsisFactorsR(plan, outputDirectory);
-
- RDataFrame dataFrame;
- int nbExperiments;
- int factorNumber = plan.getFactors().size();
- List<Factor> factors = plan.getFactors();
- SensitivityScenarios thisExperiment = new SensitivityScenarios();
- List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
-
- //Test all factors, if one is discrete, return null
- for (int i = 0; i < factorNumber; i++) {
- if (factors.get(i).getDomain() instanceof DiscreteDomain) {
- throw new SensitivityException(factors.get(i).getName() +
- " has a discrete domain, this is not acceptable for fast " +
- "method.");
- }
- }
- String rInstruction = "a<-fast99(" +
- "model=NULL," +
- "factors=%s, " +
- "n=%s, " +
- "M=%s, " +
- "q = \"qunif\", " +
- "q.arg=list(min=0,max=1))";
- String rCall = String.format(rInstruction, factors.size(), param_n,
- param_M);
-
- if (param_modifR) {
- rCall = editRInstruction(rCall);
- }
-
- try {
-
- REngine engine = new RProxy();
-
- engine.clearSession();
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- // Load sensitivity package into R (if package already loaded,
- // nothing happens.
- engine.voidEval("library(sensitivity)");
-
- // Run sensitivity analysis
- engine.voidEval(rCall);
-
- // Creating the factors vector.
- rInstruction = "factornames<-c(";
- for (int i = 0; i < factorNumber; i++) {
- String factorName = factors.get(i).getName();
- if (i != (factorNumber - 1)) {
- rInstruction += "\"" + factorName + "\",";
- } else {
- rInstruction += "\"" + factorName + "\"";
- }
- }
-
- rInstruction += ")";
-
- engine.voidEval(rInstruction);
-
- // Get back experiment plan
- dataFrame = (RDataFrame) engine.eval("a$X");
- dataFrame.setVariable("a$X");
-
- nbExperiments = (Integer)engine.eval("dim(a$X)[1]");
-
- String factorDistribution = "isis.factor.distribution<-data.frame(" +
- "NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
-
- // Creating the vectors.
- String distribution = "";
- String parameters = "";
- String factorNames = "";
-
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = factors.get(i);
- ContinuousDomain domain = (ContinuousDomain) factor.getDomain();
- if (i != 0) {
- distribution += ",";
- parameters += ",";
- factorNames += ",";
- }
-
- distribution += "\"qunif\"";
- parameters += "\"[" + domain.getMinBound() + ";" +
- domain.getMaxBound() + "]\"";
- factorNames += "\"" + factor.getName() + "\"";
- }
- engine.voidEval(String.format(factorDistribution, factorNames,
- distribution, parameters));
-
- engine.voidEval("call<-a$call");
-
-
- engine.voidEval("isis.MethodExp<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"call\"=call)");
-
- engine.voidEval("attr(isis.MethodExp,\"nomModel\")<-" +
- "\"isis-fish-externe-R\"");
-
- engine.voidEval("isis.simule<-data.frame(a$X)");
-
- engine.voidEval("attr(isis.simule,\"nomModel\")<-" +
- "\"isis-fish-externe-R\"");
-
- engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- // Setting up the scenarios.
- for (int j = 0; j < nbExperiments; j++) {
- Scenario experimentScenario = new Scenario();
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = plan.getFactors().get(i);
- Domain domain = factor.getDomain();
- if ((domain instanceof MatrixContinuousDomain)
- || (domain instanceof EquationContinuousDomain)) {
- factor.setValueForIdentifier(dataFrame.get(i,j));
- } else {
- ContinuousDomain continuousDomain = (ContinuousDomain)domain;
- Double min = continuousDomain.getCalculatorMinBound();
- Double max = continuousDomain.getCalculatorMaxBound();
- Double dFValue = (Double)dataFrame.get(i,j);
- Double value = min + (max - min) * dFValue;
- factor.setValueForIdentifier(value);
- }
- experimentScenario.addFactor(factor);
- }
- thisExperimentScenarios.add(experimentScenario);
- thisExperiment.setScenarios(thisExperimentScenarios);
- }
- } catch (RException eee) {
- throw new SensitivityException("Can't generate scenarios", eee);
- }
- return thisExperiment;
-
- }
-
- @Override
- public void analyzeResult(List<SimulationStorage> simulationStorages,
- File outputDirectory) throws SensitivityException {
-
- SimulationStorage storage = simulationStorages.get(0);
- String simulationName = storage.getName().replaceAll("-", "");
-
- try {
-
- REngine engine = new RProxy();
-
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.setwd(outputDirectory);
-
- // Call R
- // Load sensitivity package into R (if package already loaded,
- // nothing happens.
- engine.voidEval("library(sensitivity)");
-
- SimulationParameter param = simulationStorages.get(0).getParameter();
-
- int sensitivityNumber = param.getSensitivityExport().size();
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- SensitivityExport sensitivityExport =
- param.getSensitivityExport().get(k);
-
- String rInstruction = createImportInstruction(sensitivityExport,
- simulationStorages);
-
- // Send the simulation results
- engine.voidEval(rInstruction);
-
- //Put results in isis.simule
- engine.voidEval("isis.simule<-data.frame(isis.simule," +
- sensitivityExport.getExportFilename() + ")");
- }
-
- //adding attribute to isis.Simule
- engine.voidEval("attr(isis.simule,\"nomModel\")<-" +
- "\"isis-fish-externe-R\"");
- engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- // Creates the R expression to import results in R
- String name = param.getSensitivityExport().get(k)
- .getExportFilename();
-
- //Compute results
- engine.voidEval("tell(a,y=" + name + ")");
-
- engine.voidEval("names(a$V)<-factornames");
- engine.voidEval("names(a$X)<-factornames");
- engine.voidEval("names(a$D1)<-factornames");
- engine.voidEval("names(a$Dt)<-factornames");
-
- //creating isis.methodAnalyse
- engine.voidEval("isis.methodAnalyse<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"isis.simule\"=isis.simule," +
- "call_method=\"tell(a,y=" + name + ")" + "\"," +
- "\"analysis_result\"=a)");
-
- //setting isis.methodAnalyse attributes
- engine.voidEval("attr(isis.methodAnalyse,\"nomModel\")<-" +
- "\"isis-fish-externe-R\")");
-
- //Create the data.frame of scenarios and results for export purpose
- engine.voidEval("dfresults<-data.frame(a$X,a$y)");
-
- //Set working directory
- engine.setwd(outputDirectory);
-
- //Export V
- engine.voidEval("write.csv(a$V,\"" + name + "_V.csv\")");
-
- //Export D1
- engine.voidEval("write.csv(a$D1,\"" + name + "_D1.csv\")");
-
- //Export Dt
- engine.voidEval("write.csv(a$Dt,\"" + name + "_Dt.csv\")");
- //Set dfresults names
- engine.voidEval("resultsnames<-c(factornames,\"Result\")");
- engine.voidEval("names(dfresults)<-resultsnames");
-
- //Export results
- engine.voidEval("write.csv(dfresults,\"" + name +
- "_Results.csv\")");
- //FIXME export through java to enable export when using Rserve
-
- String renameIsisMethodAnalyse = "%s.isis.methodAnalyse" +
- "<-isis.methodAnalyse";
-
- engine.voidEval(String.format(renameIsisMethodAnalyse,
- simulationName + "." + name));
-
- }
-
- //Rename R objects for saving purpose
- renameObjects(engine, simulationName);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- } catch (Exception e) {
- throw new SensitivityException("Can't evaluate results", e);
- }
- }
-
- @Override
- public String getDescription() {
- return "Implementation of FAST method using R (needs the sensitivity " +
- "package to work)";
- }
-
-}
Deleted: branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRFrF2.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRFrF2.java 2012-11-06 10:23:44 UTC (rev 306)
+++ branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRFrF2.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -1,389 +0,0 @@
-/*
- * #%L
- * IsisFish data
- * %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package sensitivityanalysis;
-
-import java.io.File;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RException;
-import org.nuiton.j2r.RProxy;
-import org.nuiton.math.matrix.MatrixFactory;
-import org.nuiton.math.matrix.MatrixND;
-import org.nuiton.util.FileUtil;
-
-import fr.ifremer.isisfish.datastore.SimulationStorage;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
-import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
-import fr.ifremer.isisfish.simulator.sensitivity.Factor;
-import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
-import fr.ifremer.isisfish.util.Doc;
-
-/**
- * Implementation of FrF2 method using R.
- *
- * @author jcouteau
- * @version $Revision: 94 $
- *
- * Last update : $Date: 2009-04-03 13:13:35 +0200 (ven., 03 avr. 2009) $ By :
- * $Author: chatellier $
- */
-public class SensitivityCalculatorRFrF2 extends AbstractSensitivityAnalysis {
-
- //TODO jcouteau 20110607 need to use new ethods on REngine instead of coding R sentences by hand.
-
- /** to use log facility, just put in your code: log.info("..."); */
- private static Log log = LogFactory
- .getLog(SensitivityCalculatorRFrF2.class);
-
- @Doc("is the arabic numeral for the requested resolution of the design( 3 <= resolution <= 5). (if resolution=3, model = sum(Xi), if resolution = 4 or 5, model = sum(Xi)+sum(XiXj)")
- public int param_resolution;
-
- /**
- * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
- * continue.
- *
- * @return <tt>true</tt> s'il sait la gerer
- */
- @Override
- public boolean canManageCardinality() {
- return true;
- }
-
- @Override
- public SensitivityScenarios compute(DesignPlan plan, File outputdirectory)
- throws SensitivityException {
-
- double[] dataframe;
- int nbExperiments;
- int factorNumber = plan.getFactors().size();
- List<Factor> factors = plan.getFactors();
- SensitivityScenarios thisExperiment = new SensitivityScenarios();
- List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
-
- testNoDiscrete(factors);
-
- try {
- REngine engine = new RProxy();
-
- //Clear session
- engine.voidEval("rm(list=ls())");
-
- engine.voidEval("library(FrF2)");
-
- //Set the working directory (for import and exports)
- engine.voidEval("setwd(\""
- + outputdirectory.getAbsolutePath().replaceAll("\\\\", "/")
- + "\")");
-
- String rInstruction = "a<-FrF2(nfactors=" + factorNumber
- + ",resolution=" + param_resolution + ")";
-
- engine.voidEval(rInstruction);
-
- // Export the FrF2 object for the second run in a .FrF2 file
- engine.voidEval("dput(a,file=\".FrF2\")");
-
- // Get back experiment plan
- dataframe = (double[]) engine.eval("a$desnum");
-
- // Creating the factors vector.
- rInstruction = "factornames<-c(";
- for (int i = 0; i < factorNumber; i++) {
- if (i != (factorNumber - 1)) {
- rInstruction = rInstruction + "\""
- + factors.get(i).getName() + "\",";
- } else {
- rInstruction = rInstruction + "\""
- + factors.get(i).getName() + "\"";
- }
- }
-
- rInstruction += ")";
-
- engine.voidEval(rInstruction);
-
- // Export the factornames object for the second run in a .factornames file
- engine.voidEval("dput(factornames,file=\".factornames\")");
-
-
- nbExperiments = dataframe.length / factorNumber;
-
- // Transform the result from R in a matrix
- MatrixND frf2 = MatrixFactory.getInstance().create(dataframe,
- new int[] { factorNumber, nbExperiments });
-
- // Setting up the scenarios.
- for (int j = 0; j < nbExperiments; j++) {
- Scenario experimentScenario = new Scenario();
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = plan.getFactors().get(i);
-
- if (frf2.getValue(new int[]{i, j}) == -1) {
- factor.setValueForIdentifier(0);
- } else if (frf2.getValue(new int[]{i, j}) == 1) {
- factor.setValueForIdentifier(1);
- }
-
- experimentScenario.addFactor(factor);
- }
- thisExperimentScenarios.add(experimentScenario);
- thisExperiment.setScenarios(thisExperimentScenarios);
- }
-
- //Create the factors vectors
- for (int j = 0; j < factorNumber; j++) {
- Factor factor = thisExperimentScenarios.get(0).getFactors()
- .get(j);
-
- String vector = "factor" + j + "<-c(";
- for (int i = 0; i < nbExperiments; i++) {
- if (i < (nbExperiments - 1)) {
- vector = vector + factor.getDisplayedValue() + ",";
- } else {
- vector = vector + factor.getDisplayedValue();
- }
-
- }
- vector = vector + ")";
- engine.voidEval(vector);
- }
-
- //Create the data data.frame from the factors
- String data = "data<-data.frame(";
- for (int j = 0; j < factorNumber; j++) {
- if (j < factorNumber - 1) {
- data = data + "factor" + j + "=factor(factor" + j + "),";
- } else {
- data = data + "factor" + j + "=factor(factor" + j + "))";
- }
-
- }
- engine.voidEval(data);
-
- // Set output directory
- engine.voidEval("setwd(\""
- + outputdirectory.getAbsolutePath().replaceAll("\\\\", "/")
- + "\")");
-
- // Export the scenario matrix for the second run in a .FrF2.csv file
- engine.voidEval("write.csv(data,file=\".FrF2.csv\")");
-
- engine.terminate();
-
- } catch (RException e) {
- throw new SensitivityException("Can't generate scenarios", e);
- }
- return thisExperiment;
-
- }
-
- @Override
- public void analyzeResult(List<SimulationStorage> simulationStorages,
- File outputdirectory) throws SensitivityException {
-
- try {
-
- REngine engine = new RProxy();
-
- //Clear session
- engine.voidEval("rm(list=ls())");
-
- SimulationParameter param = simulationStorages.get(0)
- .getParameter();
- int sensitivityNumber = param.getSensitivityExport().size();
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- engine.voidEval("library(FrF2)");
-
- // Set output directory
- engine.voidEval("setwd(\""
- + outputdirectory.getAbsolutePath().replaceAll("\\\\",
- "/") + "\")");
-
- //Get back the FrF2 object
- engine.voidEval("a<-dget(\".FrF2\")");
-
- //Get back the scenarios
- engine.voidEval("factors<-read.csv(\".FrF2.csv\")");
-
- // Get the factornames object in the .factornames file
- engine.voidEval("factornames<-dget(\".factornames\")");
-
- //Get back the factors number
- int factorNumber = ((Double) engine.eval("length(factors)-1"))
- .intValue();
-
- // Creates the R expression to import results in R
- String name = param.getSensitivityExport().get(k)
- .getExportFilename();
- String rInstruction = name + "<-c(";
- for (int l = 0; l < simulationStorages.size(); l++) {
- File importFile = new File(simulationStorages.get(l)
- .getDirectory().toString()
- + File.separator
- + SimulationStorage.RESULT_EXPORT_DIRECTORY, param
- .getSensitivityExport().get(k).getExportFilename()
- + param.getSensitivityExport().get(k)
- .getExtensionFilename());
- String simulResult = FileUtil.readAsString(importFile);
- double simulationResult = Double.valueOf(simulResult);
- if (l < simulationStorages.size() - 1) {
- rInstruction = rInstruction + simulationResult + ",";
- } else {
- rInstruction = rInstruction + simulationResult;
- }
- }
- rInstruction = rInstruction + ")";
-
- // Send the simulation results
- engine.voidEval(rInstruction);
-
- //Create the dataforaov data.frame
- String dataframe = "dataforaov<-data.frame(factors,result=result)";
- engine.voidEval(dataframe);
-
- //get back the resolution
- int resolution = (Integer) engine.eval("res.catlg(a$catentry)");
-
- String aovCall;
-
- switch (resolution) {
- case 3:
- //Call aov()
- aovCall = "aovresult<-aov(result~";
- for (int j = 0; j < factorNumber; j++) {
- if (j < (factorNumber - 1)) {
- aovCall = aovCall + "factor" + j + "+";
- } else {
- aovCall = aovCall + "factor" + j
- + ",data=dataforaov)";
- }
- }
- engine.voidEval(aovCall);
- break;
- case 4:
- aovCall = "aovresult<-aov(result~";
- for (int j = 0; j < factorNumber; j++) {
- aovCall = aovCall + "factor" + j + "+";
- }
- for (int i = 0; i < factorNumber; i++) {
- for (int j = 0; j < factorNumber; j++) {
- if (i < j) {
- aovCall = aovCall + "factor" + i + "*factor"
- + j + "+";
- }
- }
- }
- aovCall = aovCall.substring(0, aovCall.length() - 1);
- aovCall = aovCall + ",data=dataforaov)";
- engine.voidEval(aovCall);
- break;
- case 5:
- aovCall = "aovresult<-aov(result~";
- for (int j = 0; j < factorNumber; j++) {
- aovCall = aovCall + "factor" + j + "+";
- }
- for (int i = 0; i < factorNumber; i++) {
- for (int j = 0; j < factorNumber; j++) {
- if (i < j) {
- aovCall = aovCall + "factor" + i + "*factor"
- + j + "+";
- }
- }
- }
- aovCall = aovCall.substring(0, aovCall.length() - 1);
- aovCall = aovCall + ",data=dataforaov)";
- engine.voidEval(aovCall);
- break;
- default:
- log.info("This resolution is not managed");
- break;
- }
-
- /*Export the results
- *Export format is csv, data separated by ','
- *Results Export name is sensitivityExportName_Results.csv
- *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
- */
-
- //Compute Sum of Squares and Sensitivity indices
- engine.voidEval("SoS<-summary(aovresult)[[1]][1:"
- + factorNumber + ",2]");
- engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:"
- + factorNumber + "]");
- engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
-
- //Create a data.frame to export sensitivity important results in one file.
- engine.voidEval("exportsensitivity=data.frame(SoS[1:"
- + factorNumber + "],IndSensibilite[1:" + factorNumber
- + "])");
- engine.voidEval("names(exportsensitivity)<-c(" +
- "\"Sum Of Squares\",\"Sensitivity indices\")");
-
- engine.voidEval("row.names(exportsensitivity)<-factornames");
-
- /*Set the export directory
- *Export directory is the first simulation export directory.
- */
- engine.voidEval("setwd(\""
- + outputdirectory.getAbsolutePath().replaceAll("\\\\",
- "/") + "\")");
-
- //Set dataforaov names
- engine.voidEval("resultsnames<-c(\"Simulation\"," +
- "factornames,\"Result\")");
- engine.voidEval("names(dataforaov)<-resultsnames");
-
- //Save the results with the scenarios.
- engine.voidEval("write.csv(dataforaov,\""
- + param.getSensitivityExport().get(k)
- .getExportFilename() + "_Results.csv\")");
-
- //Save the sensitivity indices
- engine.voidEval("write.csv(exportsensitivity,\""
- + param.getSensitivityExport().get(k)
- .getExportFilename()
- + "_SensitivityIndices.csv\")");
-
- //FIXME export through java to enable export when using Rserve (when distant Rserve).
- engine.terminate();
- }
-
- } catch (Exception e) {
- throw new SensitivityException("Can't evaluate results", e);
- }
-
- }
-
- @Override
- public String getDescription() {
- return "Implementation of FrF2 method method using R, at least 4 factors need to be declared (nneds the 'sensitivity' package to work)";
- }
-}
Deleted: branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRMorris.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRMorris.java 2012-11-06 10:23:44 UTC (rev 306)
+++ branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRMorris.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -1,358 +0,0 @@
-/*
- * #%L
- * IsisFish data
- * %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package sensitivityanalysis;
-
-import fr.ifremer.isisfish.datastore.SimulationStorage;
-import fr.ifremer.isisfish.export.SensitivityExport;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
-import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
-import fr.ifremer.isisfish.simulator.sensitivity.Factor;
-import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.util.Doc;
-import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RException;
-import org.nuiton.j2r.RProxy;
-import org.nuiton.j2r.types.RDataFrame;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * Implementation of Morris method using R.
- *
- * @author jcouteau
- * @version $Revision$
- *
- * Last update : $Date$ By :
- * $Author$
- */
-public class SensitivityCalculatorRMorris
- extends AbstractSensitivityAnalysis {
-
- @Doc("Integer giving the number of repetitions of the design, i.e. the number of elementary effect computed per factor. (Default value : 4)")
- public int param_r = 4;
-
- @Doc("True to be able to modify the code sent to R")
- public boolean param_modifR = false;
-
- /**
- * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
- * continus.
- *
- * @return <tt>true</tt> s'il sait la gerer
- */
- @Override
- public boolean canManageCardinality() {
- return false;
- }
-
- @Override
- public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
- throws SensitivityException {
-
- setIsisFactorsR(plan, outputDirectory);
-
- RDataFrame dataFrame;
- int nbExperiments;
- int factorNumber = plan.getFactors().size();
-
- SensitivityScenarios thisExperiment = new SensitivityScenarios();
-
- List<Factor> factors = plan.getFactors();
-
- if (param_r == 0) {
- param_r = 4;
- }
-
- testNoDiscrete(factors);
-
- // Creating the vectors.
- String factorNames = "";
- String levels = "";
- String gridJump = "";
- String binf = "";
- String bsup = "";
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = factors.get(i);
- ContinuousDomain domain = (ContinuousDomain) factor.getDomain();
- if (i != 0) {
- factorNames += ",";
- levels += ",";
- gridJump += ",";
- binf += ",";
- bsup += ",";
- }
-
- factorNames += "\"" + factor.getName() + "\"";
-
- levels += factor.getCardinality();
-
- gridJump += factor.getCardinality() / 2;
-
- binf += domain.getCalculatorMinBound();
-
- bsup += domain.getCalculatorMaxBound();
- }
-
- String rInstruction = "a<-morris(model=NULL,factors=c(%s),r=%s," +
- "design=list(type=\"oat\",levels=c(%s),grid.jump=c(%s))," +
- "binf=c(%s),bsup=c(%s))";
-
- String rCall = String.format(rInstruction, factorNames, param_r,
- levels, gridJump, binf, bsup);
-
- if (param_modifR) {
- rCall = editRInstruction(rCall);
- }
-
- REngine engine = null;
-
- try {
- engine = new RProxy();
-
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- // Load sensitivity package into R (if package already loaded,
- // nothing happens.
- engine.voidEval("library(sensitivity)");
-
- // Run sensitivity analysis
- engine.voidEval(rCall);
-
- // Creating the factors vector.
- rInstruction = "factornames<-c(%s)";
- rCall = String.format(rInstruction, factorNames);
-
- engine.voidEval(rCall);
-
- // Set output directory
- engine.setwd(outputDirectory);
-
- // Get back experiment plan
- engine.eval("expPlan<-as.data.frame(a$X)");
- dataFrame = (RDataFrame) engine.eval("expPlan");
- dataFrame.setVariable("expPlan");
-
- nbExperiments = (Integer)engine.eval("dim(expPlan)[1]");
-
- String factorDistribution = "isis.factor.distribution<-data.frame(" +
- "NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
-
- String distribution = "";
- String parameters = "";
-
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = factors.get(i);
- ContinuousDomain domain = (ContinuousDomain) factor.getDomain();
- if (i != 0) {
- distribution += ",";
- parameters += ",";
- }
-
- distribution += "\"qunif\"";
- parameters += "\"[" + domain.getMinBound() + ";" +
- domain.getMaxBound() + "]\"";
- }
- engine.voidEval(String.format(factorDistribution, factorNames,
- distribution, parameters));
-
- engine.voidEval("call<-a$call");
- engine.voidEval("isis.MethodExp<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"call\"=call)");
- engine.voidEval("attr(isis.MethodExp,\"nomModel\")<-" +
- "\"isis-fish-externe-R\"");
- engine.voidEval("isis.simule<-data.frame(expPlan)");
- engine.voidEval("attr(isis.simule,\"nomModel\")<-" +
- "\"isis-fish-externe-R\"");
- engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- // Setting up the scenarios.
- List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
- for (int j = 0; j < nbExperiments; j++) {
- Scenario experimentScenario = new Scenario();
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = factors.get(i);
- factor.setValueForIdentifier(dataFrame.get(i, j));
- experimentScenario.addFactor(factor);
- }
- thisExperimentScenarios.add(experimentScenario);
- thisExperiment.setScenarios(thisExperimentScenarios);
- }
-
- } catch (RException eee) {
- throw new SensitivityException("Can't generate scenarios", eee);
- }
-
- return thisExperiment;
-
- }
-
- @Override
- public void analyzeResult(List<SimulationStorage> simulationStorages,
- File outputDirectory) throws SensitivityException {
-
- SimulationStorage storage = simulationStorages.get(0);
- String simulationName = storage.getName().replaceAll("-", "");
-
- REngine engine = null;
-
- try {
- engine = new RProxy();
-
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- // Call R
- // Load sensitivity package into R (if package already loaded,
- // nothing happens.
- engine.voidEval("library(sensitivity)");
-
- //Set the working directory (for exports)
- engine.setwd(outputDirectory);
-
- SimulationParameter param = simulationStorages.get(0)
- .getParameter();
- int sensitivityNumber = param.getSensitivityExport().size();
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- SensitivityExport sensitivityExport =
- param.getSensitivityExport().get(k);
-
- String rInstruction = createImportInstruction(sensitivityExport,
- simulationStorages);
-
- // Send the simulation results
- engine.voidEval(rInstruction);
-
- //Put results in isis.simule
- engine.voidEval("isis.simule<-data.frame(isis.simule," +
- sensitivityExport.getExportFilename() + ")");
- }
-
- //adding attribute to isis.Simule
- engine.voidEval("attr(isis.simule,\"nomModel\")<-" +
- "\"isis-fish-externe-R\"");
-
- engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- // Creates the R expression to import results in R
- String name = param.getSensitivityExport().get(k)
- .getExportFilename();
-
- //Compute results
- engine.voidEval("tell(a,y=" + name + ")");
-
- //creating isis.methodAnalyse
- engine.voidEval("isis.methodAnalyse<-list(" +
- //"\"isis.factors\"=isis.factors," +
- //"\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"isis.simule\"=isis.simule," +
- "\"call_method\"=\"tell(a,y=" + name + ")" + "\"," +
- "\"analysis_result\"=a)");
-
- //setting isis.methodAnalyse attributes
- engine.voidEval("attr(isis.methodAnalyse,\"nomModel\")<-" +
- "\"isis-fish-externe-R\"");
-
- // Get back the sensitivity results, mu, mu star and sigma.
- engine.voidEval("mu<-apply(a$ee, 2, mean)");
- engine.voidEval("mu.star <- apply(a$ee, 2, function(a) mean(abs(a)))");
- engine.voidEval("sigma <- apply(a$ee, 2, sd)");
-
- //Create the data.frame of sensitivity indices for export purpose
- engine.voidEval("df<-data.frame(mu,mu.star,sigma)");
- engine.voidEval("row.names(df)<-factornames");
-
- //Create the data.frame of scenarios and results for export purpose
- engine.voidEval("dfresults<-data.frame(a$X," + name + ")");
-
- //Set dfresults names
- engine.voidEval("resultsnames<-c(factornames,\"Result\")");
- engine.voidEval("names(dfresults)<-resultsnames");
-
- //Export sensitivity indices
- engine.voidEval("write.csv(df," +
- "\"" + name + "_SensitivityIndices.csv\")");
-
- //Export results
- engine.voidEval("write.csv(dfresults," +
- "\"" + name + "_Results.csv\")");
- //FIXME export through java to enable export when using Rserve
-
- String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-" +
- "isis.methodAnalyse";
-
- engine.voidEval(String.format(renameIsisMethodAnalyse,
- simulationName + "." + name));
-
- }
-
- //Rename R objects for saving purpose
- renameObjects(engine,simulationName);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- } catch (Exception e) {
- throw new SensitivityException("Can't evaluate results", e);
- }
-
- }
-
- @Override
- public String getDescription() {
- return "Implementation of Morris method using R (needs the sensitivity" +
- " package to work)";
- }
-
-}
Deleted: branches/4.2.2/sensitivityanalysis/SensitivityCalculatorROptimumLHS.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/SensitivityCalculatorROptimumLHS.java 2012-11-06 10:23:44 UTC (rev 306)
+++ branches/4.2.2/sensitivityanalysis/SensitivityCalculatorROptimumLHS.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -1,405 +0,0 @@
-/*
- * #%L
- * IsisFish data
- * %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package sensitivityanalysis;
-
-import java.io.File;
-import java.util.List;
-
-import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RProxy;
-
-import fr.ifremer.isisfish.datastore.SimulationStorage;
-import fr.ifremer.isisfish.export.SensitivityExport;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
-import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
-import fr.ifremer.isisfish.simulator.sensitivity.Factor;
-import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.util.Doc;
-import org.nuiton.j2r.types.RDataFrame;
-
-/**
- * Implementation of Optimum Latin Hypercube method using R.
- *
- * @author jcouteau
- * @version $Revision: 1.0 $
- */
-public class SensitivityCalculatorROptimumLHS extends
- AbstractSensitivityAnalysis {
-
- @Doc("Number of simulations (default=10)")
- public int param_simulationNumber = 10;
- @Doc("The maximum number of times the Columnwise Pairwise algorithm is applied to all the columns(default=2).")
- public int param_MaxSweeps = 2;
- @Doc("The optimal stopping criterion (between 0 and 1) (default=0.1).")
- public double param_eps = 0.1;
- @Doc("True to be able to modify the code sent to R")
- public boolean param_modifR = false;
-
- /**
- * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
- * continue.
- *
- * @return <tt>true</tt> s'il sait la gerer
- */
- @Override
- public boolean canManageCardinality() {
- return true;
- }
-
- @Override
- public SensitivityScenarios compute(DesignPlan plan, File outputdirectory)
- throws SensitivityException {
-
- setIsisFactorsR(plan, outputdirectory);
-
- int factorNumber = plan.getFactors().size();
- List<Factor> factors = plan.getFactors();
- RDataFrame dataFrame;
- SensitivityScenarios thisExperiment = new SensitivityScenarios();
- List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
-
- //Test all factors, if one is discrete, return null
- testNoDiscrete(factors);
-
- try {
- REngine engine = new RProxy();
-
- //Clear session
- engine.clearSession();
-
- //Set working directory to get Isis R session
- engine.loadRData(outputdirectory.getParentFile(),
- outputdirectory.getName());
-
- //Load the lhs library
- engine.voidEval("library(lhs)");
-
- String rInstruction = "x<-optimumLHS(n=%s,k=%s,maxSweeps=%s,eps=%s)";
-
- String rCall = String.format(rInstruction, param_simulationNumber,
- factorNumber, param_MaxSweeps, param_eps);
-
- if (param_modifR) {
- rCall = editRInstruction(rCall);
- }
-
- //Create the scenarios
- engine.voidEval(rCall);
-
- // Get back experiment plan
- engine.eval("expPlan<-as.data.frame(x)");
- dataFrame = (RDataFrame)engine.eval("expPlan");
- dataFrame.setVariable("expPlan");
-
- // Setting up the scenarios.
- for (int j = 0; j < param_simulationNumber; j++) {
- Scenario experimentScenario = new Scenario();
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = plan.getFactors().get(i);
- factor.setValueForIdentifier(dataFrame.get(i, j));
- experimentScenario.addFactor(factor);
- }
- thisExperimentScenarios.add(experimentScenario);
- thisExperiment.setScenarios(thisExperimentScenarios);
- }
-
- String isisFactorDistribution = "isis.factor.distribution<-" +
- "data.frame(" +
- "NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
-
- String distribution = "";
- String parameters = "";
- String factorNames = "";
-
- for (int i = 0; i < factors.size(); i++) {
- Factor tempFactor = factors.get(i);
- ContinuousDomain domain = (ContinuousDomain) tempFactor.getDomain();
- if (i != 0) {
- distribution += ",";
- factorNames += ",";
- parameters += ",";
- }
-
- factorNames += "\"" + factors.get(i).getName() + "\"";
- distribution += "\"qunif\"";
- //add [min;max] to parameters
- parameters += "\"[" + domain.getMinBound() + ";" +
- domain.getMaxBound() + "]\"";
- }
-
- engine.voidEval(String.format(isisFactorDistribution, factorNames,
- distribution, parameters));
-
- engine.voidEval("call<-" + "\"x<-optimumLHS("
- + "n=" + param_simulationNumber
- + ",k=" + factorNumber
- + ",maxSweeps=" + param_MaxSweeps
- + ",eps=" + param_eps + ")\"");
-
- engine.voidEval("isis.MethodExp<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"call\"=call)");
-
- engine.voidEval("attr(isis.MethodExp," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- engine.voidEval("isis.simule<-data.frame(x)");
-
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
-
- String data = "data<-data.frame(";
-
- //Create the factors vectors and the dataFrame instruction
- for (int j = 0; j < factors.size(); j++) {
- //The factor values vector
- String vector;
- //Get back the factor
- Scenario scenario = thisExperimentScenarios.get(0);
- Factor factor = scenario.getFactors().get(j);
- String factorName = factor.getName().replaceAll(" ", "");
-
- vector = factorName + "<-c(";
- for (int i = 0; i < param_simulationNumber; i++) {
- //Get back the displayed value the factor
- Scenario tempScenario = thisExperimentScenarios.get(i);
- Factor tempFactor = tempScenario.getFactors().get(j);
- Object value = tempFactor.getDisplayedValue();
-
- if (i < (param_simulationNumber - 1)) {
- vector = vector + value + ",";
- } else {
- vector += value;
- }
-
- }
- vector += ")";
- engine.voidEval(vector);
-
- if (j < factors.size() - 1) {
- data += factorName + "=factor(" + factorName + "),";
- } else {
- data += factorName + "=factor(" + factorName + "))";
- }
- }
- engine.voidEval(data);
-
- // Creating the factors vector.
- rInstruction = "factornames<-c(";
- for (int i = 0; i < factorNumber; i++) {
- if (i != (factorNumber - 1)) {
- rInstruction = rInstruction + "\""
- + factors.get(i).getName() + "\",";
- } else {
- rInstruction = rInstruction + "\""
- + factors.get(i).getName() + "\"";
- }
- }
-
- rInstruction += ")";
-
- engine.voidEval(rInstruction);
-
- // Save Isis R session
- engine.saveRData(outputdirectory.getParentFile(),
- outputdirectory.getName());
-
- engine.terminate();
-
- } catch (Exception e) {
- throw new SensitivityException("Can't generate scenarios", e);
- }
-
- return thisExperiment;
- }
-
- @Override
- public void analyzeResult(List<SimulationStorage> simulationStorages,
- File outputDirectory) throws SensitivityException {
-
- //The first storage to get the name and parameters all along the method
- SimulationStorage storage = simulationStorages.get(0);
-
- String simulationName = storage.getName().replaceAll("-", "");
-
- try {
-
- REngine engine = new RProxy();
-
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.voidEval("factors<-data.frame(x)");
- engine.voidEval("names(factors)<-factornames");
-
- //Get back the factors number
- int factorNumber = (Integer) engine.eval("length(factors[1,])");
- //Get back the simulation number
- param_simulationNumber = (Integer) (engine.eval("length(factors[,1])"));
-
- SimulationParameter param = storage.getParameter();
- int sensitivityNumber = param.getSensitivityExport().size();
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- SensitivityExport sensitivityExport =
- param.getSensitivityExport().get(k);
-
- String rInstruction = createImportInstruction(sensitivityExport,
- simulationStorages);
-
- // Send the simulation results
- engine.voidEval(rInstruction);
-
- //Put results in isis.simule
- engine.voidEval("isis.simule<-data.frame(isis.simule," +
- sensitivityExport.getExportFilename() + ")");
- }
-
- //adding attribute to isis.Simule
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
- engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- // Creates the R expression to import results in R
- SensitivityExport export = param.getSensitivityExport().get(k);
- String name = export.getExportFilename();
-
- //Create the dataforaov data.frame
- String dataframe = "dataforaov<-data.frame(factors," +
- name + "=" + name + ")";
- engine.voidEval(dataframe);
-
- //Call aov()
- String aovCall = "aovresult<-aov(" + name + "~";
- for (int j = 0; j < factorNumber; j++) {
-
- String factorName = (String) engine.eval("names(factors)[" + (j + 1) + "]");
- factorName = factorName.replaceAll(" ", ".");
-
- if (j < (factorNumber - 1)) {
- aovCall += factorName +
- "+";
- } else {
- aovCall += factorName + ",data=dataforaov)";
- }
- }
- engine.voidEval(aovCall);
-
- /*Export the results
- *Export format is csv, data separated by ','
- *Results Export name is sensitivityExportName_Results.csv
- *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
- */
-
- //Compute Sum of Squares and Sensitivity indices
- engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
- engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
- engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
-
- //Create a data.frame to export sensitivity important results in one file.
- engine.voidEval("exportsensitivity<-data.frame(" +
- "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
- "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
- engine.voidEval("names(exportsensitivity)<-c(" +
- "\"Sum Of Squares\"," +
- "\"Sensitivity indices\")");
- engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
-
-
- //Set dataforaov names
- engine.voidEval("names(dataforaov)<-c(factornames,\"Result\")");
-
- /*Set the export directory
- *Export directory is the first simulation export directory.
- */
- engine.setwd(outputDirectory);
-
- //Save the results with the scenarios.
- engine.voidEval("write.csv(dataforaov,\"" +
- name + "_Results.csv\")");
-
- //Save the sensitivity indices
- engine.voidEval("write.csv(exportsensitivity,\"" +
- name + "_SensitivityIndices.csv\")");
- //FIXME export through java to enable export when using Rserve (when distant Rserve).
-
- //creating isis.methodAnalyse
- engine.voidEval("isis.methodAnalyse<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"isis.simule\"=isis.simule," +
- "call_method=\"" + aovCall + "\""+
- ",\"analysis_result\"=list(aovresult,IndSensibilite))");
-
- engine.voidEval("attr(isis.methodAnalyse," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-" +
- "isis.methodAnalyse";
-
- engine.voidEval(String.format(renameIsisMethodAnalyse,
- simulationName + "." + name));
-
- }
-
- //Rename R objects for saving purpose
- renameObjects(engine, simulationName);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- engine.terminate();
-
- } catch (Exception e) {
- throw new SensitivityException("Can't evaluate results", e);
- }
-
- }
-
- @Override
- public String getDescription() {
- return "Implementation of Random Latin Hypercube method method " +
- "using R (needs 'lhs' package to work)";
- }
-
-}
Deleted: branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRRandomLHS.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRRandomLHS.java 2012-11-06 10:23:44 UTC (rev 306)
+++ branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRRandomLHS.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -1,403 +0,0 @@
-/*
- * #%L
- * IsisFish data
- * %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package sensitivityanalysis;
-
-import java.io.File;
-import java.lang.String;
-import java.util.List;
-
-import fr.ifremer.isisfish.export.SensitivityExport;
-import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RProxy;
-import org.nuiton.j2r.types.RDataFrame;
-
-import fr.ifremer.isisfish.datastore.SimulationStorage;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
-import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
-import fr.ifremer.isisfish.simulator.sensitivity.Factor;
-import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.util.Doc;
-
-/**
- * Implementation of Random Latin Hypercube method using R.
- *
- * @author jcouteau
- * @version $Revision: 1.0 $
- */
-public class SensitivityCalculatorRRandomLHS extends
- AbstractSensitivityAnalysis {
-
- @Doc("Simulation number (default=10)")
- public int param_simulationNumber = 10;
- @Doc("True to be able to modify the code sent to R")
- public boolean param_modifR = false;
-
- /**
- * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
- * continue.
- *
- * @return <tt>true</tt> s'il sait la gerer
- */
- @Override
- public boolean canManageCardinality() {
- return true;
- }
-
- @Override
- public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
- throws SensitivityException {
-
- setIsisFactorsR(plan, outputDirectory);
-
- int factorNumber = plan.getFactors().size();
- RDataFrame dataFrame; //The dataframe to get back the scenarios from R
- SensitivityScenarios thisExperiment = new SensitivityScenarios(); //The experiment we will build
- List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios(); //The list of scenarios
- List<Factor> factors = plan.getFactors(); //The factors
-
- testNoDiscrete(factors);
-
- try {
-
- REngine engine = new RProxy(); //The R engine
-
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- //Load the lhs library
- engine.voidEval("library(lhs)");
-
- //Create the scenarios
- String rInstruction = "x<-randomLHS(%s,%s)";
- String rCall = String.format(rInstruction, param_simulationNumber,
- factorNumber);
-
- if (param_modifR) {
- rCall = editRInstruction(rCall);
- }
-
- engine.voidEval(rCall);
-
- // Get back experiment plan
- engine.eval("expPlan<-as.data.frame(x)");
- dataFrame = (RDataFrame)engine.eval("expPlan");
- dataFrame.setVariable("expPlan");
-
- // Setting up the scenarios.
- for (int j = 0; j < param_simulationNumber; j++) {
- Scenario experimentScenario = new Scenario();
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = plan.getFactors().get(i); //The factor we are setting
- factor.setValueForIdentifier(dataFrame.get(i,j));
- experimentScenario.addFactor(factor);
- }
- thisExperimentScenarios.add(experimentScenario);
- thisExperiment.setScenarios(thisExperimentScenarios);
- }
-
- String isisFactorDistribution = "isis.factor.distribution<-" +
- "data.frame(" +
- "NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
-
- String distribution = "";
- String parameters = "";
- String factorNames = "";
-
-
- //Create the strings for the isis.MethodExp instruction
- for (int i = 0; i < factors.size(); i++) {
- ContinuousDomain domain = (ContinuousDomain)factors.get(i).getDomain();
- if (i != 0) {
- distribution += ","; //the distribution
- factorNames += ","; //the factor names
- parameters += ","; //the parameters
- }
-
- factorNames += "\"" + factors.get(i).getName() + "\"";
- distribution += "\"qunif\""; //all distributions are qunif
- double min = domain.getCalculatorMinBound();
- double max = domain.getCalculatorMaxBound();
- parameters += "\"[" + min + ";" + max + "]\"";
- }
- engine.voidEval(String.format(isisFactorDistribution, factorNames,
- distribution, parameters));
-
- engine.voidEval("call<-" + "\"x<-randomLHS("
- + param_simulationNumber + "," + factorNumber + ")\"");
-
- engine.voidEval("isis.MethodExp<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"call\"=call)");
-
- engine.voidEval("attr(isis.MethodExp," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- engine.voidEval("isis.simule<-data.frame(x)");
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
- engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
-
- String data = "data<-data.frame(";
-
- //Create the factors vectors and the dataFrame instruction
- for (int j = 0; j < factors.size(); j++) {
- Scenario firstScenario = thisExperimentScenarios.get(0);
- Factor factor = firstScenario.getFactors().get(j);
- String factorName = factor.getName().replaceAll(" ", "");
-
- //the vector of the factor values
- //read all the values one by one from the already created
- //scenarios.
- String vector = factorName + "<-c(";
- for (int i = 0; i < param_simulationNumber; i++) {
- Scenario scenario = thisExperimentScenarios.get(i);
- List<Factor> factorList = scenario.getFactors();
- Factor factor1 = factorList.get(j);
- if (i < (param_simulationNumber - 1)) {
- vector += factor1.getDisplayedValue() + ",";
- } else {
- vector += factor1.getDisplayedValue();
- }
-
- }
- vector = vector + ")";
- engine.voidEval(vector);
-
- //add factor1=factor(factor1) for each factor...
- if (j < factors.size() - 1) {
- data += factorName + "=factor(" + factorName + "),";
- } else {
- data += factorName + "=factor(" + factorName + "))";
- }
-
- }
- engine.voidEval(data);
-
- // Creating the factors vector.
- rInstruction = "factornames<-c(";
- for (int i = 0; i < factorNumber; i++) {
- if (i != (factorNumber - 1)) {
- rInstruction = rInstruction + "\""
- + factors.get(i).getName() + "\",";
- } else {
- rInstruction = rInstruction + "\""
- + factors.get(i).getName() + "\"";
- }
- }
- rInstruction += ")";
- engine.voidEval(rInstruction);
-
- // Clean RData
- for (Factor factor:factors) {
- engine.remove(factor.getName().replaceAll(" ", ""));
- }
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
- } catch (Exception e) {
- throw new SensitivityException("Can't generate scenarios", e);
- }
-
- return thisExperiment;
- }
-
- @Override
- public void analyzeResult(List<SimulationStorage> simulationStorages,
- File outputDirectory) throws SensitivityException {
-
- SimulationStorage simulationStorage1 = simulationStorages.get(0);
- String simName = simulationStorage1.getName();
- String simulationName = simName.replaceAll("-", "");
- SimulationParameter param = simulationStorage1.getParameter();
- int sensitivityNumber = param.getSensitivityExport().size();
- //List<SensitivityExport> export = param.getSensitivityExport();
-
- try {
- REngine engine = new RProxy();
-
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.voidEval("factors<-data.frame(x)");
-
- //Get back the factors number
- int factorNumber = (Integer) engine.eval("length(factors)");
-
- //Get back the simulation number
- param_simulationNumber = (Integer) (engine.eval("length(factors[,1])"));
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- SensitivityExport sensitivityExport =
- param.getSensitivityExport().get(k);
-
- String rInstruction = createImportInstruction(sensitivityExport,
- simulationStorages);
-
- // Send the simulation results
- engine.voidEval(rInstruction);
-
- //Put results in isis.simule
- engine.voidEval("isis.simule<-data.frame(isis.simule," +
- sensitivityExport.getExportFilename() + ")");
- }
-
- //adding attribute to isis.Simule
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- // Creates the R expression to import results in R
- String name = param.getSensitivityExport().get(k)
- .getExportFilename();
-
- //Create the dataforaov data.frame
- String dataframe = "dataforaov<-data.frame(factors," + name
- + "=" + name + ")";
- engine.voidEval(dataframe);
-
- //Call aov()
- String aovCall = "aovresult<-aov(" + name + "~";
- for (int j = 0; j < factorNumber; j++) {
-
- if (j < (factorNumber - 1)) {
- aovCall += engine.eval("names(factors)[" + (j + 1) + "]")
- + "+";
- } else {
- aovCall += engine.eval("names(factors)[" + (j + 1) + "]")
- + ",data=dataforaov)";
- }
- }
- engine.voidEval(aovCall);
-
- /*Export the results
- *Export format is csv, data separated by ','
- *Results Export name is sensitivityExportName_Results.csv
- *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
- */
-
- //Compute Sum of Squares and Sensitivity indices
- engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
- engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
- engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
-
- //Create a data.frame to export sensitivity important results in one file.
- engine.voidEval("exportsensitivity<-data.frame(" +
- "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
- "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
- engine.voidEval("names(exportsensitivity)<-c(" +
- "\"Sum Of Squares\"," +
- "\"Sensitivity indices\")");
- engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
-
-
- //Set dataforaov names
- engine.voidEval("resultsnames<-c(factornames,\"Result\")");
- engine.voidEval("names(dataforaov)<-resultsnames");
-
- /*Set the export directory
- *Export directory is the first simulation export directory.
- */
- engine.setwd(outputDirectory);
-
- //Save the results with the scenarios.
- engine.voidEval("write.csv(dataforaov,\"" +
- param.getSensitivityExport().get(k).getExportFilename() +
- "_Results.csv\")");
-
- //Save the sensitivity indices
- engine.voidEval("write.csv(exportsensitivity,\"" +
- param.getSensitivityExport().get(k).getExportFilename() +
- "_SensitivityIndices.csv\")");
- //FIXME export through java to enable export when using Rserve (when distant Rserve).
-
- //creating isis.methodAnalyse
- engine.voidEval("isis.methodAnalyse<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"isis.simule\"=isis.simule," +
- "call_method=\"" + aovCall + "\"," +
- "\"analysis_result\"=list(aovresult,IndSensibilite))");
-
- engine.voidEval("attr(isis.methodAnalyse," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-" +
- "isis.methodAnalyse";
- engine.voidEval(String.format(renameIsisMethodAnalyse,
- simulationName + "." + name));
-
- }
-
- //Rename R objects for saving purpose
- renameObjects(engine, simulationName);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
- } catch (Exception e) {
- throw new SensitivityException("Can't evaluate results", e);
- }
-
- }
-
- @Override
- public String getDescription() {
- return "Implementation of Random Latin Hypercube method method using" +
- " R needs the 'lhs' package to work)";
- }
-
-}
Deleted: branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRSobol.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRSobol.java 2012-11-06 10:23:44 UTC (rev 306)
+++ branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRSobol.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -1,343 +0,0 @@
-/*
- * #%L
- * IsisFish data
- * %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package sensitivityanalysis;
-
-import java.io.File;
-import java.util.List;
-
-import fr.ifremer.isisfish.export.SensitivityExport;
-import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RProxy;
-
-import fr.ifremer.isisfish.datastore.SimulationStorage;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
-import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
-import fr.ifremer.isisfish.simulator.sensitivity.Domain;
-import fr.ifremer.isisfish.simulator.sensitivity.Factor;
-import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.util.Doc;
-import org.nuiton.j2r.types.RDataFrame;
-
-/**
- * Implementation of Sobol method using R.
- *
- * @author jcouteau
- * @version $Revision: 89 $
- *
- * Last update : $Date: 2009-03-25 13:45:16 +0100 (mer., 25 mars 2009) $ By :
- * $Author: jcouteau $
- */
-public class SensitivityCalculatorRSobol extends AbstractSensitivityAnalysis {
-
- @Doc("the size of the 2 random samples")
- public int param_n = 20;
-
- @Doc("the number of bootstrap replicates.")
- public int param_nboot = 20;
-
- @Doc("True to be able to modify the code sent to R")
- public boolean param_modifR = false;
-
- /**
- * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
- * continue.
- *
- * @return <tt>true</tt> s'il sait la gerer
- */
- @Override
- public boolean canManageCardinality() {
- return true;
- }
-
- @Override
- public SensitivityScenarios compute(DesignPlan plan, File outputdirectory)
- throws SensitivityException {
-
- setIsisFactorsR(plan, outputdirectory);
-
- RDataFrame dataFrame;
- int nbExperiments;
- int factorNumber = plan.getFactors().size();
- List<Factor> factors = plan.getFactors();
- SensitivityScenarios thisExperiment = new SensitivityScenarios();
- List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
-
- testNoDiscrete(factors);
-
- String rInstruction = "a<-sobol2002(model=NULL,X1=X1,X2=X2,nboot=%s)";
- String rCall = String.format(rInstruction, param_nboot);
-
- if (param_modifR) {
- rCall = editRInstruction(rCall);
- }
-
- try {
- REngine engine = new RProxy();
-
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputdirectory.getParentFile(),
- outputdirectory.getName());
-
- engine.voidEval("library(sensitivity)");
-
- engine.voidEval("X1<-data.frame(matrix(runif(" + factorNumber + "*"
- + param_n + "),nrow=" + param_n + "))");
- engine.voidEval("X2<-data.frame(matrix(runif(" + factorNumber + "*"
- + param_n + "),nrow=" + param_n + "))");
-
- engine.voidEval(rCall);
-
- // Creating the factors vector.
- rInstruction = "factornames<-c(";
- for (int i = 0; i < factorNumber; i++) {
- String factorName = factors.get(i).getName();
- if (i != (factorNumber - 1)) {
- rInstruction += "\"" + factorName + "\",";
- } else {
- rInstruction += "\"" + factorName + "\"";
- }
- }
-
- rInstruction += ")";
-
- engine.voidEval(rInstruction);
-
- // Get back experiment plan
- dataFrame = (RDataFrame) engine.eval("a$X");
- dataFrame.setVariable("a$X");
-
- nbExperiments = dataFrame.dim()[0];
-
- String isisFactorDistribution = "isis.factor.distribution<-" +
- "data.frame(NomFacteur=c(%s)," +
- "NomDistribution=c(%s)," +
- "ParametreDistribution=c(%s))";
-
- // Creating the vectors.
- String distribution = "";
- String parameters = "";
- String factorNames = "";
-
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = factors.get(i);
- Domain domain = factor.getDomain();
- if (i != 0) {
- distribution += ",";
- parameters += ",";
- factorNames += ",";
- }
-
- distribution += "\"qunif\"";
- ContinuousDomain continuousDomain = (ContinuousDomain) domain;
- double min = continuousDomain.getCalculatorMinBound();
- double max = continuousDomain.getCalculatorMaxBound();
- parameters += "\"[" + min + ";" + max + "]\"";
- factorNames += "\"" + factor.getName() + "\"";
- }
-
- engine.voidEval(String.format(isisFactorDistribution, factorNames,
- distribution, parameters));
-
- engine.voidEval("call<-a$call");
-
- engine.voidEval("isis.MethodExp<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"call\"=call)");
-
- engine.voidEval("attr(isis.MethodExp," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- engine.voidEval("isis.simule<-data.frame(a$X)");
-
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
-
- // Save Isis R session
- engine.saveRData(outputdirectory.getParentFile(),
- outputdirectory.getName());
-
- // Setting up the scenarios.
- for (int j = 0; j < nbExperiments; j++) {
- Scenario experimentScenario = new Scenario();
- for (int i = 0; i < factorNumber; i++) {
- Factor factor = plan.getFactors().get(i);
- Double dFValue = (Double) dataFrame.get(i, j);
- factor.setValueForIdentifier(dFValue);
- experimentScenario.addFactor(factor);
- }
- thisExperimentScenarios.add(experimentScenario);
- }
-
- } catch (Exception e) {
- throw new SensitivityException("Can't generate scenarios", e);}
-
-
- thisExperiment.setScenarios(thisExperimentScenarios);
- return thisExperiment;
-
- }
-
- @Override
- public void analyzeResult(List<SimulationStorage> simulationStorages,
- File outputDirectory) throws SensitivityException {
-
- SimulationStorage firstStorage = simulationStorages.get(0);
- SimulationParameter param = firstStorage.getParameter();
- int sensitivityNumber = param.getSensitivityExport().size();
- String simulationName = firstStorage.getName().replaceAll("-", "");
-
- try {
-
- REngine engine = new RProxy();
-
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- // Call R
- // Load sensitivity package into R (if package already loaded,
- // nothing happens.
- engine.voidEval("library(sensitivity)");
-
- //Set X1 names
- engine.voidEval("names(X1)<-factornames");
- //Set X2 names
- engine.voidEval("names(X2)<-factornames");
-
- //Set a$X names
- engine.voidEval("names(a$X)<-factornames");
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- SensitivityExport sensitivityExport =
- param.getSensitivityExport().get(k);
-
- String rInstruction = createImportInstruction(sensitivityExport,
- simulationStorages);
-
- // Send the simulation results
- engine.voidEval(rInstruction);
-
- //Put results in isis.simule
- engine.voidEval("isis.simule<-data.frame(isis.simule," +
- sensitivityExport.getExportFilename() + ")");
- }
-
- //adding attribute to isis.Simule
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- SensitivityExport sensitivityExport = param.getSensitivityExport().get(k);
- String name = sensitivityExport.getExportFilename();
-
- //Compute results
- engine.voidEval("tell(a,y=" + name + ")");
-
- engine.voidEval("row.names(a$S)<-names(a$X)");
- engine.voidEval("row.names(a$T)<-names(a$X)");
- engine.voidEval("row.names(a$V)<-c(\"global\"," +
- "names(a$X),paste(\"-\",names(a$X),sep=\"\"))");
-
- //creating isis.methodAnalyse
- engine.voidEval("isis.methodAnalyse<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"isis.simule\"=isis.simule," +
- "call_method=\"tell(a,y=" + name + ")" + "\"," +
- "\"analysis_result\"=a)");
-
- //setting isis.methodAnalyse attributes
- engine.voidEval("attr(isis.methodAnalyse," +
- "\"nomModel\")<-\"isis-fish-externe-R\")");
-
- //Create the data.frame of scenarios and results for export purpose
- engine.voidEval("dfresults<-data.frame(a$X,a$y)");
-
- //Set working directory
- engine.setwd(outputDirectory);
-
- //Export V
- engine.voidEval("write.csv(a$V,\""
- + name
- + "_SensitivityIndices.csv\")");
- //Export DD
- engine.voidEval("write.csv(a$D,\""
- + name + "_D.csv\")");
-
- //Export S
- engine.voidEval("write.csv(a$S,\""
- + name + "_S.csv\")");
-
- //Export results
- engine.voidEval("write.csv(dfresults,\""
- + name + "_Results.csv\")");
- //FIXME export through java to enable export when using Rserve
-
- String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-" +
- "isis.methodAnalyse";
- engine.voidEval(String.format(renameIsisMethodAnalyse,
- simulationName + "." + name));
-
- }
-
- //Rename R objects for saving purpose
- renameObjects(engine, simulationName);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
- } catch (Exception e) {
- throw new SensitivityException("Can't evaluate results", e);
- }
- }
-
- @Override
- public String getDescription() {
- return "Implementation of Sobol method using R (use of the R " +
- "sobol2002 method, needs the 'sensitivity' package to work)";
- }
-}
Deleted: branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRegularFractions.java
===================================================================
--- branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRegularFractions.java 2012-11-06 10:23:44 UTC (rev 306)
+++ branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRegularFractions.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -1,399 +0,0 @@
-/*
- * #%L
- * IsisFish data
- * %%
- * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
- * #L%
- */
-
-package sensitivityanalysis;
-
-import java.io.File;
-import java.util.List;
-
-import fr.ifremer.isisfish.export.SensitivityExport;
-import org.nuiton.j2r.REngine;
-import org.nuiton.j2r.RException;
-import org.nuiton.j2r.RProxy;
-import org.nuiton.j2r.types.RDataFrame;
-
-import fr.ifremer.isisfish.datastore.SimulationStorage;
-import fr.ifremer.isisfish.simulator.SimulationParameter;
-import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
-import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
-import fr.ifremer.isisfish.simulator.sensitivity.Domain;
-import fr.ifremer.isisfish.simulator.sensitivity.Factor;
-import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
-import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationContinuousDomain;
-import fr.ifremer.isisfish.simulator.sensitivity.domain.MatrixContinuousDomain;
-import fr.ifremer.isisfish.util.Doc;
-
-public class SensitivityCalculatorRegularFractions extends
- AbstractSensitivityAnalysis {
-
- @Doc("the path of the directory where the R function is stored (do not indicate the RegularFractions.R file name)")
- public String param_pathToFunction = "";
-
- @Doc("unique prime number of levels of all input and unit factors")
- public int param_p = 2;
-
- @Doc("number of unit factors (so that there are N=p^r units)")
- public int param_r = 2;
-
- @Doc("resolution of the fraction")
- public int param_resolution = 2;
-
- @Doc("True to be able to modify the code sent to R")
- public boolean param_modifR = false;
-
- /**
- * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
- * continue.
- *
- * @return <tt>true</tt> s'il sait la gerer
- */
- @Override
- public boolean canManageCardinality() {
- return true;
- }
-
- @Override
- public SensitivityScenarios compute(DesignPlan plan, File outputDirectory)
- throws SensitivityException {
-
- setIsisFactorsR(plan, outputDirectory);
-
- RDataFrame dataFrame;
- int factorNumber = plan.getFactors().size();
- List<Factor> factors = plan.getFactors();
- SensitivityScenarios thisExperiment = new SensitivityScenarios();
- List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
-
- String factorNames = "";
-
- //Test all factors, if one is discrete, return null
- //Create a string with all factors names
- for (int i = 0; i < factorNumber; i++) {
- Domain domain = factors.get(i).getDomain();
- if (i != 0) {
- factorNames += ",";
- }
-
- factorNames += "\"" + factors.get(i).getName() + "\"";
-
- if (domain instanceof DiscreteDomain) {
- throw new SensitivityException(factors.get(i).getName() +
- " has a discrete domain, this is not acceptable for " +
- "this method.");
- }
- }
-
- try {
-
- REngine engine = new RProxy();
-
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- //Set the working directory (to import the R function)
- engine.setwd(new File(param_pathToFunction));
-
- //Import the function
- engine.voidEval("source(\"regularfractions.R\")");
-
- //Create the instruction
- String rInstruction = "x<-regular.fraction(%s,%s,%s,%s)";
- String rCall = String.format(rInstruction, factors.size(), param_p,
- param_r, param_resolution);
-
- if (param_modifR) {
- rCall = editRInstruction(rCall);
- }
-
- // Run function
- engine.voidEval(rCall);
-
- // Run function
- engine.voidEval("call<-\"" + rCall + "\"");
-
- // Creating the factors vector.
- rInstruction = "factornames<-c(%s)";
- rCall = String.format(rInstruction, factorNames);
-
- engine.voidEval(rCall);
-
-
- // Get back experiment plan
- engine.eval("expPlan<-as.data.frame(x[[1]])");
- dataFrame = (RDataFrame)engine.eval("expPlan");
- dataFrame.setVariable("expPlan");
-
- //Get back the simulation number
- int simulationNumber = (Integer) engine.eval("length(x[[1]][,1])");
-
- // Setting up the scenarios.
- for (int j = 0; j < simulationNumber; j++) {
- Scenario experimentScenario = new Scenario();
- for (int i = 0; i < factors.size(); i++) {
- Factor factor = plan.getFactors().get(i);
- Domain domain = factor.getDomain();
- Double dFValue = (Double)dataFrame.get(i,j);
- if ((domain instanceof MatrixContinuousDomain)
- || (domain instanceof EquationContinuousDomain)) {
- factor.setValueForIdentifier(dFValue);
- } else {
- ContinuousDomain contDomain = (ContinuousDomain)domain;
- Double max = contDomain.getCalculatorMaxBound();
- Double min = contDomain.getCalculatorMinBound();
- Double value = min + (max - min) * dFValue / (param_p - 1);
- factor.setValueForIdentifier(value);
- }
- experimentScenario.addFactor(factor);
- }
- thisExperimentScenarios.add(experimentScenario);
- thisExperiment.setScenarios(thisExperimentScenarios);
- }
-
- String dataframe = "data<-data.frame(";
-
- //Create the factors vectors and the dataframe instruction
- for (int j = 0; j < factorNumber; j++) {
- Factor factor = factors.get(j);
- String factorName = factor.getName().replaceAll(" ", "");
-
- String vector = factorName + "<-c(";
- for (int i = 0; i < simulationNumber; i++) {
- Scenario scenario = thisExperimentScenarios.get(i);
- List<Factor> newFactors = scenario.getFactors();
- Factor factor1 = newFactors.get(j);
-
- if (i < (simulationNumber - 1)) {
- vector += factor1.getDisplayedValue() + ",";
- } else {
- vector += factor1.getDisplayedValue();
- }
-
- }
- vector = vector + ")";
- engine.voidEval(vector);
-
- if (j < factorNumber - 1) {
- dataframe += factorName + "=factor(" + factorName + "),";
- } else {
- dataframe += factorName + "=factor(" + factorName + "))";
- }
-
- }
- engine.voidEval(dataframe);
-
- engine.voidEval("isis.factor.distribution<-c(0.0)");
-
- engine.voidEval("isis.MethodExp<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"call\"=call)");
-
- engine.voidEval("attr(isis.MethodExp," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- //Create isis.Simule
- engine.voidEval("isis.simule<-data.frame(data)");
-
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
- } catch (RException eee) {
- throw new SensitivityException("Can't generate scenarios", eee);
- }
-
- return thisExperiment;
-
- }
-
- @Override
- public void analyzeResult(List<SimulationStorage> simulationStorages,
- File outputDirectory) throws SensitivityException {
-
- SimulationStorage firstStorage = simulationStorages.get(0);
- SimulationParameter param = firstStorage.getParameter();
- List<SensitivityExport> exports = param.getSensitivityExport();
- int sensitivityNumber = exports.size();
- String simulationName = firstStorage.getName().replaceAll("-", "");
-
- try {
-
- REngine engine = new RProxy();
-
- //Clear session
- engine.clearSession();
-
- //Get Isis R session
- engine.loadRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- //Get back the factors number
- int factorNumber = (Integer) engine.eval("dim(data)[2]");
-
- for (int k = 0; k < sensitivityNumber; k++) {
-
- SensitivityExport sensitivityExport =
- param.getSensitivityExport().get(k);
-
- String rInstruction = createImportInstruction(sensitivityExport,
- simulationStorages);
-
- // Send the simulation results
- engine.voidEval(rInstruction);
-
- //Put results in isis.simule
- engine.voidEval("isis.simule<-data.frame(isis.simule," +
- sensitivityExport.getExportFilename() + ")");
- }
-
- //adding attribute to isis.Simule
- engine.voidEval("attr(isis.simule," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- for (SensitivityExport export : exports) {
-
- String name = export.getExportFilename();
-
- //Create the dataforaov data.frame
- String dataFrame = "dataforaov<-data.frame(data," +
- name + "=" + name + ")";
- engine.voidEval(dataFrame);
-
- //Call aov()
- String aovCall = "aovresult<-aov(" + name + "~(";
- for (int j = 0; j < factorNumber; j++) {
-
- if (j < (factorNumber - 1)) {
- aovCall = aovCall
- + engine.eval("names(data)[" + (j + 1) + "]")
- + "+";
- } else {
- aovCall = aovCall
- + engine.eval("names(data)[" + (j + 1) + "]")
- + ")";
- if (param_resolution <= 4) {
- aovCall += ",data=dataforaov)";
- } else {
- aovCall += "^2,data=dataforaov)";
- }
- }
- }
- engine.voidEval(aovCall);
-
- /*Export the results
- *Export format is csv, data separated by ','
- *Results Export name is sensitivityExportName_Results.csv
- *Sensitivity Indices export name is sensitivityExportName_SensitivityIndices.csv
- */
-
- //Compute Sum of Squares and Sensitivity indices
- engine.voidEval("SoS<-summary(aovresult)[[1]][1:dim(summary(aovresult)[[1]])[1],2]");
- engine.voidEval("names(SoS)<-dimnames(summary(aovresult)[[1]])[[1]][1:dim(summary(aovresult)[[1]])[1]]");
- engine.voidEval("IndSensibilite<-SoS/sum(SoS)");
-
- //Create a data.frame to export sensitivity important results in one file.
- engine.voidEval("exportsensitivity<-data.frame(" +
- "SoS[1:dim(summary(aovresult)[[1]])[1]]," +
- "IndSensibilite[1:dim(summary(aovresult)[[1]])[1]])");
- engine.voidEval("names(exportsensitivity)<-c(" +
- "\"Sum Of Squares\"," +
- "\"Sensitivity indices\")");
- engine.voidEval("row.names(exportsensitivity)<-dimnames(summary(aovresult)[[1]])[1][[1]][1:dim(summary(aovresult)[[1]])[1]]");
-
- //Set dataforaov names
- engine.voidEval("resultsnames<-c(factornames,\"Result\")");
- engine.voidEval("names(dataforaov)<-resultsnames");
-
- /*Set the export directory
- *Export directory is the first simulation export directory.
- */
- engine.setwd(outputDirectory);
-
- //Save the results with the scenarios.
- engine.voidEval("write.csv(dataforaov,\"" + name +
- "_Results.csv\")");
-
- //Save the sensitivity indices
- engine.voidEval("write.csv(exportsensitivity,\"" + name +
- "_SensitivityIndices.csv\")");
- //FIXME export through java to enable export when using Rserve (when distant Rserve).
-
- //creating isis.methodAnalyse
- engine.voidEval("isis.methodAnalyse<-list(" +
- "\"isis.factors\"=isis.factors," +
- "\"isis.factor.distribution\"=isis.factor.distribution," +
- "\"isis.simule\"=isis.simule," +
- "\"call_method\"=\"" + aovCall + "\"," +
- "\"analysis_result\"=list(aovresult,IndSensibilite))");
-
- engine.voidEval("attr(isis.methodAnalyse," +
- "\"nomModel\")<-\"isis-fish-externe-R\"");
-
- String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-isis.methodAnalyse";
- engine.voidEval(String.format(renameIsisMethodAnalyse,
- simulationName + "." + name));
-
- }
-
- //Rename R objects for saving purpose
- renameObjects(engine,simulationName);
-
- //Clean temporary R objects
- for (String object:engine.ls()) {
- if (!object.startsWith(simulationName)){
- engine.remove(object);
- }
- }
-
- // Save Isis R session
- engine.saveRData(outputDirectory.getParentFile(),
- outputDirectory.getName());
-
- engine.terminate();
-
- } catch (Exception eee) {
- throw new SensitivityException("Can't evaluate results", eee);
- }
-
- }
-
- @Override
- public String getDescription() {
- return "Implementation of Regular fractions method using R";
- }
-
-}
Copied: branches/4.2.2/sensitivityanalysis/Sobol.java (from rev 305, branches/4.2.2/sensitivityanalysis/SensitivityCalculatorRSobol.java)
===================================================================
--- branches/4.2.2/sensitivityanalysis/Sobol.java (rev 0)
+++ branches/4.2.2/sensitivityanalysis/Sobol.java 2012-11-07 14:18:20 UTC (rev 307)
@@ -0,0 +1,343 @@
+/*
+ * #%L
+ * IsisFish data
+ * %%
+ * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
+ * #L%
+ */
+
+package sensitivityanalysis;
+
+import java.io.File;
+import java.util.List;
+
+import fr.ifremer.isisfish.export.SensitivityExport;
+import org.nuiton.j2r.REngine;
+import org.nuiton.j2r.RProxy;
+
+import fr.ifremer.isisfish.datastore.SimulationStorage;
+import fr.ifremer.isisfish.simulator.SimulationParameter;
+import fr.ifremer.isisfish.simulator.sensitivity.AbstractSensitivityAnalysis;
+import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan;
+import fr.ifremer.isisfish.simulator.sensitivity.Domain;
+import fr.ifremer.isisfish.simulator.sensitivity.Factor;
+import fr.ifremer.isisfish.simulator.sensitivity.Scenario;
+import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException;
+import fr.ifremer.isisfish.simulator.sensitivity.SensitivityScenarios;
+import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain;
+import fr.ifremer.isisfish.util.Doc;
+import org.nuiton.j2r.types.RDataFrame;
+
+/**
+ * Implementation of Sobol method using R.
+ *
+ * @author jcouteau
+ * @version $Revision: 89 $
+ *
+ * Last update : $Date: 2009-03-25 13:45:16 +0100 (mer., 25 mars 2009) $ By :
+ * $Author: jcouteau $
+ */
+public class Sobol extends AbstractSensitivityAnalysis {
+
+ @Doc("the size of the 2 random samples")
+ public int param_n = 20;
+
+ @Doc("the number of bootstrap replicates.")
+ public int param_nboot = 20;
+
+ @Doc("True to be able to modify the code sent to R")
+ public boolean param_modifR = false;
+
+ /**
+ * Retourne vrai si le calculateur sait gerer la cardinalité des facteurs
+ * continue.
+ *
+ * @return <tt>true</tt> s'il sait la gerer
+ */
+ @Override
+ public boolean canManageCardinality() {
+ return true;
+ }
+
+ @Override
+ public SensitivityScenarios compute(DesignPlan plan, File outputdirectory)
+ throws SensitivityException {
+
+ setIsisFactorsR(plan, outputdirectory);
+
+ RDataFrame dataFrame;
+ int nbExperiments;
+ int factorNumber = plan.getFactors().size();
+ List<Factor> factors = plan.getFactors();
+ SensitivityScenarios thisExperiment = new SensitivityScenarios();
+ List<Scenario> thisExperimentScenarios = thisExperiment.getScenarios();
+
+ testNoDiscrete(factors);
+
+ String rInstruction = "a<-sobol2002(model=NULL,X1=X1,X2=X2,nboot=%s)";
+ String rCall = String.format(rInstruction, param_nboot);
+
+ if (param_modifR) {
+ rCall = editRInstruction(rCall);
+ }
+
+ try {
+ REngine engine = new RProxy();
+
+ //Clear session
+ engine.clearSession();
+
+ //Get Isis R session
+ engine.loadRData(outputdirectory.getParentFile(),
+ outputdirectory.getName());
+
+ engine.voidEval("library(sensitivity)");
+
+ engine.voidEval("X1<-data.frame(matrix(runif(" + factorNumber + "*"
+ + param_n + "),nrow=" + param_n + "))");
+ engine.voidEval("X2<-data.frame(matrix(runif(" + factorNumber + "*"
+ + param_n + "),nrow=" + param_n + "))");
+
+ engine.voidEval(rCall);
+
+ // Creating the factors vector.
+ rInstruction = "factornames<-c(";
+ for (int i = 0; i < factorNumber; i++) {
+ String factorName = factors.get(i).getName();
+ if (i != (factorNumber - 1)) {
+ rInstruction += "\"" + factorName + "\",";
+ } else {
+ rInstruction += "\"" + factorName + "\"";
+ }
+ }
+
+ rInstruction += ")";
+
+ engine.voidEval(rInstruction);
+
+ // Get back experiment plan
+ dataFrame = (RDataFrame) engine.eval("a$X");
+ dataFrame.setVariable("a$X");
+
+ nbExperiments = dataFrame.dim()[0];
+
+ String isisFactorDistribution = "isis.factor.distribution<-" +
+ "data.frame(NomFacteur=c(%s)," +
+ "NomDistribution=c(%s)," +
+ "ParametreDistribution=c(%s))";
+
+ // Creating the vectors.
+ String distribution = "";
+ String parameters = "";
+ String factorNames = "";
+
+ for (int i = 0; i < factorNumber; i++) {
+ Factor factor = factors.get(i);
+ Domain domain = factor.getDomain();
+ if (i != 0) {
+ distribution += ",";
+ parameters += ",";
+ factorNames += ",";
+ }
+
+ distribution += "\"qunif\"";
+ ContinuousDomain continuousDomain = (ContinuousDomain) domain;
+ double min = continuousDomain.getCalculatorMinBound();
+ double max = continuousDomain.getCalculatorMaxBound();
+ parameters += "\"[" + min + ";" + max + "]\"";
+ factorNames += "\"" + factor.getName() + "\"";
+ }
+
+ engine.voidEval(String.format(isisFactorDistribution, factorNames,
+ distribution, parameters));
+
+ engine.voidEval("call<-a$call");
+
+ engine.voidEval("isis.MethodExp<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"call\"=call)");
+
+ engine.voidEval("attr(isis.MethodExp," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ engine.voidEval("isis.simule<-data.frame(a$X)");
+
+ engine.voidEval("attr(isis.simule," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ engine.voidEval("names(isis.simule)<-isis.factors[[1]]");
+
+ // Save Isis R session
+ engine.saveRData(outputdirectory.getParentFile(),
+ outputdirectory.getName());
+
+ // Setting up the scenarios.
+ for (int j = 0; j < nbExperiments; j++) {
+ Scenario experimentScenario = new Scenario();
+ for (int i = 0; i < factorNumber; i++) {
+ Factor factor = plan.getFactors().get(i);
+ Double dFValue = (Double) dataFrame.get(i, j);
+ factor.setValueForIdentifier(dFValue);
+ experimentScenario.addFactor(factor);
+ }
+ thisExperimentScenarios.add(experimentScenario);
+ }
+
+ } catch (Exception e) {
+ throw new SensitivityException("Can't generate scenarios", e);}
+
+
+ thisExperiment.setScenarios(thisExperimentScenarios);
+ return thisExperiment;
+
+ }
+
+ @Override
+ public void analyzeResult(List<SimulationStorage> simulationStorages,
+ File outputDirectory) throws SensitivityException {
+
+ SimulationStorage firstStorage = simulationStorages.get(0);
+ SimulationParameter param = firstStorage.getParameter();
+ int sensitivityNumber = param.getSensitivityExport().size();
+ String simulationName = firstStorage.getName().replaceAll("-", "");
+
+ try {
+
+ REngine engine = new RProxy();
+
+ //Clear session
+ engine.clearSession();
+
+ //Get Isis R session
+ engine.loadRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+
+ // Call R
+ // Load sensitivity package into R (if package already loaded,
+ // nothing happens.
+ engine.voidEval("library(sensitivity)");
+
+ //Set X1 names
+ engine.voidEval("names(X1)<-factornames");
+ //Set X2 names
+ engine.voidEval("names(X2)<-factornames");
+
+ //Set a$X names
+ engine.voidEval("names(a$X)<-factornames");
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ SensitivityExport sensitivityExport =
+ param.getSensitivityExport().get(k);
+
+ String rInstruction = createImportInstruction(sensitivityExport,
+ simulationStorages);
+
+ // Send the simulation results
+ engine.voidEval(rInstruction);
+
+ //Put results in isis.simule
+ engine.voidEval("isis.simule<-data.frame(isis.simule," +
+ sensitivityExport.getExportFilename() + ")");
+ }
+
+ //adding attribute to isis.Simule
+ engine.voidEval("attr(isis.simule," +
+ "\"nomModel\")<-\"isis-fish-externe-R\"");
+
+ engine.voidEval("attr(isis.simule,\"call\")<-isis.MethodExp$call");
+
+ for (int k = 0; k < sensitivityNumber; k++) {
+
+ SensitivityExport sensitivityExport = param.getSensitivityExport().get(k);
+ String name = sensitivityExport.getExportFilename();
+
+ //Compute results
+ engine.voidEval("tell(a,y=" + name + ")");
+
+ engine.voidEval("row.names(a$S)<-names(a$X)");
+ engine.voidEval("row.names(a$T)<-names(a$X)");
+ engine.voidEval("row.names(a$V)<-c(\"global\"," +
+ "names(a$X),paste(\"-\",names(a$X),sep=\"\"))");
+
+ //creating isis.methodAnalyse
+ engine.voidEval("isis.methodAnalyse<-list(" +
+ "\"isis.factors\"=isis.factors," +
+ "\"isis.factor.distribution\"=isis.factor.distribution," +
+ "\"isis.simule\"=isis.simule," +
+ "call_method=\"tell(a,y=" + name + ")" + "\"," +
+ "\"analysis_result\"=a)");
+
+ //setting isis.methodAnalyse attributes
+ engine.voidEval("attr(isis.methodAnalyse," +
+ "\"nomModel\")<-\"isis-fish-externe-R\")");
+
+ //Create the data.frame of scenarios and results for export purpose
+ engine.voidEval("dfresults<-data.frame(a$X,a$y)");
+
+ //Set working directory
+ engine.setwd(outputDirectory);
+
+ //Export V
+ engine.voidEval("write.csv(a$V,\""
+ + name
+ + "_SensitivityIndices.csv\")");
+ //Export DD
+ engine.voidEval("write.csv(a$D,\""
+ + name + "_D.csv\")");
+
+ //Export S
+ engine.voidEval("write.csv(a$S,\""
+ + name + "_S.csv\")");
+
+ //Export results
+ engine.voidEval("write.csv(dfresults,\""
+ + name + "_Results.csv\")");
+ //FIXME export through java to enable export when using Rserve
+
+ String renameIsisMethodAnalyse = "%s.isis.methodAnalyse<-" +
+ "isis.methodAnalyse";
+ engine.voidEval(String.format(renameIsisMethodAnalyse,
+ simulationName + "." + name));
+
+ }
+
+ //Rename R objects for saving purpose
+ renameObjects(engine, simulationName);
+
+ //Clean temporary R objects
+ for (String object:engine.ls()) {
+ if (!object.startsWith(simulationName)){
+ engine.remove(object);
+ }
+ }
+
+ // Save Isis R session
+ engine.saveRData(outputDirectory.getParentFile(),
+ outputDirectory.getName());
+ } catch (Exception e) {
+ throw new SensitivityException("Can't evaluate results", e);
+ }
+ }
+
+ @Override
+ public String getDescription() {
+ return "Implementation of Sobol method using R (use of the R " +
+ "sobol2002 method, needs the 'sensitivity' package to work)";
+ }
+}
1
0