var trainingSet dataset.Dataset BeforeEach(func() { var err error estimator, err = gradientdescentestimator.NewGradientDescentParameterEstimator( 0.000001, 0.001, 50, lossGradient, ) Ω(err).ShouldNot(HaveOccurred()) }) Context("When the estimator hasn't been trained", func() { It("Returns an error", func() { _, err := estimator.Estimate([]float64{0.02, 0.1, 0.1, 0.1}) Ω(err).Should(BeAssignableToTypeOf(gdeErrors.UntrainedEstimatorError{})) }) }) Context("When the parameter guess is empty", func() { BeforeEach(func() { err := estimator.Train(trainingSet) Ω(err).ShouldNot(HaveOccurred()) }) It("Returns an error", func() { _, err := estimator.Estimate([]float64{}) Ω(err).Should(BeAssignableToTypeOf(gdeErrors.EmptyInitialParametersError{})) }) })
err = trainingSet.AddRowFromStrings([]string{ fmt.Sprintf("%.10f", x0), fmt.Sprintf("%.10f", x1), fmt.Sprintf("%.10f", y), }) Ω(err).ShouldNot(HaveOccurred()) } } err = estimator.Train(trainingSet) Ω(err).ShouldNot(HaveOccurred()) }) Context("Given a mis-shaped initial parameter guess", func() { It("Returns an error", func() { _, err := estimator.Estimate([]float64{1.75, -3.25}) Ω(err).Should(HaveOccurred()) }) }) Context("Given a valid initial parameter guess", func() { It("Does not return an error", func() { _, err := estimator.Estimate([]float64{1.75, -3.25, 4.25}) Ω(err).ShouldNot(HaveOccurred()) }) It("Estimates the true parameters", func() { estimatedParameters, _ := estimator.Estimate([]float64{1.75, -3.25, 4.25}) Ω(estimatedParameters).Should(HaveLen(3)) for i := 0; i < 3; i++ {