def save_statistics_histogram(sequence_paths, histogram_output_path): # Compute histograms for every model statistic Pin = [] Din = [] SCin = [] Dout = [] for sequence in sequence_paths: statistics = util.compute_statistics(sequence, '%s_out' % sequence) Pin.append(statistics[0]) Din.append(statistics[1]) SCin.append(statistics[2]) Dout.append(statistics[3]) fig = plt.figure() plt.subplot(2, 2, 1) plt.hist(Pin) plt.title('Pin') plt.subplot(2, 2, 2) plt.hist(Din) plt.title('Din') plt.subplot(2, 2, 3) plt.hist(SCin) plt.title('SCin') plt.subplot(2, 2, 4) plt.hist(Dout) plt.title('Dout') print('Saving 4D tuple distribution histogram to %s' % histogram_output_path) plt.savefig(histogram_output_path)
def main(): # Parse command line arguments if (len(sys.argv) != 5): print( 'Usage: python power_model_prediction.py <Sequences paths file> <power model binary path> <power model type = 4d_table/linear/quadratic/cubic/full_linear> <output error file path>' ) sys.exit(1) sequences_paths_file = os.path.abspath(sys.argv[1]) power_model_binary_path = os.path.abspath(sys.argv[2]) power_model_type = sys.argv[3] output_error_file_path = os.path.abspath(sys.argv[4]) power_model = None print('Reading power model binary (pickled) from path %s' % power_model_binary_path) with open(power_model_binary_path, 'rb') as f: power_model = pickle.load(f) print('Successfully read power model binary into memory') print('Reading sequences paths file from file %s' % sequences_paths_file) sequence_paths = [] with open(sequences_paths_file, 'r') as f: for sequence_path in f: sequence_paths.append(sequence_path.strip()) print('Successfully read sequence paths into memory') # Compute statistics and actual power for the test sequences actual_power = [] seq_statistics = [] for sequence in sequence_paths: power = util.compute_power('%s_pt_power' % sequence) actual_power.append(power) statistics = util.compute_statistics(sequence, '%s_out' % sequence) seq_statistics.append(statistics) # Predict power using the model that we have available prediction = None if power_model_type == '4d_table': prediction = util.compute_4d_table_power_estimate( power_model, seq_statistics) elif power_model_type == 'linear' or power_model_type == 'quadratic' or power_model_type == 'cubic': prediction = util.compute_coeff_based_power_estimate( power_model, seq_statistics, power_model_type) else: print('Please specify a valid model type.') sys.exit(1) errors = [] with open(output_error_file_path, 'w') as f: for idx in range(0, len(prediction)): pt_power = actual_power[idx] pred_power = prediction[idx] error = (pt_power - pred_power) / pt_power errors.append(error) print('seq: %03d, actual: %.10f, predicted: %.10f, error: %.4f' % (idx, pt_power, pred_power, error)) f.write('%.10f|%.10f|%.4f\n' % (pt_power, pred_power, error))
def construct_cubic_model(sequence_paths): print('Computing cubic power model based on overall Pin, Din, SCin, Dout') A = np.zeros((len(sequence_paths), 35)) b = np.zeros((len(sequence_paths), 1)) for idx in range(0, len(sequence_paths)): power = util.compute_power('%s_pt_power' % sequence_paths[idx]) statistics = util.compute_statistics(sequence_paths[idx], '%s_out' % sequence_paths[idx]) A[idx] = util.construct_cubic_vector(statistics) b[idx] = power power_model = np.linalg.lstsq(A, b)[0] print('Computed these coefficients using least squares') print(power_model) return power_model
def construct_4d_table(sequence_paths): print('Computing 4D table power model') power_model = {} for sequence in sequence_paths: power = util.compute_power('%s_pt_power' % sequence) statistics = util.compute_statistics(sequence, '%s_out' % sequence) if statistics in power_model: print 'special case - multiple power numbers for same 4D tuple' power_model[statistics].append(power) else: power_model[statistics] = [power] # Take average of all power numbers that share a common tuple final_power_model = {} for stat_tuple, power_list in power_model.iteritems(): final_power_model[stat_tuple] = np.mean(power_list) return final_power_model