Permalink
Browse files

modified code to save fig

  • Loading branch information...
1 parent 6393000 commit 3a63aca4b1407e1168ea8766895368387663bd42 @kykamath committed Mar 30, 2012
View
BIN .DS_Store
Binary file not shown.
View
Binary file not shown.
@@ -0,0 +1,15 @@
+{"id": "30.3050_-81.3450", "links": {"32.6250_-117.1600": 0.2, "44.5150_-80.9100": 0.4, "36.9750_-95.7000": 0.6, "39.1500_-76.5600": 0.6, "37.7000_-122.3800": 0.2, "43.2100_-79.7500": 0.6, "39.5850_-75.5450": 0.8, "39.8750_-75.1100": 0.2, "40.7450_-74.3850": 0.6, "39.4400_-118.7550": 0.6, "38.8600_-76.9950": 0.2, "40.7450_-73.3700": 0.6, "47.4150_-121.9450": 0.8, "40.6000_-73.9500": 0.6}}
+{"id": "32.6250_-117.1600", "links": {"44.5150_-80.9100": 0.2, "30.3050_-81.3450": 0.2, "36.9750_-95.7000": 0.2, "39.1500_-76.5600": 0.2, "37.7000_-122.3800": 0.2, "43.2100_-79.7500": 0.2, "39.5850_-75.5450": 0.2, "39.8750_-75.1100": 0.2, "40.7450_-74.3850": 0.2, "39.4400_-118.7550": 0.2, "38.8600_-76.9950": 0.2, "40.7450_-73.3700": 0.2, "47.4150_-121.9450": 0.2, "40.6000_-73.9500": 0.2}}
+{"id": "36.9750_-95.7000", "links": {"32.6250_-117.1600": 0.2, "30.3050_-81.3450": 0.6, "44.5150_-80.9100": 0.4, "39.1500_-76.5600": 0.6, "37.7000_-122.3800": 0.2, "43.2100_-79.7500": 0.6, "39.5850_-75.5450": 0.6, "39.8750_-75.1100": 0.2, "40.7450_-74.3850": 0.6, "39.4400_-118.7550": 0.6, "38.8600_-76.9950": 0.2, "40.7450_-73.3700": 0.8, "47.4150_-121.9450": 0.6, "40.6000_-73.9500": 0.6}}
+{"id": "37.7000_-122.3800", "links": {"32.6250_-117.1600": 0.25, "30.3050_-81.3450": 0.25, "44.5150_-80.9100": 0.25, "36.9750_-95.7000": 0.25, "39.1500_-76.5600": 0.25, "43.2100_-79.7500": 0.25, "39.5850_-75.5450": 0.25, "39.8750_-75.1100": 0.25, "40.7450_-74.3850": 0.25, "39.4400_-118.7550": 0.25, "38.8600_-76.9950": 0.25, "40.7450_-73.3700": 0.25, "47.4150_-121.9450": 0.25, "40.6000_-73.9500": 0.25}}
+{"id": "38.8600_-76.9950", "links": {"32.6250_-117.1600": 0.25, "30.3050_-81.3450": 0.25, "44.5150_-80.9100": 0.25, "36.9750_-95.7000": 0.25, "39.1500_-76.5600": 0.25, "37.7000_-122.3800": 0.25, "43.2100_-79.7500": 0.25, "39.5850_-75.5450": 0.25, "39.8750_-75.1100": 0.25, "40.7450_-74.3850": 0.25, "39.4400_-118.7550": 0.25, "40.7450_-73.3700": 0.25, "47.4150_-121.9450": 0.25, "40.6000_-73.9500": 0.25}}
+{"id": "39.1500_-76.5600", "links": {"32.6250_-117.1600": 0.142857142857, "30.3050_-81.3450": 0.428571428571, "44.5150_-80.9100": 0.285714285714, "36.9750_-95.7000": 0.428571428571, "40.6000_-73.9500": 0.428571428571, "37.7000_-122.3800": 0.142857142857, "43.2100_-79.7500": 0.428571428571, "39.5850_-75.5450": 0.428571428571, "39.8750_-75.1100": 0.142857142857, "40.7450_-74.3850": 0.428571428571, "39.4400_-118.7550": 0.571428571429, "38.8600_-76.9950": 0.142857142857, "40.7450_-73.3700": 0.428571428571, "47.4150_-121.9450": 0.428571428571}}
+{"id": "39.4400_-118.7550", "links": {"32.6250_-117.1600": 0.2, "30.3050_-81.3450": 0.6, "44.5150_-80.9100": 0.4, "36.9750_-95.7000": 0.6, "39.1500_-76.5600": 0.8, "37.7000_-122.3800": 0.2, "43.2100_-79.7500": 0.6, "39.5850_-75.5450": 0.6, "39.8750_-75.1100": 0.2, "40.7450_-74.3850": 0.6, "38.8600_-76.9950": 0.2, "40.7450_-73.3700": 0.6, "47.4150_-121.9450": 0.6, "40.6000_-73.9500": 0.6}}
+{"id": "39.5850_-75.5450", "links": {"32.6250_-117.1600": 0.125, "30.3050_-81.3450": 0.5, "44.5150_-80.9100": 0.25, "36.9750_-95.7000": 0.375, "39.1500_-76.5600": 0.375, "37.7000_-122.3800": 0.125, "43.2100_-79.7500": 0.375, "47.4150_-121.9450": 0.5, "39.8750_-75.1100": 0.125, "40.7450_-74.3850": 0.375, "39.4400_-118.7550": 0.375, "38.8600_-76.9950": 0.125, "40.7450_-73.3700": 0.375, "40.6000_-73.9500": 0.375}}
+{"id": "39.8750_-75.1100", "links": {"32.6250_-117.1600": 0.25, "30.3050_-81.3450": 0.25, "44.5150_-80.9100": 0.25, "36.9750_-95.7000": 0.25, "39.1500_-76.5600": 0.25, "37.7000_-122.3800": 0.25, "43.2100_-79.7500": 0.25, "39.5850_-75.5450": 0.25, "40.7450_-74.3850": 0.25, "39.4400_-118.7550": 0.25, "38.8600_-76.9950": 0.25, "40.7450_-73.3700": 0.25, "47.4150_-121.9450": 0.25, "40.6000_-73.9500": 0.25}}
+{"id": "40.6000_-73.9500", "links": {"44.5150_-80.9100": 0.272727272727, "30.3050_-81.3450": 0.272727272727, "36.9750_-95.7000": 0.272727272727, "39.1500_-76.5600": 0.272727272727, "43.2100_-79.7500": 0.363636363636, "39.5850_-75.5450": 0.272727272727, "40.7450_-74.3850": 0.272727272727, "39.4400_-118.7550": 0.272727272727, "40.7450_-73.3700": 0.272727272727, "47.4150_-121.9450": 0.272727272727}}
+{"id": "40.7450_-73.3700", "links": {"32.6250_-117.1600": 0.166666666667, "30.3050_-81.3450": 0.5, "44.5150_-80.9100": 0.333333333333, "36.9750_-95.7000": 0.666666666667, "39.1500_-76.5600": 0.5, "37.7000_-122.3800": 0.166666666667, "43.2100_-79.7500": 0.5, "39.5850_-75.5450": 0.5, "39.8750_-75.1100": 0.166666666667, "40.7450_-74.3850": 0.5, "39.4400_-118.7550": 0.5, "38.8600_-76.9950": 0.166666666667, "47.4150_-121.9450": 0.5, "40.6000_-73.9500": 0.5}}
+{"id": "40.7450_-74.3850", "links": {"32.6250_-117.1600": 0.142857142857, "30.3050_-81.3450": 0.428571428571, "44.5150_-80.9100": 0.285714285714, "36.9750_-95.7000": 0.428571428571, "39.1500_-76.5600": 0.428571428571, "37.7000_-122.3800": 0.142857142857, "43.2100_-79.7500": 0.428571428571, "39.5850_-75.5450": 0.428571428571, "39.8750_-75.1100": 0.142857142857, "39.4400_-118.7550": 0.428571428571, "38.8600_-76.9950": 0.142857142857, "40.7450_-73.3700": 0.428571428571, "47.4150_-121.9450": 0.428571428571, "40.6000_-73.9500": 0.428571428571}}
+{"id": "43.2100_-79.7500", "links": {"32.6250_-117.1600": 0.2, "30.3050_-81.3450": 0.6, "44.5150_-80.9100": 0.6, "36.9750_-95.7000": 0.6, "39.1500_-76.5600": 0.6, "37.7000_-122.3800": 0.2, "39.5850_-75.5450": 0.6, "39.8750_-75.1100": 0.2, "40.7450_-74.3850": 0.6, "39.4400_-118.7550": 0.6, "38.8600_-76.9950": 0.2, "40.7450_-73.3700": 0.6, "47.4150_-121.9450": 0.6, "40.6000_-73.9500": 0.8}}
+{"id": "44.5150_-80.9100", "links": {"32.6250_-117.1600": 0.25, "30.3050_-81.3450": 0.5, "36.9750_-95.7000": 0.5, "39.1500_-76.5600": 0.5, "37.7000_-122.3800": 0.25, "43.2100_-79.7500": 0.75, "39.5850_-75.5450": 0.5, "39.8750_-75.1100": 0.25, "40.7450_-74.3850": 0.5, "39.4400_-118.7550": 0.5, "38.8600_-76.9950": 0.25, "40.7450_-73.3700": 0.5, "47.4150_-121.9450": 0.5, "40.6000_-73.9500": 0.75}}
+{"id": "47.4150_-121.9450", "links": {"32.6250_-117.1600": 0.2, "30.3050_-81.3450": 0.8, "44.5150_-80.9100": 0.4, "36.9750_-95.7000": 0.6, "39.1500_-76.5600": 0.6, "37.7000_-122.3800": 0.2, "43.2100_-79.7500": 0.6, "39.5850_-75.5450": 0.8, "39.8750_-75.1100": 0.2, "40.7450_-74.3850": 0.6, "39.4400_-118.7550": 0.6, "38.8600_-76.9950": 0.2, "40.7450_-73.3700": 0.6, "40.6000_-73.9500": 0.6}}
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -91,48 +91,29 @@ def plotAllData(prediction_models):
plotPointsOnWorldMap(locations, blueMarble=False, bkcolor='#CFCFCF', c=colors, lw = 0)
plt.title(prediction_model)
plt.show()
-
-#def plotPointsOnNYMap(points, blueMarble=False, bkcolor='#85A6D9', returnBaseMapObject = False, pointLabels=[], *args, **kwargs):
-# from mpl_toolkits.basemap import Basemap
-# m = Basemap(llcrnrlon=-74.415894, llcrnrlat=40.467845, urcrnrlon=-71.740723, urcrnrlat=41.265421, projection='lcc', lat_1=40, lat_2=42, lon_0=-73.152466, resolution='l', area_thresh=10000)
-# m.drawmapboundary(fill_color='#85A6D9')
-#
-# m.fillcontinents(color='white',lake_color='#85A6D9')
-# m.drawstates(color='#6D5F47', linewidth=.4)
-# m.drawcoastlines(color='#6D5F47', linewidth=.4)
-# m.drawcountries(color='#6D5F47', linewidth=.4)
-#
-# m.drawmeridians(np.arange(-180, 180, 30), color='#bbbbbb')
-# m.drawparallels(np.arange(-90, 90, 30), color='#bbbbbb')
-# lats, lngs = zip(*points)
-#
-# x,y = m(lngs,lats)
-# scatterPlot = m.scatter(x, y, zorder = 2, *args, **kwargs)
-#
-# for population, xpt, ypt in zip(pointLabels, x, y):
-# label_txt = str(population)
-# plt.text( xpt, ypt, label_txt, color = 'black', size='small', horizontalalignment='center', verticalalignment='center', zorder = 3)
-# if not returnBaseMapObject: return scatterPlot
-# else: return (scatterPlot, m)
-
-def grid_visualization():
- BIN_ACCURACY = 1.45
- map_from_location_bin_to_color = {}
- set_of_observed_location_ids = set()
- tuples_of_location_and_bin_color = []
- for count, data in enumerate(iterateJsonFromFile(hashtagsWithoutEndingWindowWithoutLatticeApproximationFile%('complete', '2011-04-01', '2012-01-31'))):
- for location, time in data['oc']:
- location_id = getLatticeLid(location, LOCATION_ACCURACY)
- if location_id not in set_of_observed_location_ids:
- set_of_observed_location_ids.add(location_id)
- location_bin = getLatticeLid(location, BIN_ACCURACY)
- if location_bin not in map_from_location_bin_to_color: map_from_location_bin_to_color[location_bin] = GeneralMethods.getRandomColor()
- tuples_of_location_and_bin_color.append((location, map_from_location_bin_to_color[location_bin]))
- print count
- if count==1000: break
- locations, colors = zip(*tuples_of_location_and_bin_color)
- plotPointsOnWorldMap(locations, blueMarble=False, bkcolor='#CFCFCF', c=colors, lw = 0)
- plt.show()
+class GeneralAnalysis():
+ @staticmethod
+ def grid_visualization():
+ BIN_ACCURACY = 1.45
+ map_from_location_bin_to_color = {}
+ set_of_observed_location_ids = set()
+ tuples_of_location_and_bin_color = []
+ for count, data in enumerate(iterateJsonFromFile(hashtagsWithoutEndingWindowWithoutLatticeApproximationFile%('complete', '2011-04-01', '2012-01-31'))):
+ for location, time in data['oc']:
+ location_id = getLatticeLid(location, LOCATION_ACCURACY)
+ if location_id not in set_of_observed_location_ids:
+ set_of_observed_location_ids.add(location_id)
+ location_bin = getLatticeLid(location, BIN_ACCURACY)
+ if location_bin not in map_from_location_bin_to_color: map_from_location_bin_to_color[location_bin] = GeneralMethods.getRandomColor()
+ tuples_of_location_and_bin_color.append((location, map_from_location_bin_to_color[location_bin]))
+ print count
+ if count==1000: break
+ locations, colors = zip(*tuples_of_location_and_bin_color)
+ plotPointsOnWorldMap(locations, blueMarble=False, bkcolor='#CFCFCF', c=colors, lw = 0)
+ # plt.show()
+ file_learning_analysis = './images/%s.png'%(GeneralMethods.get_method_id())
+ FileIO.createDirectoryForFile(file_learning_analysis)
+ plt.savefig(file_learning_analysis)
def follow_the_leader_method(map_from_model_to_weight): return min(map_from_model_to_weight.iteritems(), key=itemgetter(1))[0]
def hedging_method(map_from_model_to_weight):
@@ -467,5 +448,5 @@ def run():
#plotRealData()
#plotCoverageDistance()
-grid_visualization()
+GeneralAnalysis.grid_visualization()
#LearningAnalysis.run()
@@ -0,0 +1,35 @@
+def count_non_flips((reduced_no_of_non_flips, reduced_previously_selected_model), (current_ep_time_unit, current_selected_model)):
+ if reduced_previously_selected_model==current_selected_model: reduced_no_of_non_flips+=1.0
+ return (reduced_no_of_non_flips, current_selected_model)
+
+tuples_of_ep_time_unit_and_selected_model = zip([1,1,2,3,3,4], [1,1,1,1,1])
+print reduce(count_non_flips, tuples_of_ep_time_unit_and_selected_model, (0.0, None))
+
+#from numpy import arange,sqrt, random, linalg
+#from multiprocessing import Pool
+#
+#global counter
+#counter = 0
+#def cb(r):
+# global counter
+# print counter, r
+# counter +=1
+#
+#def det((i,j)):
+# return i+j
+#
+#class T:
+# @staticmethod
+# def runExperiment():
+# po = Pool()
+# #for i in xrange(1,300):
+# # j = random.normal(1,1,(100,100))
+# # po.apply_async(det,(j,),callback=cb)
+#
+# po.map_async(det, ((i,j) for i,j in zip(xrange(1,10), xrange(1,10))), callback=cb)
+# po.close()
+# po.join()
+# print counter
+#
+#
+#T.runExperiment()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,8 @@
+import matplotlib
+import matplotlib.pyplot as plt
+cm = matplotlib.cm.get_cmap('RdYlBu')
+xy = range(20)
+z = xy
+sc = plt.scatter(xy, xy, c=z, cmap='cool')
+plt.colorbar(sc)
+plt.show()

0 comments on commit 3a63aca

Please sign in to comment.