<jupyter_start><jupyter_text>Testing size complexity<jupyter_code>with open('../inputs/size_test_input.txt', 'w') as outtxt:
    for i in range(1, 13):
        data = generate_matrix(i)
        print np.linalg.det(data)
        outtxt.write('{}\n'.format(i))
        outtxt.write('{}\n'.format(data).replace('[', ' ').replace(']',' '))
        outtxt.write('\n')
def parse_input(filename):
    orders = []
    times = []
    
    for line in open(filename).readlines():
        if line.startswith('Order'):
            line = line.split()
            orders.append(line[1])
            times.append(line[3].rstrip('ns'))
            
    orders = np.array(map(int, orders))
    times = map(int, times)
    times = np.array([item/(10.**9) for item in times])
    
    indx = np.argsort(orders)
    orders = orders[indx]
    times = times[indx]
    
    return orders[:-1], times[:-1]
def exp_func(x, a, b, c):
    return a*10**(b*np.array(x)) + c
fig = plt.figure(figsize=(10, 5))

orders, times = parse_input("../output/size_test_output.txt")
xvals = np.linspace(min(orders), max(orders), 30)
p0=[2e-9, .9, 1e-05]
popt, pcov = curve_fit(exp_func, orders, times, p0=p0)

#-- Linear plot
ax = fig.add_subplot(2, 1, 1)
ax.plot(orders, times, marker='o', label='Data')
#ax.plot(xvals, exp_func(xvals, *popt), color='y')
ax.plot(xvals, exp_func(xvals, *p0), color='r', label='Fit: $(2E-9)10^{.9n} + 1E-5$')
ax.set_title("Calculation time vs Order (2.8Ghz Core i7)")
ax.set_ylabel("Time (s)")
ax.set_xlim(0, 13)
ax.legend(shadow=True, numpoints=1, loc='best')
#-- Log plot

ax2 = fig.add_subplot(2, 1, 2)
ax2.semilogy(orders, times, marker='o')
#ax2.semilogy(xvals, exp_func(xvals, *popt), color='y')
ax2.semilogy(xvals, exp_func(xvals, *p0), color='r')
ax2.set_ylabel("Log Time (s)")
ax2.set_xlim(0, 13)
ax2.set_xlabel("Matrix Order")

fig.savefig('time_complexity.pdf')<jupyter_output><empty_output><jupyter_text>Storage requirement<jupyter_code>def recursion_size(n):
    if n == 1:
        return 1
    else:
        return n*n + recursion_size(n-1)
fig = plt.figure(figsize=(10, 5))

orders = range(1, 13)
spaces = map(recursion_size, orders)
xvals = np.linspace(min(orders), max(orders), 30)
pars = sp.polyfit(orders, spaces, 3)
yvals = sp.polyval(pars, xvals)

#-- Linear plot
ax = fig.add_subplot(1, 1, 1)
ax.plot(orders, spaces, marker='o', label='Data')
ax.plot(xvals, yvals, color='r', label='Fit $O(n^3)$')
ax.set_title("Total array elements vs order.")
ax.set_ylabel("Space (elements)")
ax.set_xlabel("Matrix Order")
ax.set_xlim(0, max(orders)+1)
ax.legend(shadow=True, numpoints=1, loc='best')

fig.savefig('space_complexity.pdf')
pars
with open('../inputs/random_input.txt', 'w') as outtxt:
    for i in range(1, 50):
        data = generate_matrix((i%9) + 1)
        outtxt.write('{}\n'.format((i%9) + 1))
        outtxt.write('{}\n'.format(data).replace('[', ' ').replace(']',' '))
        outtxt.write('\n')
ls ../output/<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19979750253121836, 'fraction_numerical': 0.028349645629429633, 'mean_word_length': 3.9983136593591904, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '271610', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1169, 'n_words': 224, 'path': 'JHU/615.202.81.FA15_data_structures/module_08/analysis/analysis.ipynb', 'repo_name': 'justincely/classwork', 'size': '2963'}