Example #1
0
 public void ExecutePlan(IPlan plan, MorphoSyntacticContext initialContext)
 {
     var baseAction = TrainingAction.ImplementPlan(plan, _vectors, _contextMaps);
     //todo - could loop to reduce error
     var error = baseAction.Train(_network,initialContext);
     baseAction.SaveContexts(_contextMaps);
 }
 public static MorphoSyntacticContext InitialState()
 {
     var result = new MorphoSyntacticContext {Elements = new double[VectorLength]};
     var r = new Random();
     for (var i = 0; i < result.Elements.Length; i++)
     {
         result.Elements[i] = r.NextDouble()*Epsilon;
     }
     return result;
 }
Example #3
0
 public virtual double Train(INeuralNetwork network, MorphoSyntacticContext context)
 {
     var error = 0.0;
     var denominator = 0.0;
     foreach (var contained in ChildActions)
     {
         denominator += 1.0;
         error += contained.Train(network, context);
     }
     return (denominator > 0.0 ? error/denominator : 0.0);
 }
Example #4
0
        public override double Train(INeuralNetwork network, MorphoSyntacticContext context)
        {
            if (_inputArray == null && _wordVector != null)
            {
                _inputArray = new double[_wordVector.Elements.Length + context.Elements.Length];
                _wordVector.Elements.CopyTo(_inputArray, 0);
            }
            if (_inputArray == null) return base.Train(network, context);

            context.Elements.CopyTo(_inputArray, WordVector.VectorLength);

            var example = new Example {Input = _inputArray, ExpectedResult = _outputArray};
            network.Theta.LoadFrom(_weights);
            var error = network.Train(example, 0.01);
            network.Theta.SaveTo(ref _weights);

            var childContext = new MorphoSyntacticContext(network.HiddenLayer);
            error = (error + base.Train(network, childContext)/2.0);
            return error;
        }
Example #5
0
 public Example(WordVector word, MorphoSyntacticContext context, double[] target )
 {
     Input = new double[WordVector.VectorLength + MorphoSyntacticContext.VectorLength];
     word.Elements.CopyTo(Input,0);
     context.Elements.CopyTo(Input, WordVector.VectorLength);
     ExpectedResult = target;
 }