Esempio n. 1
0
        public void FirstTrainingShouldSetMatrixDimensions()
        {
            var bamModel = new BamModel();

            bamModel.Teach(_image1, _name1);

            _output.WriteLine(bamModel.WeightsMatrix.ToString());
            bamModel.WeightsMatrix.RowCount.ShouldBeEquivalentTo(6);
            bamModel.WeightsMatrix.ColumnCount.ShouldBeEquivalentTo(4);
        }
Esempio n. 2
0
        public void TrainingByNameWithBadLengthShouldThrowArgumentException()
        {
            var bamModel          = new BamModel();
            var nameWithBadLength = Vector <float> .Build.DenseOfArray(new float[5]);

            bamModel.Teach(_image1, _name1);

            Action validatingImageLength = () => bamModel.Teach(_image2, nameWithBadLength);

            validatingImageLength.ShouldThrow <ArgumentException>();
        }
Esempio n. 3
0
        public void RecoveringImageFromNameVectorWithWrongLengthShouldThrowArgumentException()
        {
            var bamModel = new BamModel();
            var namesMatrixWithWrongColumnLength = Matrix <float> .Build.DenseOfArray(new float[1, 10]);

            bamModel.Teach(_image1, _name1);

            Action recoveringImageFromWrongName = () => bamModel.RecoverImage(namesMatrixWithWrongColumnLength);

            recoveringImageFromWrongName.ShouldThrow <ArgumentException>();
        }
Esempio n. 4
0
        public void RecoveringNameWithOneGivenImageVectorShouldReturnRightName()
        {
            var bamModel     = new BamModel();
            var imagesMatrix = Matrix <float> .Build.DenseOfRowVectors(_image1);

            var namesMatrix = Matrix <float> .Build.DenseOfRowVectors(_name1);

            bamModel.Teach(_image1, _name1);
            bamModel.Teach(_image2, _name2);

            Matrix <float> resultNamesMatrix = bamModel.RecoverName(imagesMatrix);

            _output.WriteLine(resultNamesMatrix.ToString());

            resultNamesMatrix.ShouldBeEquivalentTo(namesMatrix);
        }
Esempio n. 5
0
        public void SecondTrainingShouldGiveRightWeightMatrix()
        {
            var bamModel      = new BamModel();
            var correctMatrix = Matrix <float> .Build.DenseOfArray(new[, ]
            {
                { 0f, -2, 2, 0 },
                { 0, 2, -2, 0 },
                { 0, 2, -2, 0 },
                { 2, 0, 0, -2 },
                { -2, 0, 0, 2 },
                { 0, 2, -2, 0 }
            });

            bamModel.Teach(_image1, _name1);
            bamModel.Teach(_image2, _name2);

            _output.WriteLine(bamModel.WeightsMatrix.ToString());
            bamModel.WeightsMatrix.ShouldBeEquivalentTo(correctMatrix);
        }