#!/usr/bin/env python3

import sys
import numpy as np
import utils


def normal_equations(xs, ys, m, n):
    """
    Perform normal equations on training set

    xs : Training x values
    ys : Training y values
    m : Number of training examples
    n : Number of features

    """
    xs = utils.insert_zeroth_feature(xs, m)
    return (np.linalg.inv((xs.transpose()).dot(xs))).dot(xs.transpose()).dot(ys)


if __name__ == "__main__":
    path = sys.argv[1]
    training_xs, training_ys = utils.training_data_from_csv_file(path)
    print("Training set loaded")
    print("Computing normal equations...")
    utils.print_thetas(normal_equations(training_xs, training_ys, len(training_xs), len(training_xs[0])))
"""
Implementation of logistic regression using gradient descent

"""

import numpy as np
import sys
import utils
import math

def h(thetas, xi):
    """
    Sigmoid hypothesis function for logistic regression
    
    thetas : Theta values
    xi : Feature vector
    
    """
    return 1.0 / (1.0 + math.exp(-thetas.dot(xi)))


if __name__ == "__main__":
    path = sys.argv[1]
    training_xs, training_ys = utils.training_data_from_csv_file(path)
    thetas = utils.gradient_descent(h,
                                    training_xs,
                                    training_ys,
                                    0.001,
                                    4000)
    utils.print_thetas(thetas)