コード例 #1
0
        public Nonlinearity(NormalDistribution frequencyOfRawStimuli, NormalDistribution frequencyOfSpikeTriggeredStimuli, int points)
        {
            _frequencyOfRawStimuli = frequencyOfRawStimuli;
            _frequencyOfSpikeTriggeredStimuli = frequencyOfSpikeTriggeredStimuli;
            _points = points;

            _parameterChanged = true;
        }
コード例 #2
0
        private void PlotNormalDistribution(double[] data, Histogram histogram, string distributionName, Color color)
        {
            if (data == null || histogram == null)
                return;

            var points = 50;

            var normalDistribution = new NormalDistribution(data.Average(), Math.Variance(data), points, histogram.LowerBound, histogram.UpperBound);

            //var normalDistribution = new NormalDistribution(histogram.Mean(), histogram.Variance(), points, histogram.LowerBound, histogram.UpperBound);

            var densityCurve = normalDistribution.DensityCurve;

            var xValues = new double[points];
            var yValues = new double[points];

            for (var index = 0; index < points; index++)
            {
                xValues[index] = densityCurve[index, 0];
                yValues[index] = densityCurve[index, 1];
            }

            // Add data sources.
            var yDataSource = new EnumerableDataSource<double>(yValues);
            yDataSource.SetYMapping(Y => Y);
            yDataSource.AddMapping(ShapeElementPointMarker.ToolTipTextProperty, Y => string.Format("Normal Value \n\n{0}", Y));

            var xDataSource = new EnumerableDataSource<double>(xValues);
            xDataSource.SetXMapping(X => X);

            var compositeDataSource = new CompositeDataSource(xDataSource, yDataSource);

            // MatchValuePlotter.Viewport.Restrictions.Add(new PhysicalProportionsRestriction { ProportionRatio = 500000 });
            var graph = ChartPlotter.AddLineGraph(compositeDataSource, color, 0.5, distributionName);

            // Cache for later usage (e.g. change visibility).
            if (graph != null)
                _histogramGraphs.Add(graph);
        }
コード例 #3
0
        private void GetSTAResponseHistogramPlotData(out Histogram rawStimuliSTAResponseHistogram, out double[] rawStimuliSTAMatchValues, out Histogram spikeTriggeredStimuliSTAResponseDiagram, out double[] spikeTriggeredStimuliSTAMatchValues, out Nonlinearity nonlinearity, bool recalcData = true)
        {
            rawStimuliSTAResponseHistogram = null;
            rawStimuliSTAMatchValues = null;
            spikeTriggeredStimuliSTAResponseDiagram = null;
            spikeTriggeredStimuliSTAMatchValues = null;
            nonlinearity = null;

            if (_spikes == null)
                return;

            // caching
            if (!recalcData)
            {
                rawStimuliSTAResponseHistogram = _rawStimuliSTAResponseHistogram;
                spikeTriggeredStimuliSTAResponseDiagram = _spikeTriggeredStimuliSTAResponseDiagram;
                nonlinearity = _nonlinearity;

                return;
            }

            var spikes = new List<double[][]>();

            if (Cell1CheckBox.IsChecked != null && Cell1CheckBox.IsChecked.Value)
                spikes.Add(_spikes[0]);

            if (Cell2CheckBox.IsChecked != null && Cell2CheckBox.IsChecked.Value)
                spikes.Add(_spikes[1]);

            if (Cell3CheckBox.IsChecked != null && Cell3CheckBox.IsChecked.Value)
                spikes.Add(_spikes[2]);

            if (Cell4CheckBox.IsChecked != null && Cell4CheckBox.IsChecked.Value)
                spikes.Add(_spikes[3]);

            if (spikes.Count == 0)
                return;

            int offset;
            if (!int.TryParse(OffsetTextbox.Text, out offset))
                offset = 13;

            int maxTime;
            if (!int.TryParse(TimeTextbox.Text, out maxTime))
                maxTime = 13;

            var rawStimuliHistogramBuckets = MatchValuesForRawStimuliBucketsUpDown.Value != null ? MatchValuesForRawStimuliBucketsUpDown.Value.Value : 200;
            var spikeTriggeredStimuliHistogramBuckets = MatchValuesForSpikeTriggeredStimuliBucketsUpDown.Value != null ? MatchValuesForSpikeTriggeredStimuliBucketsUpDown.Value.Value : 200;
            double[,] smoothKernel = null;
            bool useDynamicDivisorForEdges = false;

            GetSmoothKernel(out smoothKernel, out useDynamicDivisorForEdges);

            SpikeTriggeredAnalysis.CalculateSTAResponseHistogram(_stimuli, spikes.ToArray(), false, offset, maxTime, smoothKernel, useDynamicDivisorForEdges, rawStimuliHistogramBuckets, out rawStimuliSTAMatchValues, out rawStimuliSTAResponseHistogram);
            SpikeTriggeredAnalysis.CalculateSTAResponseHistogram(_stimuli, spikes.ToArray(), true, offset, maxTime, smoothKernel, useDynamicDivisorForEdges, spikeTriggeredStimuliHistogramBuckets, out spikeTriggeredStimuliSTAMatchValues, out spikeTriggeredStimuliSTAResponseDiagram);

            _rawStimuliSTAResponseHistogram = rawStimuliSTAResponseHistogram;
            _rawStimuliSTAMatchValues = rawStimuliSTAMatchValues;

            _spikeTriggeredStimuliSTAResponseDiagram = spikeTriggeredStimuliSTAResponseDiagram;
            _spikeTriggeredStimuliSTAMatchValues = spikeTriggeredStimuliSTAMatchValues;

            var frequencyRawStimuli = new NormalDistribution(rawStimuliSTAMatchValues.Average(), Math.Variance(rawStimuliSTAMatchValues), 10, rawStimuliSTAResponseHistogram.LowerBound, rawStimuliSTAResponseHistogram.UpperBound);
            var frequencySpikeTriggeredStimuli = new NormalDistribution(spikeTriggeredStimuliSTAMatchValues.Average(), Math.Variance(spikeTriggeredStimuliSTAMatchValues), 10, spikeTriggeredStimuliSTAResponseDiagram.LowerBound, spikeTriggeredStimuliSTAResponseDiagram.UpperBound);

            nonlinearity =
                // caching
                _nonlinearity = new Nonlinearity(frequencyRawStimuli, frequencySpikeTriggeredStimuli, 100);
        }