Skip to content
Snippets Groups Projects
Commit 9148ce1e authored by BrunoDatoMeneses's avatar BrunoDatoMeneses
Browse files

ENH: n dimension launchers updates

parent e8632c10
No related branches found
No related tags found
2 merge requests!2Merge dev into develop,!1Merge Master
<?xml version="1.0" encoding="UTF-8"?>
<BlackBox>
<Inputs>
</Inputs>
<Outputs>
<Output Name="x" DefaultValue="0"></Output>
<Output Name="y" DefaultValue="0"></Output>
<Output Name="test" DefaultValue="0"></Output>
</Outputs>
<Functions>
</Functions>
</BlackBox>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<System>
<!-- General config options -->
<Configuration>
<Learning allowed = "true" creationOfNewContext = "true" loadPresetContext = "false"></Learning>
</Configuration>
<StartingAgents>
<Sensor Name="px1" Source="x1"></Sensor>
<Sensor Name="px2" Source="x2"></Sensor>
<Sensor Name="px3" Source="x3"></Sensor>
<Sensor Name="px4" Source="x4"></Sensor>
<Controller Name="Controller" Oracle="test"></Controller>
</StartingAgents>
</System>
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
<StartingAgents> <StartingAgents>
<Sensor Name="px" Source="x"></Sensor> <Sensor Name="px1" Source="x1"></Sensor>
<Sensor Name="py" Source="y"></Sensor> <Sensor Name="px2" Source="x2"></Sensor>
<Sensor Name="px3" Source="x3"></Sensor>
<Controller Name="Controller" Oracle="test"></Controller> <Controller Name="Controller" Oracle="test"></Controller>
......
package experiments.nDimensionsLaunchers;
import java.io.Serializable;
import java.util.HashMap;
import mas.agents.localModel.TypeLocalModel;
import mas.init.amoeba.AMOEBAFactory;
import mas.kernel.AMOEBA;
// TODO: Auto-generated Javadoc
/**
* The Class BadContextLauncherEasy.
*/
public class NDimLauncher implements Serializable {
public static final boolean viewer = true;
public static final boolean verboseriticity = true;
static HashMap<String,Double> output;
public static void main(String[] args) {
launch(viewer);
}
public static void launch(boolean viewer) {
/*Here we create AMOEBA.*/
AMOEBA amoeba = AMOEBAFactory.createAMOEBA(viewer,"threeDimensionsLauncher.xml");
/* These method calls allow to setup AMOEBA*/
amoeba.setLocalModel(TypeLocalModel.MILLER_REGRESSION);
/* Error parameter */
amoeba.setDataForErrorMargin(1000, 5, 0.4, 0.1, 40, 80);
amoeba.setDataForInexactMargin(500, 2.5, 0.2, 0.05, 40, 80);
/* Other parameters */
amoeba.setRememberState(false);
amoeba.setGenerateCSV(false);
// Dimension 3
NDimManager f_XY_Manager = new NDimManager(50.0, 3);
for (int i = 0 ; i < 500 ; i++) {
/*Random samples of the studied system */
f_XY_Manager.playOneStep(0);
output = f_XY_Manager.getOutput();
/*This is a learning step of AMOEBA*/
amoeba.learn(output);
}
}
}
package experiments.nDimensionsLaunchers;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Random;
import mas.kernel.StudiedSystem;
// TODO: Auto-generated Javadoc
/**
* The Class BadContextManager.
*/
public class NDimManager implements StudiedSystem, Serializable{
double[] x ;
double[] modelCoefs1;
double[] modelCoefs2;
double result = 0;
boolean firstStep = true;
double spaceSize;
Random generator;
int dim ;
public NDimManager(double size, int dimension) {
generator = new Random(29);
this.spaceSize= size;
this.dim = dimension;
x = new double[dim];
modelCoefs1 = new double[dim];
modelCoefs2 = new double[dim];
for(int i = 0; i<dimension; i++) {
x[i] = 0.0;
modelCoefs1[i] = (int) (Math.random() * 255);
modelCoefs2[i] = (int) (Math.random() * 255);
}
System.out.println("COEFS");
for(int i = 0; i<dimension; i++) {
System.out.print(modelCoefs1[i] + " ");
System.out.println(modelCoefs2[i]);
}
}
/* (non-Javadoc)
* @see kernel.StudiedSystem#playOneStep(double)
*/
@Override
public void playOneStep(double action) {
for(int i = 0; i<dim; i++) {
x[i] = (generator.nextDouble() - 0.5) * spaceSize * 4;
}
}
/* (non-Javadoc)
* @see kernel.StudiedSystem#getOutput()
*/
@Override
public HashMap<String, Double> getOutput() {
HashMap<String, Double> out = new HashMap<String, Double>();
// boolean xPositionTest = true;
// for(int i = 0; i<1; i++) {
// xPositionTest = xPositionTest && (x[i] > 0 );
// }
for(int i = 0; i<dim; i++) {
if(x[0] > 0) {
result = getModelResult(1);
}
else {
result = getModelResult(2);
}
out.put("px" + (i + 1),x[i]);
}
out.put("oracle",result);
return out;
}
/* (non-Javadoc)
* @see kernel.StudiedSystem#switchControlMode()
*/
@Override
public void switchControlMode() {
}
private double getModelResult(int num) {
double modelresult = 0.0;
if(num == 1) {
for(int i=0; i<modelCoefs1.length;i++) {
modelresult += x[i]*modelCoefs1[i];
}
}
else if(num == 2) {
for(int i=0; i<modelCoefs2.length;i++) {
modelresult += x[i]*modelCoefs2[i];
}
}
return modelresult;
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<BlackBox>
<Inputs>
</Inputs>
<Outputs>
<Output Name="x" DefaultValue="0"></Output>
<Output Name="y" DefaultValue="0"></Output>
<Output Name="test" DefaultValue="0"></Output>
</Outputs>
<Functions>
</Functions>
</BlackBox>
\ No newline at end of file
...@@ -23,7 +23,7 @@ public class F_XY_Launcher implements Serializable { ...@@ -23,7 +23,7 @@ public class F_XY_Launcher implements Serializable {
public static void launch(boolean viewer) { public static void launch(boolean viewer) {
/*Here we create AMOEBA.*/ /*Here we create AMOEBA.*/
AMOEBA amoeba = AMOEBAFactory.createAMOEBA(viewer,"BadContext_solver.xml"); AMOEBA amoeba = AMOEBAFactory.createAMOEBA(viewer,"twoDimensionsLauncher.xml");
/* These method calls allow to setup AMOEBA*/ /* These method calls allow to setup AMOEBA*/
amoeba.setLocalModel(TypeLocalModel.MILLER_REGRESSION); amoeba.setLocalModel(TypeLocalModel.MILLER_REGRESSION);
......
...@@ -57,8 +57,7 @@ public class F_XY_Manager implements StudiedSystem, Serializable{ ...@@ -57,8 +57,7 @@ public class F_XY_Manager implements StudiedSystem, Serializable{
result = (y > -spaceSize && y < spaceSize && x < spaceSize && x > -spaceSize) ? 2*x + y : 5*x - 8*y; result = (y > -spaceSize && y < spaceSize && x < spaceSize && x > -spaceSize) ? 2*x + y : 5*x - 8*y;
//result = (2*x) + (4*y) + x*y;
// result = (x > 2*y) ? 0.0 : 1.0;
out.put("px",x); out.put("px",x);
out.put("py",y); out.put("py",y);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment