public FuzzyNeuron(Func<double, double> f, Func<IFuzzyNumber> littleFuzzyNumberGenerator) { _propagatedError = null; if(f != null) _f = f; _generateLittleFuzzyNumber = littleFuzzyNumberGenerator; }
public void AddInput(ILink link, IFuzzyNumber weight) { _inputs.Add(link); _weights.Add(new Link(weight)); _weightsDeltas.Add(new Link()); _weightsLambdas.Add(_defaultWeightLambda); }
public StepState(int cycle, int step, double cycleError, IFuzzyNumber gradientNorm = null) : this() { Cycle = cycle; Step = step; CycleError = cycleError; GradientNorm = gradientNorm; }
public Matrix(int rows, int columns) { _values = new IFuzzyNumber[rows][]; for (int i = 0; i < rows; i++) { _values[i] = new IFuzzyNumber[columns]; } }
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); }
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>(); }
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); }
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); }
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++; } }
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); }
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); }
public void Set(IFuzzyNumber source) { _alphaLevels.Clear(); source.ForeachLevel((alpha, interval) => _alphaLevels.Add(alpha, new IntervalD(interval))); }
public IFuzzyNumber Div(IFuzzyNumber x) { return new RealNumber(_value / x.GetMod().X); }
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); }
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); }
public Link(IFuzzyNumber signal) { Signal = signal; }
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); }
public FuzzyNeuron(Func<IFuzzyNumber> littleFuzzyNumberGenerator) { _propagatedError = null; _generateLittleFuzzyNumber = littleFuzzyNumberGenerator; }
public void Set(IFuzzyNumber source) { _value = source.GetMod().X; }
public IFuzzyNumber Mul(IFuzzyNumber x) { return new RealNumber(_value*x.GetMod().X); }
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); }
public Matrix(IFuzzyNumber[][] values) { _values = values; }
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); }
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)); } }
public Vector(IFuzzyNumber[] values) { _values = values; }
public IFuzzyNumber Mul(IFuzzyNumber y) { return Operation((a, b) => a*b, this, y); }
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); }
public IFuzzyNumber Sum(IFuzzyNumber x) { return new RealNumber(_value + x.GetMod().X); }