(data=None, fname='kmeans')
| 727 | |
| 728 | |
| 729 | def kmeans_fig(data=None, fname='kmeans'): |
| 730 | # bolt vs raw floats, k=16 on top and k=32 on the bottom |
| 731 | |
| 732 | ALGOS = ['Bolt', 'Matmul'] |
| 733 | Ks = [16, 64] |
| 734 | |
| 735 | sb.set_context("talk") |
| 736 | set_palette() |
| 737 | figsize = (6, 6) |
| 738 | fig, axes = plt.subplots(2, 1, figsize=figsize) |
| 739 | |
| 740 | fake_data = data is None |
| 741 | if fake_data: |
| 742 | dicts = [] |
| 743 | |
| 744 | bolt_times = np.linspace(0, 100, 21) |
| 745 | bolt_errs = np.max(Ks) * np.exp(-.1 * bolt_times) |
| 746 | |
| 747 | matmul_times = np.linspace(0, 100, 11) |
| 748 | matmul_errs = np.max(Ks) * np.exp(-.05 * matmul_times) |
| 749 | |
| 750 | for i in range(3): # simulate multiple trials |
| 751 | # bolt_errs *= (1 + .2 * np.random.randn(*bolt_errs.shape)) |
| 752 | # matmul_errs *= (1 + .2 * np.random.randn(*matmul_errs.shape)) |
| 753 | bolt_errs += 5 * np.random.randn(*bolt_errs.shape) |
| 754 | matmul_errs += 5 * np.random.randn(*matmul_errs.shape) |
| 755 | bolt_errs = np.maximum(0, bolt_errs) |
| 756 | matmul_errs = np.maximum(0, matmul_errs) |
| 757 | bolt_errs = np.sort(bolt_errs)[::-1] |
| 758 | matmul_errs = np.sort(matmul_errs)[::-1] |
| 759 | for k in Ks: |
| 760 | for t, err in zip(bolt_times, bolt_errs): |
| 761 | dicts.append({'trial': i, 'algo': 'Bolt', 'k': k, 't': t, 'err': err / k}) |
| 762 | for t, err in zip(matmul_times, matmul_errs): |
| 763 | dicts.append({'trial': i, 'algo': 'Matmul', 'k': k, 't': t, 'err': err / k}) |
| 764 | |
| 765 | # data = pd.DataFrame.from_records(dicts, index=[0]) |
| 766 | data = pd.DataFrame.from_records(dicts) |
| 767 | # print data |
| 768 | # return |
| 769 | |
| 770 | # ------------------------ plot curves |
| 771 | |
| 772 | for i, k in enumerate(Ks): |
| 773 | ax = axes[i] |
| 774 | df = data.loc[data['k'] == k] |
| 775 | df.rename(columns={'algo': ' '}, inplace=True) # hide from legend |
| 776 | |
| 777 | # sb.tsplot(value='err', condition=' ', unit='k', time='t', data=df, ax=ax, n_boot=100) |
| 778 | sb.tsplot(value='err', condition=' ', unit='trial', time='t', data=df, |
| 779 | ax=ax, ci=95, n_boot=500) |
| 780 | |
| 781 | # ------------------------ configure axes |
| 782 | |
| 783 | # configure all axes |
| 784 | for i, ax in enumerate(axes.ravel()): |
| 785 | title = "K-Means Convergence, K={}".format(Ks[i]) |
| 786 | ax.set_title(title, y=1.01) |
nothing calls this directly
no test coverage detected