def plotAndSave(od,ed,fn): surprise = Surprise(od, plotprefix="") edv = surprise.createVisualiser(50,50) #fig=edv.plotSurpriseGradient() fig = od.plotArtefacts(stroke='black',fill='white') edv.plotExpectationContours(plot=fig,showDU=True,showMU=True) #edv.plotUncertaintyChannel(onMedian=False,plot=pl.gcf().add_subplot(14,1,14)) edv.save(fn)
defaults = {'C': 3,'gamma': 0.1} val1 = ['Release Year'] val2 = ['Width (mm)'] for v1 in val1: for v2 in val2: if v1 is not v2: start_time = time.time() print "Modelling",v1,"(independent) against",v2,"(dependent)." od = Updater(parser, v1, contours, v2, None) #fig = od.plotObservedContours() if (v1,v2) in found.keys(): #ed = ExpectedDistribution(od,found[(v1,v2)]) s = Surprise(od,params=found[(v1,v2)]) else: #ed = ExpectedDistribution(od,defaults) s = Surprise(od,params=defaults) edv = s.createVisualiser(100,100) #ExpectedDistributionVisualiser(ed,od,None,50,20) edv.setLimits() #fig=edv.plotSurpriseGradient() fig=od.plotArtefacts(stroke='black',fill='black') #od.plotObservedContours(plot=fig) edv.plotExpectationContours(plot=fig,showDU=True,showMU=True) #edv.plotUncertaintyChannel(onMedian=False,plot=pl.gcf().add_subplot(14,1,14)) fn = "".join(['-'.join([v1,v2,str(od.weight_std_ratio),str(s.params['C']),str(s.params['gamma']),'plotone.png'])]) edv.save(fn) #edv.show() print time.time() - start_time, "seconds"
mpl.rc('figure',figsize=[18, 12]) mpl.rc('figure.subplot',left=0.05,right=0.995,top=0.995,bottom=0.05) namecols = [0] timecols = [2] valcols = [2,3,4,5,6,7,8,9,10,11,12,13,14] parser = Parser("data/AllPhoneData_pruned.csv",namecols,timecols,valcols) contours = 4 properties = parser.getProperties() gridlog = Log(sys.argv[1]) for ind_attr in properties: for dep_attr in properties: if ind_attr == dep_attr: continue updater = Updater(parser, ind_attr, contours, dep_attr, None) surprise = None params = gridlog.getBestParams(ind_attr,dep_attr) if params is not None: print "Found",params,"for independent:",ind_attr,"dependent:",dep_attr surprise = Surprise(updater, params=params,lims=updater.allLimits([5,5])) else: print "Found no params in log for independent:",ind_attr,"dependent:",dep_attr,", using defaults" surprise = Surprise(updater, params={'C':1,'gamma':0.01},lims=updater.allLimits([5,5])) edv = surprise.createVisualiser(250,100) fig=edv.plotSurpriseGradient() updater.plotArtefacts(plot=fig,stroke='black',fill='white') updater.plotObservedContours(plot=fig) edv.plotExpectationContours(plot=fig,showDU=True,showMU=True) fn = "".join(['-'.join([ind_attr,dep_attr,str(updater.weight_std_ratio),str(surprise.ed.params[0.5]['C']),str(surprise.ed.params[0.5]['gamma'])])+'_hires.png']) edv.save(fn)