Skip to content

Commit

Permalink
Add realizprob for the nodes and change realizprob to infosetprob for…
Browse files Browse the repository at this point in the history
… the infosets
  • Loading branch information
Konstantinos Varsos committed Oct 14, 2023
1 parent f8f9925 commit 4825bf4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/games/behav.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,4 @@ template <class T> class MixedBehaviorProfile : public DVector<T> {

} // end namespace Gambit

#endif // LIBGAMBIT_BEHAV_H
#endif // LIBGAMBIT_BEHAV_H
8 changes: 4 additions & 4 deletions src/games/behav.imp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void MixedBehaviorProfile<T>::UndefinedToCentroid()
GamePlayer player = efg->GetPlayer(pl);
for (int iset = 1; iset <= player->NumInfosets(); iset++) {
GameInfoset infoset = player->GetInfoset(iset);
if (GetRealizProb(infoset) > (T) 0) {
if (GetInfosetProb(infoset) > (T) 0) {
continue;
}
T total = (T) 0;
Expand All @@ -270,7 +270,7 @@ MixedBehaviorProfile<T> MixedBehaviorProfile<T>::Normalize() const
GamePlayer player = efg->GetPlayer(pl);
for (int iset = 1; iset <= player->NumInfosets(); iset++) {
GameInfoset infoset = player->GetInfoset(iset);
if (GetRealizProb(infoset) == (T) 0) {
if (GetInfosetProb(infoset) == (T) 0) {
continue;
}
T total = (T) 0;
Expand Down Expand Up @@ -416,7 +416,7 @@ const T &MixedBehaviorProfile<T>::GetRealizProb(const GameNode &node) const
}

template <class T>
T MixedBehaviorProfile<T>::GetRealizProb(const GameInfoset &iset) const
T MixedBehaviorProfile<T>::GetInfosetProb(const GameInfoset &iset) const
{
ComputeSolutionData();
T prob = (T) 0;
Expand Down Expand Up @@ -555,7 +555,7 @@ T MixedBehaviorProfile<T>::DiffActionValue(const GameAction &p_action,
DiffNodeValue(member->GetChild(p_action->GetNumber()), player, p_oppAction);
}

return deriv / GetRealizProb(p_action->GetInfoset());
return deriv / GetInfosetProb(p_action->GetInfoset());
}

template <class T>
Expand Down
8 changes: 4 additions & 4 deletions src/gui/analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ gbtAnalysisProfileList<T>::GetBeliefProb(const GameNode &p_node,
if (!p_node->GetPlayer()) return "";

try {
if (m_behavProfiles[index].GetRealizProb(p_node->GetInfoset()) > Rational(0)) {
if (m_behavProfiles[index].GetInfosetProb(p_node->GetInfoset()) > Rational(0)) {
return lexical_cast<std::string>(m_behavProfiles[index].GetBeliefProb(p_node),
m_doc->GetStyle().NumDecimals());
}
Expand Down Expand Up @@ -298,7 +298,7 @@ gbtAnalysisProfileList<T>::GetInfosetProb(const GameNode &p_node,
if (!p_node->GetPlayer()) return "";

try {
return lexical_cast<std::string>(m_behavProfiles[index].GetRealizProb(p_node->GetInfoset()),
return lexical_cast<std::string>(m_behavProfiles[index].GetInfosetProb(p_node->GetInfoset()),
m_doc->GetStyle().NumDecimals());
}
catch (IndexException &) {
Expand All @@ -315,7 +315,7 @@ gbtAnalysisProfileList<T>::GetInfosetValue(const GameNode &p_node,
if (!p_node->GetPlayer() || p_node->GetPlayer()->IsChance()) return "";

try {
if (m_behavProfiles[index].GetRealizProb(p_node->GetInfoset()) > Rational(0)) {
if (m_behavProfiles[index].GetInfosetProb(p_node->GetInfoset()) > Rational(0)) {
return lexical_cast<std::string>(m_behavProfiles[index].GetPayoff(p_node->GetInfoset()),
m_doc->GetStyle().NumDecimals());
}
Expand Down Expand Up @@ -385,7 +385,7 @@ gbtAnalysisProfileList<T>::GetActionValue(const GameNode &p_node, int p_act,
if (!p_node->GetPlayer() || p_node->GetPlayer()->IsChance()) return "";

try {
if (m_behavProfiles[index].GetRealizProb(p_node->GetInfoset()) > Rational(0)) {
if (m_behavProfiles[index].GetInfosetProb(p_node->GetInfoset()) > Rational(0)) {
return lexical_cast<std::string>(m_behavProfiles[index].GetPayoff(p_node->GetInfoset()->GetAction(p_act)),
m_doc->GetStyle().NumDecimals());
}
Expand Down
34 changes: 32 additions & 2 deletions src/pygambit/behav.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,13 @@ class MixedBehaviorProfile:
If `player` is a `Player` from a different game.
KeyError
If `player` is a string and no player in the game has that label.
ValueError
If `player` resolves to the chance player
"""
return self._payoff(self.game._resolve_player(player, 'payoff'))
resolved_player = self.game._resolve_player(player, 'payoff')
if resolved_player.is_chance:
raise ValueError("payoff() is not defined for the chance player")
return self._payoff(resolved_player)

def node_value(self, player: typing.Union[Player, str],
node: typing.Union[Node, str]):
Expand Down Expand Up @@ -339,8 +344,13 @@ class MixedBehaviorProfile:
If `infoset` is an `Infoset` from a different game.
KeyError
If `infoset` is a string and no information set in the game has that label.
ValueError
If `infoset` resolves to an infoset that belongs to the chance player
"""
return self._infoset_value(self.game._resolve_infoset(infoset, 'infoset_value'))
resolved_infoset = self.game._resolve_infoset(infoset, 'infoset_value')
if resolved_infoset.player.is_chance:
raise ValueError("infoset_value() is not defined for the chance player")
return self._infoset_value(resolved_infoset)

def action_value(self, action: typing.Union[Action, str]):
"""Returns the expected payoff to the player of playing an action conditional on reaching its
Expand All @@ -358,12 +368,32 @@ class MixedBehaviorProfile:
If `action` is an `Action` from a different game.
KeyError
If `action` is a string and no action in the game has that label.
ValueError
If `action` resolves to an action that belongs to the chance player
"""
resolved_action = self.game._resolve_action(action, 'action_value')
if resolved_action.infoset.player.is_chance:
raise ValueError("action_value() is not defined for the chance player")
return self._action_value(resolved_action)

def realiz_prob(self, node: typing.Union[Node, str]):
"""Returns the probability with which an node is reached.
Parameters
----------
node : Node or str
The node to get the payoff for. If a string is passed, the
node is determined by finding the node with that label, if any.
Raises
------
MismatchError
If `node` is an `Node` from a different game.
KeyError
If `node` is a string and no node in the game has that label.
"""
return self._realiz_prob(self.game._resolve_node(node, 'node_prob'))

def infoset_prob(self, infoset: typing.Union[Infoset, str]):
"""Returns the probability with which an information set is reached.
Expand Down

0 comments on commit 4825bf4

Please sign in to comment.