<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using NeuralNetworkConstructor.Network.Node.ActivationFunction;
using NeuralNetworkConstructor.Network.Node.Synapse;
using System;
using NeuralNetworkConstructor.Common;

namespace NeuralNetworkConstructor.Network.Node
{
    public class Neuron : INode, IRefreshable
    {

        protected readonly Func<double, double> _activationFunction;
        private double? _calculatedOutput;

        public ICollection<ISynapse> Synapses { get; } = new List<ISynapse>();

        public event Action<Neuron> OnOutputCalculated;

        public Neuron(IActivationFunction function)
            : this(function.Calculate)
        {
        }

        public Neuron(Func<double, double> function)
        {
            _activationFunction = function;
        }

        public Neuron(IActivationFunction function, ICollection<ISynapse> synapses)
            : this(function)
        {
            Synapses = synapses;
        }

        public void AddSynapse(ISynapse synapse)
        {
            Synapses.Add(synapse);
        }

        public virtual double Output()
        {
            if (_calculatedOutput != null)
            {
                return _calculatedOutput.Value;
            }

            _calculatedOutput = _activationFunction == null
                ? _activationFunction.Invoke(Synapses.Sum(x => x.Output()))
                : Synapses.Sum(x => x.Output());
            NotifyOutputCalculated();
            return _calculatedOutput.Value;
        }

        protected void NotifyOutputCalculated()<commit_msg>Fix activation function invoking<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using NeuralNetworkConstructor.Network.Node.ActivationFunction;
using NeuralNetworkConstructor.Network.Node.Synapse;
using System;
using NeuralNetworkConstructor.Common;

namespace NeuralNetworkConstructor.Network.Node
{
    public class Neuron : INode, IRefreshable
    {

        protected readonly Func<double, double> _activationFunction;
        private double? _calculatedOutput;

        public ICollection<ISynapse> Synapses { get; } = new List<ISynapse>();

        public event Action<Neuron> OnOutputCalculated;

        public Neuron(IActivationFunction function)
            : this(function.Calculate)
        {
        }

        public Neuron(Func<double, double> function)
        {
            _activationFunction = function;
        }

        public Neuron(IActivationFunction function, ICollection<ISynapse> synapses)
            : this(function)
        {
            Synapses = synapses;
        }

        public void AddSynapse(ISynapse synapse)
        {
            Synapses.Add(synapse);
        }

        public virtual double Output()
        {
            if (_calculatedOutput != null)
            {
                return _calculatedOutput.Value;
            }

            _calculatedOutput = _activationFunction != null
                ? _activationFunction.Invoke(Synapses.Sum(x => x.Output()))
                : Synapses.Sum(x => x.Output());
            NotifyOutputCalculated();
            return _calculatedOutput.Value;
        }

        protected void NotifyOutputCalculated()
{'fraction_non_alphanumeric': 0.07885749767153058, 'fraction_numerical': 0.0, 'mean_word_length': 2.274390243902439, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4547057', 'n_tokens_mistral': 881, 'n_tokens_neox': 785, 'n_words': 166}