示例#1
0
 public OverlapDeconvSolverHandler(int numDeconvWindows, int maxScans, int maxTransitions, int overlapRegions, int cycleLength) :
     base(numDeconvWindows, maxScans, maxTransitions)
 {
     _overlapRegionsInApprox = overlapRegions;
     _cycleLength            = cycleLength;
     _deconvBlock            = new DeconvBlock(_overlapRegionsInApprox, _overlapRegionsInApprox, maxTransitions);
 }
        public void Condition(DeconvBlock db)
        {
            int numRows = db.NumRows;

            if (numRows >= 5)
            {
                int rowsPerSection = numRows / 5;
                for (int i = 0; i < numRows; ++i)
                {
                    int smoothCoefIndex = i / rowsPerSection;
                    // boundary scenario
                    if (smoothCoefIndex >= 5)
                    {
                        smoothCoefIndex = 4;
                    }
                    double smoothCoef = _smoothCoefs[smoothCoefIndex];
                    for (int j = 0; j < db.Masks.NumCols; ++j)
                    {
                        db.Masks.Matrix[i, j] *= smoothCoef;
                    }
                    for (int j = 0; j < db.BinnedData.NumCols; ++j)
                    {
                        db.BinnedData.Matrix[i, j] *= smoothCoef;
                    }
                }
            }
            db.BinnedData.Matrix.NormalizeColumns(1);
        }
 public OverlapDeconvSolverHandler(int numDeconvWindows, int maxScans, int maxTransitions, int overlapRegions, int cycleLength)
     : base(numDeconvWindows, maxScans, maxTransitions)
 {
     _overlapRegionsInApprox = overlapRegions;
     _cycleLength = cycleLength;
     _deconvBlock = new DeconvBlock(_overlapRegionsInApprox, _overlapRegionsInApprox, maxTransitions);
 }
        protected virtual void SetTolerance(DeconvBlock db)
        {
            // Number of blocks of scans that you average over
            int maxCount = db.Masks.NumRows;

            _tol     = db.Masks.Matrix.L1Norm() * 10.0 * double.Epsilon * maxCount;
            _maxIter = db.Masks.NumCols * 3;
        }
        public virtual void Solve(DeconvBlock db)
        {
            ClearMatrices();
            _conditioner.Condition(db);

            if (!_tol.HasValue)
            {
                SetTolerance(db);
            }
            var matrixAt = db.Masks.Matrix.Transpose();

            FindFirstGuess(db.Masks.Matrix, db.BinnedData.Matrix, ref _firstGuess);
            db.Masks.Matrix.Multiply(_firstGuess, _matrixAx);
            _matrixDiffBig.Clear();
            db.BinnedData.Matrix.Subtract(_matrixAx, _matrixDiffBig);
            matrixAt.Multiply(_matrixDiffBig, _matrixWs);

            var matrixResult = db.Solution;

            // if useFirstGuess constructor parameter is true,
            // don't bother iterating, just use the first guess
            if (_useFirstGuess)
            {
                for (int colNum = 0; colNum < db.BinnedData.NumCols; ++colNum)
                {
                    CopyColumnToVector(_firstGuess, colNum, _initializeCol);
                    matrixResult.Matrix.SetColumn(colNum, _initializeCol);
                }
                return;
            }
            for (int colNum = 0; colNum < db.BinnedData.NumCols; ++colNum)
            {
                _initializeCol.Clear();
                CopyColumnToVector(_firstGuess, colNum, _initializeCol);
                CopyColumnToVector(db.BinnedData.Matrix, colNum, _binnedDataCol);
                _matrixAxCol.Clear();
                _matrixWsCol.Clear();
                CopyColumnToVector(_matrixAx, colNum, _matrixAxCol);
                CopyColumnToVector(_matrixWs, colNum, _matrixWsCol);
                if (SolveColumn(db.Masks.Matrix, _binnedDataCol,
                                _initializeCol, matrixAt, _matrixAxCol, _matrixWsCol,
                                ref _solutionCol))
                {
                    matrixResult.Matrix.SetColumn(colNum, _solutionCol);
                }
                else
                {
                    // can't figure out the results, so set the value to the
                    // least squares initial guess
                    matrixResult.Matrix.SetColumn(colNum, _initializeCol);
                }
            }
        }
 protected override void SetTolerance(DeconvBlock db)
 {
     base.SetTolerance(db);
     _tol = 1e-8;
 }
示例#7
0
 public MsxDeconvSolverHandler(int numDeconvWindows, int maxScans, int maxTransitions)
     : base(numDeconvWindows, maxScans, maxTransitions)
 {
     _deconvBlock = new DeconvBlock(numDeconvWindows, maxScans, maxTransitions);
 }
示例#8
0
        /// <summary>
        /// Test the WeightedConditioner class which is responsible for "conditioning"
        /// the A and b matrices in the equation Ax=b when solving for x.  b contains
        /// transition intensity values to be deconvolved, A encodes the precursor isolation
        /// window scheme used.  The conditioner weights the entries in the center rows of each
        /// matrix higher than those on the edges.
        /// </summary>
        private static void TestWeightedMatrixPrepare()
        {
            // If the matrices have less than 5 rows, the conditioner should have
            // no effect.
            DeconvBlock dbSmall = new DeconvBlock(5, 5, 4);

            double[] mask = { 1.0, 1.0, 1.0, 1.0, 0.0 };
            double[] data = { 2.0, 2.0, 2.0, 2.0 };
            for (int i = 0; i < 4; ++i)
            {
                dbSmall.Add(mask, data);
            }
            var conditioner = new WeightedConditioner();

            conditioner.Condition(dbSmall);
            var conditionedMasks = dbSmall.Masks;
            var conditionedData  = dbSmall.BinnedData;

            for (int i = 0; i < 4; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData        = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(mask, conditionedMask);
                AssertEx.AreEqualDeep(data, condData);
            }

            // If the matrices have more than 5 rows, check that the weighting
            // is applied correctly.
            DeconvBlock dbLarge = new DeconvBlock(5, 11, 4);

            for (int i = 0; i < 11; ++i)
            {
                dbLarge.Add(mask, data);
            }
            conditioner.Condition(dbLarge);
            conditionedMasks = dbLarge.Masks;
            conditionedData  = dbLarge.BinnedData;
            var expectedMask = new[] { -0.086, -0.086, -0.086, -0.086, 0.0 };
            var expectedData = new[] { 2 * -0.086, 2 * -0.086, 2 * -0.086, 2 * -0.086 };

            for (int i = 0; i < 2; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData        = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(expectedMask, conditionedMask);
                AssertEx.AreEqualDeep(expectedData, condData);
            }
            expectedMask = new[] { 0.343, 0.343, 0.343, 0.343, 0.0 };
            expectedData = new[] { 2 * 0.343, 2 * 0.343, 2 * 0.343, 2 * 0.343 };
            for (int i = 2; i < 4; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData        = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(expectedMask, conditionedMask);
                AssertEx.AreEqualDeep(expectedData, condData);
            }

            expectedMask = new[] { 0.486, 0.486, 0.486, 0.486, 0.0 };
            expectedData = new[] { 2 * 0.486, 2 * 0.486, 2 * 0.486, 2 * 0.486 };
            for (int i = 4; i < 6; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData        = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(expectedMask, conditionedMask);
                AssertEx.AreEqualDeep(expectedData, condData);
            }

            expectedMask = new[] { 0.343, 0.343, 0.343, 0.343, 0.0 };
            expectedData = new[] { 2 * 0.343, 2 * 0.343, 2 * 0.343, 2 * 0.343 };
            for (int i = 6; i < 8; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData        = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(expectedMask, conditionedMask);
                AssertEx.AreEqualDeep(expectedData, condData);
            }

            expectedMask = new[] { -0.086, -0.086, -0.086, -0.086, 0.0 };
            expectedData = new[] { 2 * -0.086, 2 * -0.086, 2 * -0.086, 2 * -0.086 };
            for (int i = 8; i < 11; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData        = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(expectedMask, conditionedMask);
                AssertEx.AreEqualDeep(expectedData, condData);
            }
        }
        /// <summary>
        /// Test the WeightedConditioner class which is responsible for "conditioning"
        /// the A and b matrices in the equation Ax=b when solving for x.  b contains
        /// transition intensity values to be deconvolved, A encodes the precursor isolation
        /// window scheme used.  The conditioner weights the entries in the center rows of each
        /// matrix higher than those on the edges.
        /// </summary>
        private static void TestWeightedMatrixPrepare()
        {
            // If the matrices have less than 5 rows, the conditioner should have
            // no effect.
            DeconvBlock dbSmall = new DeconvBlock(5,5,4);
            double[] mask = {1.0,1.0,1.0,1.0, 0.0};
            double[] data = {2.0,2.0,2.0,2.0};
            for (int i = 0; i<4; ++i)
            {
                dbSmall.Add(mask, data);
            }
            var conditioner = new WeightedConditioner();
            conditioner.Condition(dbSmall);
            var conditionedMasks = dbSmall.Masks;
            var conditionedData = dbSmall.BinnedData;
            for (int i = 0; i<4; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(mask, conditionedMask);
                AssertEx.AreEqualDeep(data, condData);
            }

            // If the matrices have more than 5 rows, check that the weighting
            // is applied correctly.
            DeconvBlock dbLarge = new DeconvBlock(5, 11, 4);
            for (int i = 0; i<11; ++i)
            {
                dbLarge.Add(mask, data);
            }
            conditioner.Condition(dbLarge);
            conditionedMasks = dbLarge.Masks;
            conditionedData = dbLarge.BinnedData;
            var expectedMask = new[] {-0.086, -0.086, -0.086, -0.086, 0.0};
            var expectedData = new[] {2*-0.086, 2*-0.086, 2*-0.086, 2*-0.086};
            for (int i = 0; i<2; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(expectedMask, conditionedMask);
                AssertEx.AreEqualDeep(expectedData, condData);
            }
            expectedMask = new[] {0.343, 0.343, 0.343, 0.343, 0.0};
            expectedData = new[] {2*0.343, 2*0.343, 2*0.343, 2*0.343};
            for (int i = 2; i<4; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(expectedMask, conditionedMask);
                AssertEx.AreEqualDeep(expectedData, condData);
            }

            expectedMask = new[] {0.486, 0.486, 0.486, 0.486, 0.0};
            expectedData = new[] {2*0.486, 2*0.486, 2*0.486, 2*0.486};
            for (int i = 4; i<6; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(expectedMask, conditionedMask);
                AssertEx.AreEqualDeep(expectedData, condData);
            }

            expectedMask = new[] {0.343, 0.343, 0.343, 0.343, 0.0};
            expectedData = new[] {2*0.343, 2*0.343, 2*0.343, 2*0.343};
            for (int i = 6; i<8; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(expectedMask, conditionedMask);
                AssertEx.AreEqualDeep(expectedData, condData);
            }

            expectedMask = new[] {-0.086, -0.086, -0.086, -0.086, 0.0};
            expectedData = new[] {2*-0.086, 2*-0.086, 2*-0.086, 2*-0.086};
            for (int i = 8; i<11; ++i)
            {
                var conditionedMask = conditionedMasks.Matrix.Row(i, 0, 5).ToArray();
                var condData = conditionedData.Matrix.Row(i, 0, 4).ToArray();
                AssertEx.AreEqualDeep(expectedMask, conditionedMask);
                AssertEx.AreEqualDeep(expectedData, condData);
            }
        }
示例#10
0
 public MsxDeconvSolverHandler(int numDeconvWindows, int maxScans, int maxTransitions) :
     base(numDeconvWindows, maxScans, maxTransitions)
 {
     _deconvBlock = new DeconvBlock(numDeconvWindows, maxScans, maxTransitions);
 }