r318 - in trunk: . exports rules scripts sensitivityanalysis sensitivityexports simulationplans simulators
Author: echatellier Date: 2014-04-17 18:44:56 +0200 (Thu, 17 Apr 2014) New Revision: 318 Url: http://forge.codelutin.com/projects/isis-fish-data/repository/revisions/318 Log: Merge branches/4.2.2 into trunk Added: trunk/sensitivityanalysis/DOptimal.java trunk/sensitivityanalysis/Fast.java trunk/sensitivityanalysis/Morris.java trunk/sensitivityanalysis/OptimumLHS.java trunk/sensitivityanalysis/RandomLHS.java trunk/sensitivityanalysis/RegularExpandGrid.java trunk/sensitivityanalysis/RegularFractions.java trunk/sensitivityanalysis/Sobol.java Removed: trunk/sensitivityanalysis/SensitivityCalculatorJavaExpandGrid.java trunk/sensitivityanalysis/SensitivityCalculatorRDOptimal.java trunk/sensitivityanalysis/SensitivityCalculatorRExpandGrid.java trunk/sensitivityanalysis/SensitivityCalculatorRFast.java trunk/sensitivityanalysis/SensitivityCalculatorRFrF2.java trunk/sensitivityanalysis/SensitivityCalculatorRMorris.java trunk/sensitivityanalysis/SensitivityCalculatorROptimumLHS.java trunk/sensitivityanalysis/SensitivityCalculatorRRandomLHS.java trunk/sensitivityanalysis/SensitivityCalculatorRSobol.java trunk/sensitivityanalysis/SensitivityCalculatorRegularFractions.java Modified: trunk/ trunk/exports/Abundances.java trunk/exports/Biomasses.java trunk/exports/CapturesNombre.java trunk/exports/CapturesNombreStrategies.java trunk/exports/CapturesPoids.java trunk/exports/CapturesPoidsStrategies.java trunk/exports/CellsDefinition.java trunk/exports/EffortsMetier.java trunk/exports/MetierZone.java trunk/exports/NonActivite.java trunk/exports/OwnerMargin.java trunk/exports/RegionDefinition.java trunk/exports/RejetsNombre.java trunk/exports/RejetsPoids.java trunk/exports/VesselMargin.java trunk/exports/ZonesDefinition.java trunk/pom.xml trunk/rules/Cantonnement.java trunk/rules/CantonnementPreSimu.java trunk/rules/ChangementParamControlablePresimu.java trunk/rules/EffortReduction.java trunk/rules/GraviteVPUE1.java trunk/rules/InterdictionEngin.java trunk/rules/InterdictionEnginPreSimu.java trunk/rules/TACpoids.java trunk/rules/TailleMin.java trunk/rules/TotalClosure.java trunk/scripts/GravityModel.java trunk/scripts/MinimisationUtil.java trunk/scripts/ObjectiveFunction.java trunk/scripts/ObjectiveFunctionBaranov.java trunk/scripts/ResultName.java trunk/scripts/RuleUtil.java trunk/scripts/SiMatrix.java trunk/sensitivityexports/SensitivityBiomassReferenceY9.java trunk/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java trunk/sensitivityexports/SensitivityBiomassRelativeY6.java trunk/sensitivityexports/SensitivityBiomassY3.java trunk/sensitivityexports/SensitivityCatchWeightReferenceY7.java trunk/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java trunk/sensitivityexports/SensitivityCatchWeightRelativeY4.java trunk/sensitivityexports/SensitivityCatchWeightY1.java trunk/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java trunk/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java trunk/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java trunk/sensitivityexports/SensitivitySpawningBiomassY2.java trunk/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java trunk/simulationplans/SimulationNumberRestriction.java trunk/simulators/DefaultSimulator.java trunk/simulators/SimulatorEffortByCell.java Property changes on: trunk ___________________________________________________________________ Added: svn:mergeinfo + /branches/4.2.2:305-317 Modified: trunk/exports/Abundances.java =================================================================== --- trunk/exports/Abundances.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/Abundances.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -26,7 +26,6 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; import org.nuiton.math.matrix.*; import scripts.ResultName; @@ -37,7 +36,7 @@ import fr.ifremer.isisfish.datastore.SimulationStorage; /** - * Abundance.java + * Abundances.java * * Created: 1 septembre 2006 * @@ -52,8 +51,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 @@ -73,22 +72,22 @@ @Override public String getDescription() { - return _("Exporte les abondances en nombre tableau avec des lignes pop;id;zone;date;nombre."); + return "Exporte les abondances en nombre tableau avec des lignes pop;id;zone;date;nombre."; } @Override 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: trunk/exports/Biomasses.java =================================================================== --- trunk/exports/Biomasses.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/Biomasses.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -53,8 +51,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 @@ -74,22 +72,22 @@ @Override public String getDescription() { - return _("Exporte les biomasses tableau avec des lignes pop;id;zone;date;nombre"); + return "Exporte les biomasses tableau avec des lignes pop;id;zone;date;nombre"; } @Override 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: trunk/exports/CapturesNombre.java =================================================================== --- trunk/exports/CapturesNombre.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/CapturesNombre.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -36,8 +36,6 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; - /** * CapturesNombre.java * @@ -54,7 +52,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() { @@ -73,7 +73,7 @@ @Override public String getDescription() { - return _("Export les captures en nombre de la simulation. tableau pop;metier;id;zone;nombre"); + return "Export les captures en nombre de la simulation. tableau pop;metier;id;zone;nombre"; } @Override @@ -82,8 +82,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: trunk/exports/CapturesNombreStrategies.java =================================================================== --- trunk/exports/CapturesNombreStrategies.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/CapturesNombreStrategies.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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,8 +37,6 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; - /** * CapturesNombreStrategies.java * @@ -55,7 +53,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() { @@ -74,12 +74,11 @@ @Override public String getDescription() { - return _("Export les captures en nombre de la simulation. tableau pop;strategie;metier;id;zone;nombre"); + return "Export les captures en nombre de la simulation. tableau pop;strategie;metier;id;zone;nombre"; } @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: trunk/exports/CapturesPoids.java =================================================================== --- trunk/exports/CapturesPoids.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/CapturesPoids.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -36,8 +36,6 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; - /** * CapturesPoids.java * @@ -54,7 +52,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() { @@ -73,7 +73,7 @@ @Override public String getDescription() { - return _("Export les captures en poids de la simulation. tableau pop;metier;id;zone;nombre"); + return "Export les captures en poids de la simulation. tableau pop;metier;id;zone;nombre"; } @Override Modified: trunk/exports/CapturesPoidsStrategies.java =================================================================== --- trunk/exports/CapturesPoidsStrategies.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/CapturesPoidsStrategies.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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,8 +37,6 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; - /** * CapturesPoidsStrategies.java * @@ -55,7 +53,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() { @@ -74,7 +74,7 @@ @Override public String getDescription() { - return _("Export les captures en poids de la simulation. tableau pop;strategie;metier;id;zone;nombre"); + return "Export les captures en poids de la simulation. tableau pop;strategie;metier;id;zone;nombre"; } @Override Modified: trunk/exports/CellsDefinition.java =================================================================== --- trunk/exports/CellsDefinition.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/CellsDefinition.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import java.util.List; @@ -50,11 +48,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 @@ -74,7 +72,7 @@ @Override public String getDescription() { - return _("Export cell's position(longitute/latitute)"); + return "Export cell's position(longitute/latitute)"; } @Override Modified: trunk/exports/EffortsMetier.java =================================================================== --- trunk/exports/EffortsMetier.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/EffortsMetier.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,7 +52,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 @@ -74,13 +72,13 @@ @Override public String getDescription() { - return _("retourne un tableau strategie;metier;date;effort"); + return "retourne un tableau strategie;metier;date;effort"; } @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: trunk/exports/MetierZone.java =================================================================== --- trunk/exports/MetierZone.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/MetierZone.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -26,7 +26,6 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; import org.nuiton.math.matrix.*; import scripts.ResultName; @@ -51,8 +50,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 @@ -72,7 +71,7 @@ @Override public String getDescription() { - return _("Export zone used by metier during simulation"); + return "Export zone used by metier during simulation"; } @Override @@ -82,7 +81,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: trunk/exports/NonActivite.java =================================================================== --- trunk/exports/NonActivite.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/NonActivite.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,7 +52,7 @@ static private Log log = LogFactory.getLog(NonActivite.class); protected String [] necessaryResult = { - ResultName.MATRIX_NO_ACTIVITY + ResultName.MATRIX_NO_ACTIVITY }; @Override @@ -74,13 +72,13 @@ @Override public String getDescription() { - return _("retourne un tableau strategie;metier;date;proportion"); + return "retourne un tableau strategie;metier;date;proportion"; } @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: trunk/exports/OwnerMargin.java =================================================================== --- trunk/exports/OwnerMargin.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/OwnerMargin.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,7 +52,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 @@ -74,15 +72,15 @@ @Override public String getDescription() { - return _("Exporte les profits du patrons, retourne un tableau strategy;date;value"); + return "Exporte les profits du patrons, retourne un tableau strategy;date;value"; } @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: trunk/exports/RegionDefinition.java =================================================================== --- trunk/exports/RegionDefinition.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/RegionDefinition.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -26,7 +26,6 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; import org.nuiton.topia.TopiaContext; import fr.ifremer.isisfish.entities.*; @@ -49,11 +48,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 @@ -73,7 +72,7 @@ @Override public String getDescription() { - return _("Export region description"); + return "Export region description"; } @Override Modified: trunk/exports/RejetsNombre.java =================================================================== --- trunk/exports/RejetsNombre.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/RejetsNombre.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -54,7 +52,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() { @@ -73,7 +73,7 @@ @Override public String getDescription() { - return _("Export les rejets en nombre de la simulation. tableau pop;metier;id;zone;date;nombre"); + return "Export les rejets en nombre de la simulation. tableau pop;metier;id;zone;date;nombre"; } @Override Modified: trunk/exports/RejetsPoids.java =================================================================== --- trunk/exports/RejetsPoids.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/RejetsPoids.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -54,8 +52,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 @@ -75,7 +73,7 @@ @Override public String getDescription() { - return _("Export les rejets en poids de la simulation. tableau pop;metier;id;zone;date;nombre"); + return "Export les rejets en poids de la simulation. tableau pop;metier;id;zone;date;nombre"; } @Override Modified: trunk/exports/VesselMargin.java =================================================================== --- trunk/exports/VesselMargin.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/VesselMargin.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package exports; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,7 +52,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 @@ -74,13 +72,13 @@ @Override public String getDescription() { - return _("cvs out strategy;date;value"); + return "cvs out strategy;date;value"; } @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: trunk/exports/ZonesDefinition.java =================================================================== --- trunk/exports/ZonesDefinition.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/exports/ZonesDefinition.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -27,7 +27,6 @@ import java.io.Writer; import java.util.List; -import static org.nuiton.i18n.I18n._; import org.nuiton.topia.TopiaContext; import fr.ifremer.isisfish.entities.*; @@ -51,11 +50,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 @@ -75,7 +74,7 @@ @Override public String getDescription() { - return _("Export cell's zone constitution"); + return "Export cell's zone constitution"; } @Override Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/pom.xml 2014-04-17 16:44:56 UTC (rev 318) @@ -14,7 +14,7 @@ <packaging>jar</packaging> <!--Version --> - <version>4.2.1</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.1.0</version> + <version>4.3.0.0-SNAPSHOT</version> <scope>compile</scope> </dependency> </dependencies> Modified: trunk/rules/Cantonnement.java =================================================================== --- trunk/rules/Cantonnement.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/rules/Cantonnement.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -50,6 +48,8 @@ /** * Cantonnement.java * + * Remplace aussi Cantonnement Engin + * * Created: 30 novembre 2006 * * @author anonymous <anonymous@labs.libre-entreprise.org> @@ -58,10 +58,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 +76,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 @@ -101,7 +97,7 @@ public String getDescription() throws Exception { // fermeture saisiniere de zone qui peut être réduite à un engin // et a certaines années de la simulation - return _("Cantonnement: can be used to Cantonnement with gear if you put gear in parameter"); + return "Cantonnement: can be used to Cantonnement with gear if you put gear in parameter"; } /** @@ -126,7 +122,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 +200,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 +215,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: trunk/rules/CantonnementPreSimu.java =================================================================== --- trunk/rules/CantonnementPreSimu.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/rules/CantonnementPreSimu.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,9 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n.n_; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -73,15 +70,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 @@ -95,7 +92,7 @@ */ @Override public String getDescription() throws Exception { - return _("Cantonnement: can be used to Cantonnement with gear if you put gear in parameter"); + return "Cantonnement: can be used to Cantonnement with gear if you put gear in parameter"; } private void reportNonActivite(SimulationContext context, @@ -107,7 +104,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 @@ -116,7 +114,7 @@ matNonActiviteMois = MatrixFactory.getInstance().create( ResultName.MATRIX_NO_ACTIVITY, new List[]{listestrategies, metiers}, - new String[]{n_("Strategies"), n_("Metiers")}); + new String[]{"Strategies", "Metiers"}); tableNonActivite.put(month, matNonActiviteMois); } @@ -160,16 +158,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: trunk/rules/ChangementParamControlablePresimu.java =================================================================== --- trunk/rules/ChangementParamControlablePresimu.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/rules/ChangementParamControlablePresimu.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import java.util.ArrayList; import java.util.List; @@ -77,11 +75,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 @@ -95,7 +93,7 @@ */ @Override public String getDescription() throws Exception { - return _("Change gear parameter value for all metier with this gear"); + return "Change gear parameter value for all metier with this gear"; } /** Modified: trunk/rules/EffortReduction.java =================================================================== --- trunk/rules/EffortReduction.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/rules/EffortReduction.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import java.util.List; import org.apache.commons.logging.Log; @@ -57,9 +55,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 @@ -75,7 +77,7 @@ */ @Override public String getDescription() { - return _("Reduce monthly effort of each strategy of the percent indicated"); + return "Reduce monthly effort of each strategy of the percent indicated"; } /** Modified: trunk/rules/GraviteVPUE1.java =================================================================== --- trunk/rules/GraviteVPUE1.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/rules/GraviteVPUE1.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -59,21 +57,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 @@ -87,7 +84,7 @@ */ @Override public String getDescription() throws Exception { - return _("Calcule les proportion par métier chaque mois en fonction de la VPUE du métier l'année précédante"); + return "Calcule les proportion par métier chaque mois en fonction de la VPUE du métier l'année précédante"; /*"HYPOTHESES GRAVITE" " attention cette règle doit toujours être mise avant les mesures de gestion"+ " si pour un metier Effort (métier annee-1,mois) = 0 et propinitiale (métier, mois) !=0 (ie métier potentiellement pratiqué), alors "+ @@ -146,7 +143,6 @@ SommePropInitial.setValue(str, info.getMonth(), somme); } } - } /** @@ -164,8 +160,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: trunk/rules/InterdictionEngin.java =================================================================== --- trunk/rules/InterdictionEngin.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/rules/InterdictionEngin.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -71,11 +69,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 @@ -90,7 +88,7 @@ @Override public String getDescription() throws Exception { // interdiction des metiers utilisant cet engin - return _("Prohibited gear"); + return "Prohibited gear"; } /** @@ -167,7 +165,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 +182,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 +201,7 @@ siMatrix.getMetiers(step)); matNonActivite.setValue(Strat, metier, StratMonthInfo.getProportionMetier(metier)); - StratMonthInfo.setProportionMetier(metier,0); + StratMonthInfo.setProportionMetier(metier, 0); } } Modified: trunk/rules/InterdictionEnginPreSimu.java =================================================================== --- trunk/rules/InterdictionEnginPreSimu.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/rules/InterdictionEnginPreSimu.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,9 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; -import static org.nuiton.i18n.I18n.n_; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -70,14 +67,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 @@ -91,7 +88,7 @@ */ @Override public String getDescription() throws Exception { - return _("Prohibited gear"); + return "Prohibited gear"; } /** @@ -159,7 +156,7 @@ matNonActiviteMois = MatrixFactory.getInstance().create( ResultName.MATRIX_NO_ACTIVITY, new List[]{ListeStrat, ListeMetiers}, - new String[]{n_("Strategies"), n_("Metiers")}); + new String[]{"Strategies", "Metiers"}); tableNonActivite.put(mois, matNonActiviteMois); } @@ -207,7 +204,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 +212,7 @@ if (noActivity == null) { metierMon.setNoActivity(step, mat.copy()); - } - else { + } else { noActivity = noActivity.add(mat); } // fin Modified: trunk/rules/TACpoids.java =================================================================== --- trunk/rules/TACpoids.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/rules/TACpoids.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import java.util.HashSet; import java.util.Set; @@ -87,13 +85,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, }; /** @@ -111,7 +109,7 @@ */ @Override public String getDescription() { - return _("TAC weight in tons.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed as a proportion of the biomass use propTac other than 0."); + return "TAC weight in tons.\nIf you want survival discard use propSurvie other than 0.\nIf you wish TAC computed as a proportion of the biomass use propTac other than 0."; } /** Modified: trunk/rules/TailleMin.java =================================================================== --- trunk/rules/TailleMin.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/rules/TailleMin.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin, Stéphanie Mahevas, Chatellier Eric + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.math.matrix.MatrixIterator; @@ -79,7 +77,7 @@ protected boolean affectation = true; - public String[] necessaryResult = { + protected String[] necessaryResult = { // put here all necessary result for this rule // example: // ResultName.MATRIX_BIOMASS, @@ -98,9 +96,9 @@ */ @Override public String getDescription() throws Exception { - return _("Tous les poissons dont la taille est inférieure à TailleMin" + return "Tous les poissons dont la taille est inférieure à TailleMin" + " ne seront pas capturés. Ils sont placés en rejets et rejetés" - + " suivant la proportion de survie."); + + " suivant la proportion de survie."; } /** Modified: trunk/rules/TotalClosure.java =================================================================== --- trunk/rules/TotalClosure.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/rules/TotalClosure.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package rules; -import static org.nuiton.i18n.I18n._; - import java.util.List; import org.apache.commons.logging.Log; @@ -57,8 +55,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 @@ -68,7 +66,7 @@ @Override public String getDescription() throws Exception { - return _("Total closure of the fishery"); + return "Total closure of the fishery"; } /** @@ -77,6 +75,7 @@ */ @Override public void init(SimulationContext context) throws Exception { + } /** Modified: trunk/scripts/GravityModel.java =================================================================== --- trunk/scripts/GravityModel.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/scripts/GravityModel.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2006 - 2014 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 @@ -22,7 +22,7 @@ package scripts; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.n; import java.util.Collection; import java.util.List; @@ -111,7 +111,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -156,7 +156,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -208,7 +208,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_COSTS_OF_FISHING_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -262,7 +262,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_FUEL_COSTS_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -306,7 +306,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -367,7 +367,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -420,7 +420,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -469,8 +469,8 @@ .create( ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET, new List[] { strategies, metiers, pops }, - new String[] { n_("Strategies"), n_("Metiers"), - n_("Populations") }); + new String[] { n("Strategies"), n("Metiers"), + n("Populations") }); for (int p = 0; p < pops.size(); p++) { Population pop = pops.get(p); @@ -574,7 +574,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -623,7 +623,7 @@ .create( ResultName.MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -677,7 +677,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -745,7 +745,7 @@ .create( ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -799,7 +799,7 @@ .create( ResultName.MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -854,7 +854,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -911,7 +911,7 @@ .create( ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -968,7 +968,7 @@ .create( ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -1022,7 +1022,7 @@ .create( ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL, new List[] { strategies }, - new String[] { n_("Strategies") }); + new String[] { n("Strategies") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -1073,7 +1073,7 @@ .create( ResultName.MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY, new List[] { strategies }, - new String[] { n_("Strategies") }); + new String[] { n("Strategies") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -1119,7 +1119,7 @@ .create( ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL, new List[] { strategies }, - new String[] { n_("Strategies") }); + new String[] { n("Strategies") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -1170,7 +1170,7 @@ .create( ResultName.MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY, new List[] { strategies }, - new String[] { n_("Strategies") }); + new String[] { n("Strategies") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); Modified: trunk/scripts/MinimisationUtil.java =================================================================== --- trunk/scripts/MinimisationUtil.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/scripts/MinimisationUtil.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2012 Ifremer, CodeLutin, Chatellier Eric + * Copyright (C) 2012, 2014 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: trunk/scripts/ObjectiveFunction.java =================================================================== --- trunk/scripts/ObjectiveFunction.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/scripts/ObjectiveFunction.java 2014-04-17 16:44:56 UTC (rev 318) @@ -1,6 +1,9 @@ /* - * Copyright (C) 2012 lgasche - * + * #%L + * IsisFish data + * %% + * Copyright (C) 2012, 2014 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: trunk/scripts/ObjectiveFunctionBaranov.java =================================================================== --- trunk/scripts/ObjectiveFunctionBaranov.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/scripts/ObjectiveFunctionBaranov.java 2014-04-17 16:44:56 UTC (rev 318) @@ -1,6 +1,9 @@ /* - * Copyright (C) 2012 lgasche - * + * #%L + * IsisFish data + * %% + * Copyright (C) 2012, 2014 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: trunk/scripts/ResultName.java =================================================================== --- trunk/scripts/ResultName.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/scripts/ResultName.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin + * Copyright (C) 2006 - 2014 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 @@ -22,7 +22,7 @@ package scripts; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.n; import fr.ifremer.isisfish.util.Doc; // pour pouvoir afficher une aide contextuelle (BUG#1605) @@ -51,7 +51,7 @@ * Dimension 4 : Zone */ @Doc(value = "do the doc of Result matrixDiscardsWeightPerStrMet") - static final public String MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP = n_("matrixDiscardsWeightPerStrMetPerZonePop"); + static final public String MATRIX_DISCARDS_WEIGHT_PER_STR_MET_PER_ZONE_POP = n("matrixDiscardsWeightPerStrMetPerZonePop"); /** * Matrix with five dimensions @@ -62,7 +62,7 @@ * Dimension 5 : Zone */ @Doc(value = "do the doc of Result matrixDiscardsPerStrMet") - static final public String MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP = n_("matrixDiscardsPerStrMetPerZonePop"); + static final public String MATRIX_DISCARDS_PER_STR_MET_PER_ZONE_POP = n("matrixDiscardsPerStrMetPerZonePop"); /** * Matrix with five dimensions @@ -73,7 +73,7 @@ * Dimension 5 : Zone */ @Doc(value = "do the doc of Result matrixLandingPerMet") - static final public String MATRIX_LANDING_PER_MET = n_("matrixLandingPerMet"); + static final public String MATRIX_LANDING_PER_MET = n("matrixLandingPerMet"); /** * Matrix with three dimensions @@ -82,7 +82,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixEffortPerStrategyMet") - static final public String MATRIX_EFFORT_PER_STRATEGY_MET = n_("matrixEffortPerStrategyMet"); + static final public String MATRIX_EFFORT_PER_STRATEGY_MET = n("matrixEffortPerStrategyMet"); /** * Matrix with three dimensions @@ -91,7 +91,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixEffortNominalPerStrategyMet") - static final public String MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET = n_("matrixEffortNominalPerStrategyMet"); + static final public String MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET = n("matrixEffortNominalPerStrategyMet"); /** * Matrix with five dimensions @@ -102,7 +102,7 @@ * Dimension 5 : Zone */ @Doc(value = "Disponible uniquement avec les simulations par Zone. do the doc of Result matrixCatchRatePerStrategyMet") - static final public String MATRIX_CATCH_RATE_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchRatePerStrategyMet"); + static final public String MATRIX_CATCH_RATE_PER_STRATEGY_MET_PER_ZONE_POP = n("matrixCatchRatePerStrategyMet"); /** * Matrix with five dimensions @@ -113,10 +113,10 @@ * Dimension 5 : Zone * * N'est calculé que si l'effort est calculé par cellule et non par zone. - * @see SimulatorEffortByCell + * @see simulators.SimulatorEffortByCell */ @Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZoneMet") - static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET = n_("matrixCatchPerStrategyMetPerZoneMet"); + static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET = n("matrixCatchPerStrategyMetPerZoneMet"); /** * Matrix with five dimensions @@ -127,7 +127,7 @@ * Dimension 5 : Zone */ @Doc(value = "do the doc of Result matrixCatchPerStrategyMetPerZonePop") - static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchPerStrategyMetPerZonePop"); + static final public String MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_POP = n("matrixCatchPerStrategyMetPerZonePop"); /** * Matrix with five dimensions @@ -138,10 +138,10 @@ * Dimension 5 : Zone * * N'est calculé que si l'effort est calculé par cellule et non par zone. - * @see SimulatorEffortByCell + * @see simulators.SimulatorEffortByCell */ @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZoneMet") - static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET = n_("matrixCatchWeightPerStrategyMetPerZoneMet"); + static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_MET = n("matrixCatchWeightPerStrategyMetPerZoneMet"); /** * Matrix with five dimensions @@ -152,7 +152,7 @@ * Dimension 5 : Zone */ @Doc(value = "do the doc of Result matrixCatchWeightPerStrategyMetPerZonePop") - static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP = n_("matrixCatchWeightPerStrategyMetPerZonePop"); + static final public String MATRIX_CATCH_WEIGHT_PER_STRATEGY_MET_PER_ZONE_POP = n("matrixCatchWeightPerStrategyMetPerZonePop"); /** * Matrix with five dimensions @@ -163,14 +163,14 @@ * Dimension 5 : Zone */ @Doc(value = "Disponible uniquement avec les simulations par Zone. do the doc of Result matrixFishingMortality") - static final public String MATRIX_FISHING_MORTALITY = n_("matrixFishingMortality"); + static final public String MATRIX_FISHING_MORTALITY = n("matrixFishingMortality"); /** * Matrix with 1 dimension * Dimension 1 : TimeStep */ @Doc(value = "do the doc of Result matrixTotalFishingMortality") - static final public String MATRIX_TOTAL_FISHING_MORTALITY = n_("matrixTotalFishingMortality"); + static final public String MATRIX_TOTAL_FISHING_MORTALITY = n("matrixTotalFishingMortality"); /** * Matrix with 2 dimensions @@ -178,7 +178,7 @@ * Dimension 2 : Group */ @Doc(value = "do the doc of Result matrixFishingMortalityPerGroup") - static final public String MATRIX_FISHING_MORTALITY_PER_GROUP = n_("matrixFishingMortalityPerGroup"); + static final public String MATRIX_FISHING_MORTALITY_PER_GROUP = n("matrixFishingMortalityPerGroup"); /** * Matrix with three dimensions @@ -187,7 +187,7 @@ * Dimension 3 : Zone (semantics : Dimension 2) */ @Doc(value = "do the doc of Result matrixAbundance") - static final public String MATRIX_ABUNDANCE = n_("matrixAbundance"); + static final public String MATRIX_ABUNDANCE = n("matrixAbundance"); /** * Matrix with three dimensions @@ -196,7 +196,7 @@ * Dimension 3 : Zone */ @Doc(value = "do the doc of Result matrixAbundanceBeginMonth") - static final public String MATRIX_ABUNDANCE_BEGIN_MONTH = n_("matrixAbundanceBeginMonth"); + static final public String MATRIX_ABUNDANCE_BEGIN_MONTH = n("matrixAbundanceBeginMonth"); /** * Matrix with three dimensions @@ -205,7 +205,7 @@ * Dimension 3 : Zone */ @Doc(value = "do the doc of Result matrixBiomass") - static final public String MATRIX_BIOMASS = n_("matrixBiomass"); + static final public String MATRIX_BIOMASS = n("matrixBiomass"); /** * Matrix with three dimensions @@ -214,7 +214,7 @@ * Dimension 3 : Zone */ @Doc(value = "do the doc of Result matrixBiomassBeginMonth") - static final public String MATRIX_BIOMASS_BEGIN_MONTH = n_("matrixBiomassBeginMonth"); + static final public String MATRIX_BIOMASS_BEGIN_MONTH = n("matrixBiomassBeginMonth"); /** * Matrix with three dimensions @@ -223,7 +223,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixFishingTimePerMonthPerVessel") - static final public String MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL = n_("matrixFishingTimePerMonthPerVessel"); + static final public String MATRIX_FISHING_TIME_PER_MONTH_PER_VESSEL = n("matrixFishingTimePerMonthPerVessel"); /** * Matrix with three dimensions @@ -232,7 +232,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixFuelCostsOfTravelPerVessel") - static final public String MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL = n_("matrixFuelCostsOfTravelPerVessel"); + static final public String MATRIX_FUEL_COSTS_OF_TRAVEL_PER_VESSEL = n("matrixFuelCostsOfTravelPerVessel"); /** * Matrix with three dimensions @@ -241,7 +241,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixCostsOfFishingPerVessel") - static final public String MATRIX_COSTS_OF_FISHING_PER_VESSEL = n_("matrixCostsOfFishingPerVessel"); + static final public String MATRIX_COSTS_OF_FISHING_PER_VESSEL = n("matrixCostsOfFishingPerVessel"); /** * Matrix with three dimensions @@ -250,7 +250,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixFuelCostsPerVessel") - static final public String MATRIX_FUEL_COSTS_PER_VESSEL = n_("matrixFuelCostsPerVessel"); + static final public String MATRIX_FUEL_COSTS_PER_VESSEL = n("matrixFuelCostsPerVessel"); /** * Matrix with three dimensions @@ -259,7 +259,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixRepairAndMaintenanceGearCostsPerVessel") - static final public String MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL = n_("matrixRepairAndMaintenanceGearCostsPerVessel"); + static final public String MATRIX_REPAIR_AND_MAINTENANCE_GEAR_COSTS_PER_VESSEL = n("matrixRepairAndMaintenanceGearCostsPerVessel"); /** * Matrix with three dimensions @@ -268,7 +268,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixOtherRunningCostsPerVessel") - static final public String MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL = n_("matrixOtherRunningCostsPerVessel"); + static final public String MATRIX_OTHER_RUNNING_COSTS_PER_VESSEL = n("matrixOtherRunningCostsPerVessel"); /** * Matrix with three dimensions @@ -277,7 +277,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixSharedNotFixedCostsPerVessel") - static final public String MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL = n_("matrixSharedNotFixedCostsPerVessel"); + static final public String MATRIX_SHARED_NOT_FIXED_COSTS_PER_VESSEL = n("matrixSharedNotFixedCostsPerVessel"); /** * Matrix with four dimensions @@ -287,7 +287,7 @@ * Dimension 4 : Population */ @Doc(value = "do the doc of Result matrixGrossValueOfLandingsPerSpeciesPerStrategyMet") - static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsPerSpeciesPerStrategyMet"); + static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_SPECIES_PER_STRATEGY_MET = n("matrixGrossValueOfLandingsPerSpeciesPerStrategyMet"); /** * Matrix with three dimensions @@ -296,7 +296,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixGrossValueOfLandingsPerStrategyMet") - static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsPerStrategyMet"); + static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n("matrixGrossValueOfLandingsPerStrategyMet"); /** * Matrix with three dimensions @@ -307,7 +307,7 @@ * Matrix calculated in the non generic Rule : GraviteVPUE1LangEtGrossValueOtherSpeciesECOMOD */ @Doc(value = "do the doc of Result matrixGrossValueOfLandingsOtherSpeciesPerStrategyMet") - static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_OTHER_SPECIES_PER_STRATEGY_MET = n_("matrixGrossValueOfLandingsOtherSpeciesPerStrategyMet"); + static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_OTHER_SPECIES_PER_STRATEGY_MET = n("matrixGrossValueOfLandingsOtherSpeciesPerStrategyMet"); /** * Matrix with three dimensions @@ -316,7 +316,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixGrossValueOfLandingsPerStrategyMetPerVessel") - static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixGrossValueOfLandingsPerStrategyMetPerVessel"); + static final public String MATRIX_GROSS_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n("matrixGrossValueOfLandingsPerStrategyMetPerVessel"); /** * Matrix with three dimensions @@ -325,7 +325,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixNetValueOfLandingsPerStrategyMet") - static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n_("matrixNetValueOfLandingsPerStrategyMet"); + static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET = n("matrixNetValueOfLandingsPerStrategyMet"); /** * Matrix with three dimensions @@ -334,7 +334,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixNetValueOfLandingsPerStrategyMetPerVessel") - static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixNetValueOfLandingsPerStrategyMetPerVessel"); + static final public String MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET_PER_VESSEL = n("matrixNetValueOfLandingsPerStrategyMetPerVessel"); /** * Matrix with three dimensions @@ -343,7 +343,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixNetRenevueToSharePerStrategyMetPerVessel") - static final public String MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL = n_("matrixNetRenevueToSharePerStrategyMetPerVessel"); + static final public String MATRIX_NET_RENEVUE_TO_SHARE_PER_STRATEGY_MET_PER_VESSEL = n("matrixNetRenevueToSharePerStrategyMetPerVessel"); /** * Matrix with three dimensions @@ -352,7 +352,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixCrewSharePerStrategyPerVessel") - static final public String MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL = n_("matrixCrewSharePerStrategyPerVessel"); + static final public String MATRIX_CREW_SHARE_PER_STRATEGY_MET_PER_VESSEL = n("matrixCrewSharePerStrategyPerVessel"); /** * Matrix with three dimensions @@ -361,7 +361,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel") - static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel"); + static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n("matrixOwnerMarginOverVariableCostsPerStrategyMetPerVessel"); /** * Matrix with three dimensions @@ -370,7 +370,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel") - static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n_("matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel"); + static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_MET_PER_VESSEL = n("matrixVesselMarginOverVariableCostsPerStrategyMetPerVessel"); /** * Matrix with three dimensions @@ -379,7 +379,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixOwnerMarginOverVariableCostsPerStrategyPerVessel") - static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n_("matrixOwnerMarginOverVariableCostsPerStrategyPerVessel"); + static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n("matrixOwnerMarginOverVariableCostsPerStrategyPerVessel"); /** * Matrix with two dimensions @@ -387,7 +387,7 @@ * Dimension 2 : Strategy */ @Doc(value = "do the doc of Result matrixOwnerMarginOverVariableCostsPerStrategy") - static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n_("matrixOwnerMarginOverVariableCostsPerStrategy"); + static final public String MATRIX_OWNER_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n("matrixOwnerMarginOverVariableCostsPerStrategy"); /** * Matrix with two dimensions @@ -395,7 +395,7 @@ * Dimension 2 : Strategy */ @Doc(value = "do the doc of Result matrixVesselMarginOverVariableCostsPerStrategyPerVessel") - static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n_("matrixVesselMarginOverVariableCostsPerStrategyPerVessel"); + static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY_PER_VESSEL = n("matrixVesselMarginOverVariableCostsPerStrategyPerVessel"); /** * Matrix with two dimensions @@ -403,7 +403,7 @@ * Dimension 2 : Strategy */ @Doc(value = "do the doc of Result matrixVesselMarginOverVariableCostsPerStrategy") - static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n_("matrixVesselMarginOverVariableCostsPerStrategy"); + static final public String MATRIX_VESSEL_MARGIN_OVER_VARIABLE_COSTS_PER_STRATEGY = n("matrixVesselMarginOverVariableCostsPerStrategy"); /** * Matrix with three dimensions @@ -412,7 +412,7 @@ * Dimension 3 : Metier */ @Doc(value = "do the doc of Result matrixNoActivity") - static final public String MATRIX_NO_ACTIVITY = n_("matrixNoActivity"); + static final public String MATRIX_NO_ACTIVITY = n("matrixNoActivity"); /** * Matrix with three dimensions @@ -421,7 +421,7 @@ * Dimension 3 : Zone */ @Doc(value = "do the doc of Result matrixMetierZone") - static final public String MATRIX_METIER_ZONE = n_("matrixMetierZone"); + static final public String MATRIX_METIER_ZONE = n("matrixMetierZone"); /** * Matrix with two dimensions @@ -429,5 +429,5 @@ * Dimension 2 : Group */ @Doc(value = "do the doc of Result matrixPrice") - static final public String MATRIX_PRICE = n_("matrixPrice"); + static final public String MATRIX_PRICE = n("matrixPrice"); } Modified: trunk/scripts/RuleUtil.java =================================================================== --- trunk/scripts/RuleUtil.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/scripts/RuleUtil.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, CodeLutin, Chatellier Eric + * Copyright (C) 2006 - 2014 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 @@ -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: trunk/scripts/SiMatrix.java =================================================================== --- trunk/scripts/SiMatrix.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/scripts/SiMatrix.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, Code Lutin, Benjamin Poussin + * Copyright (C) 2006 - 2014 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 @@ -22,7 +22,7 @@ package scripts; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.n; import java.util.ArrayList; import java.util.Collection; @@ -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 { @@ -213,7 +209,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_METIER_ZONE, new List[] { metiers, zones }, - new String[] { n_("Metiers"), n_("Zones") }); + new String[] { n("Metiers"), n("Zones") }); for (Metier metier : metiers) { Collection<Zone> zoneMetier = metier.getMetierSeasonInfo( @@ -229,7 +225,7 @@ List<PopulationGroup> groups = pop.getPopulationGroup(); MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_PRICE, new List[] { groups }, - new String[] { n_("PopulationGroup") }); + new String[] { n("PopulationGroup") }); for (PopulationGroup group : groups) { result.setValue(group, group.getPrice()); @@ -284,8 +280,8 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_CATCH_PER_STRATEGY_MET_PER_ZONE_MET, new List[] { strategies, metiers, groups, zones }, - new String[] { n_("Strategies"), n_("Metiers"), n_("Groups"), - n_("Zones") }); + new String[] { n("Strategies"), n("Metiers"), n("Groups"), + n("Zones") }); // matrice temporaire ou les zones pops sont sommees MatrixND tmp = matrixCatchPerStrategyMetPerCell.sumOverDim(3); @@ -412,8 +408,8 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_CATCH_RATE_PER_STRATEGY_MET_PER_ZONE_POP, new List[] { strategies, metiers, groups, zones }, - new String[] { n_("Strategies"), n_("Metiers"), n_("Groups"), - n_("Zones") }); + new String[] { n("Strategies"), n("Metiers"), n("Groups"), + n("Zones") }); // Optimisation Hilaire for (int s = 0; s < strategies.size(); s++) { @@ -561,8 +557,8 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_FISHING_MORTALITY, new List[] { strategies, metiers, groups, zones }, - new String[] { n_("Strategies"), n_("Metiers"), n_("Groups"), - n_("Zones") }); + new String[] { n("Strategies"), n("Metiers"), n("Groups"), + n("Zones") }); Month month = step.getMonth(); PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month); @@ -673,8 +669,8 @@ MatrixND result = MatrixFactory.getInstance().create( "matrixCatchRatePerStrategyMetPerCell", new List[] { strategies, metiers, groups, zones, cells }, - new String[] { n_("Strategies"), n_("Metiers"), n_("Groups"), - n_("Zones"), n_("Cells") }); + new String[] { n("Strategies"), n("Metiers"), n("Groups"), + n("Zones"), n("Cells") }); // Optimisation Hilaire MatrixND matrixFishingMortalityPerCellSumOverGroup = matrixFishingMortalityPerCell @@ -832,8 +828,8 @@ MatrixND result = MatrixFactory.getInstance().create( "matrixFishingMortalityPerCell", new List[] { strategies, metiers, groups, zones, cells }, - new String[] { n_("Strategies"), n_("Metiers"), n_("Groups"), - n_("Zones"), n_("Cells") }); + new String[] { n("Strategies"), n("Metiers"), n("Groups"), + n("Zones"), n("Cells") }); Month month = step.getMonth(); PopulationSeasonInfo infoPop = pop.getPopulationSeasonInfo(month); @@ -1080,8 +1076,8 @@ /** * - * @param setOfVessels - * @param zone + * @param sov + * @param zoneMetier * @return */ protected double travelTimePerTrip(SetOfVessels sov, @@ -1257,7 +1253,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_ABUNDANCE + "_PER_CELL", new List[] { groups, zones, allCells }, - new String[] { n_("Groups"), n_("Zones"), n_("Cells") }); + new String[] { n("Groups"), n("Zones"), n("Cells") }); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -1322,7 +1318,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_ABUNDANCE, new List[] { groups, zones }, - new String[] { n_("Groups"), n_("Zones") }); + new String[] { n("Groups"), n("Zones") }); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -1357,7 +1353,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_ABUNDANCE, new List[] { groups, zones }, - new String[] { n_("Groups"), n_("Zones") }); + new String[] { n("Groups"), n("Zones") }); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -1435,7 +1431,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_BIOMASS, new List[] { groups, zones }, - new String[] { n_("Groups"), n_("Zones") }); + new String[] { n("Groups"), n("Zones") }); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -1458,7 +1454,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_BIOMASS_BEGIN_MONTH, new List[] { groups, zones }, - new String[] { n_("Groups"), n_("Zones") }); + new String[] { n("Groups"), n("Zones") }); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -1480,7 +1476,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_ABUNDANCE_BEGIN_MONTH, new List[] { groups, zones }, - new String[] { n_("Groups"), n_("Zones") }); + new String[] { n("Groups"), n("Zones") }); for (int g = 0; g < groups.size(); g++) { PopulationGroup group = groups.get(g); @@ -1493,12 +1489,6 @@ return result; } - /////////////////////////////////////////////////////////////////////////// - // - // - // - /////////////////////////////////////////////////////////////////////////// - /** * @param step * @return @@ -1511,7 +1501,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_EFFORT_PER_STRATEGY_MET, new List[] { strategies, metiers }, - new String[] { n_("Strategies"), n_("Metiers") }); + new String[] { n("Strategies"), n("Metiers") }); for (int s = 0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -1526,12 +1516,6 @@ return result; } - /////////////////////////////////////////////////////////////////////////// - // - // - // - /////////////////////////////////////////////////////////////////////////// - /** * * @@ -1556,11 +1540,6 @@ return result; } - /////////////////////////////////////////////////////////////////////////// - // - // - // - /////////////////////////////////////////////////////////////////////////// public MatrixND matrixEffortNominalPerStrategyMet(TimeStep step) throws TopiaException { List<Strategy> strategies = getStrategies(step); @@ -1569,7 +1548,7 @@ MatrixND result = MatrixFactory.getInstance().create( ResultName.MATRIX_EFFORT_NOMINAL_PER_STRATEGY_MET, new List[]{strategies, metiers}, - new String[]{n_("Strategies"), n_("Metiers")}); + new String[]{n("Strategies"), n("Metiers")}); for (int s=0; s < strategies.size(); s++) { Strategy str = strategies.get(s); @@ -1606,7 +1585,7 @@ MatrixND tfgMatrix = MatrixFactory.getInstance().create( ResultName.MATRIX_FISHING_MORTALITY_PER_GROUP, new List[]{populations, groups}, // On travaille sur les pops ET les groupes - new String[]{n_("Population"), n_("Group")}); + new String[]{n("Population"), n("Group")}); for (PopulationGroup group : groups) { @@ -1614,7 +1593,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 Copied: trunk/sensitivityanalysis/DOptimal.java (from rev 317, branches/4.2.2/sensitivityanalysis/DOptimal.java) =================================================================== --- trunk/sensitivityanalysis/DOptimal.java (rev 0) +++ trunk/sensitivityanalysis/DOptimal.java 2014-04-17 16:44:56 UTC (rev 318) @@ -0,0 +1,369 @@ +/* + * #%L + * IsisFish data + * %% + * 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 + * 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.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 = openEngine(outputDirectory); + + 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 = 0.0; + Double max = 1.0; + + for (int i = 0; i < card; i++) { + //add the ith value + vector += (min + (i * (max - min) / (card - 1))) + ","; + } + } else { + int nbValues = ((DiscreteDomain) domain).getValuesCount(); + 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 = "isis.methodAnalyse<-optFederov(~(%s),data=expandgrid, " + + "approximate =FALSE, center=F, criterion = \"D\"," + + "nRepeats=10)"; + } else { + rCall = "isis.methodAnalyse<-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(isis.methodAnalyse$design)"); + RDataFrame dataFrame = (RDataFrame)engine.eval("expPlan"); + dataFrame.setVariable("expPlan"); + int nbExperiments = (Integer)engine.eval("dim(isis.methodAnalyse$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 += "\"[0.0;1.0]\""; + } 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<-isis.methodAnalyse$design"); + engine.voidEval("attr(isis.simule," + + "\"nomModel\")<-\"isis-fish-externe-R\""); + engine.voidEval("names(isis.simule)<-isis.factors[[1]]"); + + closeEngine(engine, outputDirectory); + + } 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 = openEngine(outputDirectory); + + //Get back the factors number + int factorNumber = (Integer)engine.eval("dim(isis.methodAnalyse$design)[2]"); + + SimulationParameter param = simulationStorages.get(0).getParameter(); + int sensitivityNumber = param.getSensitivityExport().size(); + + String firstStorageName = outputDirectory.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(isis.methodAnalyse$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(isis.methodAnalyse$design)[" + (j + 1) + "]") + + "+"; + } else { + aovCall = aovCall + + engine.eval("names(isis.methodAnalyse$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 + String exportMethodAnalyse = String.format("%s.isis.methodAnalyse", firstStorageName + "." + name); + engine.voidEval(exportMethodAnalyse + "<-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(" + exportMethodAnalyse + "," + + "\"nomModel\")<-\"isis-fish-externe-R\""); + } + + closeEngine(engine, outputDirectory); + + } 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: trunk/sensitivityanalysis/Fast.java (from rev 317, branches/4.2.2/sensitivityanalysis/Fast.java) =================================================================== --- trunk/sensitivityanalysis/Fast.java (rev 0) +++ trunk/sensitivityanalysis/Fast.java 2014-04-17 16:44:56 UTC (rev 318) @@ -0,0 +1,283 @@ +/* + * #%L + * IsisFish data + * %% + * 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 + * 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 fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.export.SensitivityExport; +import fr.ifremer.isisfish.simulator.SimulationParameter; +import fr.ifremer.isisfish.util.Doc; + +import org.nuiton.j2r.types.RDataFrame; + +/** + * Implementation of Fast method using R. + * + * @author jcouteau + * @version $Revision: 3842 $ + * + * Last update : $Date: 2013-11-22 18:52:48 +0100 (ven., 22 nov. 2013) $ 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(); + + // only run with continuous + checkAllFactorContinuous(factors); + + String rInstruction = "isis.methodAnalyse<-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 = openEngine(outputDirectory); + + // 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("isis.methodAnalyse$X"); + dataFrame.setVariable("isis.methodAnalyse$X"); + + nbExperiments = (Integer)engine.eval("dim(isis.methodAnalyse$X)[1]"); + + engine.voidEval(getIsisFactorDistribution(factors)); + + engine.voidEval("call<-isis.methodAnalyse$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(isis.methodAnalyse$X)"); + + engine.voidEval("attr(isis.simule,\"nomModel\")<-" + + "\"isis-fish-externe-R\""); + + engine.voidEval("names(isis.simule)<-isis.factors[[1]]"); + + // 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); + factor.setValueForIdentifier(dataFrame.get(i,j)); + experimentScenario.addFactor(factor); + } + thisExperimentScenarios.add(experimentScenario); + thisExperiment.setScenarios(thisExperimentScenarios); + } + + closeEngine(engine, outputDirectory); + } catch (RException eee) { + throw new SensitivityException("Can't generate scenarios", eee); + } + return thisExperiment; + + } + + @Override + public void analyzeResult(List<SimulationStorage> simulationStorages, + File outputDirectory) throws SensitivityException { + + String simulationName = outputDirectory.getName().replaceAll("-", ""); + + try { + + REngine engine = openEngine(outputDirectory); + + // for export + 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(isis.methodAnalyse,y=" + name + ")"); + + engine.voidEval("names(isis.methodAnalyse$V)<-isis.factor.distribution$NomFacteur"); + engine.voidEval("names(isis.methodAnalyse$X)<-isis.factor.distribution$NomFacteur"); + engine.voidEval("names(isis.methodAnalyse$D1)<-isis.factor.distribution$NomFacteur"); + engine.voidEval("names(isis.methodAnalyse$Dt)<-isis.factor.distribution$NomFacteur"); + + //creating isis.methodAnalyse + String exportMethodAnalyse = String.format("%s.isis.methodAnalyse", simulationName + "." + name); + engine.voidEval(exportMethodAnalyse + "<-list(" + + "\"isis.factors\"=isis.factors," + + "\"isis.factor.distribution\"=isis.factor.distribution," + + "\"isis.simule\"=isis.simule," + + "call_method=\"tell(isis.methodAnalyse,y=" + name + ")" + "\"," + + "\"analysis_result\"=isis.methodAnalyse)"); + + //setting isis.methodAnalyse attributes + engine.voidEval("attr(" + exportMethodAnalyse + ",\"nomModel\")<-" + + "\"isis-fish-externe-R\")"); + + //Create the data.frame of scenarios and results for export purpose + engine.voidEval("dfresults<-data.frame(isis.methodAnalyse$X,isis.methodAnalyse$y)"); + + //Set working directory + engine.setwd(outputDirectory); + + //Export V + engine.voidEval("write.csv(isis.methodAnalyse$V,\"" + name + "_V.csv\")"); + + //Export D1 + engine.voidEval("write.csv(isis.methodAnalyse$D1,\"" + name + "_D1.csv\")"); + + //Export Dt + engine.voidEval("write.csv(isis.methodAnalyse$Dt,\"" + name + "_Dt.csv\")"); + //Set dfresults names + engine.voidEval("resultsnames<-c(isis.factor.distribution$NomFacteur,\"Result\")"); + engine.voidEval("names(dfresults)<-isis.factor.distribution$NomFacteur"); + + //Export results + engine.voidEval("write.csv(dfresults,\"" + name + + "_Results.csv\")"); + //FIXME export through java to enable export when using Rserve + } + + closeEngine(engine, outputDirectory); + + } 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: trunk/sensitivityanalysis/Morris.java (from rev 317, branches/4.2.2/sensitivityanalysis/Morris.java) =================================================================== --- trunk/sensitivityanalysis/Morris.java (rev 0) +++ trunk/sensitivityanalysis/Morris.java 2014-04-17 16:44:56 UTC (rev 318) @@ -0,0 +1,324 @@ +/* + * #%L + * IsisFish data + * %% + * 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 + * 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.util.Doc; + +import org.apache.commons.lang3.StringUtils; +import org.nuiton.j2r.REngine; +import org.nuiton.j2r.RException; +import org.nuiton.j2r.types.RDataFrame; + +import java.io.File; +import java.util.List; +import java.util.Map; + +/** + * 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; + } + + checkAllUniformDistribution(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); + if (i != 0) { + factorNames += ","; + levels += ","; + gridJump += ","; + binf += ","; + bsup += ","; + } + + factorNames += "\"" + factor.getName() + "\""; + + levels += factor.getCardinality(); + + gridJump += factor.getCardinality() / 2; + + binf += 0; + bsup += 1; + } + + String rInstruction = "isis.methodAnalyse<-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); + } + + try { + REngine engine = openEngine(outputDirectory); + + // 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(isis.methodAnalyse$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 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)); + + engine.voidEval("call<-isis.methodAnalyse$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]]"); + + // 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); + } + + closeEngine(engine, outputDirectory); + + } catch (RException eee) { + throw new SensitivityException("Can't generate scenarios", eee); + } + + return thisExperiment; + + } + + @Override + public void analyzeResult(List<SimulationStorage> simulationStorages, + File outputDirectory) throws SensitivityException { + + String simulationName = outputDirectory.getName().replaceAll("-", ""); + + try { + REngine engine = openEngine(outputDirectory); + + // 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(isis.methodAnalyse,y=" + name + ")"); + + //creating isis.methodAnalyse + String exportMethodAnalyse = String.format("%s.isis.methodAnalyse", simulationName + "." + name); + engine.voidEval(exportMethodAnalyse + "<-list(" + + //"\"isis.factors\"=isis.factors," + + //"\"isis.factor.distribution\"=isis.factor.distribution," + + "\"isis.simule\"=isis.simule," + + "\"call_method\"=\"tell(isis.methodAnalyse,y=" + name + ")" + "\"," + + "\"analysis_result\"=isis.methodAnalyse)"); + + //setting isis.methodAnalyse attributes + engine.voidEval("attr(" + exportMethodAnalyse + ",\"nomModel\")<-" + + "\"isis-fish-externe-R\""); + + // Get back the sensitivity results, mu, mu star and sigma. + engine.voidEval("mu<-apply(isis.methodAnalyse$ee, 2, mean)"); + engine.voidEval("mu.star <- apply(isis.methodAnalyse$ee, 2, function(a) mean(abs(a)))"); + engine.voidEval("sigma <- apply(isis.methodAnalyse$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)<-isis.factor.distribution$NomFacteur"); + + //Create the data.frame of scenarios and results for export purpose + engine.voidEval("dfresults<-data.frame(isis.methodAnalyse$X," + name + ")"); + + //Set dfresults names + engine.voidEval("resultsnames<-c(isis.factor.distribution$NomFacteur,\"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 + + } + + closeEngine(engine, outputDirectory); + + } 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: trunk/sensitivityanalysis/OptimumLHS.java (from rev 317, branches/4.2.2/sensitivityanalysis/OptimumLHS.java) =================================================================== --- trunk/sensitivityanalysis/OptimumLHS.java (rev 0) +++ trunk/sensitivityanalysis/OptimumLHS.java 2014-04-17 16:44:56 UTC (rev 318) @@ -0,0 +1,337 @@ +/* + * #%L + * IsisFish data + * %% + * 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 + * 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 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.util.Doc; + +import org.nuiton.j2r.types.RDataFrame; + +/** + * Implementation of Optimum Latin Hypercube method using R. + * + * @author jcouteau + * @version $Revision: 3842 $ + */ +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 + checkAllFactorContinuous(factors); + + try { + REngine engine = openEngine(outputDirectory); + + //Load the lhs library + engine.voidEval("library(lhs)"); + + String rInstruction = "isis.methodAnalyse<-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(isis.methodAnalyse)"); + 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); + } + + engine.voidEval(getIsisFactorDistribution(factors)); + + engine.voidEval("call<-" + "\"isis.methodAnalyse<-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(isis.methodAnalyse)"); + + 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); + + closeEngine(engine, outputDirectory); + + } 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 = outputDirectory.getName().replaceAll("-", ""); + + try { + + REngine engine = openEngine(outputDirectory); + + engine.voidEval("factors<-data.frame(isis.methodAnalyse)"); + engine.voidEval("names(factors)<-isis.factor.distribution$NomFacteur"); + + //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(isis.factor.distribution$NomFacteur,\"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 + String exportMethodAnalyse = String.format("%s.isis.methodAnalyse", simulationName + "." + name); + engine.voidEval(exportMethodAnalyse + "<-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(" + exportMethodAnalyse + "," + + "\"nomModel\")<-\"isis-fish-externe-R\""); + + } + + closeEngine(engine, outputDirectory); + + } 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: trunk/sensitivityanalysis/RandomLHS.java (from rev 317, branches/4.2.2/sensitivityanalysis/RandomLHS.java) =================================================================== --- trunk/sensitivityanalysis/RandomLHS.java (rev 0) +++ trunk/sensitivityanalysis/RandomLHS.java 2014-04-17 16:44:56 UTC (rev 318) @@ -0,0 +1,330 @@ +/* + * #%L + * IsisFish data + * %% + * 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 + * 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.types.RDataFrame; + +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.simulator.SimulationParameter; +import fr.ifremer.isisfish.simulator.sensitivity.*; +import fr.ifremer.isisfish.util.Doc; + +/** + * Implementation of Random Latin Hypercube method using R. + * + * @author jcouteau + * @version $Revision: 3842 $ + */ +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 + + checkAllFactorContinuous(factors); + + try { + + REngine engine = openEngine(outputDirectory); + + //Load the lhs library + engine.voidEval("library(lhs)"); + + //Create the scenarios + String rInstruction = "isis.methodAnalyse<-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(isis.methodAnalyse)"); + 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); + } + + engine.voidEval(getIsisFactorDistribution(factors)); + + engine.voidEval("call<-" + "\"isis.methodAnalyse<-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(isis.methodAnalyse)"); + 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) { + String factorName = factor.getName().replaceAll(" ", ""); + engine.remove(factorName); + } + + closeEngine(engine, outputDirectory); + + } 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 simulationName = outputDirectory.getName().replaceAll("-", ""); + SimulationParameter param = simulationStorage1.getParameter(); + int sensitivityNumber = param.getSensitivityExport().size(); + //List<SensitivityExport> export = param.getSensitivityExport(); + + try { + REngine engine = openEngine(outputDirectory); + + engine.voidEval("factors<-data.frame(isis.methodAnalyse)"); + + //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(isis.factor.distribution$NomFacteur,\"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 + String exportMethodAnalyse = String.format("%s.isis.methodAnalyse", simulationName + "." + name); + engine.voidEval(exportMethodAnalyse + "<-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(" + exportMethodAnalyse + "," + + "\"nomModel\")<-\"isis-fish-externe-R\""); + } + + closeEngine(engine, outputDirectory); + + } 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: trunk/sensitivityanalysis/RegularExpandGrid.java (from rev 317, branches/4.2.2/sensitivityanalysis/RegularExpandGrid.java) =================================================================== --- trunk/sensitivityanalysis/RegularExpandGrid.java (rev 0) +++ trunk/sensitivityanalysis/RegularExpandGrid.java 2014-04-17 16:44:56 UTC (rev 318) @@ -0,0 +1,344 @@ +/* + * #%L + * IsisFish data + * %% + * 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 + * 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.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 = openEngine(outputDirectory); + + //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 = 0.0; + Double max = 1.0; + + for (int i = 0; i < card; i++) { + //add the ith value + vector += (min + (i * (max - min) / (card - 1))) + ","; + } + } + + if (domain instanceof DiscreteDomain) { + int nbValues = ((DiscreteDomain) domain).getValuesCount(); + 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 = "isis.methodAnalyse<-expand.grid(%s)"; + + String rCall = String.format(expandGrid,factorsNames); + + if (param_modifR) { + rCall = editRInstruction(rCall); + } + + engine.voidEval(rCall); + + engine.eval("expPlan<-as.data.frame(isis.methodAnalyse)"); + RDataFrame dataFrame = (RDataFrame)engine.eval("expPlan"); + dataFrame.setVariable("expPlan"); + int nbExperiments = (Integer)engine.eval("dim(isis.methodAnalyse)[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 += "\"[0.0;1.0]\""; + } 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<-isis.methodAnalyse"); + engine.voidEval("attr(isis.simule," + + "\"nomModel\")<-\"isis-fish-externe-R\""); + engine.voidEval("names(isis.simule)<-isis.factors[[1]]"); + + closeEngine(engine, outputDirectory); + + } 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 = openEngine(outputDirectory); + + //Get back the factors number + int factorNumber = (Integer)engine.eval("dim(isis.methodAnalyse)[2]"); + + SimulationParameter param = simulationStorages.get(0).getParameter(); + int sensitivityNumber = param.getSensitivityExport().size(); + + String firstStorageName = outputDirectory.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(isis.methodAnalyse," + + 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(isis.methodAnalyse)[" + (j + 1) + "]") + + "+"; + } else { + aovCall = aovCall + + engine.eval("names(isis.methodAnalyse)[" + (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 + String exportMethodAnalyse = String.format("%s.isis.methodAnalyse", firstStorageName + "." + name); + engine.voidEval(exportMethodAnalyse + "<-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(" + exportMethodAnalyse + "," + + "\"nomModel\")<-\"isis-fish-externe-R\""); + } + + closeEngine(engine, outputDirectory); + + } catch (Exception e) { + throw new SensitivityException("Can't evaluate results", e); + } + + } + + @Override + public String getDescription() { + return "Implementation of Expand Grid method using R"; + } +} Copied: trunk/sensitivityanalysis/RegularFractions.java (from rev 317, branches/4.2.2/sensitivityanalysis/RegularFractions.java) =================================================================== --- trunk/sensitivityanalysis/RegularFractions.java (rev 0) +++ trunk/sensitivityanalysis/RegularFractions.java 2014-04-17 16:44:56 UTC (rev 318) @@ -0,0 +1,343 @@ +/* + * #%L + * IsisFish data + * %% + * 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 + * 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.types.RDataFrame; + +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.simulator.SimulationParameter; +import fr.ifremer.isisfish.simulator.sensitivity.*; +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 + checkAllFactorContinuous(factors); + + //Create a string with all factors names + for (int i = 0; i < factorNumber; i++) { + if (i != 0) { + factorNames += ","; + } + + factorNames += "\"" + factors.get(i).getName() + "\""; + } + + try { + + REngine engine = openEngine(outputDirectory); + + //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 = "isis.methodAnalyse<-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(isis.methodAnalyse[[1]])"); + dataFrame = (RDataFrame)engine.eval("expPlan"); + dataFrame.setVariable("expPlan"); + + //Get back the simulation number + int simulationNumber = (Integer) engine.eval("length(isis.methodAnalyse[[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); + factor.setValueForIdentifier(dataFrame.get(i,j)); + 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(getIsisFactorDistribution(factors)); + + 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]]"); + + closeEngine(engine, outputDirectory); + + } 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 = outputDirectory.getName().replaceAll("-", ""); + + try { + + REngine engine = openEngine(outputDirectory); + + //Get back the factors number + int factorNumber = (Integer) engine.eval("dim(isis.simule)[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(isis.simule," + + 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(isis.simule)[" + (j + 1) + "]") + + "+"; + } else { + aovCall = aovCall + + engine.eval("names(isis.simule)[" + (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(isis.factor.distribution$NomFacteur,\"Result\")"); + engine.voidEval("names(dataforaov)<-isis.factor.distribution$NomFacteur"); + + /*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 + String exportMethodAnalyse = String.format("%s.isis.methodAnalyse", simulationName + "." + name); + engine.voidEval(exportMethodAnalyse + "<-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(" + exportMethodAnalyse + "," + + "\"nomModel\")<-\"isis-fish-externe-R\""); + } + + closeEngine(engine, outputDirectory); + + } catch (Exception eee) { + throw new SensitivityException("Can't evaluate results", eee); + } + + } + + @Override + public String getDescription() { + return "Implementation of Regular fractions method using R"; + } + +} Deleted: trunk/sensitivityanalysis/SensitivityCalculatorJavaExpandGrid.java =================================================================== --- trunk/sensitivityanalysis/SensitivityCalculatorJavaExpandGrid.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityanalysis/SensitivityCalculatorJavaExpandGrid.java 2014-04-17 16:44:56 UTC (rev 318) @@ -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: trunk/sensitivityanalysis/SensitivityCalculatorRDOptimal.java =================================================================== --- trunk/sensitivityanalysis/SensitivityCalculatorRDOptimal.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityanalysis/SensitivityCalculatorRDOptimal.java 2014-04-17 16:44:56 UTC (rev 318) @@ -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: trunk/sensitivityanalysis/SensitivityCalculatorRExpandGrid.java =================================================================== --- trunk/sensitivityanalysis/SensitivityCalculatorRExpandGrid.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityanalysis/SensitivityCalculatorRExpandGrid.java 2014-04-17 16:44:56 UTC (rev 318) @@ -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: trunk/sensitivityanalysis/SensitivityCalculatorRFast.java =================================================================== --- trunk/sensitivityanalysis/SensitivityCalculatorRFast.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityanalysis/SensitivityCalculatorRFast.java 2014-04-17 16:44:56 UTC (rev 318) @@ -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: trunk/sensitivityanalysis/SensitivityCalculatorRFrF2.java =================================================================== --- trunk/sensitivityanalysis/SensitivityCalculatorRFrF2.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityanalysis/SensitivityCalculatorRFrF2.java 2014-04-17 16:44:56 UTC (rev 318) @@ -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: trunk/sensitivityanalysis/SensitivityCalculatorRMorris.java =================================================================== --- trunk/sensitivityanalysis/SensitivityCalculatorRMorris.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityanalysis/SensitivityCalculatorRMorris.java 2014-04-17 16:44:56 UTC (rev 318) @@ -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: trunk/sensitivityanalysis/SensitivityCalculatorROptimumLHS.java =================================================================== --- trunk/sensitivityanalysis/SensitivityCalculatorROptimumLHS.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityanalysis/SensitivityCalculatorROptimumLHS.java 2014-04-17 16:44:56 UTC (rev 318) @@ -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: trunk/sensitivityanalysis/SensitivityCalculatorRRandomLHS.java =================================================================== --- trunk/sensitivityanalysis/SensitivityCalculatorRRandomLHS.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityanalysis/SensitivityCalculatorRRandomLHS.java 2014-04-17 16:44:56 UTC (rev 318) @@ -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: trunk/sensitivityanalysis/SensitivityCalculatorRSobol.java =================================================================== --- trunk/sensitivityanalysis/SensitivityCalculatorRSobol.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityanalysis/SensitivityCalculatorRSobol.java 2014-04-17 16:44:56 UTC (rev 318) @@ -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: trunk/sensitivityanalysis/SensitivityCalculatorRegularFractions.java =================================================================== --- trunk/sensitivityanalysis/SensitivityCalculatorRegularFractions.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityanalysis/SensitivityCalculatorRegularFractions.java 2014-04-17 16:44:56 UTC (rev 318) @@ -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: trunk/sensitivityanalysis/Sobol.java (from rev 317, branches/4.2.2/sensitivityanalysis/Sobol.java) =================================================================== --- trunk/sensitivityanalysis/Sobol.java (rev 0) +++ trunk/sensitivityanalysis/Sobol.java 2014-04-17 16:44:56 UTC (rev 318) @@ -0,0 +1,286 @@ +/* + * #%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.apache.commons.lang3.StringUtils; +import org.nuiton.j2r.REngine; + +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.simulator.SimulationParameter; +import fr.ifremer.isisfish.util.Doc; + +import org.nuiton.j2r.types.RDataFrame; + +/** + * Implementation of Sobol method using R. + * + * @author jcouteau + * @version $Revision: 3842 $ + * + * Last update : $Date: 2013-11-22 18:52:48 +0100 (ven., 22 nov. 2013) $ 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(); + + checkAllFactorContinuous(factors); + + String rInstruction = "isis.methodAnalyse<-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 = openEngine(outputDirectory); + + engine.voidEval("library(sensitivity)"); + + 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. + 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("isis.methodAnalyse$X"); + dataFrame.setVariable("isis.methodAnalyse$X"); + + nbExperiments = dataFrame.dim()[0]; + + engine.voidEval(getIsisFactorDistribution(factors)); + + engine.voidEval("call<-isis.methodAnalyse$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(isis.methodAnalyse$X)"); + + engine.voidEval("attr(isis.simule," + + "\"nomModel\")<-\"isis-fish-externe-R\""); + + engine.voidEval("names(isis.simule)<-isis.factors[[1]]"); + + // 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); + } + + closeEngine(engine, outputDirectory); + + } 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 = outputDirectory.getName().replaceAll("-", ""); + + try { + + REngine engine = openEngine(outputDirectory); + + // 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(isis.methodAnalyse$S)<-names(isis.methodAnalyse$X)"); + engine.voidEval("row.names(isis.methodAnalyse$T)<-names(isis.methodAnalyse$X)"); + engine.voidEval("row.names(isis.methodAnalyse$V)<-c(\"global\"," + + "names(isis.methodAnalyse$X),paste(\"-\",names(isis.methodAnalyse$X),sep=\"\"))"); + + //creating isis.methodAnalyse + String exportMethodAnalyse = String.format("%s.isis.methodAnalyse", simulationName + "." + name); + engine.voidEval(exportMethodAnalyse + "<-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(" + exportMethodAnalyse + "," + + "\"nomModel\")<-\"isis-fish-externe-R\")"); + + //Create the data.frame of scenarios and results for export purpose + engine.voidEval("dfresults<-data.frame(isis.methodAnalyse$X,isis.methodAnalyse$y)"); + + //Set working directory + engine.setwd(outputDirectory); + + //Export V + engine.voidEval("write.csv(isis.methodAnalyse$V,\"" + + name + + "_SensitivityIndices.csv\")"); + //Export DD + engine.voidEval("write.csv(isis.methodAnalyse$D,\"" + + name + "_D.csv\")"); + + //Export S + engine.voidEval("write.csv(isis.methodAnalyse$S,\"" + + name + "_S.csv\")"); + + //Export results + engine.voidEval("write.csv(dfresults,\"" + + name + "_Results.csv\")"); + //FIXME export through java to enable export when using Rserve + + } + + closeEngine(engine, outputDirectory); + } 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)"; + } +} Modified: trunk/sensitivityexports/SensitivityBiomassReferenceY9.java =================================================================== --- trunk/sensitivityexports/SensitivityBiomassReferenceY9.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivityBiomassReferenceY9.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 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 @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.File; import java.io.Writer; @@ -113,7 +111,7 @@ @Override public String getDescription() { - return _("Biomass for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass for the last time step. Biomass is the sum on the groups and zones"; } @Override Modified: trunk/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java =================================================================== --- trunk/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivityBiomassRelativeReferenceY12.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 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 @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.File; import java.io.Writer; @@ -121,7 +119,7 @@ @Override public String getDescription() { - return _("Biomass for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass for the last time step. Biomass is the sum on the groups and zones"; } @Override Modified: trunk/sensitivityexports/SensitivityBiomassRelativeY6.java =================================================================== --- trunk/sensitivityexports/SensitivityBiomassRelativeY6.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivityBiomassRelativeY6.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 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 @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -77,7 +75,7 @@ @Override public String getDescription() { - return _("Biomass for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass for the last time step. Biomass is the sum on the groups and zones"; } @Override Modified: trunk/sensitivityexports/SensitivityBiomassY3.java =================================================================== --- trunk/sensitivityexports/SensitivityBiomassY3.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivityBiomassY3.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 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 @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -67,7 +65,7 @@ @Override public String getDescription() { - return _("Biomass for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass for the last time step. Biomass is the sum on the groups and zones"; } @Override Property changes on: trunk/sensitivityexports/SensitivityBiomassY3.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/sensitivityexports/SensitivityCatchWeightReferenceY7.java =================================================================== --- trunk/sensitivityexports/SensitivityCatchWeightReferenceY7.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivityCatchWeightReferenceY7.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 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 @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.File; import java.io.Writer; @@ -114,9 +112,9 @@ @Override public String getDescription() { - return _("Captures in weight for the last year for the popage " + + return "Captures in weight for the last year for the popage " + "population. Captures is the sum of zones, groups, metiers " + - "and strategies"); + "and strategies"; } @Override Property changes on: trunk/sensitivityexports/SensitivityCatchWeightReferenceY7.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java =================================================================== --- trunk/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 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 @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.File; import java.io.Writer; @@ -39,14 +37,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; @@ -129,7 +128,7 @@ @Override public String getDescription() { - return _("Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"); + return "Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"; } @Override Property changes on: trunk/sensitivityexports/SensitivityCatchWeightRelativeReferenceY10.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/sensitivityexports/SensitivityCatchWeightRelativeY4.java =================================================================== --- trunk/sensitivityexports/SensitivityCatchWeightRelativeY4.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivityCatchWeightRelativeY4.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 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 @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -43,7 +41,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; @@ -85,7 +85,7 @@ @Override public String getDescription() { - return _("Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"); + return "Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"; } @Override Property changes on: trunk/sensitivityexports/SensitivityCatchWeightRelativeY4.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/sensitivityexports/SensitivityCatchWeightY1.java =================================================================== --- trunk/sensitivityexports/SensitivityCatchWeightY1.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivityCatchWeightY1.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 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 @@ -21,8 +21,6 @@ */ package sensitivityexports; -import static org.nuiton.i18n.I18n._; - import java.io.Writer; import org.apache.commons.logging.Log; @@ -43,7 +41,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; @@ -76,7 +76,7 @@ @Override public String getDescription() { - return _("Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"); + return "Captures in weight for the last year for the popage population. Captures is the sum of zones, groups, metiers and strategies"; } @Override Property changes on: trunk/sensitivityexports/SensitivityCatchWeightY1.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java =================================================================== --- trunk/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric + * Copyright (C) 2009 - 2014 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 @@ -42,21 +42,21 @@ import java.util.List; import java.util.Map; -import static org.nuiton.i18n.I18n._; - public class SensitivitySpawningBiomassReferenceY8 implements SensitivityExport { /** to use log facility, just put in your code: log.info("..."); */ 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) @@ -134,7 +134,7 @@ @Override public String getDescription() { - return _("Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"; } @Override Property changes on: trunk/sensitivityexports/SensitivitySpawningBiomassReferenceY8.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java =================================================================== --- trunk/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric + * Copyright (C) 2009 - 2014 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 @@ -42,8 +42,6 @@ import java.util.List; import java.util.Map; -import static org.nuiton.i18n.I18n._; - public class SensitivitySpawningBiomassRelativeReferenceY11 implements SensitivityExport { @@ -57,7 +55,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) @@ -160,7 +158,7 @@ @Override public String getDescription() { - return _("Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"; } @Override Property changes on: trunk/sensitivityexports/SensitivitySpawningBiomassRelativeReferenceY11.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java =================================================================== --- trunk/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric + * Copyright (C) 2009 - 2014 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 @@ -37,15 +37,15 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; - public class SensitivitySpawningBiomassRelativeY5 implements SensitivityExport { /** to use log facility, just put in your code: log.info("..."); */ 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; @@ -94,7 +94,7 @@ @Override public String getDescription() { - return _("Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"; } @Override Property changes on: trunk/sensitivityexports/SensitivitySpawningBiomassRelativeY5.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/sensitivityexports/SensitivitySpawningBiomassY2.java =================================================================== --- trunk/sensitivityexports/SensitivitySpawningBiomassY2.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/sensitivityexports/SensitivitySpawningBiomassY2.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2012 Ifremer, Code Lutin, Jean Couteau, Chatellier Eric + * Copyright (C) 2009 - 2014 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 @@ -37,15 +37,15 @@ import java.io.Writer; -import static org.nuiton.i18n.I18n._; - public class SensitivitySpawningBiomassY2 implements SensitivityExport { /** to use log facility, just put in your code: log.info("..."); */ 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; @@ -79,7 +79,7 @@ @Override public String getDescription() { - return _("Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"); + return "Biomass of the genitors for the last time step. Biomass is the sum on the groups and zones"; } @Override Property changes on: trunk/sensitivityexports/SensitivitySpawningBiomassY2.java ___________________________________________________________________ Deleted: svn:mergeinfo - Modified: trunk/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java =================================================================== --- trunk/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/simulationplans/CalibrationSimplexePasVariable2Capturabilite.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2007 - 2011 Ifremer, CodeLutin, Sigrid Lehuta + * Copyright (C) 2007 - 2014 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 @@ -21,8 +21,6 @@ */ package simulationplans; -import static org.nuiton.i18n.I18n._; - import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -37,16 +35,16 @@ import org.nuiton.util.FileUtil; import org.nuiton.util.StringUtil; +import scripts.ResultName; import fr.ifremer.isisfish.datastore.ResultStorage; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.entities.Population; import fr.ifremer.isisfish.entities.PopulationGroup; -import fr.ifremer.isisfish.simulator.SimulationPlanContext; import fr.ifremer.isisfish.simulator.SimulationPlan; +import fr.ifremer.isisfish.simulator.SimulationPlanContext; import fr.ifremer.isisfish.util.Doc; +import fr.ifremer.isisfish.util.ScriptUtil; -import scripts.ResultName; - /** * CalibrationSimplexePasVariable2Capturabilite. * @@ -110,7 +108,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 }; @@ -123,9 +121,9 @@ * @return L'aide ou la description du plan */ public String getDescription() throws Exception { - return _("Calibration using variable step Simplex method (Walters): user" + + return "Calibration using variable step Simplex method (Walters): user" + "gives a file of observations (here catches)(.csv), simulated output" + - "will try to approach oservations by changing the values of catchability"); + "will try to approach oservations by changing the values of catchability"; } /** @@ -385,7 +383,7 @@ exportHisto += experiences.getExperience(number).q1 + ";" + experiences.getExperience(number).q2 + ";" + experiences.getExperience(number).criteria + "\n"; - org.nuiton.util.FileUtil.writeString(exportHistoric, exportHisto); + ScriptUtil.writeString(exportHistoric, exportHisto); return doNext; }// fin du after simulation Modified: trunk/simulationplans/SimulationNumberRestriction.java =================================================================== --- trunk/simulationplans/SimulationNumberRestriction.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/simulationplans/SimulationNumberRestriction.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2011 Ifremer, CodeLutin + * Copyright (C) 2006 - 2014 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 @@ -21,8 +21,6 @@ */ package simulationplans; -import static org.nuiton.i18n.I18n._; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -49,11 +47,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 @@ -68,7 +66,7 @@ */ @Override public String getDescription() throws Exception { - return _("Permit to specify maximum simulation numbers"); + return "Permit to specify maximum simulation numbers"; } /** Modified: trunk/simulators/DefaultSimulator.java =================================================================== --- trunk/simulators/DefaultSimulator.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/simulators/DefaultSimulator.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2006 - 2012 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin, Chatellier Eric + * Copyright (C) 2006 - 2014 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 @@ -49,8 +49,8 @@ import java.util.List; -import static org.nuiton.i18n.I18n._; -import static org.nuiton.i18n.I18n.n_; +import static org.nuiton.i18n.I18n.t; +import static org.nuiton.i18n.I18n.n; /** * DefaultSimulator.java @@ -132,12 +132,12 @@ control.setStep(step); control.setProgress(step.getStep()); - control.setText(_("begin step " + step)); + control.setText(t("begin step " + step)); // // Reload parameters for current step // - control.setText(_("Reloading parameters")); + control.setText(t("Reloading parameters")); // reload context parameters with db.rollbackTransaction() context param.reloadContextParameters(); rules = param.getRules(); @@ -287,9 +287,9 @@ siMatrix.getMetiers(step), pop.getPopulationGroup(), pop.getPopulationZone() }, - new String[] { n_("Strategies"), - n_("Metiers"), n_("Groups"), - n_("Zones") }); + new String[] { n("Strategies"), + n("Metiers"), n("Groups"), + n("Zones") }); } resManager.addResult(step, pop, discard); @@ -410,7 +410,7 @@ log.debug("N after mig: " + N); - //Recrutement + // reproduction MatrixND R = info.getReproductionMatrix(month, N); log.debug("R: " + R); Modified: trunk/simulators/SimulatorEffortByCell.java =================================================================== --- trunk/simulators/SimulatorEffortByCell.java 2014-04-17 14:57:23 UTC (rev 317) +++ trunk/simulators/SimulatorEffortByCell.java 2014-04-17 16:44:56 UTC (rev 318) @@ -2,7 +2,7 @@ * #%L * IsisFish data * %% - * Copyright (C) 2009 - 2013 Ifremer, Code Lutin, Benjamin Poussin + * Copyright (C) 2009 - 2014 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
participants (1)
-
echatellier@users.forge.codelutin.com