Permalink
Browse files

new experiments with Vowpal Wabbit. conjugate_gradient training takes…

… a bit longer but isn't exploding.
  • Loading branch information...
1 parent 981e6b4 commit e3f5a63339d4b4d0230955c389b3fed96ce9b91e @rspeer committed Nov 10, 2011
Showing with 751 additions and 4 deletions.
  1. +37 −4 convert_to_r_fmt.py
  2. +1 −0 oneoff/all_features_input.txt
  3. +711 −0 oneoff/all_features_output.txt
  4. +2 −0 oneoff/vw-train-script.sh
View
@@ -8,6 +8,7 @@
import card_info as ci
@rrenaud

rrenaud Dec 20, 2011

Contributor

I screwed up a git move. This code is old, the new file is game_state_features.py

import game
import random
+import sys
import utils
def nice_feature_name(n):
@@ -28,7 +29,7 @@ def deck_size_deck_extractor(deck_comp, game_state, player):
return [sum(deck_comp.itervalues())]
def action_balance_deck_extractor(deck_comp, game_state, player):
- ret = 0
+ ret = 0.0
for card, quant in deck_comp.iteritems():
ret += (ci.num_plus_actions(card) - ci.is_action(card)) * quant
return [ret / (sum(deck_comp.itervalues()) or 1)]
@@ -122,6 +123,27 @@ def output_state(state, output_file, sep=' '):
output_file.write(formatted_str)
output_file.write('\n')
+def output_vw_state(state, output_file):
+ named_features = zip(all_feature_names, state)
+ feature_str = ' '.join('%s:%s' % (feature, value)
+ for feature, value in named_features
+ if value and feature != "outcome_")
+ outcome = state[-1]*2-1
+ uid = random_id()
+ formatted_str = "%s 1.0 %s|Features %s" % (outcome, uid, feature_str)
+ print >> output_file, formatted_str
+
+def convert_r_to_vw(input_file, output_file):
+ global all_feature_names
+ skipped_first = False
+ for line in input_file:
+ if skipped_first:
+ state = map(int, line.strip().split())
+ output_vw_state(state, output_file)
+ else:
+ all_feature_names = line.strip().split()
+ skipped_first = True
+
def get_all_feature_names():
header = feature_names(_common_extractor_list)
@@ -131,6 +153,10 @@ def get_all_feature_names():
header.append('outcome_')
return header
+all_feature_names = get_all_feature_names()
+
+def random_id():
+ return hex(random.randrange(0, 1<<32))[2:]
def write_r_header(output_file):
outputted = ' '.join(get_all_feature_names()) + '\n'
@@ -163,16 +189,16 @@ def main():
# limit = 10000
r_output_file = open(prefix + 'r_format.data', 'w')
weka_output_file = open(prefix + 'games.arff', 'w')
+ vw_output_file = open(prefix + 'games.vw.txt', 'w')
librf_output_file = open(prefix + 'librf_games.csv', 'w')
librf_labels_file = open(prefix + 'librf_games_labels.txt', 'w')
libsvm_output_file = open(prefix + 'libsvm_games.txt', 'w')
write_r_header(r_output_file)
write_weka_header(weka_output_file, force_classification)
for raw_game in utils.progress_meter(
- c.test.games.find(
- {'_id': {'$gt': 'game-20110715'} }
- ), 100):
+ c.test.games.find()
+ ):
g = game.Game(raw_game)
if g.dubious_quality() or len(g.get_player_decks()) != 2:
continue
@@ -192,10 +218,17 @@ def main():
#librf_labels_file.write('%d\n' % encoded_state[-1])
output_libsvm_state(encoded_state, libsvm_output_file)
+ output_vw_state(encoded_state, vw_output_file)
#else:
# assert False, ('did not find turn %d in %s' % (saved_turn_ind,
# game.get_id()))
+def convert_main():
+ infile = open('data/r_format.data')
+ outfile = open('data/games.vw', 'w')
+ convert_r_to_vw(infile, outfile)
+ infile.close()
+ outfile.close()
if __name__ == '__main__':
main()
@@ -0,0 +1 @@
+0 0 0|Features num_piles_low_:1 num_piles_empty_:1 Adventurer:1 Alchemist:1 Ambassador:1 Apothecary:1 Apprentice:1 Archivist:1 Bag_of_Gold:1 Bank:1 Baron:1 Bazaar:1 Bishop:1 Black_Market:1 Border_Village:1 Bridge:1 Bureaucrat:1 Cache:1 Caravan:1 Cartographer:1 Cellar:1 Chancellor:1 Chapel:1 City:1 Colony:1 Conspirator:1 Contraband:1 Copper:1 Coppersmith:1 Council_Room:1 Counting_House:1 Courtyard:1 Crossroads:1 Curse:1 Cutpurse:1 Develop:1 Diadem:1 Duchy:1 Duke:1 Duchess:1 Embargo:1 Embassy:1 Envoy:1 Estate:1 Expand:1 Explorer:1 Fairgrounds:1 Familiar:1 Farming_Village:1 Farmland:1 Feast:1 Festival:1 Fishing_Village:1 Followers:1 Fools_Gold:1 Forge:1 Fortune_Teller:1 Gardens:1 Ghost_Ship:1 Gold:1 Golem:1 Goons:1 Governor:1 Grand_Market:1 Great_Hall:1 Haggler:1 Hamlet:1 Harem:1 Harvest:1 Haven:1 Herbalist:1 Highway:1 Hoard:1 Horn_of_Plenty:1 Horse_Traders:1 Hunting_Party:1 Ill-Gotten_Gains:1 Inn:1 Ironworks:1 Island:1 Jack_of_All_Trades:1 Jester:1 Kings_Court:1 Laboratory:1 Library:1 Lighthouse:1 Loan:1 Lookout:1 Mandarin:1 Market:1 Margrave:1 Masquerade:1 Menagerie:1 Merchant_Ship:1 Militia:1 Mine:1 Mining_Village:1 Minion:1 Mint:1 Moat:1 Moneylender:1 Monument:1 Mountebank:1 Native_Village:1 Navigator:1 Nobles:1 Noble_Brigand:1 Nomad_Camp:1 Oasis:1 Oracle:1 Outpost:1 Pawn:1 Pearl_Diver:1 Peddler:1 Philosophers_Stone:1 Pirate_Ship:1 Platinum:1 Possession:1 Potion:1 Princess:1 Province:1 Quarry:1 Rabble:1 Remake:1 Remodel:1 Royal_Seal:1 Saboteur:1 Salvager:1 Scheme:1 Scout:1 Scrying_Pool:1 Sea_Hag:1 Secret_Chamber:1 Shanty_Town:1 Silk_Road:1 Silver:1 Smithy:1 Smugglers:1 Spice_Merchant:1 Spy:1 Stables:1 Stash:1 Steward:1 Swindler:1 Tactician:1 Talisman:1 Thief:1 Throne_Room:1 Torturer:1 Tournament:1 Trade_Route:1 Trader:1 Trading_Post:1 Transmute:1 Treasure_Map:1 Treasury:1 Tribute:1 Trusty_Steed:1 Tunnel:1 University:1 Upgrade:1 Vault:1 Venture:1 Village:1 Vineyard:1 Walled_Village:1 Warehouse:1 Watchtower:1 Wharf:1 Wishing_Well:1 Witch:1 Woodcutter:1 Workers_Village:1 Workshop:1 Young_Witch:1 turn_tiebreaker_:1 turn_no_:1 my_Adventurer:1 my_Alchemist:1 my_Ambassador:1 my_Apothecary:1 my_Apprentice:1 my_Archivist:1 my_Bag_of_Gold:1 my_Bank:1 my_Baron:1 my_Bazaar:1 my_Bishop:1 my_Black_Market:1 my_Border_Village:1 my_Bridge:1 my_Bureaucrat:1 my_Cache:1 my_Caravan:1 my_Cartographer:1 my_Cellar:1 my_Chancellor:1 my_Chapel:1 my_City:1 my_Colony:1 my_Conspirator:1 my_Contraband:1 my_Copper:1 my_Coppersmith:1 my_Council_Room:1 my_Counting_House:1 my_Courtyard:1 my_Crossroads:1 my_Curse:1 my_Cutpurse:1 my_Develop:1 my_Diadem:1 my_Duchy:1 my_Duke:1 my_Duchess:1 my_Embargo:1 my_Embassy:1 my_Envoy:1 my_Estate:1 my_Expand:1 my_Explorer:1 my_Fairgrounds:1 my_Familiar:1 my_Farming_Village:1 my_Farmland:1 my_Feast:1 my_Festival:1 my_Fishing_Village:1 my_Followers:1 my_Fools_Gold:1 my_Forge:1 my_Fortune_Teller:1 my_Gardens:1 my_Ghost_Ship:1 my_Gold:1 my_Golem:1 my_Goons:1 my_Governor:1 my_Grand_Market:1 my_Great_Hall:1 my_Haggler:1 my_Hamlet:1 my_Harem:1 my_Harvest:1 my_Haven:1 my_Herbalist:1 my_Highway:1 my_Hoard:1 my_Horn_of_Plenty:1 my_Horse_Traders:1 my_Hunting_Party:1 my_Ill-Gotten_Gains:1 my_Inn:1 my_Ironworks:1 my_Island:1 my_Jack_of_All_Trades:1 my_Jester:1 my_Kings_Court:1 my_Laboratory:1 my_Library:1 my_Lighthouse:1 my_Loan:1 my_Lookout:1 my_Mandarin:1 my_Market:1 my_Margrave:1 my_Masquerade:1 my_Menagerie:1 my_Merchant_Ship:1 my_Militia:1 my_Mine:1 my_Mining_Village:1 my_Minion:1 my_Mint:1 my_Moat:1 my_Moneylender:1 my_Monument:1 my_Mountebank:1 my_Native_Village:1 my_Navigator:1 my_Nobles:1 my_Noble_Brigand:1 my_Nomad_Camp:1 my_Oasis:1 my_Oracle:1 my_Outpost:1 my_Pawn:1 my_Pearl_Diver:1 my_Peddler:1 my_Philosophers_Stone:1 my_Pirate_Ship:1 my_Platinum:1 my_Possession:1 my_Potion:1 my_Princess:1 my_Province:1 my_Quarry:1 my_Rabble:1 my_Remake:1 my_Remodel:1 my_Royal_Seal:1 my_Saboteur:1 my_Salvager:1 my_Scheme:1 my_Scout:1 my_Scrying_Pool:1 my_Sea_Hag:1 my_Secret_Chamber:1 my_Shanty_Town:1 my_Silk_Road:1 my_Silver:1 my_Smithy:1 my_Smugglers:1 my_Spice_Merchant:1 my_Spy:1 my_Stables:1 my_Stash:1 my_Steward:1 my_Swindler:1 my_Tactician:1 my_Talisman:1 my_Thief:1 my_Throne_Room:1 my_Torturer:1 my_Tournament:1 my_Trade_Route:1 my_Trader:1 my_Trading_Post:1 my_Transmute:1 my_Treasure_Map:1 my_Treasury:1 my_Tribute:1 my_Trusty_Steed:1 my_Tunnel:1 my_University:1 my_Upgrade:1 my_Vault:1 my_Venture:1 my_Village:1 my_Vineyard:1 my_Walled_Village:1 my_Warehouse:1 my_Watchtower:1 my_Wharf:1 my_Wishing_Well:1 my_Witch:1 my_Woodcutter:1 my_Workers_Village:1 my_Workshop:1 my_Young_Witch:1 my_score_:1 my_unique_:1 my_action_balance_:1 my_deck_size_:1 opp_Adventurer:1 opp_Alchemist:1 opp_Ambassador:1 opp_Apothecary:1 opp_Apprentice:1 opp_Archivist:1 opp_Bag_of_Gold:1 opp_Bank:1 opp_Baron:1 opp_Bazaar:1 opp_Bishop:1 opp_Black_Market:1 opp_Border_Village:1 opp_Bridge:1 opp_Bureaucrat:1 opp_Cache:1 opp_Caravan:1 opp_Cartographer:1 opp_Cellar:1 opp_Chancellor:1 opp_Chapel:1 opp_City:1 opp_Colony:1 opp_Conspirator:1 opp_Contraband:1 opp_Copper:1 opp_Coppersmith:1 opp_Council_Room:1 opp_Counting_House:1 opp_Courtyard:1 opp_Crossroads:1 opp_Curse:1 opp_Cutpurse:1 opp_Develop:1 opp_Diadem:1 opp_Duchy:1 opp_Duke:1 opp_Duchess:1 opp_Embargo:1 opp_Embassy:1 opp_Envoy:1 opp_Estate:1 opp_Expand:1 opp_Explorer:1 opp_Fairgrounds:1 opp_Familiar:1 opp_Farming_Village:1 opp_Farmland:1 opp_Feast:1 opp_Festival:1 opp_Fishing_Village:1 opp_Followers:1 opp_Fools_Gold:1 opp_Forge:1 opp_Fortune_Teller:1 opp_Gardens:1 opp_Ghost_Ship:1 opp_Gold:1 opp_Golem:1 opp_Goons:1 opp_Governor:1 opp_Grand_Market:1 opp_Great_Hall:1 opp_Haggler:1 opp_Hamlet:1 opp_Harem:1 opp_Harvest:1 opp_Haven:1 opp_Herbalist:1 opp_Highway:1 opp_Hoard:1 opp_Horn_of_Plenty:1 opp_Horse_Traders:1 opp_Hunting_Party:1 opp_Ill-Gotten_Gains:1 opp_Inn:1 opp_Ironworks:1 opp_Island:1 opp_Jack_of_All_Trades:1 opp_Jester:1 opp_Kings_Court:1 opp_Laboratory:1 opp_Library:1 opp_Lighthouse:1 opp_Loan:1 opp_Lookout:1 opp_Mandarin:1 opp_Market:1 opp_Margrave:1 opp_Masquerade:1 opp_Menagerie:1 opp_Merchant_Ship:1 opp_Militia:1 opp_Mine:1 opp_Mining_Village:1 opp_Minion:1 opp_Mint:1 opp_Moat:1 opp_Moneylender:1 opp_Monument:1 opp_Mountebank:1 opp_Native_Village:1 opp_Navigator:1 opp_Nobles:1 opp_Noble_Brigand:1 opp_Nomad_Camp:1 opp_Oasis:1 opp_Oracle:1 opp_Outpost:1 opp_Pawn:1 opp_Pearl_Diver:1 opp_Peddler:1 opp_Philosophers_Stone:1 opp_Pirate_Ship:1 opp_Platinum:1 opp_Possession:1 opp_Potion:1 opp_Princess:1 opp_Province:1 opp_Quarry:1 opp_Rabble:1 opp_Remake:1 opp_Remodel:1 opp_Royal_Seal:1 opp_Saboteur:1 opp_Salvager:1 opp_Scheme:1 opp_Scout:1 opp_Scrying_Pool:1 opp_Sea_Hag:1 opp_Secret_Chamber:1 opp_Shanty_Town:1 opp_Silk_Road:1 opp_Silver:1 opp_Smithy:1 opp_Smugglers:1 opp_Spice_Merchant:1 opp_Spy:1 opp_Stables:1 opp_Stash:1 opp_Steward:1 opp_Swindler:1 opp_Tactician:1 opp_Talisman:1 opp_Thief:1 opp_Throne_Room:1 opp_Torturer:1 opp_Tournament:1 opp_Trade_Route:1 opp_Trader:1 opp_Trading_Post:1 opp_Transmute:1 opp_Treasure_Map:1 opp_Treasury:1 opp_Tribute:1 opp_Trusty_Steed:1 opp_Tunnel:1 opp_University:1 opp_Upgrade:1 opp_Vault:1 opp_Venture:1 opp_Village:1 opp_Vineyard:1 opp_Walled_Village:1 opp_Warehouse:1 opp_Watchtower:1 opp_Wharf:1 opp_Wishing_Well:1 opp_Witch:1 opp_Woodcutter:1 opp_Workers_Village:1 opp_Workshop:1 opp_Young_Witch:1 opp_score_:1 opp_unique_:1 opp_action_balance_:1 opp_deck_size_:1 diff_Adventurer:1 diff_Alchemist:1 diff_Ambassador:1 diff_Apothecary:1 diff_Apprentice:1 diff_Archivist:1 diff_Bag_of_Gold:1 diff_Bank:1 diff_Baron:1 diff_Bazaar:1 diff_Bishop:1 diff_Black_Market:1 diff_Border_Village:1 diff_Bridge:1 diff_Bureaucrat:1 diff_Cache:1 diff_Caravan:1 diff_Cartographer:1 diff_Cellar:1 diff_Chancellor:1 diff_Chapel:1 diff_City:1 diff_Colony:1 diff_Conspirator:1 diff_Contraband:1 diff_Copper:1 diff_Coppersmith:1 diff_Council_Room:1 diff_Counting_House:1 diff_Courtyard:1 diff_Crossroads:1 diff_Curse:1 diff_Cutpurse:1 diff_Develop:1 diff_Diadem:1 diff_Duchy:1 diff_Duke:1 diff_Duchess:1 diff_Embargo:1 diff_Embassy:1 diff_Envoy:1 diff_Estate:1 diff_Expand:1 diff_Explorer:1 diff_Fairgrounds:1 diff_Familiar:1 diff_Farming_Village:1 diff_Farmland:1 diff_Feast:1 diff_Festival:1 diff_Fishing_Village:1 diff_Followers:1 diff_Fools_Gold:1 diff_Forge:1 diff_Fortune_Teller:1 diff_Gardens:1 diff_Ghost_Ship:1 diff_Gold:1 diff_Golem:1 diff_Goons:1 diff_Governor:1 diff_Grand_Market:1 diff_Great_Hall:1 diff_Haggler:1 diff_Hamlet:1 diff_Harem:1 diff_Harvest:1 diff_Haven:1 diff_Herbalist:1 diff_Highway:1 diff_Hoard:1 diff_Horn_of_Plenty:1 diff_Horse_Traders:1 diff_Hunting_Party:1 diff_Ill-Gotten_Gains:1 diff_Inn:1 diff_Ironworks:1 diff_Island:1 diff_Jack_of_All_Trades:1 diff_Jester:1 diff_Kings_Court:1 diff_Laboratory:1 diff_Library:1 diff_Lighthouse:1 diff_Loan:1 diff_Lookout:1 diff_Mandarin:1 diff_Market:1 diff_Margrave:1 diff_Masquerade:1 diff_Menagerie:1 diff_Merchant_Ship:1 diff_Militia:1 diff_Mine:1 diff_Mining_Village:1 diff_Minion:1 diff_Mint:1 diff_Moat:1 diff_Moneylender:1 diff_Monument:1 diff_Mountebank:1 diff_Native_Village:1 diff_Navigator:1 diff_Nobles:1 diff_Noble_Brigand:1 diff_Nomad_Camp:1 diff_Oasis:1 diff_Oracle:1 diff_Outpost:1 diff_Pawn:1 diff_Pearl_Diver:1 diff_Peddler:1 diff_Philosophers_Stone:1 diff_Pirate_Ship:1 diff_Platinum:1 diff_Possession:1 diff_Potion:1 diff_Princess:1 diff_Province:1 diff_Quarry:1 diff_Rabble:1 diff_Remake:1 diff_Remodel:1 diff_Royal_Seal:1 diff_Saboteur:1 diff_Salvager:1 diff_Scheme:1 diff_Scout:1 diff_Scrying_Pool:1 diff_Sea_Hag:1 diff_Secret_Chamber:1 diff_Shanty_Town:1 diff_Silk_Road:1 diff_Silver:1 diff_Smithy:1 diff_Smugglers:1 diff_Spice_Merchant:1 diff_Spy:1 diff_Stables:1 diff_Stash:1 diff_Steward:1 diff_Swindler:1 diff_Tactician:1 diff_Talisman:1 diff_Thief:1 diff_Throne_Room:1 diff_Torturer:1 diff_Tournament:1 diff_Trade_Route:1 diff_Trader:1 diff_Trading_Post:1 diff_Transmute:1 diff_Treasure_Map:1 diff_Treasury:1 diff_Tribute:1 diff_Trusty_Steed:1 diff_Tunnel:1 diff_University:1 diff_Upgrade:1 diff_Vault:1 diff_Venture:1 diff_Village:1 diff_Vineyard:1 diff_Walled_Village:1 diff_Warehouse:1 diff_Watchtower:1 diff_Wharf:1 diff_Wishing_Well:1 diff_Witch:1 diff_Woodcutter:1 diff_Workers_Village:1 diff_Workshop:1 diff_Young_Witch:1 diff_score_:1 diff_unique_:1 diff_action_balance_:1 diff_deck_size_:1
Oops, something went wrong.

0 comments on commit e3f5a63

Please sign in to comment.