Exemplo n.º 1
0
    private RemoveChannels RemoveEmptyChannels(Matrix <double> input)
    {
        //Scan for and store all non-zero channels (i.e. only use loaded channels)
        //Return an updated matrix with empty channels removed, and a bool array identifying which channels are used.

        double[,] InputArray = input.ToArray();
        bool[] usedCol = new bool[InputArray.GetLength(1)];
        int    count   = 0;

        for (int i = InputArray.GetLength(1) - 1; i >= 0; i--)
        {
            if (InputArray[2, i] == 0)
            {
                usedCol[i] = false;
                input      = input.RemoveColumn(i);
            }
            else
            {
                usedCol[i] = true;
                count++;
            }
        }

        RemoveChannels result = new RemoveChannels();

        result.ReducedMatrix = input;
        result.usedCol       = usedCol;
        return(result);
    }
Exemplo n.º 2
0
    //Called after gathering training data
    public Vector <double>[] Solve(double[,] X, double[,] yArray)
    {
        //Solve matrix to generate weights for runtime calibration

        double[]          y     = new double[yArray.GetLength(0)];
        Vector <double>[] theta = new Vector <double> [yArray.GetLength(1)];

        //Process each collum one by one
        for (int i = 0; i < yArray.GetLength(1); i++)
        {
            //Clone raw data to manipulate
            double[,] Xclone = X.Clone() as double[, ];

            //Disable channels not used for this solve
            Xclone = DisableChannels(Xclone, ActiveSensors, i);

            Matrix <double> XMatrix = CreateMatrix.DenseOfArray(Xclone);

            RemoveChannels temp = RemoveEmptyChannels(XMatrix);
            XMatrix = temp.ReducedMatrix;
            //Get a solution vector
            y = getCollumn(yArray, i);
            Matrix <double> tempMat = XMatrix;

            //Perform Regression fit
            Vector <double> yVector = CreateVector.DenseOfArray(y);
            theta[i] = MultipleRegression.Svd <double>(tempMat, yVector);

            //Add removed collumns
            theta[i] = PadArray(temp.usedCol, theta[i]);
        }

        return(theta);
    }