示例#1
0
 public void UpdateFields(DataSetRow row)
 {
     dorsal.text   = row.tag_id.ToString();
     distance.text = row.total_distance.ToString();
     speed.text    = row.speed.ToString();
     energy.text   = row.energy.ToString();
 }
示例#2
0
        public static DataSet generateTraining()
        {
            DataSet dataSet = new DataSet(Data.CHAR_WIDTH * Data.CHAR_HEIGHT, Data.DIGITS.Length);

            for (int i = 0; i < Data.DIGITS.Length; i++)
            {
                // setup input
                DataSetRow inputRow = Data.convertImageIntoData(Data.DIGITS[i]);
                double[]   input    = inputRow.Input;

                // setup output
                double[] output = new double[Data.DIGITS.Length];

                for (int j = 0; j < Data.DIGITS.Length; j++)
                {
                    if (j == i)
                    {
                        output[j] = 1;
                    }
                    else
                    {
                        output[j] = 0;
                    }
                }
                //creating new training element with specified input and output
                DataSetRow row = new DataSetRow(input, output);
                //adding row to data set
                dataSet.addRow(row);
            }
            return(dataSet);
        }
示例#3
0
        public void DataSetRow_Merge_ValueChanged_OriginalsNotChanged()
        {
            DataSetRow originalRow = new DataSetRow
            {
                ["UserId"]   = 123,
                ["DomainId"] = 1001
            };

            DataSetRow newRow = new DataSetRow
            {
                ["DomainId"] = 2001
            };

            DataSetRow result = originalRow.Merge(newRow);

            Assert.AreEqual(2, originalRow.Count);
            Assert.AreEqual(123, originalRow["UserId"]);
            Assert.AreEqual(1001, originalRow["DomainId"]);

            Assert.AreEqual(1, newRow.Count);
            Assert.AreEqual(2001, newRow["DomainId"]);

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(123, result["UserId"]);
            Assert.AreEqual(2001, result["DomainId"]);
        }
示例#4
0
        /// <summary>
        /// Used internally to calculate the error for a training set.
        /// </summary>
        /// <param name="trainingSet"> The training set to calculate for. </param>
        /// <returns> The error value. </returns>
        private double determineError(DataSet trainingSet)
        {
            double result = 0d;

            IEnumerator <DataSetRow> iterator = trainingSet.iterator();

            while (iterator.MoveNext() && !Stopped)
            {
                DataSetRow trainingSetRow = iterator.Current;
                double[]   input          = trainingSetRow.Input;
                Network.Input = input;
                Network.calculate();
                double[] output        = Network.Output;
                double[] desiredOutput = trainingSetRow.DesiredOutput;

                double[] patternError = ErrorFunction.calculatePatternError(desiredOutput, output);
                double   sqrErrorSum  = 0;
                foreach (double error in patternError)
                {
                    sqrErrorSum += (error * error);
                }
                result += sqrErrorSum / (2 * patternError.Length);
            }

            return(result);
        }
示例#5
0
        /// <summary>
        /// Benchmrk preparation consists of training set and neural networ creatiion.
        /// This method generates training set with 100 rows, where every row has 10 input and 5 output elements
        /// Neural network has two hiddden layers with 8 and 7 neurons, and runs learning rule for 2000 iterations
        /// </summary>
        public override void prepareTest()
        {
            int trainingSetSize = 100;
            int inputSize       = 10;
            int outputSize      = 5;

            this.trainingSet = new DataSet(inputSize, outputSize);

            for (int i = 0; i < trainingSetSize; i++)
            {
                double[] input = new double[inputSize];
                for (int j = 0; j < inputSize; j++)
                {
                    input[j] = new Random(1).NextDouble();
                }

                double[] output = new double[outputSize];
                for (int j = 0; j < outputSize; j++)
                {
                    output[j] = new Random(2).NextDouble();
                }

                DataSetRow trainingSetRow = new DataSetRow(input, output);
                trainingSet.addRow(trainingSetRow);
            }


            network = new MultiLayerPerceptron(inputSize, 8, 7, outputSize);
            ((MomentumBackpropagation)network.LearningRule).MaxIterations = 2000;
        }
    public void UpdatePlayers(int indexUpdate, int nextUpdate)
    {
        if (indexUpdate > ParseData.rows.Count || nextUpdate > ParseData.rows.Count)
        {
            Debug.LogError("Incorrect Index Calculation");
            return;
        }

        HashSet <Player> updatedPlayers = new HashSet <Player>();

        DateTime dateTime = ParseData.rows[indexUpdate].time;

        for (int i = indexUpdate; i < ParseData.rows.Count &&
             dateTime == ParseData.rows[i].time; i++)
        {
            DataSetRow row     = ParseData.rows[i];
            DataSetRow?nextRow = NextRow(row.tag_id, nextUpdate);
            //Debug.Log(row.time.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture));
            if (!players.ContainsKey(row.tag_id))
            {
                SpawnPlayer(row.tag_id);
            }

            Player player = players[row.tag_id];
            player.UpdatePlayer(row, nextRow);
            if (/*player.gameObject.activeSelf || */ row.speed >= 0)
            {
                player.gameObject.SetActive(true);
                playersWithoutLog[player] = 0;
                updatedPlayers.Add(player);
            }
        }
        UpdateNoLog(updatedPlayers);
    }
示例#7
0
    private void Awake()
    {
        rows = new List <DataSetRow>();
        List <string> row = new List <string>();

        using (var reader = new CsvFileReader(pathDataset))
        {
            while (reader.ReadRow(row))
            {
                DateTime date = DateTime.Parse(row[0], null, System.Globalization.DateTimeStyles.RoundtripKind);
                int      tag  = Int32.Parse(row[1]);

                float x_pos = float.Parse(row[2], CultureInfo.InvariantCulture);
                float y_pos = float.Parse(row[3], CultureInfo.InvariantCulture);

                float heading   = float.Parse(row[4], CultureInfo.InvariantCulture);
                float direction = float.Parse(row[5], CultureInfo.InvariantCulture);

                float energy         = float.Parse(row[6], CultureInfo.InvariantCulture);
                float speed          = float.Parse(row[7], CultureInfo.InvariantCulture);
                float total_distance = float.Parse(row[8], CultureInfo.InvariantCulture);

                DataSetRow setRow = new DataSetRow(date, tag, x_pos, y_pos, heading, direction, energy, speed, total_distance);
                rows.Add(setRow);
            }
        }
    }
示例#8
0
        private void learnPattern(DataSetRow dataSetRow, int neighborhood)
        {
            neuralNetwork.Input = dataSetRow.Input;
            neuralNetwork.calculate();
            Neuron winner = ClosestNeuron;

            if (winner.Output == 0)
            {
                return;                 // ako je vec istrenirana jedna celija, izadji
            }

            Layer mapLayer  = neuralNetwork.getLayerAt(1);
            int   winnerIdx = mapLayer.IndexOf(winner);

            adjustCellWeights(winner, 0);

            int cellNum = mapLayer.NeuronsCount;

            for (int p = 0; p < cellNum; p++)
            {
                if (p == winnerIdx)
                {
                    continue;
                }
                if (isNeighbor(winnerIdx, p, neighborhood))
                {
                    Neuron cell = mapLayer.getNeuronAt(p);
                    adjustCellWeights(cell, 1);
                }         // if
            }             // for
        }
 /// <summary>
 /// Trains network with the pattern from the specified training element
 /// </summary>
 /// <param name="DataSetItem">
 ///            unsupervised training element which contains network input </param>
 protected internal virtual void learnPattern(DataSetRow trainingElement)
 {
     double[] input = trainingElement.Input;
     this.neuralNetwork.Input = input;
     this.neuralNetwork.calculate();
     this.updateNetworkWeights();
 }
示例#10
0
        public void DataSetRow_Values_CanSetViaIndexInitialiserConstructorAndRetrieveValue()
        {
            DataSetRow row = new DataSetRow
            {
                ["UserId"] = 123
            };

            Assert.AreEqual(123, row["UserId"]);
        }
示例#11
0
        public void DataSetRow_Values_CanSetViaConstructorAndRetrieveValue()
        {
            DataSetRow row = new DataSetRow
            {
                { "UserId", 123 }
            };

            Assert.AreEqual(123, row["UserId"]);
        }
示例#12
0
        public void DataSetRow_Count_OneItem_1()
        {
            DataSetRow row = new DataSetRow
            {
                { "UserId", 123 }
            };

            Assert.AreEqual(1, row.Count);
        }
示例#13
0
        public void DataSetRow_Values_RetrieveUnsetValue_ThrowException()
        {
            DataSetRow row = new DataSetRow();

            var exception = Assert.Throws <KeyNotFoundException>(() => { object result = row["UserId"]; });

            Assert.IsNotNull(exception);
            Assert.AreEqual("UserId was not found in the data set", exception.Message);
        }
示例#14
0
        public void DataSetRow_Values_CanSetAndRetrieveValue()
        {
#pragma warning disable IDE0028 // Simplify collection initialization
            DataSetRow row = new DataSetRow();
#pragma warning restore IDE0028 // Simplify collection initialization
            row["UserId"] = 123;

            Assert.AreEqual(123, row["UserId"]);
        }
示例#15
0
        public void DataSetRow_Count_TwoItems_2()
        {
            DataSetRow row = new DataSetRow
            {
                { "UserId", 123 },
                { "DomainId", 1001 }
            };

            Assert.AreEqual(2, row.Count);
        }
示例#16
0
        /// <summary>
        /// Asserts that the row matches the expected data.  Also asserts that all columns in the expected data exist
        /// </summary>
        /// <param name="expectedData">The expected data to match.  Respects <see cref="Comparisons.Abstract.IComparison"/> objects</param>
        /// <returns>Returns the same <see cref="RowResult"/> object</returns>
        public RowResult AssertValues(DataSetRow expectedData)
        {
            expectedData = expectedData ?? new DataSetRow();

            foreach (KeyValuePair <string, object> record in expectedData)
            {
                AssertValue(record.Key, record.Value);
            }
            return(this);
        }
示例#17
0
 /// <summary>
 /// Trains network with the input and desired output pattern from the specified training element
 /// </summary>
 /// <param name="trainingElement"> supervised training element which contains input and desired output </param>
 protected internal virtual void learnPattern(DataSetRow trainingElement)
 {
     double[] input = trainingElement.Input;
     this.neuralNetwork.Input = input;
     this.neuralNetwork.calculate();
     double[] output        = this.neuralNetwork.Output;
     double[] desiredOutput = trainingElement.DesiredOutput;
     double[] patternError  = errorFunction.calculatePatternError(output, desiredOutput);
     this.updateNetworkWeights(patternError);
 }
        /// <summary>
        /// This method does one learning epoch for the unsupervised learning rules.
        /// It iterates through the training set and trains network weights for each
        /// element
        /// </summary>
        /// <param name="trainingSet">
        ///            training set for training network </param>
        public override void doLearningEpoch(DataSet trainingSet)
        {
            IEnumerator <DataSetRow> iterator = trainingSet.iterator();

            while (iterator.MoveNext() && !Stopped)
            {
                DataSetRow trainingSetRow = iterator.Current;
                learnPattern(trainingSetRow);
            }
        }
示例#19
0
        // TODO; remove sampleCount param its ame as  list count
        private static DataSet createDataSet(List <MNISTImage> imageList, int sampleCount)
        {
            int     pixelCount = imageList[0].Size;
            int     totalSize  = 1024;
            DataSet dataSet    = new DataSet(totalSize, 10);

            for (int i = 0; i < sampleCount; i++)
            {
                MNISTImage dImage = imageList[i];
                double[]   input  = new double[totalSize];
                double[]   output = new double[10];
                for (int j = 0; j < 10; j++)
                {
                    output[j] = 0;
                }

                for (int j = 0; j < totalSize; j++)
                {
                    input[j] = 0;
                }

                output[dImage.Label] = 1;
                sbyte[] imageData = dImage.Data;
                int     k         = 66;
                for (int j = 0; j < pixelCount; j++)
                {
                    if ((imageData[j] & 0xff) > 0)
                    {
                        input[k++] = 255;
                    }
                    else
                    {
                        k++;
                    }
                    if (j % 28 == 27)
                    {
                        k += 4;
                    }
                }
                DataSetRow row = new DataSetRow(input, output);
                dataSet.addRow(row);
            }
            dataSet.setColumnName(1024, "0");
            dataSet.setColumnName(1025, "1");
            dataSet.setColumnName(1026, "2");
            dataSet.setColumnName(1027, "3");
            dataSet.setColumnName(1028, "4");
            dataSet.setColumnName(1029, "5");
            dataSet.setColumnName(1030, "6");
            dataSet.setColumnName(1031, "7");
            dataSet.setColumnName(1032, "8");
            dataSet.setColumnName(1033, "9");

            return(dataSet);
        }
示例#20
0
        public void DataSetRow_Values_CanSetViaDictionaryConstructorAndRetrieveValue()
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>
            {
                ["UserId"] = 123
            };

            DataSetRow row = new DataSetRow(dictionary);

            Assert.AreEqual(123, row["UserId"]);
        }
示例#21
0
        public void DataSetRow_ToString_OneValue_ReturnValue()
        {
            DataSetRow row = new DataSetRow
            {
                ["UserId"] = 123
            };

            Assert.AreEqual(@"
[UserId, 123]"
                            , row.ToString());
        }
示例#22
0
        public void DataSetRow_ToString_TwoValues_ReturnValues()
        {
            DataSetRow row = new DataSetRow
            {
                ["UserId"]   = 123,
                ["DomainId"] = 1001
            };

            Assert.AreEqual(@"
[UserId, 123]
[DomainId, 1001]", row.ToString());
        }
示例#23
0
        public void DataSetRow_Merge_WithNoOriginalWithNewKey_ReturnOriginalAndNew()
        {
            DataSetRow row = new DataSetRow();

            DataSetRow result = row.Merge(new DataSetRow
            {
                ["AddressId"] = 2001
            });

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(2001, result["AddressId"]);
        }
示例#24
0
        public void DataSetRow_Merge_WithEmpty_ReturnOriginal()
        {
            DataSetRow row = new DataSetRow
            {
                ["UserId"]   = 123,
                ["DomainId"] = 1001
            };

            DataSetRow result = row.Merge(new DataSetRow());

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(123, result["UserId"]);
            Assert.AreEqual(1001, result["DomainId"]);
        }
示例#25
0
        public async Task IdentityOnlyTable_InsertIdentityManually_DataSet()
        {
            DataSetRow data1 = await TestRunner.InsertDataAsync(_tableName, new DataSetRow
            {
                ["Id"] = 2004
            });

            QueryResult results = await TestRunner.ExecuteTableAsync(_tableName);

            results
            .AssertRowCount(1)
            .AssertValue(0, "Id", 2004);

            Assert.AreEqual(2004, data1["Id"]);
        }
示例#26
0
        public async Task IdentityOnlyTable_CanInsertDefaultData_Twice_DifferentIds()
        {
            DataSetRow data1 = await TestRunner.InsertDefaultAsync(_tableName);

            DataSetRow data2 = await TestRunner.InsertDefaultAsync(_tableName);

            QueryResult results = await TestRunner.ExecuteTableAsync(_tableName);

            results
            .AssertRowCount(2)
            .AssertColumnExists("Id")
            .AssertValue(0, "Id", data1["Id"])
            .AssertValue(1, "Id", data2["Id"]);

            Assert.AreNotEqual(data1["Id"], data2["Id"]);
        }
示例#27
0
        /// <summary>
        /// Prints Neuroph data set
        /// </summary>
        /// <param name="neurophDataset"> Dataset Neuroph data set </param>
        public static void printDataset(DataSet neurophDataset)
        {
            Console.WriteLine("Neuroph dataset");
            IEnumerator iterator = neurophDataset.GetEnumerator();

            while (iterator.hasNext())
            {
                DataSetRow row = (DataSetRow)iterator.next();
                Console.WriteLine("inputs");
                Console.WriteLine(Arrays.ToString(row.Input));
                if (row.DesiredOutput.Length > 0)
                {
                    Console.WriteLine("outputs");
                    Console.WriteLine(Arrays.ToString(row.DesiredOutput));
                }
            }
        }
示例#28
0
        public void DataSetRow_Merge_WithExistingKeyDifferentType_ReturnNew()
        {
            DataSetRow row = new DataSetRow
            {
                ["UserId"]   = 123,
                ["DomainId"] = 1001
            };

            DataSetRow result = row.Merge(new DataSetRow
            {
                ["DomainId"] = DateTime.Parse("01-Mar-2020")
            });

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(123, result["UserId"]);
            Assert.AreEqual(DateTime.Parse("01-Mar-2020"), result["DomainId"]);
        }
示例#29
0
        public void DataSetRow_Merge_WithExistingKeyNullValue_ReturnNew()
        {
            DataSetRow row = new DataSetRow
            {
                ["UserId"]   = 123,
                ["DomainId"] = 1001
            };

            DataSetRow result = row.Merge(new DataSetRow
            {
                ["DomainId"] = null
            });

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(123, result["UserId"]);
            Assert.AreEqual(null, result["DomainId"]);
        }
示例#30
0
    public void UpdatePlayer(DataSetRow row, DataSetRow?nextRow)
    {
        lastRow = row;
        nextPos = pos = new Vector3(row.x_pos, 0, row.y_pos);
        //this.transform.position = new Vector3(row.x_pos, 0, row.y_pos);
        if (nextRow != null)
        {
            nextPos = nextRow.Value.GetPos();
            Vector3 currentPos = row.GetPos();

            this.transform.LookAt(nextPos);

            //Vector3 direction = Vector3.Lerp(currentPos, nextPos, 0.6f);
            Vector3 move = nextPos - currentPos;
            thirdPerson.Move(move, false, false);
        }
    }