public static void calculateWeights(final String pathToA, final String targetTrajectoryFile, final String weightsFile, final int offset) {
        try {
            RealMatrix A = csvToMatrix(pathToA);
            // cut first n elements
            A = A.getSubMatrix(offset, A.getRowDimension() - 1, 0, A.getColumnDimension() - 1);
            A = addNoise(A);

            RealMatrix b = csvToMatrix(targetTrajectoryFile);

            // adjust b to cutting
            int n = offset % b.getRowDimension();

            if (n > 0) {
                RealMatrix tmp = b.getSubMatrix(n, b.getRowDimension() - 1, 0, b.getColumnDimension() - 1);
                b = b.getSubMatrix(0, n - 1, 0, b.getColumnDimension() - 1);
                double[][] tmpArray = tmp.getData();
                double[][] tmpArray2 = b.getData();
                b = MatrixUtils.createRealMatrix(concat(tmpArray, tmpArray2));
                tmpArray = b.getData();

                for (int i = 0; tmpArray.length < A.getRowDimension(); ++i) {
                    tmpArray2 = new double[1][tmpArray[0].length];

                    for (int j = 0; j < tmpArray[i].length; ++j) {
                        tmpArray2[0][j] = tmpArray[i][j];
                    }

                    tmpArray = concat(tmpArray, tmpArray2);
                }

                b = MatrixUtils.createRealMatrix(tmpArray);
            }

            DecompositionSolver solver = new SingularValueDecomposition(A).getSolver();
            RealMatrix x = solver.solve(b).transpose();
            matrixToCsv(x, weightsFile);

        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, "Could not read a file: " + ex.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE);
            Logger.getLogger(Weights.class.getName()).log(Level.WARNING, "Could not read a file: {0}", ex);
        } catch (DimensionMismatchException ex) {
            JOptionPane.showMessageDialog(null, "<html>Could not calculate the "
                    + "pseudo-inverse since a dimension mismatch occurred.<br />"
                    + "Please make sure that all lines of the CSV file posses "
                    + "the same amount of entries.<br />Hint: Remove the last "
                    + "line and try it again.</html>", "Matrix Dimension Mismatch", JOptionPane.ERROR_MESSAGE);
            Logger.getLogger(Weights.class.getName()).log(Level.WARNING, "A dimension mismatch occurred: {0}", ex);
        }
    }