Skip to content
Snippets Groups Projects
Commit f14bb865 authored by Hugo Roussel's avatar Hugo Roussel
Browse files

Merge branch 'endogenousRequests' into dev

parents 68f02464 a29ffb0c
Branches
No related tags found
2 merge requests!3Merge masters,!2Merge dev into develop
...@@ -108,7 +108,8 @@ public class Context extends AmoebaAgent { ...@@ -108,7 +108,8 @@ public class Context extends AmoebaAgent {
for (Percept p : var) { for (Percept p : var) {
Range r; Range r;
Pair<Double, Double> radiuses = getAmas().getHeadAgent().getMaxRadiusesForContextCreation(p); //Pair<Double, Double> radiuses = getAmas().getHeadAgent().getMaxRadiusesForContextCreation(p);
Pair<Double, Double> radiuses = getAmas().getHeadAgent().getRadiusesForContextCreation(p);
r = new Range(this, p.getValue() - radiuses.getA(), p.getValue() + radiuses.getB(), 0, true, true, p); r = new Range(this, p.getValue() - radiuses.getA(), p.getValue() + radiuses.getB(), 0, true, true, p);
...@@ -122,7 +123,7 @@ public class Context extends AmoebaAgent { ...@@ -122,7 +123,7 @@ public class Context extends AmoebaAgent {
p.addContextProjection(this); p.addContextProjection(this);
} }
expand(); //expand();
localModel = getAmas().buildLocalModel(this); localModel = getAmas().buildLocalModel(this);
firstPoint.setOracleProposition(getAmas().getHeadAgent().getOracleValue()); firstPoint.setOracleProposition(getAmas().getHeadAgent().getOracleValue());
...@@ -181,7 +182,9 @@ public class Context extends AmoebaAgent { ...@@ -181,7 +182,9 @@ public class Context extends AmoebaAgent {
ArrayList<Percept> var = getAmas().getPercepts(); ArrayList<Percept> var = getAmas().getPercepts();
for (Percept v : var) { for (Percept v : var) {
Range r; Range r;
Pair<Double, Double> radiuses = getAmas().getHeadAgent().getMaxRadiusesForContextCreation(v); //Pair<Double, Double> radiuses = getAmas().getHeadAgent().getMaxRadiusesForContextCreation(v);
Pair<Double, Double> radiuses = getAmas().getHeadAgent().getRadiusesForContextCreation(v);
r = new Range(this, v.getValue() - radiuses.getA(), v.getValue() + radiuses.getB(), 0, true, true, v); r = new Range(this, v.getValue() - radiuses.getA(), v.getValue() + radiuses.getB(), 0, true, true, v);
...@@ -193,7 +196,7 @@ public class Context extends AmoebaAgent { ...@@ -193,7 +196,7 @@ public class Context extends AmoebaAgent {
v.addContextProjection(this);; v.addContextProjection(this);;
} }
expand(); //expand();
this.confidence = bestNearestContext.confidence; this.confidence = bestNearestContext.confidence;
if (bestNearestContext.getLocalModel().getType() == TypeLocalModel.MILLER_REGRESSION) { if (bestNearestContext.getLocalModel().getType() == TypeLocalModel.MILLER_REGRESSION) {
...@@ -562,7 +565,7 @@ public class Context extends AmoebaAgent { ...@@ -562,7 +565,7 @@ public class Context extends AmoebaAgent {
for (Percept pct : getAmas().getPercepts()) { for (Percept pct : getAmas().getPercepts()) {
currentDistance = this.distance(ctxt, pct); currentDistance = this.distance(ctxt, pct);
if(currentDistance<-pct.getMappingErrorAllowedMin() && getAmas().getCycle()>1000) { if(currentDistance<-pct.getMappingErrorAllowedMin() && getAmas().getCycle()>500) {
getEnvironment().trace(TRACE_LEVEL.DEBUG,new ArrayList<String>(Arrays.asList("OVERLAP",pct.getName(), ""+this,""+ctxt)) ); getEnvironment().trace(TRACE_LEVEL.DEBUG,new ArrayList<String>(Arrays.asList("OVERLAP",pct.getName(), ""+this,""+ctxt)) );
overlapCounts+=1; overlapCounts+=1;
overlapDistances.put(pct, Math.abs(currentDistance)); overlapDistances.put(pct, Math.abs(currentDistance));
...@@ -572,7 +575,7 @@ public class Context extends AmoebaAgent { ...@@ -572,7 +575,7 @@ public class Context extends AmoebaAgent {
} }
if (currentDistance > pct.getMappingErrorAllowedMin() && getAmas().getCycle()>2000) { if (currentDistance > pct.getMappingErrorAllowedMin() && getAmas().getCycle()>1000) {
getEnvironment().trace(TRACE_LEVEL.DEBUG,new ArrayList<String>(Arrays.asList("VOID",pct.getName(), ""+this,""+ctxt, "distance", ""+currentDistance)) ); getEnvironment().trace(TRACE_LEVEL.DEBUG,new ArrayList<String>(Arrays.asList("VOID",pct.getName(), ""+this,""+ctxt, "distance", ""+currentDistance)) );
voidDistances.put(pct, currentDistance); voidDistances.put(pct, currentDistance);
bounds.put(pct, this.voidBounds(ctxt, pct)); bounds.put(pct, this.voidBounds(ctxt, pct));
...@@ -584,7 +587,7 @@ public class Context extends AmoebaAgent { ...@@ -584,7 +587,7 @@ public class Context extends AmoebaAgent {
} }
if (overlapCounts == getAmas().getPercepts().size()) { if (overlapCounts == getAmas().getPercepts().size() && getAmas().getCycle() > 500) {
getEnvironment().trace(TRACE_LEVEL.INFORM, new ArrayList<String>(Arrays.asList(getAmas().getPercepts().size() + "OVERLAPS", ""+this,""+ctxt)) ); getEnvironment().trace(TRACE_LEVEL.INFORM, new ArrayList<String>(Arrays.asList(getAmas().getPercepts().size() + "OVERLAPS", ""+this,""+ctxt)) );
...@@ -593,14 +596,14 @@ public class Context extends AmoebaAgent { ...@@ -593,14 +596,14 @@ public class Context extends AmoebaAgent {
return new EndogenousRequest(request, bounds, 7, new ArrayList<Context>(Arrays.asList(this,ctxt)), REQUEST.OVERLAP); return new EndogenousRequest(request, bounds, 7, new ArrayList<Context>(Arrays.asList(this,ctxt)), REQUEST.OVERLAP);
} }
} }
else if(overlapCounts == getAmas().getPercepts().size()-1 && voidDistances.size() == 1) { else if(overlapCounts == getAmas().getPercepts().size()-1 && voidDistances.size() == 1 && getAmas().getCycle() > 750) {
getEnvironment().trace(TRACE_LEVEL.INFORM, new ArrayList<String>(Arrays.asList("VOID", ""+this,""+ctxt)) ); getEnvironment().trace(TRACE_LEVEL.INFORM, new ArrayList<String>(Arrays.asList("VOID", ""+this,""+ctxt)) );
HashMap<Percept, Double> request = boundsToRequest(bounds); HashMap<Percept, Double> request = boundsToRequest(bounds);
if(request != null) { if(request != null) {
if(getAmas().getHeadAgent().isVoid(request)) { if(getAmas().getHeadAgent().isRealVoid(request)) {
return new EndogenousRequest(request, bounds, 5, new ArrayList<Context>(Arrays.asList(this,ctxt)), REQUEST.VOID); return new EndogenousRequest(request, bounds, 5, new ArrayList<Context>(Arrays.asList(this,ctxt)), REQUEST.VOID);
} }
} }
......
...@@ -107,9 +107,9 @@ public class Head extends AmoebaAgent { ...@@ -107,9 +107,9 @@ public class Head extends AmoebaAgent {
} }
private void playWithOracle() { private void playWithOracle() {
getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("\n\n")));
getAmas().data.executionTimes[0]=System.currentTimeMillis(); getAmas().data.executionTimes[0]=System.currentTimeMillis();
getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("\n------------------------------------------------------------------------------------" getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("------------------------------------------------------------------------------------"
+ "---------------------------------------- PLAY WITH ORACLE"))); + "---------------------------------------- PLAY WITH ORACLE")));
if (activatedContexts.size() > 0) { if (activatedContexts.size() > 0) {
...@@ -1693,6 +1693,14 @@ public class Head extends AmoebaAgent { ...@@ -1693,6 +1693,14 @@ public class Head extends AmoebaAgent {
} }
public Pair<Double, Double> getRadiusesForContextCreation(Percept pct) {
return new Pair<Double, Double>(
pct.getRadiusContextForCreation(),
pct.getRadiusContextForCreation());
}
public Pair<Double, Double> getMaxRadiusesForContextCreation(Percept pct) { public Pair<Double, Double> getMaxRadiusesForContextCreation(Percept pct) {
// Pair<Double, Double> maxRadiuses = new Pair<Double, Double>( // Pair<Double, Double> maxRadiuses = new Pair<Double, Double>(
// Math.min(pct.getRadiusContextForCreation(), Math.abs(pct.getMin() - pct.getValue())), // Math.min(pct.getRadiusContextForCreation(), Math.abs(pct.getMin() - pct.getValue())),
...@@ -1853,15 +1861,21 @@ public class Head extends AmoebaAgent { ...@@ -1853,15 +1861,21 @@ public class Head extends AmoebaAgent {
} }
public boolean isVoid(HashMap<Percept, Double> request) { public boolean isRealVoid(HashMap<Percept, Double> request) {
boolean test; boolean test;
for(Context ctxt : activatedNeighborsContexts) { for(Context ctxt : activatedNeighborsContexts) {
test = true; test = true;
for(Percept pct : getAmas().getPercepts()) { for(Percept pct : getAmas().getPercepts()) {
test = test && ctxt.getRanges().get(pct).contains2(request.get(pct)); // test = test && ctxt.getRanges().get(pct).contains2(request.get(pct));
test = test && ctxt.getRanges().get(pct).contains(request.get(pct), pct.getMappingErrorAllowedMin());
} }
getEnvironment().trace(TRACE_LEVEL.DEBUG, new ArrayList<String>(Arrays.asList("IS REAL VOID",ctxt.getName(), "-->", ""+!test)));
if(test) { if(test) {
return false; return false;
} }
......
...@@ -23,8 +23,8 @@ public class Percept extends AmoebaAgent { ...@@ -23,8 +23,8 @@ public class Percept extends AmoebaAgent {
private HashSet<Context> validContextProjection = new HashSet<Context>(); private HashSet<Context> validContextProjection = new HashSet<Context>();
private HashSet<Context> neighborContextProjection = new HashSet<Context>(); private HashSet<Context> neighborContextProjection = new HashSet<Context>();
private double min = Double.MAX_VALUE; private double min = Double.POSITIVE_INFINITY;
private double max = Double.MIN_VALUE; private double max = Double.NEGATIVE_INFINITY;
private double value; private double value;
......
...@@ -77,7 +77,7 @@ public class Main implements Runnable { ...@@ -77,7 +77,7 @@ public class Main implements Runnable {
Configuration.plotMilliSecondsUpdate = 20000; Configuration.plotMilliSecondsUpdate = 20000;
AMOEBA amoeba = new AMOEBA(); AMOEBA amoeba = new AMOEBA();
StudiedSystem studiedSystem = new F_N_Manager(spaceSize, dimension, nbOfModels, normType, randomExploration, explorationIncrement,explorationWidht,limitedToSpaceZone); StudiedSystem studiedSystem = new F_N_Manager(spaceSize, dimension, nbOfModels, normType, randomExploration, explorationIncrement,explorationWidht,limitedToSpaceZone, oracleNoiseRange);
amoeba.setStudiedSystem(studiedSystem); amoeba.setStudiedSystem(studiedSystem);
IBackupSystem backupSystem = new BackupSystem(amoeba); IBackupSystem backupSystem = new BackupSystem(amoeba);
File file = new File("resources/threeDimensionsLauncherUnity.xml"); File file = new File("resources/threeDimensionsLauncherUnity.xml");
......
...@@ -8,6 +8,9 @@ import java.util.ArrayList; ...@@ -8,6 +8,9 @@ import java.util.ArrayList;
import experiments.FILE; import experiments.FILE;
import fr.irit.smac.amak.Configuration; import fr.irit.smac.amak.Configuration;
import gui.AmoebaWindow; import gui.AmoebaWindow;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.Slider;
import kernel.AMOEBA; import kernel.AMOEBA;
import kernel.StudiedSystem; import kernel.StudiedSystem;
import kernel.backup.BackupSystem; import kernel.backup.BackupSystem;
...@@ -21,16 +24,17 @@ import kernel.backup.SaveHelperImpl; ...@@ -21,16 +24,17 @@ import kernel.backup.SaveHelperImpl;
public class F_N_Launcher implements Serializable { public class F_N_Launcher implements Serializable {
public static final double oracleNoiseRange = 0.0; public static final double oracleNoiseRange = 0.5;
public static final double learningSpeed = 0.01; public static final double learningSpeed = 0.01;
public static final int regressionPoints = 100; public static final int regressionPoints = 100;
public static final int dimension = 2; public static final int dimension = 2;
public static final double spaceSize = 50.0 ; public static final double spaceSize = 50.0 ;
public static final int nbOfModels = 3 ; public static final int nbOfModels = 3 ;
public static final int normType = 2 ; public static final int normType = 2 ;
public static final boolean randomExploration = true; public static final boolean randomExploration = false;
public static final boolean limitedToSpaceZone = true; public static final boolean limitedToSpaceZone = true;
public static final double mappingErrorAllowed = 0.03; //public static final double mappingErrorAllowed = 0.07; // BIG SQUARE
public static double mappingErrorAllowed = 0.03; // MULTI
public static final double explorationIncrement = 1.0 ; public static final double explorationIncrement = 1.0 ;
public static final double explorationWidht = 0.5 ; public static final double explorationWidht = 0.5 ;
...@@ -60,7 +64,7 @@ public class F_N_Launcher implements Serializable { ...@@ -60,7 +64,7 @@ public class F_N_Launcher implements Serializable {
Configuration.plotMilliSecondsUpdate = 20000; Configuration.plotMilliSecondsUpdate = 20000;
AMOEBA amoeba = new AMOEBA(); AMOEBA amoeba = new AMOEBA();
StudiedSystem studiedSystem = new F_N_Manager(spaceSize, dimension, nbOfModels, normType, randomExploration, explorationIncrement,explorationWidht,limitedToSpaceZone); StudiedSystem studiedSystem = new F_N_Manager(spaceSize, dimension, nbOfModels, normType, randomExploration, explorationIncrement,explorationWidht,limitedToSpaceZone, oracleNoiseRange);
amoeba.setStudiedSystem(studiedSystem); amoeba.setStudiedSystem(studiedSystem);
IBackupSystem backupSystem = new BackupSystem(amoeba); IBackupSystem backupSystem = new BackupSystem(amoeba);
File file = new File("resources/twoDimensionsLauncher.xml"); File file = new File("resources/twoDimensionsLauncher.xml");
...@@ -73,6 +77,21 @@ public class F_N_Launcher implements Serializable { ...@@ -73,6 +77,21 @@ public class F_N_Launcher implements Serializable {
amoeba.data.numberOfPointsForRegression = regressionPoints; amoeba.data.numberOfPointsForRegression = regressionPoints;
amoeba.getEnvironment().setMappingErrorAllowed(mappingErrorAllowed); amoeba.getEnvironment().setMappingErrorAllowed(mappingErrorAllowed);
// Exemple for adding a tool in the toolbar
Slider slider = new Slider(0.01, 0.1, mappingErrorAllowed);
slider.setShowTickLabels(true);
slider.setShowTickMarks(true);
slider.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
System.out.println("new Value "+newValue);
mappingErrorAllowed = (double)newValue;
amoeba.getEnvironment().setMappingErrorAllowed(mappingErrorAllowed);
}
});
AmoebaWindow.addToolbar(slider);
studiedSystem.playOneStep(); studiedSystem.playOneStep();
amoeba.learn(studiedSystem.getOutput()); amoeba.learn(studiedSystem.getOutput());
......
...@@ -41,6 +41,8 @@ public class F_N_Manager implements StudiedSystem{ ...@@ -41,6 +41,8 @@ public class F_N_Manager implements StudiedSystem{
HashMap<String,Double> selfRequest; HashMap<String,Double> selfRequest;
boolean activeLearning = false; boolean activeLearning = false;
double noiseRange;
/** The world. */ /** The world. */
Random generator; Random generator;
...@@ -53,13 +55,14 @@ public class F_N_Manager implements StudiedSystem{ ...@@ -53,13 +55,14 @@ public class F_N_Manager implements StudiedSystem{
private static final double gaussianVariance = 10; private static final double gaussianVariance = 10;
public F_N_Manager(double size, int dim, int nbOfModels, int nrmType, boolean rndExploration, double explIncrement, double explnVariation, boolean limiteToSpace) { public F_N_Manager(double size, int dim, int nbOfModels, int nrmType, boolean rndExploration, double explIncrement, double explnVariation, boolean limiteToSpace, double noise) {
this.spaceSize= size; this.spaceSize= size;
dimension = dim; dimension = dim;
numberOfModels = nbOfModels; numberOfModels = nbOfModels;
normType = nrmType; normType = nrmType;
x = new Double[dimension]; x = new Double[dimension];
noiseRange = noise;
spaceLimited = limiteToSpace; spaceLimited = limiteToSpace;
//gaussianCoef = Math.random()*2000; //gaussianCoef = Math.random()*2000;
...@@ -270,12 +273,13 @@ public class F_N_Manager implements StudiedSystem{ ...@@ -270,12 +273,13 @@ public class F_N_Manager implements StudiedSystem{
center[0]=0.0; center[0]=0.0;
center[1]=0.0; center[1]=0.0;
//return gaussianModel(xRequest, center,gaussianCoef, gaussianVariance); //return gaussianModel(xRequest, center,gaussianCoef, gaussianVariance);
//return squareSimpleModel(xRequest);
int subzone = subzone2D(xRequest); int subzone = subzone2D(xRequest);
if(subzone == 1) { if(subzone == 1) {
/* Disques */ /* Disques */
return modelN(xRequest); return modelN(xRequest) ;
}else if (subzone == 2) { }else if (subzone == 2) {
/* Gaussian model */ /* Gaussian model */
return gaussianModel(xRequest, subZoneCenter3D(2), gaussianCoef, gaussianVariance); return gaussianModel(xRequest, subZoneCenter3D(2), gaussianCoef, gaussianVariance);
...@@ -408,6 +412,13 @@ private double[] subZoneCenter3D(int nb) { ...@@ -408,6 +412,13 @@ private double[] subZoneCenter3D(int nb) {
xRequest[1] < (center[1]+spaceSize/2)) ? model1(xRequest[0],xRequest[1]) : model2(xRequest[0],xRequest[1]) ; xRequest[1] < (center[1]+spaceSize/2)) ? model1(xRequest[0],xRequest[1]) : model2(xRequest[0],xRequest[1]) ;
} }
private double squareSimpleModel(Double[] xRequest) {
return ((-spaceSize) < xRequest[0] &&
xRequest[0] < (spaceSize) &&
(-spaceSize) < xRequest[1] &&
xRequest[1] < (+spaceSize)) ? model1(xRequest[0],xRequest[1]) : model2(xRequest[0],xRequest[1]) ;
}
private double gaussianModel() { private double gaussianModel() {
double result = 1.0; double result = 1.0;
for(int i=0;i<dimension;i++) { for(int i=0;i<dimension;i++) {
......
package kernel;
import java.io.Serializable;
public enum SITUATION implements Serializable {
LEARN,
REQUEST,
CONCURENCE,
INCOMPETENCE
}
...@@ -34,7 +34,7 @@ public class World extends Environment { ...@@ -34,7 +34,7 @@ public class World extends Environment {
public static TRACE_LEVEL minLevel = TRACE_LEVEL.ERROR; public static TRACE_LEVEL minLevel = TRACE_LEVEL.DEBUG;
private AMOEBA amoeba; private AMOEBA amoeba;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment