Package org.cspoker.ai.bots.bot.gametree.mcts.nodes

Examples of org.cspoker.ai.bots.bot.gametree.mcts.nodes.INode


public abstract class MaxFunctionSelector implements SelectionStrategy {

  @Override
  public INode select(InnerNode innerNode) {
    ImmutableList<INode> children = innerNode.getChildren();
    INode maxNode = null;
    double maxValue = Double.NEGATIVE_INFINITY;
    for (INode node : children) {
      double value = evaluate(node);
      if(value>maxValue){
        maxValue = value;
View Full Code Here


      double[] probabilities = node.getProbabilities();
      EV = 0;
      variance = 0;
      nbSamplesInMean = 0;
      for (int i = 0; i < probabilities.length; i++) {
        INode child = children.get(i);
        int childN = child.getNbSamples();
        if (childN>0) {
          nbSamplesInMean+=child.getNbSamplesInMean();
          double childEV = child.getEV();
          EV += childN * childEV;
          double childVariance = child.getVariance();
          variance += childN * (childVariance + childEV * childEV);
        }
      }
      EV /= nbSamples;
      variance /= nbSamples;
View Full Code Here

      return nbSamplesInMean;
    }

    @Override
    public void onBackPropagate(double value) {
      INode selection = selectionStrategy.select(node);

      //TODO decide
      //this.nbSamples = selection.getNbSamples();
      ++this.nbSamples;

      this.EV = selection.getEV();
      this.variance = selection.getVariance();
      this.nbSamplesInMean = selection.getNbSamplesInMean();
      if(Double.isNaN(variance) || Double.isInfinite(variance) || variance<0) {
        throw new IllegalStateException();
      }
    }
View Full Code Here

      double[] probabilities = node.getProbabilities();
      double EV = 0;
      double EVVar = 0;
      double totalWeight = 0;
      for (int i = 0; i < probabilities.length; i++) {
        INode child = children.get(i);
        double childWeight = probabilities[i];
        if (childWeight>0) {
          double childEV = child.getEV();
          EV += childWeight * childEV;
          totalWeight += childWeight;
          double childVariance = child.getEVVar();
          EVVar += childWeight * (childVariance );//+ childEV * childEV);
        }
      }
      EV /= totalWeight;
      EVVar /= totalWeight;
View Full Code Here

      ++this.nbSamples;
     
      ImmutableList<INode> children = node.getChildren();
      Gaussian[] gaussians = new Gaussian[children.size()];
      for (int i = 0; i < children.size(); i++) {
        INode child = children.get(i);
        gaussians[i] = new Gaussian(child.getEV(),child.getEVVar());
      }
      EVGaussian = Gaussian.maxOf(gaussians);
    }
View Full Code Here

      ImmutableList<INode> children = node.getChildren();
      double[] probabilities = node.getProbabilities();
      double EV = 0;
      double EVVar = 0;
      for (int i = 0; i < probabilities.length; i++) {
        INode child = children.get(i);
        int childN = child.getNbSamples();
        if (childN>0) {
          double childEV = child.getEV();
          EV += childN * childEV;
          double childVariance = child.getEVVar();
          EVVar += childN * (childVariance );//+ childEV * childEV);
        }
      }
      EV /= nbSamples;
      EVVar /= nbSamples;
View Full Code Here

      ++this.nbSamples;
     
      ImmutableList<INode> children = node.getChildren();
      Gaussian[] gaussians = new Gaussian[children.size()];
      for (int i = 0; i < children.size(); i++) {
        INode child = children.get(i);
        gaussians[i] = new Gaussian(child.getEV(),child.getEVVar());
      }
      EVGaussian = Gaussian.maxOf(gaussians);
    }
View Full Code Here

      iterate(root);
      iterate(root);
      iterate(root);
      iterate(root);
    }while(System.currentTimeMillis()<endTime);
    INode node = root.selectChild(config.getMoveSelectionStrategy());
    config.getModel().setChosenNode(node);
//    try {
//    ImmutableList<INode> children = ((InnerNode) node).getChildren();
//    for (INode n: children) {
//      String str = " <last action> ";
//      str = "" + n.getLastAction().getAction().getUnwrappedStateAfterAction().getClass();
//      System.out.println("Child " +  str
//          + " with action " + n.getLastAction().getAction() + " with probability " +
//          n.getLastAction().getProbability());
//    }
//    } catch (ClassCastException e) {
//      System.out.println("-------------\nNO CLASS CAST\n-------------"); // do nothing
//    }
    SearchBotAction action = node.getLastAction().getAction();
    if(logger.isInfoEnabled())
      logger.info("Stopped MCTS after "+root.getNbSamples()+" samples and choosing "+action);
   
    // to calculate efficiency of sampling algorithms
//    if (tableContext.getGameState().getRound() == Round.PREFLOP)
View Full Code Here

      listener.onMCTS(root);
    }
  }

  private void iterate(RootNode root) {
    INode selectedLeaf = root.selectRecursively();
    selectedLeaf.expand();
    double value = selectedLeaf.simulate();
    selectedLeaf.backPropagate(value);
  }
View Full Code Here

  }

  long nbSamples;

  private void iterate(RootNode root) {
    INode selectedLeaf = root.selectRecursively();
    selectedLeaf.expand();
    double value = selectedLeaf.simulate();
    selectedLeaf.backPropagate(value);
  }
View Full Code Here

TOP

Related Classes of org.cspoker.ai.bots.bot.gametree.mcts.nodes.INode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.