예제 #1
0
파일: FuzzyNeuron.cs 프로젝트: Diover/nets
 public FuzzyNeuron(Func<double, double> f, Func<IFuzzyNumber> littleFuzzyNumberGenerator)
 {
     _propagatedError = null;
     if(f != null)
         _f = f;
     _generateLittleFuzzyNumber = littleFuzzyNumberGenerator;
 }
예제 #2
0
파일: FuzzyNeuron.cs 프로젝트: Diover/nets
 public void AddInput(ILink link, IFuzzyNumber weight)
 {
     _inputs.Add(link);
     _weights.Add(new Link(weight));
     _weightsDeltas.Add(new Link());
     _weightsLambdas.Add(_defaultWeightLambda);
 }
예제 #3
0
파일: StepState.cs 프로젝트: Diover/nets
 public StepState(int cycle, int step, double cycleError, IFuzzyNumber gradientNorm = null)
     : this()
 {
     Cycle = cycle;
     Step = step;
     CycleError = cycleError;
     GradientNorm = gradientNorm;
 }
예제 #4
0
파일: Matrix.cs 프로젝트: Diover/nets
 public Matrix(int rows, int columns)
 {
     _values = new IFuzzyNumber[rows][];
     for (int i = 0; i < rows; i++)
     {
         _values[i] = new IFuzzyNumber[columns];
     }
 }
예제 #5
0
파일: Vector.cs 프로젝트: Diover/nets
 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);
 }
예제 #6
0
파일: MarketTick.cs 프로젝트: Diover/nets
 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>();
 }
예제 #7
0
파일: Vector.cs 프로젝트: Diover/nets
        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);
        }
예제 #8
0
파일: Matrix.cs 프로젝트: Diover/nets
        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);
        }
예제 #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++;
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #12
0
 public void Set(IFuzzyNumber source)
 {
     _alphaLevels.Clear();
     source.ForeachLevel((alpha, interval) => _alphaLevels.Add(alpha, new IntervalD(interval)));
 }
예제 #13
0
파일: RealNumber.cs 프로젝트: Diover/nets
 public IFuzzyNumber Div(IFuzzyNumber x)
 {
     return new RealNumber(_value / x.GetMod().X);
 }
예제 #14
0
파일: Vector.cs 프로젝트: Diover/nets
 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);
 }
예제 #15
0
파일: Vector.cs 프로젝트: Diover/nets
 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);
 }
예제 #16
0
파일: Link.cs 프로젝트: Diover/nets
 public Link(IFuzzyNumber signal)
 {
     Signal = signal;
 }
예제 #17
0
파일: Matrix.cs 프로젝트: Diover/nets
        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);
        }
예제 #18
0
파일: FuzzyNeuron.cs 프로젝트: Diover/nets
 public FuzzyNeuron(Func<IFuzzyNumber> littleFuzzyNumberGenerator)
 {
     _propagatedError = null;
     _generateLittleFuzzyNumber = littleFuzzyNumberGenerator;
 }
예제 #19
0
파일: RealNumber.cs 프로젝트: Diover/nets
 public void Set(IFuzzyNumber source)
 {
     _value = source.GetMod().X;
 }
예제 #20
0
파일: RealNumber.cs 프로젝트: Diover/nets
 public IFuzzyNumber Mul(IFuzzyNumber x)
 {
     return new RealNumber(_value*x.GetMod().X);
 }
예제 #21
0
 public IFuzzyNumber Div(IFuzzyNumber y)
 {
     return Operation((a, b) => a / b, this, y);
 }
예제 #22
0
 private IFuzzyNumber SquaredVariance(List<IFuzzyNumber> set, IFuzzyNumber expectedValue)
 {
     return set.Sum(number => number.Sub(expectedValue)
                                    .Apply(x => x*x))
               .Div(set.Count - 1);
 }
예제 #23
0
파일: Matrix.cs 프로젝트: Diover/nets
 public Matrix(IFuzzyNumber[][] values)
 {
     _values = values;
 }
예제 #24
0
파일: Vector.cs 프로젝트: Diover/nets
        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);
        }
예제 #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));
            }
        }
예제 #26
0
파일: Vector.cs 프로젝트: Diover/nets
 public Vector(IFuzzyNumber[] values)
 {
     _values = values;
 }
예제 #27
0
 public IFuzzyNumber Mul(IFuzzyNumber y)
 {
     return Operation((a, b) => a*b, this, y);
 }
예제 #28
0
파일: Matrix.cs 프로젝트: Diover/nets
        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);
        }
예제 #29
0
파일: RealNumber.cs 프로젝트: Diover/nets
 public IFuzzyNumber Sum(IFuzzyNumber x)
 {
     return new RealNumber(_value + x.GetMod().X);
 }