Exemple #1
0
 public FuzzyNeuron(Func<double, double> f, Func<IFuzzyNumber> littleFuzzyNumberGenerator)
 {
     _propagatedError = null;
     if(f != null)
         _f = f;
     _generateLittleFuzzyNumber = littleFuzzyNumberGenerator;
 }
Exemple #2
0
 public void AddInput(ILink link, IFuzzyNumber weight)
 {
     _inputs.Add(link);
     _weights.Add(new Link(weight));
     _weightsDeltas.Add(new Link());
     _weightsLambdas.Add(_defaultWeightLambda);
 }
Exemple #3
0
 public StepState(int cycle, int step, double cycleError, IFuzzyNumber gradientNorm = null)
     : this()
 {
     Cycle = cycle;
     Step = step;
     CycleError = cycleError;
     GradientNorm = gradientNorm;
 }
Exemple #4
0
 public Matrix(int rows, int columns)
 {
     _values = new IFuzzyNumber[rows][];
     for (int i = 0; i < rows; i++)
     {
         _values[i] = new IFuzzyNumber[columns];
     }
 }
Exemple #5
0
 public IVector Mul(IFuzzyNumber x)
 {
     var values = new IFuzzyNumber[Length];
     for (int i = 0; i < _values.Length; i++)
     {
         values[i] = _values[i].Mul(x);
     }
     return new Vector(values);
 }
Exemple #6
0
 public MarketTick(List<IFuzzyNumber> tick, DateTime time, List<IFuzzyNumber> indicators = null)
 {
     Open = tick.ElementAt(0);
     High = tick.ElementAt(1);
     Low = tick.ElementAt(2);
     Close = tick.ElementAt(3);
     Volume = tick.ElementAt(4);
     Time = time;
     Indicators = indicators ?? new List<IFuzzyNumber>();
 }
Exemple #7
0
        public IVector MemberviseMul(IVector x)
        {
            if(Length != x.Length)
                throw new ArgumentException("Vectors dimensions differ.");

            var values = new IFuzzyNumber[Length];
            for (int i = 0; i < _values.Length; i++)
            {
                values[i] = _values[i].Mul(x[i]);
            }
            return new Vector(values);
        }
Exemple #8
0
        public IMatrix Div(IFuzzyNumber x)
        {
            var values = new IFuzzyNumber[Rows][];
            for (int i = 0; i < Rows; i++)
            {
                values[i] = new IFuzzyNumber[Columns];
            }

            for (int i = 0; i < Rows; i++)
                for (int j = 0; j < Columns; j++)
                    values[i][j] = _values[i][j].Div(x);

            return new Matrix(values);
        }
Exemple #9
0
        public void ContainsCorrectLastInputsVectorAfterFirstPropagation()
        {
            const int inputs = 2;
            var hidden = new[] { 2, 2 };
            const int outputs = 2;
            Func<double, double> activation = x => x;
            var net = new SimpleFuzzyNet(inputs, hidden, GenerateNumbers, activation, outputs);
            var input = new List<IFuzzyNumber>
                {
                    new RealNumber(1.0),
                    new RealNumber(2.0),
                };
            var lastInputs = net.GetLastInputsForWeights();
            net.Propagate(input);

            var expectedLastInputs = new IFuzzyNumber[]
                {
                    //output layer
                    //first neuron
                    new RealNumber(-2.0),
                    new RealNumber(-8.0),
                    //second neuron
                    new RealNumber(-2.0),
                    new RealNumber(-8.0),

                    //hidden 1
                    new RealNumber(1.0),
                    new RealNumber(2.0),
                    new RealNumber(1.0),
                    new RealNumber(2.0),

                    //hidden 2
                    new RealNumber(-2.0),
                    new RealNumber(4.0),
                    new RealNumber(-2.0),
                    new RealNumber(4.0),
                };

            int i = 0;
            foreach (var lastInput in lastInputs)
            {
                Assert.That(lastInput.Signal.GetMod().X, Is.EqualTo(expectedLastInputs[i].GetMod().X));
                i++;
            }
        }
Exemple #10
0
        private static IFuzzyNumber Operation(Func<double, double, double> f, IFuzzyNumber y, IFuzzyNumber x)
        {
            var resultLevels = new Dictionary<double, IntervalD>();

            y.ForeachLevel((alpha, leftLevel) =>
                {
                    var rightLevel = x.GetAlphaLevel(alpha);

                    var leftProduct      = f(leftLevel.X, rightLevel.X);
                    var leftRightProduct = f(leftLevel.X, rightLevel.Y);
                    var rightLeftProduct = f(leftLevel.Y, rightLevel.X);
                    var rightProduct     = f(leftLevel.Y, rightLevel.Y);

                    var left = Math.Min(Math.Min(leftProduct, leftRightProduct),
                                        Math.Min(rightProduct, rightLeftProduct));
                    var right = Math.Max(Math.Max(leftProduct, leftRightProduct),
                                         Math.Max(rightProduct, rightLeftProduct));

                    resultLevels.Add(alpha, new IntervalD(left, right));
                });

            return new DiscreteFuzzyNumber(resultLevels);
        }
Exemple #11
0
        public IFuzzyNumber Sum(IFuzzyNumber x)
        {
            var resultLevels = new Dictionary<double, IntervalD>();

            foreach (var leftlevel in _alphaLevels)
            {
                var rightLevel = x.GetAlphaLevel(leftlevel.Key);
                resultLevels.Add(leftlevel.Key, rightLevel + leftlevel.Value);
            }

            return new DiscreteFuzzyNumber(resultLevels);
        }
Exemple #12
0
 public void Set(IFuzzyNumber source)
 {
     _alphaLevels.Clear();
     source.ForeachLevel((alpha, interval) => _alphaLevels.Add(alpha, new IntervalD(interval)));
 }
Exemple #13
0
 public IFuzzyNumber Div(IFuzzyNumber x)
 {
     return new RealNumber(_value / x.GetMod().X);
 }
Exemple #14
0
 public IVector Sum(IVector x)
 {
     var values = new IFuzzyNumber[Length];
     for (int i = 0; i < _values.Length; i++)
     {
         values[i] = _values[i].Sum(x[i]);
     }
     return new Vector(values);
 }
Exemple #15
0
 public IVector Negate()
 {
     var values = new IFuzzyNumber[Length];
     for (int i = 0; i < _values.Length; i++)
     {
         values[i] = _values[i].Negate();
     }
     return new Vector(values);
 }
Exemple #16
0
 public Link(IFuzzyNumber signal)
 {
     Signal = signal;
 }
Exemple #17
0
        public IMatrix Mul(IMatrix x)
        {
            if (Columns != x.Rows)
                throw new ArgumentException("matrixes dimensions are different");

            var values = new IFuzzyNumber[Rows][];
            for (int i = 0; i < Rows; i++)
            {
                values[i] = new IFuzzyNumber[x.Columns];
            }

            for (int i = 0; i < Rows; i++)
                for (int j = 0; j < x.Columns; j++)
                {
                    var locali = i;
                    var localj = j;
                    values[i][j] = FuzzyNumberExtensions.Sum(0, Columns, k => _values[locali][k].Mul(x[k, localj]));
                }

            return new Matrix(values);
        }
Exemple #18
0
 public FuzzyNeuron(Func<IFuzzyNumber> littleFuzzyNumberGenerator)
 {
     _propagatedError = null;
     _generateLittleFuzzyNumber = littleFuzzyNumberGenerator;
 }
Exemple #19
0
 public void Set(IFuzzyNumber source)
 {
     _value = source.GetMod().X;
 }
Exemple #20
0
 public IFuzzyNumber Mul(IFuzzyNumber x)
 {
     return new RealNumber(_value*x.GetMod().X);
 }
Exemple #21
0
 public IFuzzyNumber Div(IFuzzyNumber y)
 {
     return Operation((a, b) => a / b, this, y);
 }
 private IFuzzyNumber SquaredVariance(List<IFuzzyNumber> set, IFuzzyNumber expectedValue)
 {
     return set.Sum(number => number.Sub(expectedValue)
                                    .Apply(x => x*x))
               .Div(set.Count - 1);
 }
Exemple #23
0
 public Matrix(IFuzzyNumber[][] values)
 {
     _values = values;
 }
Exemple #24
0
        public IMatrix OuterMul(IVector x)
        {
            var values = new IFuzzyNumber[Length][];
            for (int i = 0; i < Length; i++)
            {
                values[i] = new IFuzzyNumber[x.Length];
            }

            for (int i = 0; i < Length; i++)
                for (int j = 0; j < x.Length; j++)
                    values[i][j] = _values[i].Mul(x[j]);

            return new Matrix(values);
        }
Exemple #25
0
        public void CreateCorrectLastInputsVectorAfterSecondPropagationWithWeightsChanged()
        {
            const int inputs = 2;
            var hidden = new[] { 2, 2 };
            const int outputs = 2;
            Func<double, double> activation = x => x;
            var net = new SimpleFuzzyNet(inputs, hidden, GenerateNumbers, activation, outputs);
            var input = new List<IFuzzyNumber>
                {
                    new RealNumber(1.0),
                    new RealNumber(2.0),
                };

            var lastInputsLinks = net.GetLastInputsForWeights();
            net.Propagate(input);
            ChangeFirstWeightsOfNeuronsToOne(net.Layers);
            net.Propagate(input);
            var lastInputs = lastInputsLinks.ToSignalsVector();

            var expectedLastInputs = new IFuzzyNumber[]
                {
                    //output layer
                    //first neuron
                    new RealNumber(-5.0),
                    new RealNumber(-5.0),
                    //second neuron
                    new RealNumber(-5.0),
                    new RealNumber(-5.0),

                    //hidden 1
                    new RealNumber(1.0),
                    new RealNumber(2.0),
                    new RealNumber(1.0),
                    new RealNumber(2.0),

                    //hidden 2
                    new RealNumber(-2.0),
                    new RealNumber(3.0),
                    new RealNumber(-2.0),
                    new RealNumber(3.0),
                };

            for (int i = 0; i < expectedLastInputs.Length; i++)
            {
                Assert.That(lastInputs[i].GetMod().X, Is.EqualTo(expectedLastInputs[i].GetMod().X));
            }
        }
Exemple #26
0
 public Vector(IFuzzyNumber[] values)
 {
     _values = values;
 }
Exemple #27
0
 public IFuzzyNumber Mul(IFuzzyNumber y)
 {
     return Operation((a, b) => a*b, this, y);
 }
Exemple #28
0
        public IMatrix Sum(IMatrix x)
        {
            var values = new IFuzzyNumber[Rows][];
            for (int i = 0; i < Rows; i++)
            {
                values[i] = new IFuzzyNumber[Columns];
            }

            for (int i = 0; i < Rows; i++)
                for (int j = 0; j < Columns; j++)
                    values[i][j] = _values[i][j].Sum(x[i, j]);

            return new Matrix(values);
        }
Exemple #29
0
 public IFuzzyNumber Sum(IFuzzyNumber x)
 {
     return new RealNumber(_value + x.GetMod().X);
 }