Exemple #1
0
        private static Vector3D[] GetForces(SketchDots sketches, bool useOutput, double mult)
        {
            // Give them a very slight pull toward the origin so that the cloud doesn't drift away
            Point3D center     = Math3D.GetCenter(sketches.Sketches.Select(o => o.Position));
            double  centerMult = mult * -5;

            Vector3D centerPullForce = center.ToVector() * centerMult;

            Vector3D[] retVal = Enumerable.Range(0, sketches.Sketches.Length).
                                Select(o => centerPullForce).
                                ToArray();

            // Figure out which set of distances to use
            var distances = useOutput ? sketches.Distances_Output : sketches.Distances_Input;

            foreach (var link in distances)
            {
                // Spring from 1 to 2
                Vector3D spring       = sketches.Sketches[link.Item2].Position - sketches.Sketches[link.Item1].Position;
                double   springLength = spring.Length;

                double difference = link.Item3 - springLength;
                difference *= mult;

                if (Math3D.IsNearZero(springLength))
                {
                    spring = Math3D.GetRandomVector_Spherical_Shell(Math.Abs(difference));
                }
                else
                {
                    spring = spring.ToUnit() * Math.Abs(difference);
                }

                if (difference > 0)
                {
                    // Gap needs to be bigger, push them away
                    retVal[link.Item1] -= spring;
                    retVal[link.Item2] += spring;
                }
                else if (difference < 0)
                {
                    // Close the gap
                    retVal[link.Item1] += spring;
                    retVal[link.Item2] -= spring;
                }
            }

            return(retVal);
        }
Exemple #2
0
        //TODO: If they are only adding a new training sketch, then add to existing instead of repositioning everything (but do reavaluate all outputs, because the network is different)
        public void VisualizeThis(TrainedNework_Simple network, IEnumerable <EncogOCR_SketchData> sketches)
        {
            panelLegend.Children.Clear();

            //_viewport.Children.RemoveAll()
            //_viewport.Children.Remove(_colorWheelVisual);
            if (_sketches != null)
            {
                _viewport.Children.Remove(_sketches.Visual);
            }

            _network = network;

            if (sketches == null)
            {
                _inputSketches = null;
            }
            else
            {
                _inputSketches = sketches.ToArray();
            }

            if (_network == null || _inputSketches == null || _inputSketches.Length == 0)
            {
                return;
            }

            _hues = GetHues(_network.Outputs.Length);

            // Make a 2D legend that shows color of each name
            BuildLegend(_network.Outputs, _hues);

            //_colorWheelVisual = GetColorWheel(_hues.Item1, _hues.Item2);
            //_viewport.Children.Add(_colorWheelVisual);

            _sketches = TestSamples(_network, _inputSketches, _hues);
            _viewport.Children.Add(_sketches.Visual);
        }
        private static Vector3D[] GetForces(SketchDots sketches, bool useOutput, double mult)
        {
            // Give them a very slight pull toward the origin so that the cloud doesn't drift away
            Point3D center = Math3D.GetCenter(sketches.Sketches.Select(o => o.Position));
            double centerMult = mult * -5;

            Vector3D centerPullForce = center.ToVector() * centerMult;

            Vector3D[] retVal = Enumerable.Range(0, sketches.Sketches.Length).
                Select(o => centerPullForce).
                ToArray();

            // Figure out which set of distances to use
            var distances = useOutput ? sketches.Distances_Output : sketches.Distances_Input;

            foreach (var link in distances)
            {
                // Spring from 1 to 2
                Vector3D spring = sketches.Sketches[link.Item2].Position - sketches.Sketches[link.Item1].Position;
                double springLength = spring.Length;

                double difference = link.Item3 - springLength;
                difference *= mult;

                if (Math3D.IsNearZero(springLength))
                {
                    spring = Math3D.GetRandomVector_Spherical_Shell(Math.Abs(difference));
                }
                else
                {
                    spring = spring.ToUnit() * Math.Abs(difference);
                }

                if (difference > 0)
                {
                    // Gap needs to be bigger, push them away
                    retVal[link.Item1] -= spring;
                    retVal[link.Item2] += spring;
                }
                else if (difference < 0)
                {
                    // Close the gap
                    retVal[link.Item1] += spring;
                    retVal[link.Item2] -= spring;
                }
            }

            return retVal;
        }
        //TODO: If they are only adding a new training sketch, then add to existing instead of repositioning everything (but do reavaluate all outputs, because the network is different)
        public void VisualizeThis(TrainedNework_Simple network, IEnumerable<EncogOCR_SketchData> sketches)
        {
            panelLegend.Children.Clear();

            //_viewport.Children.RemoveAll()
            //_viewport.Children.Remove(_colorWheelVisual);
            if (_sketches != null)
            {
                _viewport.Children.Remove(_sketches.Visual);
            }

            _network = network;

            if (sketches == null)
            {
                _inputSketches = null;
            }
            else
            {
                _inputSketches = sketches.ToArray();
            }

            if (_network == null || _inputSketches == null || _inputSketches.Length == 0)
            {
                return;
            }

            _hues = GetHues(_network.Outputs.Length);

            // Make a 2D legend that shows color of each name
            BuildLegend(_network.Outputs, _hues);

            //_colorWheelVisual = GetColorWheel(_hues.Item1, _hues.Item2);
            //_viewport.Children.Add(_colorWheelVisual);

            _sketches = TestSamples(_network, _inputSketches, _hues);
            _viewport.Children.Add(_sketches.Visual);
        }