Esempio n. 1
0
func score(strategy algorithm.Strategy, state *algorithm.State, ni, no uint) []float64 {
	nn := uint(len(state.Indices)) / ni
	scores := make([]float64, nn)
	for i := uint(0); i < nn; i++ {
		scores[i] = strategy.Score(&algorithm.Element{
			Index:   state.Indices[i*ni : (i+1)*ni],
			Node:    state.Nodes[i*ni : (i+1)*ni],
			Volume:  state.Volumes[i],
			Value:   state.Values[i*no : (i+1)*no],
			Surplus: state.Surpluses[i*no : (i+1)*no],
		})
	}
	return scores
}
Esempio n. 2
0
func score(strategy algorithm.Strategy, state *algorithm.State, ni, no uint) []float64 {
	nn := uint(len(state.Counts))
	scores := []float64(nil)
	for i, j := uint(0), uint(0); i < nn; i++ {
		for m := j + state.Counts[i]; j < m; j++ {
			scores = append(scores, strategy.Score(&algorithm.Element{
				Index:   state.Indices[j*ni : (j+1)*ni],
				Node:    state.Nodes[j*ni : (j+1)*ni],
				Volume:  state.Volumes[j],
				Value:   state.Values[j*no : (j+1)*no],
				Surplus: state.Surpluses[j*no : (j+1)*no],
			}))
		}
	}
	return scores
}
Esempio n. 3
0
// Compute constructs an interpolant for a function.
func (self *Algorithm) Compute(target algorithm.Target,
	strategy algorithm.Strategy) *algorithm.Surrogate {

	ni, no := self.ni, self.no
	surrogate := algorithm.NewSurrogate(ni, no)
	for s := strategy.First(surrogate); s != nil; s = strategy.Next(s, surrogate) {
		s.Volumes = internal.Measure(self.basis, s.Indices, ni)
		s.Nodes = self.grid.Compute(s.Indices)
		s.Values = algorithm.Invoke(target, s.Nodes, ni, no)
		s.Estimates = internal.Estimate(self.basis, surrogate.Indices,
			surrogate.Surpluses, s.Nodes, ni, no)
		s.Surpluses = internal.Subtract(s.Values, s.Estimates)
		s.Scores = score(strategy, s, ni, no)
		surrogate.Push(s.Indices, s.Surpluses, s.Volumes)
	}
	return surrogate
}