Ejemplo n.º 1
0
    private int outputLength = 0;    // Replace data[0].output.length

    // Use this for initialization
    void Start()
    {
        InputData  trainingInput  = new InputData();
        OutputData trainingOutput = new OutputData();

        string[] inputKeys  = { "rouge", "vert", "bleu" };
        string[] outputKeys = { "rouge", "vert", "bleu", "jaune", "cyan", "rose", "blanc" };
        trainingInput.Add(inputKeys, new double[] { 255, 0, 0 });
        trainingOutput.Add(outputKeys, new double[] { 1, 0, 0, 0, 0, 0, 0.3 });
        trainingInput.Add(inputKeys, new double[] { 0, 255, 0 });
        trainingOutput.Add(outputKeys, new double[] { 0, 1, 0, 0, 0, 0, 0.3 });
        trainingInput.Add(inputKeys, new double[] { 0, 0, 255 });
        trainingOutput.Add(outputKeys, new double[] { 0, 0, 1, 0, 0, 0, 0.3 });
        trainingInput.Add(inputKeys, new double[] { 255, 255, 0 });
        trainingOutput.Add(outputKeys, new double[] { 0, 0, 0, 1, 0, 0, 0.6 });
        trainingInput.Add(inputKeys, new double[] { 0, 255, 255 });
        trainingOutput.Add(outputKeys, new double[] { 0, 0, 0, 0, 1, 0, 0.6 });
        trainingInput.Add(inputKeys, new double[] { 255, 0, 255 });
        trainingOutput.Add(outputKeys, new double[] { 0, 0, 0, 0, 0, 1, 0.6 });
        trainingInput.Add(inputKeys, new double[] { 255, 255, 255 });
        trainingOutput.Add(outputKeys, new double[] { 0, 0, 0, 0, 0, 0, 1 });
        trainingInput.Add(inputKeys, new double[] { 0, 0, 0 });
        trainingOutput.Add(outputKeys, new double[] { 0, 0, 0, 0, 0, 0, 0 });
        trainingInput.Add(inputKeys, new double[] { 128, 128, 128 });
        trainingOutput.Add(outputKeys, new double[] { 0, 0, 0, 0, 0, 0, 0.5 });
        trainingInput.Add(inputKeys, new double[] { 128, 0, 128 });
        trainingOutput.Add(outputKeys, new double[] { 0, 0, 0, 0, 0, 0.5, 0.5 });


        var stats = Train(trainingInput, trainingOutput);
        var input = new AssociativeArray <double>();

        input.Add(inputKeys, new double[] { 240, 2, 20 });
        Debug.Log(Run(input).ToString());
    }
        protected override void Build(InputData data)
        {
            Vector2 input = UseInput ? new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized : Vector2.zero;

            data.Add(new FloatInput(input.x));

            data.Add(new FloatInput(input.y));

            data.Add(new FloatInput(m_MainCameraTransform?.eulerAngles.y ?? 0));

            data.Add(new TriggerInput(UseInput ? Input.GetButtonDown("Jump") : false));

            data.Add(new BoolInput(UseInput ? Input.GetButton("Crouch") : false));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Validates the inputs of the <see cref="DmnModel"/> (<paramref name="source"/> and populates <see cref="InputData"/> and related <see cref="Variables"/>
        /// </summary>
        /// <param name="source">Source DMN Model parsed from XML</param>
        /// <param name="inputDataById">Temporary dictionary of input data (by ID) - input data are populated here</param>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="inputDataById"/> is null.</exception>
        /// <exception cref="DmnParserException">Missing input id</exception>
        /// <exception cref="DmnParserException">Duplicate input data name</exception>
        protected void ProcessInputDataSource(DmnModel source, IDictionary <string, DmnVariableDefinition> inputDataById)
        {
            if (source == null)
            {
                throw Logger.Fatal <ArgumentNullException>($"{nameof(source)} is null");
            }
            if (inputDataById == null)
            {
                throw Logger.Fatal <ArgumentNullException>($"{nameof(inputDataById)} is null");
            }
            if (source.InputData == null || source.InputData.Count == 0)
            {
                return;                                                         //it's not common, but OK to have no input data
            }
            //TODO    ?Input name in form varName:varType for (complex) input types
            foreach (var sourceInput in source.InputData)
            {
                if (string.IsNullOrWhiteSpace(sourceInput.Id))
                {
                    throw Logger.Fatal <DmnParserException>($"Missing input id");
                }

                var inputName    = !string.IsNullOrWhiteSpace(sourceInput.Name) ? sourceInput.Name : sourceInput.Id;
                var variableName = DmnVariableDefinition.NormalizeVariableName(inputName);
                if (InputData.ContainsKey(variableName))
                {
                    throw Logger.Fatal <DmnParserException>($"Duplicate input data name {variableName} (from {inputName})");
                }

                var variable = new DmnVariableDefinition(variableName, inputName);
                InputData.Add(variableName, variable);
                Variables.Add(variableName, variable);
                inputDataById.Add(sourceInput.Id, variable);
            }
        }
Ejemplo n.º 4
0
        public override async Task <IList <IEvent> > ProcessAction(int actionNumber)
        {
            if (actionNumber == 1)
            {
                return(new List <IEvent>()
                {
                    new CancelInputDialog(),
                });
            }
            else if (actionNumber == 0)
            {
                var gender = GetValue <Gender>("Gender");
                InputData.Add("GenderString", gender.ToString());

                var region = GetDataSourceValue <Region>("Region");
                InputData.Add("RegionString", region.Name);

                return(new List <IEvent>()
                {
                    new UpdateInputView(InputViewUpdateType.AddOrUpdate),
                    new CancelInputDialog()
                });
            }

            return(null);
        }
Ejemplo n.º 5
0
 protected override void InitBufferObjects()
 {
     OutputBuffer = new BufferBlock <TOutput>(new DataflowBlockOptions()
     {
         BoundedCapacity = MaxBufferSize
     });
     InputBuffer = new ActionBlock <TInput>(row => InputData.Add(row),
                                            new ExecutionDataflowBlockOptions()
     {
         BoundedCapacity = -1     //All data is always loaded!
     });
     InputBuffer.Completion.ContinueWith(t =>
     {
         if (t.IsFaulted)
         {
             ((IDataflowBlock)OutputBuffer).Fault(t.Exception.InnerException);
         }
         try
         {
             WriteIntoOutput();
             OutputBuffer.Complete();
         }
         catch (Exception e)
         {
             ((IDataflowBlock)OutputBuffer).Fault(e);
             throw e;
         }
     });
 }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="inputAttribute">输入数据</param>
 /// <param name="outputAttribute">输出数据</param>
 /// <param name="describe">描述</param>
 /// <param name="type1"><类型一/param>
 /// <param name="type2">类型二</param>
 /// <param name="type3">类型三</param>
 /// <param name="ishasInput">是否有输入连接</param>
 /// <param name="ishasOutput">是否有输出连接</param>
 public ScriptMethAttribute(string inputAttribute, string outputAttribute, string describe, Type [] type = null, bool ishasInput = false, bool ishasOutput = false, string functionName = "", ItemBoxEnum itemBoxEnum = ItemBoxEnum.FUNCTION)
 {
     if (type != null)
     {
         foreach (var item in type)
         {
             types.Add(item.FullName, item);
         }
         type = null;
     }
     if (ishasInput)
     {
         InputData.Add(new DataContext("输入", "INPUT"));
     }
     if (ishasOutput)
     {
         OutputData.Add(new DataContext("输出", "OUTPUT"));
     }
     if (inputAttribute.Equals("") == false)
     {
         add(InputData, (JObject)JsonConvert.DeserializeObject(inputAttribute));
     }
     if (outputAttribute.Equals("") == false)
     {
         add(OutputData, (JObject)JsonConvert.DeserializeObject(outputAttribute));
     }
     inputAttribute  = null;
     outputAttribute = null;
     this.Describe   = describe;
     ItemBoxEnum     = itemBoxEnum;
     Name            = functionName;
 }
        /// <summary>
        /// CTOR
        /// </summary>
        /// <param name="source">Source model definition  to create the execution context factory for</param>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> is null</exception>
        /// <exception cref="ArgumentException">No decisions in the source definition</exception>
        /// <exception cref="ArgumentException">No variables in the source definition</exception>
        protected DmnExecutionContextFactory(DmnDefinition source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (source.Decisions == null || source.Decisions.Count < 1)
            {
                throw new ArgumentException("No decisions in the source definition");
            }
            if (source.Variables == null || source.Variables.Count < 1)
            {
                throw new ArgumentException("No variables in the source definition");
            }

            //Decisions reference
            foreach (var sourceDecision in source.Decisions)
            {
                Decisions.Add(sourceDecision.Key, sourceDecision.Value);
            }

            //Init runtime (execution) variables
            foreach (var sourceVariable in source.Variables.Values)
            {
                var variable = new DmnExecutionVariable(sourceVariable);
                Variables.Add(variable.Name, variable);
                if (variable.IsInputParameter)
                {
                    InputData.Add(variable.Name, variable);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Validates the inputs of the <see cref="DmnModel"/> (<paramref name="source"/> and populates <see cref="InputData"/> and related <see cref="Variables"/>
        /// </summary>
        /// <param name="source">Source DMN Model parsed from XML</param>
        /// <param name="inputDataById">Temporary dictionary of input data (by ID) - input data are populated here</param>
        ///<exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="inputDataById"/> is null.</exception>
        /// <exception cref="DmnParserException">Missing input id</exception>
        /// <exception cref="DmnParserException">Duplicate input data name</exception>
        protected void ProcessInputDataSource(DmnModel source, IDictionary <string, DmnVariableDefinition> inputDataById)
        {
            if (source == null)
            {
                throw Logger.Fatal <ArgumentNullException>($"{nameof(source)} is null");
            }
            if (inputDataById == null)
            {
                throw Logger.Fatal <ArgumentNullException>($"{nameof(inputDataById)} is null");
            }
            if (source.InputData == null || source.InputData.Count == 0)
            {
                return;                                                         //it's not common, but OK to have no input data
            }
            var inputExpressionTypeByNames = source.Decisions?.Where(d => d.DecisionTable?.Inputs != null).SelectMany(d => d.DecisionTable?.Inputs)?
                                             .ToDictionary(i => string.IsNullOrEmpty(i.InputExpression?.Text) ? i.Label : i.InputExpression.Text, i => i.InputExpression?.TypeRef) ?? new Dictionary <string, string>();

            //TODO    ?Input name in form varName:varType for (complex) input types
            //TODO ?Required input parameters check for null??
            foreach (var sourceInput in source.InputData)
            {
                if (string.IsNullOrWhiteSpace(sourceInput.Id))
                {
                    throw Logger.Fatal <DmnParserException>($"Missing input id");
                }

                var inputName    = !string.IsNullOrWhiteSpace(sourceInput.Name) ? sourceInput.Name : sourceInput.Id;
                var variableName = NormalizeVariableName(inputName);
                if (InputData.ContainsKey(variableName))
                {
                    throw Logger.Fatal <DmnParserException>($"Duplicate input data name {variableName} (from {inputName})");
                }

                var variable = new DmnVariableDefinition(variableName)
                {
                    IsInputParameter = true, HasValueSetter = true
                };

                // try to evaluate variable type from expression type
                if (inputExpressionTypeByNames.TryGetValue(variableName, out var expressionType))
                {
                    CheckAndUpdateVariableType(variable, expressionType);
                }

                variable.ValueSetters.Add($"Input: {inputName}");
                InputData.Add(variableName, variable);
                Variables.Add(variableName, variable);
                inputDataById.Add(sourceInput.Id, variable);
            }
        }
        protected override void Build(InputData data)
        {
            data.Add(new Vector3Input(m_Transform.position));

            data.Add(new FloatInput(m_Transform.eulerAngles.y));

            data.Add(new BoolInput(m_Motor.isGrounded));

            data.Add(new BoolInput(m_Motor.isJumping));

            data.Add(new BoolInput(m_Motor.isCrouching));

            data.Add(new Vector3Input(m_Motor.horizontalVelocity));

            data.Add(new FloatInput(m_Motor.gravitationalAccel));
        }
Ejemplo n.º 10
0
        public TickTime WriteLine(string cmd, int timeout_ms)
        {
            lock (_locker)
            {
                TickTime ttOutput = TickTime.Now, ttError = TickTime.Now, ttInit = TickTime.Now;
                Process.StandardInput.WriteLine(cmd);

                if (!cmd.IsNullOrEmpty())
                {
                    if (InputData.Count >= MaxInputDataLength)
                    {
                        InputData.Remove(OutputData.FirstKey);
                    }

                    InputData.Add(ttInit, cmd);
                }

                if (timeout_ms <= 0)
                {
                    return(ttInit);
                }

                TickTimeout   timeout = new TickTimeout(timeout_ms, TickTime.Unit.ms);
                List <string> output = new List <string>(), error = new List <string>();

                while (!timeout.IsTriggered && !Process.HasExited)
                {
                    var outputKeys = OutputData.KeysArray;

                    if (ErrorData.Any(x => x.Key > ttInit) || OutputData.Any(x => x.Key > ttInit))
                    {
                        break;
                    }

                    Thread.Sleep(10);
                }

                return(ttInit);
            }
        }
Ejemplo n.º 11
0
 public void ToShopState()
 {
     foreach (string line in InData)
     {
         for (int i = 0; i < line.Length; i++)
         {
             if (line[i].ToString() == "a")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.APPLE));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.APPLE)));
             }
             else if (line[i].ToString() == "b")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.BUTTER));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.BUTTER)));
             }
             else if (line[i].ToString() == "B")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.BREAD));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.BREAD)));
             }
             else if (line[i].ToString() == "c")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CAKE));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CAKE)));
             }
             else if (line[i].ToString() == "C")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CHOCOLATE));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CHOCOLATE)));
             }
             else if (line[i].ToString() == "e")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.ENTRY));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.ENTRY)));
             }
             else if (line[i].ToString() == "E")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.EXIT));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.EXIT)));
             }
             else if (line[i].ToString() == "f")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CIGARETTES));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CIGARETTES)));
             }
             else if (line[i].ToString() == "g")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.PEAR));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.PEAR)));
             }
             else if (line[i].ToString() == "h")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.HAM));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.HAM)));
             }
             else if (line[i].ToString() == "H")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CHIPS));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CHIPS)));
             }
             else if (line[i].ToString() == "k")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CABBAGE));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CABBAGE)));
             }
             else if (line[i].ToString() == "m")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.MILK));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.MILK)));
             }
             else if (line[i].ToString() == "l")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.LAMB));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.LAMB)));
             }
             else if (line[i].ToString() == "p")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.PASSAGE));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.PASSAGE)));
             }
             else if (line[i].ToString() == "P")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.PRIORITY_PASSAGE));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.PRIORITY_PASSAGE)));
             }
             else if (line[i].ToString() == "r")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.FISH));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.FISH)));
             }
             else if (line[i].ToString() == "s")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.SAUSAGE));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.SAUSAGE)));
             }
             else if (line[i].ToString() == "S")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.SALT));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.SALT)));
             }
             else if (line[i].ToString() == "T")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.STRAWBERRY));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.STRAWBERRY)));
             }
             else if (line[i].ToString() == "t")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CHEESE));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.CHEESE)));
             }
             else if (line[i].ToString() == "w")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.WALL));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.WALL)));
             }
             else if (line[i].ToString() == "W")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.WATER));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.WATER)));
             }
             else if (line[i].ToString() == "y")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.YOGHURT));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.YOGHURT)));
             }
             else if (line[i].ToString() == "z")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.PEPPER));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.PEPPER)));
             }
             else if (line[i].ToString() == "L")
             {
                 InputData.Add(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.LETTUCE));
                 CellDictionary.Add(new Coordinates(Flag, i), new Cell(new Coordinates(Flag, i), new CellState(CellState.TypeOfCell.LETTUCE)));
             }
             else
             {
                 throw new Exception("Cell value is incorrect. Check your input matrix");
             }
         }
         Flag++;
     }
 }