࠷ٸ߱Լ๏ʹΑΔଟ߲ࣜճؼ(PMBOH
// fθ(x) Ϟσϧ
func PredictionFunction(x float64, thetas []float64) float64 {
result := 0.0
for i, theta := range thetas {
result += theta * math.Pow(x, float64(i))
}
return result
}
// E(θ) తؔ
func ObjectiveFunction(trainings DataSet, thetas []float64) float64 {
result := 0.0
for _, training := range trainings {
result += math.Pow((training.Y - PredictionFunction(training.X, thetas)), 2)
}
return result / 2.0
}