This repository has been archived by the owner on Nov 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
errors.go
72 lines (60 loc) · 2.42 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright ©2014 The gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package optimize
import (
"errors"
"fmt"
"math"
)
var (
// ErrZeroDimensional signifies an optimization was called with an input of length 0.
ErrZeroDimensional = errors.New("optimize: zero dimensional input")
// ErrLinesearcherFailure signifies that a Linesearcher has iterated too
// many times. This may occur if the gradient tolerance is set too low.
ErrLinesearcherFailure = errors.New("linesearch: failed to converge")
// ErrNonDescentDirection signifies that LinesearchMethod has received a
// search direction from a NextDirectioner in which the function is not
// decreasing.
ErrNonDescentDirection = errors.New("linesearch: non-descent search direction")
// ErrNoProgress signifies that LinesearchMethod cannot make further
// progress because there is no change in location after Linesearcher step
// due to floating-point arithmetic.
ErrNoProgress = errors.New("linesearch: no change in location after Linesearcher step")
// ErrLinesearcherBound signifies that a Linesearcher reached a step that
// lies out of allowed bounds.
ErrLinesearcherBound = errors.New("linesearch: step out of bounds")
)
// ErrFunc is returned when an initial function value is invalid. The error
// state may be either +Inf or NaN. ErrFunc satisfies the error interface.
type ErrFunc float64
func (err ErrFunc) Error() string {
switch {
case math.IsInf(float64(err), 1):
return "optimize: initial function value is infinite"
case math.IsNaN(float64(err)):
return "optimize: initial function value is NaN"
default:
panic("optimize: bad ErrFunc")
}
}
// ErrGrad is returned when an initial gradient is invalid. The error gradient
// may be either ±Inf or NaN. ErrGrad satisfies the error interface.
type ErrGrad struct {
Grad float64 // Grad is the invalid gradient value.
Index int // Index is the position at which the invalid gradient was found.
}
func (err ErrGrad) Error() string {
switch {
case math.IsInf(err.Grad, 0):
return fmt.Sprintf("optimize: initial gradient is infinite at position %d", err.Index)
case math.IsNaN(err.Grad):
return fmt.Sprintf("optimize: initial gradient is NaN at position %d", err.Index)
default:
panic("optimize: bad ErrGrad")
}
}
// List of shared panic strings
var (
badProblem = "optimize: objective function is undefined"
)