def test_extended_inputs(): inputs = np.array([[3]]) assert np.all(utils.extended_inputs(inputs) == np.array([[1, 3]])) inputs = np.array([[3], [4]]) assert np.all(utils.extended_inputs(inputs) == np.array([[1, 3], [1, 4]])) inputs = np.array([[3, 4, 5], [6, 7, 8]]) assert np.all( utils.extended_inputs(inputs) == np.array([[1, 3, 4, 5], [1, 6, 7, 8] ]))
def normal_equation(inputs, outputs): X = utils.extended_inputs(inputs) theta = np.linalg.inv(X.T @ X) @ X.T @ outputs return theta
def linear_model(theta, inputs): inputs_extended = utils.extended_inputs(inputs) return inputs_extended @ theta
def jacobien_rms(theta, inputs, outputs, model): n_samples = outputs.shape[0] return 1 / n_samples * ( (model(theta, inputs) - outputs) @ utils.extended_inputs(inputs))
def logistic_model(theta, inputs): inputs_extended = utils.extended_inputs(inputs) return sigmoid(inputs_extended @ theta)