Ejemplo n.º 1
0
 public void Part2()
 {
     SetNextInput(5);
     CreateAndRunComputer(new[] { 3, 225, 1, 225, 6, 6, 1100, 1, 238, 225, 104, 0, 1001, 210, 88, 224, 101, -143, 224, 224, 4, 224, 1002, 223, 8, 223, 101, 3, 224, 224, 1, 223, 224, 223, 101, 42, 92, 224, 101, -78, 224, 224, 4, 224, 1002, 223, 8, 223, 1001, 224, 3, 224, 1, 223, 224, 223, 1101, 73, 10, 225, 1102, 38, 21, 225, 1102, 62, 32, 225, 1, 218, 61, 224, 1001, 224, -132, 224, 4, 224, 102, 8, 223, 223, 1001, 224, 5, 224, 1, 224, 223, 223, 1102, 19, 36, 225, 102, 79, 65, 224, 101, -4898, 224, 224, 4, 224, 102, 8, 223, 223, 101, 4, 224, 224, 1, 224, 223, 223, 1101, 66, 56, 224, 1001, 224, -122, 224, 4, 224, 102, 8, 223, 223, 1001, 224, 2, 224, 1, 224, 223, 223, 1002, 58, 82, 224, 101, -820, 224, 224, 4, 224, 1002, 223, 8, 223, 101, 3, 224, 224, 1, 223, 224, 223, 2, 206, 214, 224, 1001, 224, -648, 224, 4, 224, 102, 8, 223, 223, 101, 3, 224, 224, 1, 223, 224, 223, 1102, 76, 56, 224, 1001, 224, -4256, 224, 4, 224, 102, 8, 223, 223, 1001, 224, 6, 224, 1, 223, 224, 223, 1102, 37, 8, 225, 1101, 82, 55, 225, 1102, 76, 81, 225, 1101, 10, 94, 225, 4, 223, 99, 0, 0, 0, 677, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1105, 0, 99999, 1105, 227, 247, 1105, 1, 99999, 1005, 227, 99999, 1005, 0, 256, 1105, 1, 99999, 1106, 227, 99999, 1106, 0, 265, 1105, 1, 99999, 1006, 0, 99999, 1006, 227, 274, 1105, 1, 99999, 1105, 1, 280, 1105, 1, 99999, 1, 225, 225, 225, 1101, 294, 0, 0, 105, 1, 0, 1105, 1, 99999, 1106, 0, 300, 1105, 1, 99999, 1, 225, 225, 225, 1101, 314, 0, 0, 106, 0, 0, 1105, 1, 99999, 8, 226, 677, 224, 102, 2, 223, 223, 1005, 224, 329, 101, 1, 223, 223, 1008, 677, 677, 224, 1002, 223, 2, 223, 1006, 224, 344, 1001, 223, 1, 223, 107, 226, 677, 224, 102, 2, 223, 223, 1005, 224, 359, 1001, 223, 1, 223, 1108, 677, 677, 224, 1002, 223, 2, 223, 1006, 224, 374, 101, 1, 223, 223, 1107, 677, 677, 224, 1002, 223, 2, 223, 1006, 224, 389, 101, 1, 223, 223, 108, 226, 677, 224, 102, 2, 223, 223, 1006, 224, 404, 101, 1, 223, 223, 7, 677, 677, 224, 102, 2, 223, 223, 1006, 224, 419, 101, 1, 223, 223, 108, 677, 677, 224, 102, 2, 223, 223, 1006, 224, 434, 1001, 223, 1, 223, 7, 226, 677, 224, 102, 2, 223, 223, 1006, 224, 449, 1001, 223, 1, 223, 108, 226, 226, 224, 102, 2, 223, 223, 1005, 224, 464, 101, 1, 223, 223, 8, 226, 226, 224, 1002, 223, 2, 223, 1006, 224, 479, 101, 1, 223, 223, 1008, 226, 226, 224, 102, 2, 223, 223, 1005, 224, 494, 1001, 223, 1, 223, 1008, 677, 226, 224, 1002, 223, 2, 223, 1005, 224, 509, 101, 1, 223, 223, 7, 677, 226, 224, 102, 2, 223, 223, 1006, 224, 524, 101, 1, 223, 223, 1007, 677, 226, 224, 1002, 223, 2, 223, 1006, 224, 539, 1001, 223, 1, 223, 1108, 677, 226, 224, 102, 2, 223, 223, 1005, 224, 554, 1001, 223, 1, 223, 8, 677, 226, 224, 1002, 223, 2, 223, 1005, 224, 569, 101, 1, 223, 223, 1108, 226, 677, 224, 1002, 223, 2, 223, 1005, 224, 584, 101, 1, 223, 223, 1107, 677, 226, 224, 102, 2, 223, 223, 1006, 224, 599, 101, 1, 223, 223, 107, 226, 226, 224, 102, 2, 223, 223, 1006, 224, 614, 1001, 223, 1, 223, 107, 677, 677, 224, 1002, 223, 2, 223, 1005, 224, 629, 1001, 223, 1, 223, 1107, 226, 677, 224, 1002, 223, 2, 223, 1006, 224, 644, 101, 1, 223, 223, 1007, 677, 677, 224, 102, 2, 223, 223, 1006, 224, 659, 1001, 223, 1, 223, 1007, 226, 226, 224, 1002, 223, 2, 223, 1006, 224, 674, 1001, 223, 1, 223, 4, 223, 99, 226 });
     State.ShouldBe(State.Terminated);
     LastOutput.ShouldBe(11826654);
 }
Ejemplo n.º 2
0
 public void LargeExampleTest(long input, long expectedOutput)
 {
     SetNextInput(input);
     CreateAndRunComputer(new[] { 3, 21, 1008, 21, 8, 20, 1005, 20, 22, 107, 8, 21, 20, 1006, 20, 31, 1106, 0, 36, 98, 0, 0, 1002, 21, 125, 20, 4, 20, 1105, 1, 46, 104, 999, 1105, 1, 46, 1101, 1000, 1, 20, 4, 20, 1105, 1, 46, 98, 99 });
     State.ShouldBe(State.Terminated);
     LastOutput.ShouldBe(expectedOutput);
 }
Ejemplo n.º 3
0
 public void Test1()
 {
     SetNextInput(666);
     CreateAndRunComputer(new[] { 3, 0, 4, 0, 99 });
     State.ShouldBe(State.Terminated);
     LastOutput.ShouldBe(666);
 }
Ejemplo n.º 4
0
 public void PositionModeJumpTest(long input, long expectedOutput)
 {
     SetNextInput(input);
     CreateAndRunComputer(new[] { 3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9 });
     State.ShouldBe(State.Terminated);
     LastOutput.ShouldBe(expectedOutput);
 }
Ejemplo n.º 5
0
 public void PositionModeLessThanTest(long input, long expectedOutput)
 {
     SetNextInput(input);
     CreateAndRunComputer(new[] { 3, 9, 7, 9, 10, 9, 4, 9, 99, -1, 8 });
     State.ShouldBe(State.Terminated);
     LastOutput.ShouldBe(expectedOutput);
 }
Ejemplo n.º 6
0
 public void ImmediateModeJumpTest(long input, long expectedOutput)
 {
     SetNextInput(input);
     CreateAndRunComputer(new[] { 3, 3, 1105, -1, 9, 1101, 0, 0, 12, 4, 12, 99, 1 });
     State.ShouldBe(State.Terminated);
     LastOutput.ShouldBe(expectedOutput);
 }
Ejemplo n.º 7
0
        public override double[] Backward(double[] dy, double lr)
        {
            var diff = LastOutput.ToArray().Sub(dy);

            var dx = new double[Weights.Length];

            for (int i = 0; i < Weights.Length; ++i)
            {
                for (int j = 0; j < Weights[i].Length; ++j)
                {
                    dx[i] += Weights[i][j] * diff[j];
                }
            }

            for (int i = 0; i < Weights.Length; ++i)
            {
                for (int j = 0; j < Weights[i].Length; ++j)
                {
                    var dw = diff[j] * LastInput[j];
                    Weights[i][j] -= lr * dw;
                }
            }

            return(dx);
        }
Ejemplo n.º 8
0
 public void ImmediateModeLessThanTest(long input, long expectedOutput)
 {
     SetNextInput(input);
     CreateAndRunComputer(new[] { 3, 3, 1107, -1, 8, 3, 4, 3, 99 });
     State.ShouldBe(State.Terminated);
     LastOutput.ShouldBe(expectedOutput);
 }
Ejemplo n.º 9
0
        public override void EventReceived(T data)
        {
            base.EventReceived(data);
            if (EventsSeen > maxT)
            {
                StopReceiving();
                return;
            }

            base.EventReceived(data);
            double lastOutput = LastOutput.GetValueOrDefault(0.0);
            double output     = -1;
            double answer     = ComputeOutput();


            //I re-randomize every time... hit in accuracy, but still private
            for (int i = 0; i < logT; i++)
            {
                thresholds[i] = Laplace(1.0 / epsilon_threshold);
            }

            double noise_compare = Laplace(1.0 / epsilon_compare);
            double noise_answer  = Laplace(1.0 / epsilon_answer);


            double noisy_compare = Math.Abs(lastOutput - answer + noise_compare);
            double thresh_t      = threshold + thresholds.Sum();

            //Console.Write ("threshold: " + thresh_t + " diff: " + noisy_compare + " ");

            if (noisy_compare <= thresh_t)
            {
                output = lastOutput;
            }
            else
            {
                output = answer + noise_answer;

                if (m < k)
                {
                    m++;
                }
                else
                {
                    throw new Exception("algorithm not (k,d) varying");
                }
            }

            LastOutput = output;


            if (OnOutput != null)
            {
                OnOutput(LastOutput.Value);
            }

            signalEndProcessed();
        }
Ejemplo n.º 10
0
 public void Clear()
 {
     ClearMarkedReferences();
     ClearCustomElementGenerators();
     TextEditor.Document                  = new TextDocument();
     definitionLookup                     = null;
     uiElementGenerator.UIElements        = null;
     referenceElementGenerator.References = null;
     references = new TextSegmentCollection <ReferenceSegment>();
     lastOutput = new LastOutput();
 }
Ejemplo n.º 11
0
        public void SetOutput(ITextOutput output, IHighlightingDefinition highlighting)
        {
            if (output == null)
            {
                throw new ArgumentNullException();
            }

            HideCancelButton();

            var newLastOutput = new LastOutput(output, highlighting);

            if (lastOutput.Equals(newLastOutput))
            {
                return;
            }
            lastOutput = newLastOutput;

            var avOutput = output as AvalonEditTextOutput;

            Debug.Assert(avOutput != null, "output should be an AvalonEditTextOutput instance");

            TextEditor.LanguageTokens = avOutput == null ? new LanguageTokens() : avOutput.LanguageTokens;
            TextEditor.LanguageTokens.Finish();

            ClearMarkedReferences();
            TextEditor.ScrollToHome();
            TextEditor.Document           = null;
            TextEditor.SyntaxHighlighting = highlighting;
            ClearCustomElementGenerators();

            if (avOutput == null)
            {
                uiElementGenerator.UIElements        = null;
                referenceElementGenerator.References = null;
                references          = new TextSegmentCollection <ReferenceSegment>();
                definitionLookup    = null;
                TextEditor.Document = new TextDocument(output.ToString());
            }
            else
            {
                uiElementGenerator.UIElements        = avOutput.UIElements;
                referenceElementGenerator.References = avOutput.References;
                references       = avOutput.References;
                definitionLookup = avOutput.DefinitionLookup;
                foreach (var elementGenerator in avOutput.ElementGenerators)
                {
                    TextEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator);
                    activeCustomElementGenerators.Add(elementGenerator);
                }

                TextEditor.Document = avOutput.GetDocument();
            }
        }
Ejemplo n.º 12
0
        public override Vector <double> CalculateOutput(Vector <double> signal)
        {
            LastSignal = signal;

            LastOutput = IncomingWeights.Multiply(signal); // weighted input
            if (HasBias)
            {
                LastOutput = LastOutput.Add(BiasWeights); // weighted input with bias
            }

            LastOutput.MapInplace(Activation.Calc); // neuron activations (neuron outputs)
            return(LastOutput.Clone());
        }
Ejemplo n.º 13
0
        public void ImproveWeights(double learningFactor, double momentum)
        {
            var output = LastOutput.Clone();

            output.MapInplace(Activation.CalcDerivative);

            var learningErrorOutput = learningFactor * Vector.op_DotMultiply(output, Error);
            var modification        = learningErrorOutput.OuterProduct(LastSignal);

            IncomingWeights += modification + (LastWeightsModification * momentum);

            if (HasBias)
            {
                BiasWeights += learningErrorOutput + (LastBiasWeightsModification * momentum);
            }

            LastWeightsModification     = modification;
            LastBiasWeightsModification = learningErrorOutput;
        }
Ejemplo n.º 14
0
 public void Example2()
 {
     CreateAndRunComputer(new[] { 1102, 34915192, 34915192, 7, 4, 7, 99, 0 });
     LastOutput.ShouldBe(1219070632396864);
 }
Ejemplo n.º 15
0
 public void OnUseNewRendererChanged()
 {
     lastOutput = new LastOutput();
 }
Ejemplo n.º 16
0
 public static void Add(object outputObject)
 {
     LastOutput.Add(outputObject);
 }
Ejemplo n.º 17
0
 public void JumpIfTrueImmediateModeTest(long input, long expectedOutput)
 {
     SetNextInput(input);
     CreateAndRunComputer(new[] { 3, 100, 1005, 100, 8, 104, 10, 99, 104, 100, 99 });
     LastOutput.ShouldBe(expectedOutput);
 }
Ejemplo n.º 18
0
 public override Vector <double> CalculateOutput(Vector <double> signal)
 {
     LastOutput = signal.Map(Activation.Calc);
     return(LastOutput.Clone());
 }
Ejemplo n.º 19
0
 public void JumpIfFalsePositionModeTest(long input, long expectedOutput)
 {
     SetNextInput(input);
     CreateAndRunComputer(new[] { 3, 100, 6, 100, 8, 104, 10, 99, 9, 104, 100, 99 });
     LastOutput.ShouldBe(expectedOutput);
 }
Ejemplo n.º 20
0
 public void Example3()
 {
     CreateAndRunComputer(new[] { 104, 1125899906842624, 99 });
     LastOutput.ShouldBe(1125899906842624);
 }
Ejemplo n.º 21
0
 public void JumpIfFalseRelativeModeTest(long input, long expectedOutput)
 {
     SetNextInput(input);
     CreateAndRunComputer(new[] { 3, 100, 109, 10, 2006, 100, 0, 104, 10, 99, 11, 104, 100, 99 });
     LastOutput.ShouldBe(expectedOutput);
 }
Ejemplo n.º 22
0
 public void OutputPositionModeTest()
 {
     CreateAndRunComputer(new[] { 4, 1, 99 });
     LastOutput.ShouldBe(1);
 }
Ejemplo n.º 23
0
 public void OutputRelativeModeTest()
 {
     CreateAndRunComputer(new[] { 9, 3, 204, 1, 99 });
     LastOutput.ShouldBe(204);
 }
Ejemplo n.º 24
0
 public void OutputImmediateModeTest()
 {
     CreateAndRunComputer(new[] { 104, 66, 99 });
     LastOutput.ShouldBe(66);
 }