Example #1
0
// for each weighted input vector, calculate the (inputs * weights) dot product
// and sum all of these dot products together to produce a sum
func (neuron *Neuron) weightedInputDotProductSum(weightedInputs []*weightedInput) float64 {

	var dotProductSummation float64
	dotProductSummation = 0

	for _, weightedInput := range weightedInputs {
		inputs := weightedInput.inputs
		weights := weightedInput.weights
		inputVector := vector.NewFrom(inputs)
		weightVector := vector.NewFrom(weights)
		dotProduct, error := vector.DotProduct(inputVector, weightVector)
		if error != nil {
			t := "%T error performing dot product between %v and %v"
			message := fmt.Sprintf(t, neuron, inputVector, weightVector)
			panic(message)
		}
		dotProductSummation += dotProduct
	}

	return dotProductSummation

}
Example #2
0
func (a *FLWMAgent) MoveRandomly(steplength float64) {
	//random direction
	bsize := float64(a.ls.Size)
	v := vector.NewFrom([]float64{a.ls.random(-bsize, bsize), a.ls.random(-bsize, bsize)})
	v.Normalize()
	v.Scale(steplength)
	x, _ := v.Get(0)
	y, _ := v.Get(1)
	x = x + a.X
	y = y + a.Y

	// check bounds
	if x < 0 {
		x = bsize + x // reenter world on the other side
	}
	if y < 0 {
		y = bsize + y // reenter world on the other side
	}
	if x > bsize {
		x = x - bsize
	}
	if y > bsize {
		y = y - bsize
	}
	if x >= float64(a.ls.Size) || x < 0 || y >= float64(a.ls.Size) || y < 0 {
		// just try again
		fmt.Printf("out of bounds %f/%f of %f\n", x, y, bsize)
		a.MoveRandomly(steplength)
		return
	}
	//fmt.Printf("move from %f/%f to %f/%f\n",a.X,a.Y,x,y)
	a.ls.tree.Move(a, qt.Twof{x, y})

	a.X = x
	a.Y = y
}