!pip freeze %pylab inline import pandas from dtk import walk, process obinna = pandas.read_csv('../data/obinna-walking.txt', delimiter='\t', index_col="TimeStamp", na_values='0.000000') obinna.head() [col for col in obinna.columns if col.endswith('.Ang') or col.endswith('ForY') or col.endswith('.Mom')] obinna['FP2.ForY'].plot(figsize=(18,10)) start = 500 stop = 3000 right_strikes, left_strikes, right_toe_off, left_toe_off = \ walk.gait_landmarks_from_grf(obinna.index.values.astype(float)[start:stop], obinna['FP1.ForY'][start:stop], obinna['FP2.ForY'][start:stop], do_plot=True, min_time=15.0, threshold=28.0) obinna['FP2.ForY'].to_csv('../data/example_vertical_grf.csv') first_foot_down = obinna[right_strikes[0]:right_toe_off[1]] second_foot_down = obinna[right_strikes[1]:right_toe_off[2]] first_foot_down['FP1.ForY'].shape second_foot_down['FP1.ForY'].shape obinna.replace? figure(figsize=(10, 8)) right_steps = {} for i, heel in enumerate(right_strikes[:-1]): right_steps[i] = obinna[heel:right_strikes[i + 1]].apply(pandas.Series.interpolate) print("Time samples in step: {}".format(len(right_steps[i]))) time = process.time_vector(len(right_steps[i]), 100) right_steps[i].index = time plot(time, right_steps[i]['FP1.ForY'], '.-') right_steps = pandas.Panel(right_steps) mean_right_steps = right_steps.mean(axis='items') mean_right_steps['FP1.ForY'].plot(figsize=(10, 8)) right_steps = right_steps.fillna(method='pad') sensors = ['RKneeFlexion.Ang', 'RAnklePlantarFlexion.Ang'] controls = ['RKneeFlexion.Mom', 'RHipFlexion.Mom', 'RAnklePlantarFlexion.Mom'] solver = walk.SimpleControlSolver(right_steps, sensors, controls) gains, sensors = solver.solve() gains.shape figure(figsize=(10, 8)) plot(gains.reshape(gains.shape[0], gains.shape[1] * gains.shape[2]), '.-') solver.sensors = ['RKneeFlexion.Ang'] gains, sensors = solver.solve() figure(figsize=(10, 8)) plot(gains.reshape(gains.shape[0], gains.shape[1] * gains.shape[2]), '.-') A, b = solver.form_a_b() A.shape, b.shape from scipy.sparse.linalg import lsmr, lsqr %%time sol1 = lsmr(A, b) %%time sol2 = lsqr(A, b) np.allclose(sol1[0], sol2[0]) sol1[0] sol2[0] %%time sol3 = solver.least_squares(A, b) sol3[0] A = np.array([[1, 2],[2, 4], [0, 0]]) b = np.array([1, 2, 3]) %%timeit np.linalg.lstsq(A, b) %%timeit lsqr(A,b) %%timeit lsmr(A, b)