# type is a string representing the type of program.
def plot_program(prog_num, bp, inX, iny, type):
    plt.cla()
    X_bp, y_bp = ascdata.get_bp_data(prog_num, bp, inX, iny)
    plot_inputs = X_bp.T[2]
    plt.plot(plot_inputs, y_bp, "b^")
    plt.savefig("stats" + "_" + "lossvalues" + "_" + type + ".png")


print "GETTING STATS"
# plot_target_histogram(0)
# nprogs = 7
# for prog_num in range(1,nprogs + 1):
#     print "for program number", prog_num
# plot_loss_value(prog_num)
# plot_hamming_distance(prog_num)
# plot_ir_counts(prog_num)
# plot_ir_percents(prog_num)
# plot_target_histogram(prog_num)

X_prog1_nz, y_prog1_nz, X_prog2_nz, y_prog2_nz, X_prog3_nz, y_prog3_nz = ascdata.load_nonzero_progs()
X_prog1, y_prog1, X_prog2, y_prog2 = ascdata.load_shrunken_progs()

# plot_program(5, int("40024f",16), X_prog1_nz, y_prog1_nz, "goodnonzero")
# plot_program(1, int("4014d2",16), X_prog2_nz, y_prog2_nz, "badnonzero")
plot_program(4, int("400649", 16), X_prog3_nz, y_prog3_nz, "sbadnonzero")

# plot_program(5, int("40024f",16), X_prog1, y_prog1, "goodshrunk")
# plot_program(1, int("4014d2",16), X_prog2, y_prog2, "badshrunk")
from sklearn.metrics import mean_squared_error
from sklearn.cross_validation import KFold
from math import sqrt
import matplotlib.pyplot as plt
import ascdata

# Use this to do a linear regression which produces a w for each program and breakpoint.
# Features: X, b
# Target: w

### IMPORT DATA ###
print "IMPORTING DATA"

X, y = ascdata.load_nonzero_asc_data()

X_prog1, y_prog1, X_prog2, y_prog2, X_prog3, y_prog3 = ascdata.load_nonzero_progs()
X_noprog1, y_noprog1, X_noprog2, y_noprog2, X_noprog3, y_noprog3 = ascdata.load_nonzero_noprogs()

# # Data isolated for all breakpoints from a specific program.
# X_prog1, y_prog1 = ascdata.get_bp_data(5, 0, X, y)
# X_prog2, y_prog2 = ascdata.get_bp_data(1, 0, X, y)
# X_prog3, y_prog3 = ascdata.get_bp_data(4, 0, X, y)

# Plot rmses for each lambda
RMSE_reduced_lambdas = [18.12, 18.11, 18.14, 18.35, 18.54, 19.07, 20.08]
RMSE_full_lambdas = [6862.26, 6863.32, 6862.94, 6877.66, 7001.80, 7323.43, 7430.91]

r2_reduced_lambdas = [0.37, 0.37, 0.37, 0.36, 0.34, 0.30, 0.23]
r2_full_lambdas = [0.35, 0.35, 0.35, 0.35, 0.32, 0.26, 0.24]