Ejemplo n.º 1
0
// Interpolation in two dimensions.
func ExampleAlgorithm_cube() {
	const (
		inputs   = 2
		outputs  = 1
		minLevel = 1
		maxLevel = 10
		accuracy = 1e-4
		order    = 1
	)

	grid := equidistant.NewClosed(inputs)
	basis := polynomial.NewClosed(inputs, order)
	algorithm := New(inputs, outputs, grid, basis)
	strategy := NewStrategy(inputs, outputs, grid, minLevel, maxLevel, accuracy)

	surrogate := algorithm.Compute(func(x, y []float64) {
		if math.Abs(2.0*x[0]-1.0) < 0.45 && math.Abs(2.0*x[1]-1.0) < 0.45 {
			y[0] = 1.0
		} else {
			y[0] = 0.0
		}
	}, strategy)

	fmt.Println(surrogate)

	// Output:
	// {inputs:2 outputs:1 nodes:477}
}
Ejemplo n.º 2
0
func New(ni, no uint, config *config.Solution) (*Solution, error) {
	power := config.Power
	if power == 0 {
		return nil, errors.New("the interpolation power should be positive")
	}

	var agrid interface {
		hybrid.Grid
		hybrid.Guide
		grid.Parenter
	}
	var abasis hybrid.Basis
	switch config.Rule {
	case "closed":
		agrid = equidistant.NewClosed(ni)
		abasis = polynomial.NewClosed(ni, power)
	case "open":
		agrid = equidistant.NewOpen(ni)
		abasis = polynomial.NewOpen(ni, power)
	default:
		return nil, errors.New("the interpolation rule is unknown")
	}

	return &Solution{
		Algorithm: *hybrid.New(ni, no, agrid, abasis),

		config: config,
		grid:   agrid,
	}, nil
}
Ejemplo n.º 3
0
func (self *fixture) initialize() {
	ni := self.surrogate.Inputs

	switch self.rule {
	case "closed":
		self.grid = equidistant.NewClosed(ni)
		self.basis = polynomial.NewClosed(ni, 1)
	default:
		panic("the rule is unknown")
	}
}