Last active
October 6, 2020 08:58
-
-
Save kayhman/7ec09daf1226132aa7c566644fb9795c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def linear_predictions(weights, inputs): | |
# y = weights[0] inputs[0] + weights[1] * inputs[1] | |
# where inputs[0] = 1.0 | |
return np.dot(inputs, weights) * 60.0 | |
def squared_loss(weights, inputs, targets): | |
# Training loss is the negative squared loss | |
preds = linear_predictions(weights, inputs) | |
err = (preds - targets)**2 | |
return np.sum(err) | |
v_avg = 30 # km/h | |
startup_time = 2 /60.0 # hours | |
inputs = np.array([[1.0, 6.0], | |
[1.0, 4.0 ]]) | |
targets = np.array([13, 10.5]) | |
weights = np.array([startup_time, 1.0 / v_avg]) # Program params are estimaed by experience, stats analysis, Least Square Error, ... | |
print("Trained loss:", squared_loss(weights, inputs, targets)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment