[cspoker] r1392 committed - Updated concept drift (works well now)

1 view
Skip to first unread message

codesite...@google.com

unread,
Aug 18, 2010, 12:45:25 PM8/18/10
to cspoker...@googlegroups.com
Revision: 1392
Author: laurent.verbruggen
Date: Wed Aug 18 09:44:56 2010
Log: Updated concept drift (works well now)
http://code.google.com/p/cspoker/source/detail?r=1392

Modified:

/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/rule/AlternatingBot.java

/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/rule/AlternatingBotFactory.java

/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ARFFFile.java

/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ARFFPlayer.java

/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ActionTrackingVisitor.java

/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/WekaOptions.java

=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/rule/AlternatingBot.java
Tue Aug 17 17:16:29 2010
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/rule/AlternatingBot.java
Wed Aug 18 09:44:56 2010
@@ -37,19 +37,22 @@
public class AlternatingBot extends AbstractBot {

private final static Logger logger = Logger.getLogger(CallBot.class);
+
+ private long threshold;

AlternatingBot(PlayerId playerId, TableId tableId, SmartLobbyContext
lobby,
- int buyIn, ExecutorService executor, BotListener... botListeners) {
+ int buyIn, ExecutorService executor, long threshold, BotListener...
botListeners) {
super(playerId, tableId, lobby, buyIn, executor, botListeners);
+ this.threshold = threshold;
}

+ private boolean printed = false;
private long nrActions = 0;
- private final long actionSwitch = 1600;

@Override
public void doNextAction() {
nrActions++;
- if (nrActions < actionSwitch) {
+ if (nrActions < threshold) {
try {
playerContext.checkOrCall();
} catch (IllegalActionException e) {
@@ -60,8 +63,10 @@
throw new IllegalStateException("Call failed.", e);
}
} else {
- if (nrActions == actionSwitch)
+ if (nrActions > threshold && !printed) {
System.out.println("=================\nNEW BOT\n====================");
+ printed = true;
+ }
GameState gameState = playerContext.getGameState();
int deficit = gameState.getDeficit(getId());

=======================================
---
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/rule/AlternatingBotFactory.java
Tue Aug 17 17:16:29 2010
+++
/trunk/ai/bots/src/main/java/org/cspoker/ai/bots/bot/rule/AlternatingBotFactory.java
Wed Aug 18 09:44:56 2010
@@ -28,9 +28,11 @@
public class AlternatingBotFactory implements BotFactory {

private final String name;
-
- public AlternatingBotFactory(String name) {
+ private final long threshold;
+
+ public AlternatingBotFactory(String name, long threshold) {
this.name = name;
+ this.threshold = threshold;
}

/**
@@ -43,7 +45,7 @@
public Bot createBot(PlayerId playerId, TableId tableId,
SmartLobbyContext lobby, int buyIn, ExecutorService executor,
BotListener... botListeners) {
- return new CallBot(playerId, tableId, lobby, buyIn, executor,
+ return new AlternatingBot(playerId, tableId, lobby, buyIn, executor,
threshold,
botListeners);
}

=======================================
---
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ARFFFile.java
Tue Aug 17 17:15:33 2010
+++
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ARFFFile.java
Wed Aug 18 09:44:56 2010
@@ -28,9 +28,12 @@
private Instances instances;
private ArrayList<Prediction> predictions;
private M5P cl = null;
-
+
+ private boolean echo = false;
+
public ARFFFile(String path, Object player, String name, String
attributes,
WekaOptions config) throws Exception {
+// if (name.equals("PreFoldCallRaise.arff")) echo = true;
this.path = path;
this.player = player;
this.name = name;
@@ -47,6 +50,11 @@
instances.delete();

predictions = new ArrayList<Prediction>();
+
+ // initiate accuracies
+ for (int i = 0; i < MAX_DECREASE; i++) {
+ accuracies[i] = -1;
+ }
}

// private double countDataLines() {
@@ -92,8 +100,6 @@
file.write(instance.toString() + nl);
file.flush();
instances.add(instance);
-// if (count != instances.numInstances())
-// System.err.println("PROBLEM");
adjustWindow();
} catch (IOException e) {
throw new IllegalStateException(e);
@@ -101,6 +107,9 @@
}

public void addPrediction(Prediction p) {
+// if (echo) System.out.println("Adding " + p);
+ for (int i = 0; i < instances.numInstances() - predictions.size()-1; i++)
+ predictions.add(null);
predictions.add(p);
}

@@ -127,22 +136,60 @@
(trueNegative + truePositive + falseNegative + falsePositive);
}

- private double prevAcc = 0.0;
+ private final int MAX_DECREASE = 10;
+ private double[] accuracies = new double[MAX_DECREASE];
+ private int currentDecrease = 0;

private boolean decreasingAcc(double accuracy) {
- double diffAcc = accuracy - prevAcc;
- prevAcc = accuracy;
- return (diffAcc < -0.01);
+ currentDecrease++;
+ if (currentDecrease > MAX_DECREASE) {
+ for (int i = 0; i < MAX_DECREASE - 1; i++) {
+ accuracies[i] = accuracies[i+1];
+ }
+ accuracies[MAX_DECREASE - 1] = accuracy;
+ } else
+ accuracies[currentDecrease - 1] = accuracy;
+
+ double slope = calculateLeastSquaresSlope(accuracies);
+
+ return (slope < 0);
}

+ private double calculateLeastSquaresSlope(double[] accuracies) {
+ double n = accuracies.length;
+ double sumY = 0.0;
+ double sumX = 0.0;
+ double sumXY = 0.0;
+ double sumX2 = 0.0;
+ for (int i = 0; i < accuracies.length; i++) {
+ if (echo) System.out.print(accuracies[i] + ", ");
+ if (accuracies[i] != -1) {
+ sumY += accuracies[i];
+ sumX += i;
+ sumXY += i*accuracies[i];
+ sumX2 += i * i;
+ }
+ }
+
+ double slope = ((n * sumXY) - (sumX * sumY)) / ((n * sumX2) - (sumX *
sumX));
+ double intercept = (sumY - (sumX * slope)) / n;
+ if (echo) System.out.print("slope: " + slope + ", intercept: " +
intercept);
+ if (echo) System.out.println("");
+
+ return slope;
+ }
+
+ private boolean printed = false;
+
private void adjustWindow() {
if (cl == null) return;
double windowSize = instances.numInstances();
double coverage = windowSize / cl.measureNumRules();
double accuracy = getAccuracy();
+ boolean decreasing = decreasingAcc(accuracy);
double l;
if ((coverage < config.getCdLowCoverage()) ||
- (accuracy < config.getCdAccuracy() && decreasingAcc(accuracy)))
+ (accuracy < config.getCdAccuracy() && decreasing))
l = Math.round(0.2 * windowSize);
else if (coverage > 2 * config.getCdHighCoverage() &&
accuracy > config.getCdAccuracy())
@@ -153,6 +200,14 @@
else
l = 0;

+ if (echo && !printed) {
+ System.out.println("L \t Accuracy \t Coverage \t Instances \t
Decreasing");
+ printed = true;
+ }
+
+ if (echo)
+ System.out.println(l + "\t" + accuracy + "\t" + coverage + "\t" +
windowSize + "\t" + decreasing);
+
for (int i = 0; i < l; i++) {
instances.delete(0);
if (!predictions.isEmpty())
=======================================
---
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ARFFPlayer.java
Tue Aug 17 17:15:33 2010
+++
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ARFFPlayer.java
Wed Aug 18 09:44:56 2010
@@ -272,12 +272,13 @@

private void incrementWriteCounter() {
writeCounter++;
- System.out.println(
- preCheckBetFile.getAccuracy() + "\t" + preCheckBetFile.getWindowSize()
+ "\t" +
- postCheckBetFile.getAccuracy() + "\t" +
postCheckBetFile.getWindowSize() + "\t" +
- preFoldCallRaiseFile.getAccuracy() + "\t" +
preFoldCallRaiseFile.getWindowSize() + "\t" +
- postFoldCallRaiseFile.getAccuracy() + "\t" +
postFoldCallRaiseFile.getWindowSize() + "\t" +
- showdownFile.getAccuracy() + "\t" + showdownFile.getWindowSize());
+ String str = "";
+ str += preCheckBetFile.getAccuracy() + "\t" +
preCheckBetFile.getWindowSize() + "\t";
+ str += postCheckBetFile.getAccuracy() + "\t" +
postCheckBetFile.getWindowSize() + "\t";
+ str += preFoldCallRaiseFile.getAccuracy() + "\t" +
preFoldCallRaiseFile.getWindowSize() + "\t";
+ str += postFoldCallRaiseFile.getAccuracy() + "\t" +
postFoldCallRaiseFile.getWindowSize() + "\t";
+// str += showdownFile.getAccuracy() + "\t" + showdownFile.getWindowSize()
+ System.out.println(str);
// System.out.println("=" + writeCounter + "=");
}
}
=======================================
---
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ActionTrackingVisitor.java
Tue Aug 17 17:15:33 2010
+++
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/ActionTrackingVisitor.java
Wed Aug 18 09:44:56 2010
@@ -316,16 +316,18 @@
Prediction p = getProbability(allInState,
allInState.getEvent().getMovedAmount());
assimilatePrediction(allInState.getNextToAct(), p);

- if (p.getAction() instanceof CallAction)
- getPropz().logCallProb(allInState.getNextToAct(), p);
- if (p.getAction() instanceof FoldAction)
- getPropz().logFoldProb(allInState.getNextToAct(), p);
- if (p.getAction() instanceof RaiseAction)
- getPropz().logRaiseProb(allInState.getNextToAct(), p);
- if (p.getAction() instanceof CheckAction)
- getPropz().logCheckProb(allInState.getNextToAct(), p);
- if (p.getAction() instanceof BetAction)
- getPropz().logBetProb(allInState.getNextToAct(), p);
+ if (p != null) {
+ if (p.getAction() instanceof CallAction)
+ getPropz().logCallProb(allInState.getNextToAct(), p);
+ if (p.getAction() instanceof FoldAction)
+ getPropz().logFoldProb(allInState.getNextToAct(), p);
+ if (p.getAction() instanceof RaiseAction)
+ getPropz().logRaiseProb(allInState.getNextToAct(), p);
+ if (p.getAction() instanceof CheckAction)
+ getPropz().logCheckProb(allInState.getNextToAct(), p);
+ if (p.getAction() instanceof BetAction)
+ getPropz().logBetProb(allInState.getNextToAct(), p);
+ }

logger.trace(getPlayerName(allInState) +
" All-in " + Util.parseDollars(allInState.getEvent().getMovedAmount())
+
=======================================
---
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/WekaOptions.java
Tue Aug 17 17:15:33 2010
+++
/trunk/ai/opponentmodels/weka/src/main/java/org/cspoker/ai/opponentmodels/weka/WekaOptions.java
Wed Aug 18 09:44:56 2010
@@ -15,7 +15,7 @@
private boolean solveConceptDrift = true;
private double cdHighCoverage = 50;
private double cdLowCoverage = 1;
- private double cdAccuracy = 0.5;
+ private double cdAccuracy = 0.7;
/** if solveConceptDrift is false, a new model must be learned at
intervals
* based on the number of reported actions */
private long learningInterval = 1;

Reply all
Reply to author
Forward
0 new messages