Beispiel #1
0
        public override void Validate(MyValidator validator)
        {
            ScriptCheckMethod      = null;
            ScriptShouldStopMethod = null;

            CSharpCodeProvider codeProvider = new CSharpCodeProvider();
            CompilerParameters parameters   = new CompilerParameters()
            {
                GenerateInMemory   = false,
                GenerateExecutable = false,
            };

            parameters.ReferencedAssemblies.Add("GoodAI.Platform.Core.dll");
            parameters.ReferencedAssemblies.Add("System.Core.dll");    //for LINQ support
            parameters.ReferencedAssemblies.Add("System.Runtime.dll"); //for LINQ support
            // TODO: load the xunit dll in Brain Simulator UI from the module directory.
            parameters.ReferencedAssemblies.Add("xunit.assert.dll");
            parameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);

            //Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
            //IEnumerable<Assembly> openTKAssemblies = loadedAssemblies.Where(x => x.ManifestModule.Name == "xunit.assert.dll");
            //if (openTKAssemblies.Count() > 0)
            //    parameters.ReferencedAssemblies.Add(openTKAssemblies.First().Location);

            CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script);

            if (results.Errors.HasErrors)
            {
                string message = "";

                foreach (CompilerError error in results.Errors)
                {
                    message += "Line " + error.Line + ": " + error.ErrorText + "\n";
                }

                validator.AddError(this, "Errors in compiled script:\n" + message);
                return;
            }
            else if (results.CompiledAssembly == null)
            {
                validator.AddError(this, "Compiled assembly is null.");
                return;
            }

            try
            {
                Type enclosingType = results.CompiledAssembly.GetType("Runtime.Script");

                ScriptCheckMethod = enclosingType.GetMethod("Check");
                validator.AssertError(ScriptCheckMethod != null, this, "Check() method not found in compiled script");

                ScriptShouldStopMethod = enclosingType.GetMethod("ShouldStop");  // optional, don't check for null
            }
            catch (Exception e)
            {
                validator.AddError(this, "Script analysis failed: " + e.GetType().Name + ": " + e.Message);
            }
        }
 private void ValidateRange(MyValidator validator, int value, int valueMin, int valueMax, string valueName)
 {
     if (value > valueMax)
     {
         validator.AddError(this, string.Format("{0} cannot be more than {1}.", valueName, valueMax));
     }
     if (value < valueMin)
     {
         validator.AddError(this, string.Format("{0} cannot be less than {1}.", valueName, valueMin));
     }
 }
Beispiel #3
0
 public override void Validate(MyValidator validator)
 {
     if (StateInput == null)
     {
         validator.AddError(this, "StateInput is not connected");
     }
     else if (StateInput.Count != MyTicTacToeWorld.NO_POSITIONS)
     {
         validator.AddError(this, "Incorrect length of StateInput, expected 9, found " + StateInput.Count);
     }
 }
        public override void Validate(MyValidator validator)
        {
            if (Sample == null)
            {
                validator.AddError(this, "Missing input 'Sample'!");
            }

            if (Target == null)
            {
                validator.AddError(this, "Missing input 'Target'!");
            }
        }
        internal override void ValidateMandatory(MyValidator validator)
        {
            base.ValidateMandatory(validator);

            if (LoadOnStart || validator.Simulation.LoadAllNodesData)
            {
                if (MyMemoryBlockSerializer.TempDataExists(this))
                {
                    validator.AddInfo(this, "Node will load data from temporal storage.");
                }
                else if (DataFolder != null && DataFolder != String.Empty)
                {
                    validator.AddInfo(this, "Node will load data from user defined folder: " + DataFolder);
                }
                else if (validator.Simulation.LoadAllNodesData)
                {
                    validator.AddInfo(this, "Node will load data from user defined folder: "
                                      + validator.Simulation.GlobalDataFolder + "\\" + MyMemoryBlockSerializer.GetNodeFolder(this));
                }
                else
                {
                    validator.AddError(this, "LoadOnStart is active and no temporal data is available. DataFolder must be defined");
                }
            }

            validator.AssertInfo(!(SaveOnStop || validator.Simulation.SaveAllNodesData), this, "Node will save data to temporal storage before stop.");

            foreach (PropertyInfo pInfo in GetInfo().OwnedMemoryBlocks)
            {
                MyAbstractMemoryBlock mb = (pInfo.GetValue(this) as MyAbstractMemoryBlock);
                validator.AssertError(mb.Count >= 0, this, "Size of " + mb.Name + " memory block cannot be negative.");
            }

            List <PropertyInfo> inputBlocks = GetInfo().InputBlocks;

            for (int i = 0; i < inputBlocks.Count; i++)
            {
                PropertyInfo pInfo = inputBlocks[i];

                if (GetAbstractInput(i) != pInfo.GetValue(this))
                {
                    validator.AddError(this, "Incompatible memory block for \"" + pInfo.Name + "\" (" + GetAbstractInput(i).GetType().GenericTypeArguments[0].Name + " != " + pInfo.PropertyType.GenericTypeArguments[0].Name + ")");
                }
            }
        }
        public override void Validate(MyValidator validator)
        {
            ValidateRange(validator, ClearedLinesPerLevel, 1, 1000000000, "ClearedLinesPerLevel");
            ValidateRange(validator, AlmostFullLinesAtStart, 0, 15, "AlmostFullLinesAtStart");

            if (ActionInput != null)
            {
                // make sure ActionInput has the required modality
                if (ActionInputModality == InputModality.Number && ActionInput.Count != 1)
                {
                    validator.AddError(this, "InputModality is Number. A single number is expected on ActionInput.");
                }
                else if (ActionInputModality == InputModality.Vector && ActionInput.Count != 6)
                {
                    validator.AddError(this, "InputModality is Vector. A vector of length 6 is expected on ActionInput.");
                }
            }
        }
Beispiel #7
0
        public override void Validate(MyValidator validator)
        {
            base.Validate(validator);

            if (!AreParametersValid())
            {
                validator.AddError(this, "Current parameter values or their combination are not valid.");
            }
        }
        public override void Validate(MyValidator validator)
        {
            base.Validate(validator);

            if (MotivationInput.Count != 1)
            {
                validator.AddError(this, "MotivationInput requires size of 1");
            }
        }
        public override void Validate(MyValidator validator)
        {
            base.Validate(validator);

            if ((InitMNIST.TrainingExamplesPerDigit < 1) || (InitMNIST.TrainingExamplesPerDigit > 7000) ||
                (InitMNIST.TestExamplesPerDigit < 1) || (InitMNIST.TestExamplesPerDigit > 7000))
            {
                validator.AddError(this, "The value of ExamplesPerDigit properties of the Init task have to be in the interval <1, 7000>");
            }
        }
Beispiel #10
0
        public override void Validate(MyValidator validator)
        {
            for (int i = 0; i < InputBranches; i++)
            {
                MyMemoryBlock <float> ai = GetInput(i);

                if (ai == null)
                {
                    validator.AddError(this, string.Format("Missing input {0}.", i));
                }
            }
        }
Beispiel #11
0
        public override void Validate(MyValidator validator)
        {
            validator.AssertError(MemorySize > 0, this, "Memory can't be empty.");

            if (Values == null || Indices == null)
            {
                validator.AddError(this, "Missing input is suspicious.");
                return;
            }

            validator.AssertError(Values.Count == Indices.Count, this, "The input vector sizes must be the same.");
            validator.AssertError(Values.Count % SymbolSize == 0, this, "The input vector size must be a multiple of SymbolSize.");
        }
Beispiel #12
0
 public override void Validate(MyValidator validator)
 {
     base.Validate(validator);
     if (ParentNetwork == null)
     {
         validator.AddError(this, "LSTM layer needs to be in a neural network group");
     }
     if (LearningTasks == LearningTasksType.BPTT)
     {
         if (!inputToTemporalTask.Enabled)
         {
             validator.AddError(this, "BPTT requires Transform Input Task to be enabled");
         }
     }
     else if (LearningTasks == LearningTasksType.RTRL)
     {
         if (inputToTemporalTask.Enabled)
         {
             validator.AddError(this, "RTRL requires Transform Input Task to be disabled");
         }
     }
 }
Beispiel #13
0
        public override void Validate(MyValidator validator)
        {
            switch (Operation)
            {
            case MyJoinOperation.StackInputs:
                return;

            case MyJoinOperation.DistanceSquared:
            case MyJoinOperation.CosineDistance:
            case MyJoinOperation.DotProduct:
                validator.AssertError(InputBranches == 2, this, "Two operands are needed for distance measures");
                break;

            case MyJoinOperation.MatMultiplication:
                bool is_correct = Input0ColHint == (Input1Count / Input1ColHint);
                // if (Input1ColHint==1) /// BrainSim. bug for Nx1 vector, column hint is one, although it should be N...
                //     is_correct = Input0ColHint == Input1Count;
                validator.AssertError(is_correct, this, "# of columns in Mat1 needs to correspond to # of rows in Mat2!");
                break;

            case MyJoinOperation.AddToIdcs:
            case MyJoinOperation.AddToIdcs_Normalize:
                validator.AssertError(InputBranches >= 3, this, "Must provide the Target vector, Source vector and the idcs as the first three inputs");
                validator.AssertError(GetInputSize(1) == GetInputSize(2), this, "Dimensions of the Source vector and idcs must be the same");
                validator.AssertError(GetInputSize(0) >= GetInputSize(1), this, "Target vector must be bigger than Source vector");
                return;

            case MyJoinOperation.GatherFromIdcs:
                validator.AssertError(InputBranches >= 2, this, "Must provide the Target vector and the idcs as the first two inputs");
                validator.AssertError(GetInputSize(0) >= GetInputSize(1), this, "Target vector must be bigger than the idcs");
                return;

            default:
                validator.AssertError(InputBranches >= 2, this, "Operation needs at least two operands");
                break;
            }

            for (int i = 0; i < InputBranches; i++)
            {
                MyMemoryBlock <float> ai = GetInput(i);

                if (ai == null)
                {
                    validator.AddError(this, string.Format("Missing input {0}.", i));
                }
                else if (InputBranches > 2) // Two inputs are allowed to be of variable size
                {
                    validator.AssertError(ai.Count == OutputSize, this, "Operand size differs from output size");
                }
            }
        }
Beispiel #14
0
        protected bool WorldSourcesExist(string[] paths, MyValidator validator)
        {
            bool exist = true;

            foreach (string path in paths)
            {
                if (!File.Exists(path))
                {
                    validator.AddError(this, string.Format("Missing dataset file \"{0}\". Check log (INFO level) for further information.", Path.GetFileName(path)));
                    exist = false;
                }
            }

            return(exist);
        }
Beispiel #15
0
        public override void Validate(MyValidator validator)
        {
            base.ValidateMandatory(validator);
            base.Validate(validator);

            Children.ForEach(node =>
            {
                try
                {
                    node.ValidateMandatory(validator);
                    node.Validate(validator);
                }
                catch (Exception e)
                {
                    MyLog.ERROR.WriteLine("Exception occured while validating " + node.Name + ": " + e.Message);
                    validator.AddError(node, "Exception occured while validating: " + e.Message);
                }
            });
        }
        private string AppendGeneratedCode(string script, MyValidator validator)
        {
            string completeScript = script;

            int location = script.IndexOf(GENERATED_CODE_LABEL);

            if (location >= 0)
            {
                completeScript = script.Substring(0, location)
                                 + GenerateVariablesCode()
                                 + script.Substring(location);
            }
            else
            {
                validator.AddError(this, "Script generator: label \"" + GENERATED_CODE_LABEL + "\" not found. No generated code available.");
            }

            return(completeScript);
        }
Beispiel #17
0
        private void ValidateHiddenVectorUser(MyValidator validator)
        {
            if (m_engineParams.HiddenVectorUserParsed != null)
            {
                // must have a correct format and must be empty or contain HiddenVectorLength numerical entries;
                // the number of unique entries must be less or equal to the number of colours and it must match the CanRepeatColors property
                if (m_engineParams.HiddenVectorUserParsed.Length != HiddenVectorLength)
                {
                    validator.AddError(this, "Number of elements specified in HiddenVectorUser must match HiddenVectorLength.");
                }
                if (!CanRepeatColors)
                {
                    HashSet <int> userPicked = new HashSet <int>(m_engineParams.HiddenVectorUserParsed);
                    if (userPicked.Count != m_engineParams.HiddenVectorUserParsed.Length)
                    {
                        validator.AddError(this, "CanRepeatColors is false, but HiddenVectorUser contains repeating colors.");
                    }
                }
                // check color codes in user input
                for (int i = 0; i < m_engineParams.HiddenVectorUserParsed.Length; i++)
                {
                    if (m_engineParams.HiddenVectorUserParsed[i] >= NumberOfColors)
                    {
                        validator.AddError(this, string.Format("HiddenVectorUser must not contain color codes greater or equal to NumberOfColors ({0}).",
                                                               NumberOfColors));
                        break;
                    }
                    if (m_engineParams.HiddenVectorUserParsed[i] < 0)
                    {
                        validator.AddError(this, string.Format("HiddenVectorUser must not contain color codes less than 0."));
                        break;
                    }
                }
            }

            if (GuessInput != null && HiddenVectorLength != GuessInput.Count)
            {
                validator.AddError(this, "Number of elements in the GuessInput memory block must match HiddenVectorLength.");
            }

            if (!CanRepeatColors && NumberOfColors < HiddenVectorLength)
            {
                validator.AddError(this, "Repeating of colors in the hidden vector is forbidden: NumberOfColors cannot be lower than HiddenVectorLength.");
            }
        }
        public override void Validate(MyValidator validator)
        {
            validator.AssertError(ImageInput != null, this, "No input image available");
            validator.AssertError(ImageInput.Dims.Rank >= 2, this, "Input image should have rank at least 2 (2 dimensions)");

            if (!validator.ValidationSucessfull)
            {
                return;
            }

            if (Execute.Enabled)
            {
                if (XCrop == null && YCrop == null)
                {
                    validator.AddError(this, "If the MaskByCoordinates is enabled, at least one of the XCrop and YCrop should be connected.");
                }
            }
            else if (ProbabilisticMask.Enabled)
            {
                if (MaskProbabilityInput == null)
                {
                    validator.AddError(this, "If the ProbabilisticMask is enabled, the MaskProbabilityInput has to be connected and have size 1");
                }
                if (RandomNumbersInput == null)
                {
                    validator.AddError(this, "If the ProbabilisticMask is enabled, the RandomNumbersInput with the same count as the Image Input " +
                                       "has to be connected. Uniform distribution from <0,1> is expected.");
                }
            }

            if (MaskValuesInput != null && ImageInput != null && MaskValuesInput.Count != ImageInput.Count)
            {
                validator.AddError(this, "MaskValuesInput.Count != Image.Count");
            }
            if (RandomNumbersInput != null && ImageInput != null && RandomNumbersInput.Count != ImageInput.Count)
            {
                validator.AddError(this, "RandomNumbersInput.Count has to be equal to ImageInput.count");
            }
            if (MaskProbabilityInput != null && MaskProbabilityInput.Count != 1)
            {
                validator.AddError(this, "MaskProbabilityInput.Count has to be 1");
            }
        }
Beispiel #19
0
        public void Compile(string script, MyValidator validator)
        {
            if (m_node.Language != this.Language)
            {
                throw new ArgumentException("Language is not supported (" + this.Language + " only): " + m_node.Language);
            }

            m_methods.Clear();

            CSharpCodeProvider codeProvider = new CSharpCodeProvider();
            CompilerParameters parameters   = new CompilerParameters()
            {
                GenerateInMemory   = false,
                GenerateExecutable = false,
            };

            parameters.ReferencedAssemblies.Add("GoodAI.Platform.Core.dll");
            parameters.ReferencedAssemblies.Add("System.Core.dll"); //for LINQ support

            // add all loaded dll modules to be accessible also from the C# node script
            foreach (FileInfo assemblyFile in MyConfiguration.ListModules())
            {
                parameters.ReferencedAssemblies.Add(assemblyFile.FullName);
            }

            parameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);

            Assembly[]             loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
            IEnumerable <Assembly> openTKAssemblies = loadedAssemblies.Where(x => x.ManifestModule.Name == "OpenTK.dll").ToList();

            if (openTKAssemblies.Any())
            {
                parameters.ReferencedAssemblies.Add(openTKAssemblies.First().Location);
            }

            CompilerResults results          = codeProvider.CompileAssemblyFromSource(parameters, script);
            Assembly        compiledAssembly = null;

            if (results.Errors.HasErrors)
            {
                string message = "";

                foreach (CompilerError error in results.Errors)
                {
                    message += "\nLine " + error.Line + ": " + error.ErrorText;
                }
                validator.AddError(m_node, "Errors in compiled script:" + message);
            }
            else
            {
                compiledAssembly = results.CompiledAssembly;
            }

            if (compiledAssembly != null)
            {
                try
                {
                    Type enclosingType = compiledAssembly.GetType("Runtime.Script");
                    Type methodEnum    = typeof(TMethodEnum);

                    foreach (string methodName in methodEnum.GetEnumNames())
                    {
                        MethodInfo method = enclosingType.GetMethod(methodName);

                        if (method != null)
                        {
                            m_methods[methodName] = method;
                        }
                        else
                        {
                            validator.AddError(m_node, methodName + "() method not found in compiled script");
                        }
                    }
                }
                catch (Exception e)
                {
                    validator.AddError(m_node, "Script analysis failed: " + e.GetType().Name + ": " + e.Message);
                }
            }
        }
Beispiel #20
0
        public override void Validate(MyValidator validator)
        {
            switch (Operation)
            {
            case MyJoinOperation.StackInputs:
                return;

            case MyJoinOperation.DistanceSquared:
            case MyJoinOperation.CosineDistance:
            case MyJoinOperation.DotProduct:
                validator.AssertError(InputBranches == 2, this, "Two operands are needed for distance measures");
                break;

            case MyJoinOperation.MatMultiplication:
                bool is_correct = Input0ColHint == (Input1Count / Input1ColHint);
                // if (Input1ColHint==1) /// BrainSim. bug for Nx1 vector, column hint is one, although it should be N...
                //     is_correct = Input0ColHint == Input1Count;
                validator.AssertError(is_correct, this, "# of columns in Mat1 needs to correspond to # of rows in Mat2!");
                break;

            case MyJoinOperation.AddToIdcs:
            case MyJoinOperation.AddToIdcs_Normalize:
                validator.AssertError(InputBranches >= 3, this, "Must provide the Target vector, Source vector and the idcs as the first three inputs");
                validator.AssertError(GetInputSize(1) == GetInputSize(2), this, "Dimensions of the Source vector and idcs must be the same");
                validator.AssertError(GetInputSize(0) >= GetInputSize(1), this, "Target vector must be bigger than Source vector");
                return;

            case MyJoinOperation.GatherFromIdcs:
                validator.AssertError(InputBranches >= 2, this, "Must provide the Target vector and the idcs as the first two inputs");
                validator.AssertError(GetInputSize(0) >= GetInputSize(1), this, "Target vector must be bigger than the idcs");
                return;

            default:
                validator.AssertError(InputBranches >= 2, this, "Operation needs at least two operands");
                break;
            }

            TensorDimensions firstInputDimensions        = null;
            bool             firstInputDimensionsRankOne = false;

            for (int i = 0; i < InputBranches; i++)
            {
                MyMemoryBlock <float> ai = GetInput(i);
                if (ai == null)
                {
                    validator.AddError(this, $"Missing input {i}.");
                    return;
                }

                if (InputBranches > 2) // Two inputs are allowed to be of variable size
                {
                    validator.AssertError(ai.Count == OutputSize, this, $"Operand #{i} size differs from output size");
                }

                if (firstInputDimensions == null)
                {
                    firstInputDimensions        = ai.Dims;
                    firstInputDimensionsRankOne = IsRankOne(firstInputDimensions);
                }

                var bothDimensionsRankOne = firstInputDimensionsRankOne && IsRankOne(ai.Dims);

                if (firstInputDimensions.Rank != ai.Dims.Rank && !bothDimensionsRankOne)
                {
                    // TODO(Premek): replace warning with error when the check gets smart enough
                    validator.AddWarning(this, $"Incompatible input ranks (input #{i}).");
                }
            }
        }