def get_data(self): colors = {100: "tomato", 500: "dodgerblue", 1000: "springgreen"} markers = {100: "s", 500: "o", 1000: "D"} for popsize in colors: x = [] y = [] for data in self.stats_process.find( {"parameters.popsize": popsize}): x.append(get_reference_array()[10] / data['ten']) y.append(get_reference_array()[len(GOOD_CANDS_LS)] / data['all']) plt.scatter(x, y, c=[colors[popsize]] * len(x), marker=markers[popsize], s=25, label="popsize=" + str(popsize)) plt.legend(loc=4) yxis = plt.ylim() plt.ylim(0.75, 6.5) xxis = plt.xlim() plt.xlim(0.75, 11.5) plt.xticks(np.arange(1, plt.xlim()[1], 1)) plt.yticks(np.arange(1, plt.ylim()[1], 1)) plt.annotate("best GA", xy=(9.9, 5.82), xytext=(10, 6), arrowprops={ "arrowstyle": "->", "connectionstyle": "arc" })
def get_data(self): colors = {100: "tomato", 500: "dodgerblue", 1000: "springgreen"} markers = {100: "s", 500: "o", 1000: "D"} for popsize in colors: x = [] y = [] for data in self.stats_process.find( {"parameters.popsize": popsize}): x.append(data['breakouts_avg']) y.append(get_reference_array()[len(GOOD_CANDS_LS)] / data['all']) plt.scatter(x, y, c=[colors[popsize]] * len(x), marker=markers[popsize], s=30, label="popsize=" + str(popsize)) plt.legend(loc=0) yxis = plt.ylim() plt.ylim(0.75, yxis[1]) plt.yticks(np.arange(1, plt.ylim()[1], 1)) xxis = plt.xlim() plt.xlim(0, xxis[1])
def get_data(self, parameter): plt.title(get_pretty_name(parameter), fontname=self.fontname) data = [] labels = self.stats_process.distinct("parameters." + parameter) if "-" not in str(labels[0]): labels.sort() else: labels.sort( key=lambda label: ord(label.split("-")[0][1]) * 10 + float( label.split("-")[1]) + float(label.split("-")[2])) for label in labels: # get the best best = self.stats_process.find({"parameters." + parameter: label}, sort=[(self.criteria, pymongo.ASCENDING)])[0] if self.criteria == "all": data.append(get_reference_array()[len(GOOD_CANDS_LS)] / best["all"]) elif self.criteria == "ten": data.append(get_reference_array()[10] / best["ten"]) ''' # get the average m_sum = 0.0 npoints = 0.0 num_to_average = 1 # average the num_to_average BEST runs for item in self.stats_process.find({"parameters." + parameter: label}, {"all": 1}, sort=[("all",pymongo.ASCENDING)]).limit(num_to_average): m_sum = m_sum + get_reference_array()[len(GOOD_CANDS_LS)] / item["all"] npoints = npoints + 1 data.append(m_sum / npoints) ''' pretty_labels = [get_pretty_name(n) for n in labels] xlocations = np.array(range(len(data))) + 0.5 width = 0.75 plt.bar(xlocations, data, width=width) plt.xticks(xlocations + width / 2, pretty_labels, fontname=self.fontname) plt.yticks(fontname=self.fontname) plt.xlim(0, xlocations[-1] + width * 2)
def get_data(self): x = [] y = [] idx = 1 for data in self.stats_process.find({}, sort=[("ten", pymongo.ASCENDING)]): x.append(idx) idx = idx + 1 y.append(get_reference_array()[10] / data["ten"]) plt.errorbar(x, y, linestyle="--", lw=self.lw, color="blue") plt.annotate("10 materials", xy=(x[50], y[50]), xytext=(10, 0), color="blue", textcoords='offset points', ha='left', va='bottom', fontname=self.fontname, fontsize=self.fontsize, arrowprops=None) x = [] y = [] idx = 1 for data in self.stats_process.find({}, sort=[("all", pymongo.ASCENDING)]): x.append(idx) idx = idx + 1 y.append(get_reference_array()[len(GOOD_CANDS_LS)] / data["all"]) plt.errorbar(x, y, lw=self.lw, color="blue") plt.annotate("all 20 materials", xy=(x[100], y[100]), xytext=(25, 5), color="blue", textcoords='offset points', ha='left', va='bottom', fontname=self.fontname, fontsize=self.fontsize, arrowprops=None)
def get_score(self, constraint): m_sum = 0.0 npoints = 0.0 num_to_average = 50000 # average the num_to_average BEST runs for item in self.stats_process.find(constraint, { "all": 1 }, sort=[("all", pymongo.ASCENDING) ]).limit(num_to_average): m_sum = m_sum + get_reference_array()[len( GOOD_CANDS_LS)] / item["all"] npoints = npoints + 1 return (m_sum / npoints)
def get_reference_data(self): x = [0, get_reference_array()[len(GOOD_CANDS_LS)]] y = [0, len(GOOD_CANDS_LS)] plt.errorbar(x, y, lw=self.lw, color="black") plt.annotate("random", xy=(x[1] * 0.15, y[1] * 0.15), xytext=(-5, 5), color="black", textcoords='offset points', ha='right', va='bottom', fontname=self.fontname, fontsize=self.fontsize, arrowprops=None)
''' from ga_optimization_ternary.database import Stats_Database from ga_optimization_ternary.utils import get_reference_array __author__ = "Anubhav Jain" __copyright__ = "Copyright 2012, The Materials Project" __version__ = "0.1" __maintainer__ = "Anubhav Jain" __email__ = "*****@*****.**" __date__ = "Oct 4, 2012" if __name__ == "__main__": sdb = Stats_Database() sdb_os = Stats_Database(extension="_OS") print get_reference_array()[20] print get_reference_array()[10] # print headers params = ["crossover_fnc", "popsize", "selection_overall", "mutation_rate", "elitism_num", "fitness_fnc"] for param in params: print param, print 'ten', 'all', 'half (OS)', 'all (OS)' for item in sdb._stats_process.find(): unique_key = item['unique_key'] if "eval_fitness_complex_product" in unique_key: unique_key = unique_key.replace("eval_fitness_complex_product", "eval_fitness_complex_product_oxide_shield") else: unique_key = unique_key.replace("eval_fitness_complex", "eval_fitness_complex_oxide_shield") unique_key = unique_key.replace("eval_fitness_simple", "eval_fitness_simple_oxide_shield")
def get_data(self): colors = { "eval_fitness_simple": "dodgerblue", "eval_fitness_complex": "dodgerblue", "eval_fitness_complex_product": "dodgerblue" } markers = { "eval_fitness_simple": "o", "eval_fitness_complex": "o", "eval_fitness_complex_product": "o" } #colors = {"eval_fitness_simple": "tomato", "eval_fitness_complex": "dodgerblue", "eval_fitness_complex_product": "springgreen"} #markers = {"eval_fitness_simple": "s", "eval_fitness_complex": "o", "eval_fitness_complex_product": "D"} for ff in colors: x = [] y = [] for data in self.stats_process.find({"parameters.fitness_fnc": ff}): unique_key = data['unique_key'] if "eval_fitness_complex_product" in unique_key: unique_key = unique_key.replace( "eval_fitness_complex_product", "eval_fitness_complex_product_oxide_shield") else: unique_key = unique_key.replace( "eval_fitness_complex", "eval_fitness_complex_oxide_shield") unique_key = unique_key.replace( "eval_fitness_simple", "eval_fitness_simple_oxide_shield") data2 = self.stats_process_os.find_one( {"unique_key": unique_key}) m_idx = len(GOOD_CANDS_LS) m_idx_OS = len(GOOD_CANDS_OS) if self.crit == "half": m_idx = int(len(GOOD_CANDS_LS) / 2) m_idx_OS = int(len(GOOD_CANDS_OS) / 2) x.append(get_reference_array()[m_idx] / data[self.crit]) y.append(get_reference_array_OS()[m_idx_OS] / data2[self.crit]) plt.scatter(x, y, c=[colors[ff]] * len(x), marker=markers[ff], s=25, label=get_pretty_name(ff)) #plt.legend(loc=4) yxis = plt.ylim() topy = 10 if self.crit == "half" else 9 topx = 11.5 if self.crit == "half" else 7 plt.ylim(0.75, topy) xxis = plt.xlim() plt.xlim(0.75, topx) plt.xticks(np.arange(1, plt.xlim()[1], 1)) plt.yticks(np.arange(1, plt.ylim()[1], 1))
self.stats_process = self.db._stats_process for it in self.stats_process.find(): p = it['parameters'] print("{}\t{}\t{}\t{}\t{}\t{}\t{}").format( p['popsize'], get_pretty_name(p['selection_fnc']), get_pretty_name(p['fitness_fnc']), get_pretty_name(p['crossover_fnc']), p['elitism_num'], it['ten'], it['all']) if __name__ == "__main__": format = "png" print get_reference_array()[20] print get_reference_array()[20] / 1547.35 print get_reference_array()[10] / 532.05 if format: mpl.rcParams['savefig.dpi'] = 160 #LSOSPlot(format=format, crit="all") #HeatMapPlot(format=format) #BreakoutPlot(format=format) #PerformancePlot(format=format) #ComparisonPlot(format=format) #ParametersPlot(format=format) PerformancePlotExclusion(format=format) #TenAllPlot(format=format) else:
''' from ga_optimization_ternary.database import Stats_Database from ga_optimization_ternary.utils import get_reference_array __author__ = "Anubhav Jain" __copyright__ = "Copyright 2012, The Materials Project" __version__ = "0.1" __maintainer__ = "Anubhav Jain" __email__ = "*****@*****.**" __date__ = "Oct 4, 2012" if __name__ == "__main__": sdb = Stats_Database() sdb_os = Stats_Database(extension="_OS") print get_reference_array()[20] print get_reference_array()[10] # print headers params = [ "crossover_fnc", "popsize", "selection_overall", "mutation_rate", "elitism_num", "fitness_fnc" ] for param in params: print param, print 'ten', 'all', 'half (OS)', 'all (OS)' for item in sdb._stats_process.find(): unique_key = item['unique_key'] if "eval_fitness_complex_product" in unique_key: unique_key = unique_key.replace(