Exemplo n.º 1
0
        private void PopulateSeriesData()
        {
            FourierTransform discreteTransform = new Dft();
            FourierTransform fastTransform = new Fft();
            FastWalshTransform walshTransform = new FastWalshTransform();

            Discretizer discretizer = new Discretizer();
            LineSeriesBuilder seriesBuilder = new LineSeriesBuilder();

            IDictionary<double, double> discreteData = discretizer.Discretize(f, 0, Period, Period/N)
                .Take(N) // Take only the given number of elements. Otherwise problem appears in FFT.
                .ToDictionary(x => x.Key, x => x.Value);

            double[] fwtData = walshTransform.DoTransform(discreteData.Values.ToArray());

            ICollection<Complex> discreteTransformData = discreteTransform.DoTransform(discreteData.Values);
            ICollection<Complex> fastTransformData = fastTransform.DoTransform(discreteData.Values);

            seriesManager.Add(SeriesNames.DftMagnitudes, seriesBuilder.CreateSeries("DFT Magnitude", discreteData.Keys, discreteTransform.Magnitudes));
            seriesManager.Add(SeriesNames.FftMagnitudes, seriesBuilder.CreateSeries("FFT Magnitude", discreteData.Keys, fastTransform.Magnitudes));
            seriesManager.Add(SeriesNames.DftPhases, seriesBuilder.CreateSeries("DFT Phase", discreteData.Keys, discreteTransform.Phases));
            seriesManager.Add(SeriesNames.FftPhases, seriesBuilder.CreateSeries("FFT Phase", discreteData.Keys, fastTransform.Phases));
            seriesManager.Add(SeriesNames.ForwardFwt, seriesBuilder.CreateSeries("FWT", discreteData.Keys, fwtData));

            double[] fwtDataInverse = walshTransform.DoTransformInverse(fwtData);
            seriesManager.Add(SeriesNames.InverseFwt, seriesBuilder.CreateSeries("IFWT", discreteData.Keys, fwtDataInverse));

            PopulateStats();
            discreteTransform.DoTransformInverse(discreteTransformData);
            fastTransform.DoTransformInverse(fastTransformData);

            seriesManager.Add(SeriesNames.OriginalF, seriesBuilder.CreateSeries("Original F(x)", discretizer.Discretize(f, 0, Period, 0.01)));
            seriesManager.Add(SeriesNames.InverseFft, seriesBuilder.CreateSeries("Inverse FFT", discreteData.Keys, fastTransform.Magnitudes));
            seriesManager.Add(SeriesNames.InverseDft, seriesBuilder.CreateSeries("Inverse DFT", discreteData.Keys, discreteTransform.Magnitudes));
        }
Exemplo n.º 2
0
Arquivo: Dft.cs Projeto: romannort/Dsp
 public override ICollection<Complex> DoTransform(Func<Double, Double> func, Int32 n)
 {
     Discretizer discretizer = new Discretizer();
     ICollection<Double> data = discretizer.Discretize(func, n, 1.0);
     ICollection<Complex> result = DoTransform(data);
     return result;
 }
Exemplo n.º 3
0
        public void DiscretizationTest()
        {
            Discretizer.DiscretizeTrainingSets();

            Discretizer.ProcessAdditionalMethodCases();

            Discretizer.ProcessAdditionalClassCases();
        }
Exemplo n.º 4
0
        public BayesianNetwork(string networkFile)
        {
            SmileLicense.ActivateLicense();
            LoadNetworkFromFile(networkFile);

            _networkFile = networkFile;

            if (!Discretizer.IsDiscretized)
            {
                Discretizer.DiscretizeTrainingSets();
            }
        }
Exemplo n.º 5
0
        public void Start( /*Func<double, double> x, Func<double, double> y*/)
        {
            const double start = 0;
            const double end = 4*Math.PI;
            const int dotsNumber = 256;

            Func<double, double> x = b => Math.Sin(4*b);
            Func<double, double> y = a => Math.Sin(a) + Math.Cos(4*a);

            Discretizer discretizer = new Discretizer();

            IDictionary<Double, Double> xData = discretizer.Discretize(x, start, end, dotsNumber);
            IDictionary<Double, Double> yData = discretizer.Discretize(y, start, end, dotsNumber);

            DiscreteConvolution dConvolution = new DiscreteConvolution();
            ICollection<Double> discreteConvolutionResult = dConvolution.Do(xData.Values, yData.Values, xData.Count);

            FastConvolution fConvolution = new FastConvolution();
            ICollection<Double> fastConvolutionResult = fConvolution.Do(xData.Values, yData.Values, xData.Count);

            DiscreteConvolution = discreteConvolutionResult
                .Select((v, i) => new KeyValuePair<Double, Double>(xData.Keys.ElementAt(i), v))
                .ToDictionary(kp => kp.Key, kp => kp.Value);

            FastConvolution = fastConvolutionResult
                .Select((v, i) => new KeyValuePair<Double, Double>(xData.Keys.ElementAt(i), v))
                .ToDictionary(kp => kp.Key, kp => kp.Value);

            DiscreteCorrelation dCorrelation = new DiscreteCorrelation();
            ICollection<Double> discreteCorrelationResult = dCorrelation.Do(xData.Values, yData.Values, xData.Count);

            FastCorrelation fCorrelation = new FastCorrelation();
            ICollection<Double> fastCorrelationResult = fCorrelation.Do(xData.Values, yData.Values, xData.Count);

            DiscreteCorrelation = discreteCorrelationResult
                .Select((v, i) => new KeyValuePair<Double, Double>(xData.Keys.ElementAt(i), v))
                .ToDictionary(kp => kp.Key, kp => kp.Value);

            FastCorrelation = fastCorrelationResult
                .Select((v, i) => new KeyValuePair<Double, Double>(xData.Keys.ElementAt(i), v))
                .ToDictionary(kp => kp.Key, kp => kp.Value);
        }
Exemplo n.º 6
0
        public void Learn()
        {
            IDictionary <string, DiscretizedData> map = GenerateBinMap();

            SetOutcomeIds();

            LaplaceEstimator.LaplaceEstimation(Discretizer.MethodDataset, _network, map, "Long_Method", 1);

            var cases = Discretizer.ProcessAdditionalMethodCases();

            if (cases.Count > 0)
            {
                //calculate the fading factor according the samplesize of the trainingset:
                double originalCount = Discretizer.MethodDataset.Tables[0].Rows.Count;
                double q             = (originalCount - cases.Count) / originalCount;

                LaplaceEstimator.Adapt(cases, Discretizer.MethodDataset, _network, map, "Long_Method", 1, q);
            }

            _network.SaveNetwork();
        }
Exemplo n.º 7
0
Arquivo: Fft.cs Projeto: romannort/Dsp
 /// <summary> Does fast fouries transform. </summary>
 /// <param name="func"></param>
 /// <param name="n"></param>
 /// <returns></returns>
 public override ICollection<Complex> DoTransform(Func<Double, Double> func, Int32 n)
 {
     Discretizer discretizer = new Discretizer();
     IList<Double> discrete = (IList<Double>)discretizer.Discretize(func, n, 1.0);
     return DoTransform(discrete);
 }