private void RebuildDistanceProps() { const double B = .75d; // y=mx+b: don't want to use a b of 1, because y gets added to a neuron's current output, so multiple objects close together would quickly saturate a neuron const double B_at_neighbor = .4d; // at a distance of nearest neighbor, what the output should be (this needs to be relatively high so that there is some overlap. Otherwise there are holes where items won't be seen) // Rise over run, but negative double slope = (B_at_neighbor - B) / _neuronDistBetween; // I want a distance of _neuronDistBetween between the outermost neuron and SearchRadius double scale = _searchRadius / (_neuronMaxRadius + _neuronDistBetween); // Take each existing length times scale to see where they should be. Don't need to worry about checking for // null, there are no neurons at 0,0,0. Point3D[] worldScalePositions = _neurons.Select(o => (o.PositionUnit.Value * (o.PositionLength * scale)).ToPoint()).ToArray(); // Store a new one _distProps = new DistanceProps(_searchRadius, _neuronMaxRadius, _neuronDistBetween, slope, B, worldScalePositions); }
private static void UpdateNeurons(Neuron_SensorPosition[] neurons, Tuple<Point3D, Quaternion> location, IEnumerable<MapObjectInfo> items, DistanceProps distProps, long botToken) { //TODO: Rotate into world // Since neuron.Value is a volatile, build up the final values in a local array double[] values = new double[neurons.Length]; Vector3D positionVect = location.Item1.ToVector(); foreach (MapObjectInfo item in items) { if (item.Token == botToken) { continue; } for (int cntr = 0; cntr < neurons.Length; cntr++) { //TODO: don't just look at item's position. Should also account for its radius double distance = (distProps.NeuronWorldPositions[cntr] + positionVect - item.Position).Length; // y=mx+b double neuronValue = (distProps.Slope * distance) + distProps.B; if (neuronValue > 0) // if the item is too far from the neuron, the slope will take the value negative, but just ignore those { values[cntr] += neuronValue; } } } // Store the new neuron values for (int cntr = 0; cntr < neurons.Length; cntr++) { if (values[cntr] > 1) { neurons[cntr].Value = 1; } else { neurons[cntr].Value = values[cntr]; } } }