示例#1
0
        /// <inheritdoc/>
        public void Recompute(bool collectStatistics)
        {
            //Spike leak handling
            if (OutputData._spikingSignal > 0)
            {
                //Spike during previous cycle, so reset the counter
                OutputData._afterFirstSpike = true;
                OutputData._spikeLeak       = 0;
            }
            ++OutputData._spikeLeak;

            double normalizedActivation;

            if (_activationFn.TypeOfActivation == ActivationType.Spiking)
            {
                //Spiking activation
                AFSpikingBase af = (AFSpikingBase)_activationFn;
                OutputData._spikingSignal = af.Compute(_tStimuli);
                //OutputData._analogSignal = OutputData._spikingSignal;
                _activationState         = af.InternalState;
                normalizedActivation     = OutputRange.Rescale(af.InternalState, af.InternalStateRange).Bound(OutputRange.Min, OutputRange.Max);
                OutputData._analogSignal = normalizedActivation;
            }
            else
            {
                //Analog activation
                _activationState     = (_analogRetainmentStrength * _activationState) + (1d - _analogRetainmentStrength) * _activationFn.Compute(_tStimuli);
                normalizedActivation = OutputRange.Rescale(_activationState, _activationFn.OutputRange).Bound(OutputRange.Min, OutputRange.Max);
                double activationDifference = _histActivationsQueue == null ? ((normalizedActivation - OutputData._analogSignal)) : (_histActivationsQueue.Full ? (normalizedActivation - _histActivationsQueue.Dequeue()) : (normalizedActivation - 0.5d));
                //Firing event decision
                bool firingEvent = activationDifference > _analogFiringThreshold;
                //Enqueue last normalized activation
                _histActivationsQueue?.Enqueue(normalizedActivation);
                //New output data
                OutputData._analogSignal  = normalizedActivation;
                OutputData._spikingSignal = firingEvent ? 1d : 0d;
            }
            //Update predictors
            _predictorsProvider?.Update(_activationState, normalizedActivation, (OutputData._spikingSignal > 0));
            //Update statistics
            if (collectStatistics)
            {
                Statistics.Update(_iStimuli, _rStimuli, _tStimuli, _activationState, OutputData._analogSignal, OutputData._spikingSignal);
            }
            return;
        }
        public override string ToString()
        {
            var members = new List <string>();

            members.Add(Constructor);
            members.AddRange(InputRange.Select(GetInputAccessor));
            members.Add(AllInputsAccessor);
            members.AddRange(OutputRange.Select(GetOutputAccessor));
            members.Add(AllOutputsAccessor);
            members.Add(AsTupleMethod);
            members.Add(SendMethod);

            return($@"namespace Refactoring.Pipelines.InputsAndOutputs
{{
    public class {ClassName}<{CommaSeparated(InputTypeParameters)}, {CommaSeparated(OutputTypeParameters)}>
    {{
        private readonly InputsAndOutputs _inputsAndOutputs;

{members.JoinWith("\n")}
    }}
}}
");
        }
示例#3
0
        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            // load document
            while (true)
            {
                try
                {
                    if (fpFile.SelectedFile == null)
                    {
                        using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(@"PdfDocumentSourceSamples.Resources.DefaultDocument.pdf"))
                            pdfDocumentSource.LoadFromStream(stream);
                    }
                    else
                    {
                        pdfDocumentSource.LoadFromFile(fpFile.SelectedFile.FullName);
                    }
                    break;
                }
                catch (PdfPasswordException)
                {
                    var password = PasswordWindow.DoEnterPassword(fpFile.SelectedFile.FullName);
                    if (password == null)
                    {
                        return;
                    }
                    pdfDocumentSource.Credential.Password = password;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            //
            OutputRange outputRange;

            if (rbtnPagesAll.IsChecked.Value)
            {
                outputRange = OutputRange.All;
            }
            else
            {
                if (!OutputRange.TryParse(tbPagesRange.Text, out outputRange))
                {
                    MessageBox.Show("Invalid range of pages.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            // execute action
            ExportProvider ep = (ExportProvider)((C1ComboBoxItem)cbExportFilter.SelectedItem).Tag;

            saveFileDialog.DefaultExt = "." + ep.DefaultExtension;
            saveFileDialog.FileName   = (fpFile.SelectedFile == null ? "DefaultDocument" : System.IO.Path.GetFileName(fpFile.SelectedFile.FullName)) + "." + ep.DefaultExtension;
            saveFileDialog.Filter     = String.Format("{0} (*.{1})|*.{1}|All files (*.*)|*.*", ep.FormatName, ep.DefaultExtension);
            bool?dr = saveFileDialog.ShowDialog();

            if (!dr.HasValue || !dr.Value)
            {
                return;
            }

            try
            {
                var exporter = ep.NewExporter();
                exporter.ShowOptions = false;
                exporter.Preview     = true;
                exporter.FileName    = saveFileDialog.FileName;
                exporter.Range       = outputRange;
                pdfDocumentSource.Export(exporter);
                MessageBox.Show("Document was successfully exported.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            if (cbPrinter.SelectedItem == null)
            {
                MessageBox.Show("Please select a printer.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // load document
            while (true)
            {
                try
                {
                    if (fpFile.SelectedFile == null)
                    {
                        using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(@"PdfDocumentSourceSamples.Resources.DefaultDocument.pdf"))
                            pdfDocumentSource.LoadFromStream(stream);
                    }
                    else
                    {
                        pdfDocumentSource.LoadFromFile(fpFile.SelectedFile.FullName);
                    }
                    break;
                }
                catch (PdfPasswordException)
                {
                    var password = PasswordWindow.DoEnterPassword(fpFile.SelectedFile.FullName);
                    if (password == null)
                    {
                        return;
                    }
                    pdfDocumentSource.Credential.Password = password;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            //
            OutputRange outputRange;

            if (rbtnPagesAll.IsChecked.Value)
            {
                outputRange = OutputRange.All;
            }
            else
            {
                if (!OutputRange.TryParse(tbPagesRange.Text, out outputRange))
                {
                    MessageBox.Show("Invalid range of pages.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            try
            {
                C1PrintOptions po = new C1PrintOptions();
                po.PrintQueue  = (PrintQueue)((C1ComboBoxItem)cbPrinter.SelectedItem).Tag;
                po.OutputRange = outputRange;
                pdfDocumentSource.Print(po);
                MessageBox.Show("Document was successfully printed.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }