Example usage for org.apache.commons.math3.linear RealVector setEntry

List of usage examples for org.apache.commons.math3.linear RealVector setEntry

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear RealVector setEntry.

Prototype

public abstract void setEntry(int index, double value) throws OutOfRangeException;

Source Link

Document

Set a single element.

Usage

From source file:com.github.thorbenlindhauer.factor.CanonicalGaussianFactor.java

protected RealVector getSubVector(RealVector vector, int[] entriesToKeep) {
    RealVector subVector = new ArrayRealVector(entriesToKeep.length);

    for (int i = 0; i < entriesToKeep.length; i++) {
        subVector.setEntry(i, vector.getEntry(entriesToKeep[i]));
    }// w  ww .  j av  a 2  s . co  m

    return subVector;
}

From source file:edu.stanford.cfuller.imageanalysistools.fitting.BisquareLinearFit.java

/**
* Calculates the weight for the next weighted least squares iteration using the bisquare weighting function.
* @param stdAdjR the standardized adjusted residuals, as computed by {@link #calculateStandardizedAdjustedResiduals(RealVector, RealVector, RealVector, RealVector)}
* @return a RealVector containing weights for each data point suitable for weighted least squares fitting.
*/// w w  w .jav  a2 s . com
protected RealVector calculateBisquareWeights(RealVector stdAdjR) {

    RealVector bisquareWeights = new ArrayRealVector(stdAdjR.getDimension(), 0.0);

    for (int i = 0; i < bisquareWeights.getDimension(); i++) {
        if (Math.abs(stdAdjR.getEntry(i)) < 1) {
            bisquareWeights.setEntry(i, Math.pow(1 - Math.pow(stdAdjR.getEntry(i), 2), 2));
        }
    }
    return bisquareWeights;
}

From source file:edu.stanford.cfuller.imageanalysistools.fitting.BisquareLinearFit.java

/**
* Calculates the standardized adjusted residuals (according to the same definition used by MATLAB) of the data points for fitting.
* 
* @param indVarValues The values of the independent variable used for the fitting.
* @param depVarValues The values of the dependent variable used for the fitting.
* @param leverages the leverages of the independent variables, as compted by {@link #calculateLeverages(RealVector)}
* @param fitParams the results of a (possibly weighted) least squares fit to the data, containing one or two components: a slope and an optional y-intercept.
* @return a RealVector containing an adjusted residual value for each data point
*///from  ww w.j a v a2  s . c o  m
protected RealVector calculateStandardizedAdjustedResiduals(RealVector indVarValues, RealVector depVarValues,
        RealVector leverages, RealVector fitParams) {

    RealVector predictedValues = indVarValues.mapMultiply(fitParams.getEntry(0));

    RealVector denom = leverages.mapMultiply(-1.0).mapAddToSelf(1 + this.CLOSE_TO_ZERO)
            .mapToSelf(new org.apache.commons.math3.analysis.function.Sqrt());

    if (!this.noIntercept) {
        predictedValues = predictedValues.mapAdd(fitParams.getEntry(1));
    }

    double stddev = 0;
    double mean = 0;

    for (int i = 0; i < depVarValues.getDimension(); i++) {
        mean += depVarValues.getEntry(i);
    }

    mean /= depVarValues.getDimension();

    stddev = depVarValues.mapSubtract(mean).getNorm()
            * (depVarValues.getDimension() * 1.0 / (depVarValues.getDimension() - 1));

    RealVector residuals = depVarValues.subtract(predictedValues).ebeDivide(denom);

    RealVector absDev = residuals.map(new org.apache.commons.math3.analysis.function.Abs());

    int smallerDim = 2;

    if (this.noIntercept) {
        smallerDim = 1;
    }

    double[] resArray = residuals.map(new org.apache.commons.math3.analysis.function.Abs()).toArray();

    java.util.Arrays.sort(resArray);

    RealVector partialRes = new ArrayRealVector(absDev.getDimension() - smallerDim + 1, 0.0);

    for (int i = smallerDim - 1; i < resArray.length; i++) {
        partialRes.setEntry(i - smallerDim + 1, resArray[i]);
    }

    double resMAD = 0;

    if (partialRes.getDimension() % 2 == 0) {
        resMAD = LocalBackgroundEstimationFilter.quickFindKth(partialRes.getDimension() / 2, partialRes)
                + LocalBackgroundEstimationFilter.quickFindKth(partialRes.getDimension() / 2 - 1, partialRes);
        resMAD /= 2.0;
    } else {
        resMAD = LocalBackgroundEstimationFilter.quickFindKth((partialRes.getDimension() - 1) / 2, partialRes);
    }

    resMAD /= 0.6745;

    if (resMAD < stddev * CLOSE_TO_ZERO) {
        resMAD = stddev * CLOSE_TO_ZERO;
    }

    return residuals.mapDivide(DEFAULT_TUNING_CONST * resMAD);

}

From source file:edu.stanford.cfuller.imageanalysistools.fitting.BisquareLinearFit.java

/**
* Performs a weighted least squares fit with supplied weights to the supplied data.
* 
* @param indVarValues A RealVector containing the values of the independent variable.
* @param depVarValues A RealVector containing the values of the dependent variable.
* @param weights A RealVector containing the weights for the data points.
* @return a RealVector containing two elements: the slope of the fit and the y-intercept of the fit.
*//*from w  w  w  . jav  a 2s .co  m*/
public RealVector wlsFit(RealVector indVarValues, RealVector depVarValues, RealVector weights) {

    //initial guess for the fit: unweighted regression.

    SimpleRegression unweighted = new SimpleRegression(!this.noIntercept);

    for (int i = 0; i < indVarValues.getDimension(); i++) {
        unweighted.addData(indVarValues.getEntry(i), depVarValues.getEntry(i));
    }

    RealVector parameters = null;

    if (this.noIntercept) {
        parameters = new ArrayRealVector(1, 0.0);
    } else {
        parameters = new ArrayRealVector(2, 0.0);
    }

    parameters.setEntry(0, unweighted.getSlope());

    if (!this.noIntercept) {
        parameters.setEntry(1, unweighted.getIntercept());
    }

    NelderMeadMinimizer nmm = new NelderMeadMinimizer(1e-12);
    WlsObjectiveFunction wof = new WlsObjectiveFunction();
    wof.setIndVar(indVarValues);
    wof.setDepVar(depVarValues);
    wof.setWeights(weights);
    wof.setShouldFitIntercept(!this.noIntercept);

    parameters = nmm.optimize(wof, parameters);

    if (this.noIntercept) {
        RealVector output = new ArrayRealVector(2, 0.0);
        output.setEntry(0, parameters.getEntry(0));
        return output;
    }

    return parameters;

}

From source file:edu.stanford.cfuller.imageanalysistools.clustering.ObjectClustering.java

/**
 * Applies basic clustering to an Image with objects.
 *
 * This will use the long-range gaussian filtering approach to assign clusters; objects sufficiently near to each other will be smeared into a single object and assigned to the same cluster.
 *
 * @param input             An Image mask labeled such that each object in the Image is assigned a unique nonzero greylevel value.  These should start at 1 and be consecutive.
 * @param original          The original image (not currently used... this is here to maintain the interface with a previous version that used this image)
 * @param gaussianFiltered  The mask with a long range Gaussian filter applied (as from {@link #gaussianFilterMask}).  This is an optional parameter;
 *                          input null to have this automatically generated by the method.  This parameter is
 *                          chiefly useful to save computation time when running the clutering multiple times.
 *                          This will be modified, so if planning to reuse the Gaussian filtered image, pass in a copy.
 *//*  w ww .  j  a  v  a2  s .co m*/
public static Image doBasicClustering(WritableImage input, Image original, Image gaussianFiltered) {

    RelabelFilter rlf = new RelabelFilter();
    LabelFilter lf = new LabelFilter();
    MaskFilter mf = new MaskFilter();

    mf.setReferenceImage(input);

    Histogram h_individualCentromeres = new Histogram(input);

    WritableImage origCopy = null;

    if (gaussianFiltered == null) {

        origCopy = gaussianFilterMask(input).getWritableInstance();

    } else {
        origCopy = gaussianFiltered.getWritableInstance();
    }

    lf.apply(origCopy);

    WritableImage mapped = ImageFactory.createWritable(origCopy);

    Histogram h_mapped_0 = new Histogram(origCopy);

    //first, find the centroid of each cluster

    org.apache.commons.math3.linear.RealVector centroids_x = new ArrayRealVector(h_mapped_0.getMaxValue() + 1);
    org.apache.commons.math3.linear.RealVector centroids_y = new ArrayRealVector(h_mapped_0.getMaxValue() + 1);

    org.apache.commons.math3.linear.RealVector counts = new ArrayRealVector(h_mapped_0.getMaxValue() + 1);

    centroids_x.mapMultiplyToSelf(0.0);
    centroids_y.mapMultiplyToSelf(0.0);
    counts.mapMultiplyToSelf(0.0);

    for (ImageCoordinate i : origCopy) {
        if (origCopy.getValue(i) > 0) {
            int value = (int) origCopy.getValue(i);
            centroids_x.setEntry(value, centroids_x.getEntry(value) + i.get(ImageCoordinate.X));
            centroids_y.setEntry(value, centroids_y.getEntry(value) + i.get(ImageCoordinate.Y));
            counts.setEntry(value, counts.getEntry(value) + 1);
        }
    }
    for (int i = 0; i < counts.getDimension(); i++) {
        if (counts.getEntry(i) == 0) {
            counts.setEntry(i, 1);
            centroids_x.setEntry(i, -1 * origCopy.getDimensionSizes().get(ImageCoordinate.X));
            centroids_y.setEntry(i, -1 * origCopy.getDimensionSizes().get(ImageCoordinate.Y));
        }
        centroids_x.setEntry(i, centroids_x.getEntry(i) / counts.getEntry(i));
        centroids_y.setEntry(i, centroids_y.getEntry(i) / counts.getEntry(i));

    }

    for (ImageCoordinate i : origCopy) {

        if (mapped.getValue(i) > 0 || input.getValue(i) == 0)
            continue;

        double minDistance = Double.MAX_VALUE;
        int minIndex = 0;

        for (int j = 0; j < centroids_x.getDimension(); j++) {
            double dist = Math.hypot(centroids_x.getEntry(j) - i.get(ImageCoordinate.X),
                    centroids_y.getEntry(j) - i.get(ImageCoordinate.Y));
            if (dist < minDistance) {
                minDistance = dist;
                minIndex = j;
            }
        }

        mapped.setValue(i, minIndex);

    }

    int[] centromereAssignments = new int[h_individualCentromeres.getMaxValue() + 1];
    java.util.Arrays.fill(centromereAssignments, 0);

    for (ImageCoordinate i : mapped) {

        if (input.getValue(i) > 0) {

            int value = (int) input.getValue(i);

            if (centromereAssignments[value] > 0) {
                mapped.setValue(i, centromereAssignments[value]);
            } else {
                centromereAssignments[value] = (int) mapped.getValue(i);
            }

        }
    }

    mf.apply(mapped);
    origCopy.copy(mapped);
    mf.setReferenceImage(origCopy);

    mf.apply(input);
    rlf.apply(input);
    rlf.apply(origCopy);

    return origCopy;
}

From source file:edu.stanford.cfuller.imageanalysistools.filter.LocalBackgroundEstimationFilter.java

/**
 * Finds the kth item sorted by increasing value in a possibly unsorted vector.
 * <p>//w w  w . j a va2  s . c  o m
 * This will likely not completely sort the vector, but will almost certainly
 * change the order of the items in the vector in place.
 * 
 * @param k         The index of the item (in the sorted vector) to find.
 * @param toFind   The RealVector in which to find the kth item.
 * @return         The value of the kth item (in the sorted vector).
 */
public static double quickFindKth(int k, RealVector toFind) {

    int n = toFind.getDimension();

    int l = 0;

    int ir = n - 1;

    while (true) {

        if (ir <= l + 1) {
            if (ir == l + 1 && toFind.getEntry(ir) < toFind.getEntry(l)) {
                swap(ir, l, toFind);
            }

            return toFind.getEntry(k);
        } else {
            int mid = (l + ir) >> 1;

            swap(mid, l + 1, toFind);

            if (toFind.getEntry(l) > toFind.getEntry(ir))
                swap(l, ir, toFind);
            if (toFind.getEntry(l + 1) > toFind.getEntry(ir))
                swap(l + 1, ir, toFind);
            if (toFind.getEntry(l) > toFind.getEntry(l + 1))
                swap(l, l + 1, toFind);

            int i = l + 1;
            int j = ir;

            double a = toFind.getEntry(l + 1);

            while (true) {
                do {
                    i++;
                } while (toFind.getEntry(i) < a);

                do {
                    j--;
                } while (toFind.getEntry(j) > a);

                if (j < i)
                    break;

                swap(i, j, toFind);
            }

            toFind.setEntry(l + 1, toFind.getEntry(j));
            toFind.setEntry(j, a);

            if (j >= k)
                ir = j - 1;
            if (j <= k)
                l = i;

        }

    }

}

From source file:edu.stanford.cfuller.imageanalysistools.fitting.NelderMeadMinimizer.java

/**
 * Constructs the initial simplex that is the starting point of the optimization given an initial guess at the minimum.
 *
 * This method will attempt to guess the scale of each parameters, but it is preferable to specify this manually using the other form of
 * generateInitialSimplex if any information about these scales is known.
 *
 * @param initialPoint      The initial guess at the minimum, one component per parameter.
 * @return                  A matrix containing p + 1 rows, each of which is one set of p parameters, which specify the simplex.
 */// w w  w  .ja  v  a 2 s. c  om
public RealMatrix generateInitialSimplex(RealVector initialPoint) {

    final double constantScale = 0.1;

    RealVector componentScales = initialPoint.mapMultiply(constantScale);

    //if the initial point has zeros in it, those entries will not be optimized
    //perturb slightly to allow optimization
    for (int i = 0; i < componentScales.getDimension(); i++) {
        if (componentScales.getEntry(i) == 0.0) {
            componentScales.setEntry(i, constantScale);
        }
    }

    return generateInitialSimplex(initialPoint, componentScales);

}

From source file:com.joptimizer.optimizers.LPStandardConverterTest.java

/**
 * Standardization of a problem on the form:
 * min(c) s.t.//from   w w w. j  ava  2s.  co  m
 * G.x < h
 * A.x = b
 */
public void testCGhAb3() throws Exception {
    log.debug("testCGhAb3");

    String problemId = "3";

    double[] c = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "c" + problemId + ".txt");
    double[][] G = Utils.loadDoubleMatrixFromFile(
            "lp" + File.separator + "standardization" + File.separator + "G" + problemId + ".csv",
            ",".charAt(0));
    double[] h = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "h" + problemId + ".txt");
    ;
    double[][] A = Utils.loadDoubleMatrixFromFile(
            "lp" + File.separator + "standardization" + File.separator + "A" + problemId + ".csv",
            ",".charAt(0));
    double[] b = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "b" + problemId + ".txt");
    double[] expectedSol = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "sol" + problemId + ".txt");
    double expectedValue = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "value" + problemId + ".txt")[0];
    double expectedTolerance = MatrixUtils.createRealMatrix(A)
            .operate(MatrixUtils.createRealVector(expectedSol)).subtract(MatrixUtils.createRealVector(b))
            .getNorm();

    //standard form conversion
    LPStandardConverter lpConverter = new LPStandardConverter();
    lpConverter.toStandardForm(c, G, h, A, b, null, null);

    int n = lpConverter.getStandardN();
    int s = lpConverter.getStandardS();
    c = lpConverter.getStandardC().toArray();
    A = lpConverter.getStandardA().toArray();
    b = lpConverter.getStandardB().toArray();
    double[] lb = lpConverter.getStandardLB().toArray();
    double[] ub = lpConverter.getStandardUB().toArray();
    log.debug("n : " + n);
    log.debug("s : " + s);

    //check consistency
    assertEquals(G.length, s);
    assertEquals(A[0].length, n);
    assertEquals(s + lpConverter.getOriginalN(), n);
    assertEquals(lb.length, n);
    assertEquals(ub.length, n);

    //check constraints
    RealMatrix GOrig = new Array2DRowRealMatrix(G);
    RealVector hOrig = new ArrayRealVector(h);
    RealMatrix AStandard = new Array2DRowRealMatrix(A);
    RealVector bStandard = new ArrayRealVector(b);
    RealVector expectedSolVector = new ArrayRealVector(expectedSol);
    RealVector Gxh = GOrig.operate(expectedSolVector).subtract(hOrig);//G.x - h
    RealVector slackVariables = new ArrayRealVector(s);
    for (int i = 0; i < s; i++) {
        slackVariables.setEntry(i, 0. - Gxh.getEntry(i));//the difference from 0
        assertTrue(slackVariables.getEntry(i) >= 0.);
    }
    RealVector sol = slackVariables.append(expectedSolVector);
    RealVector Axmb = AStandard.operate(sol).subtract(bStandard);
    assertEquals(0., Axmb.getNorm(), expectedTolerance);

    //      Utils.writeDoubleArrayToFile(new double[]{s}, "target" + File.separator   + "standardS"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(c, "target" + File.separator   + "standardC"+problemId+".txt");
    //      Utils.writeDoubleMatrixToFile(A, "target" + File.separator   + "standardA"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(b, "target" + File.separator   + "standardB"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(lb, "target" + File.separator   + "standardLB"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(ub, "target" + File.separator   + "standardUB"+problemId+".txt");
}

From source file:com.joptimizer.optimizers.LPStandardConverterTest.java

/**
 * Standardization of a problem on the form:
 * min(c) s.t./* w  w w  . j  av a  2 s  . com*/
 * G.x < h
 * A.x = b
 */
public void testCGhAb2() throws Exception {
    log.debug("testCGhAb2");

    String problemId = "2";

    double[] c = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "c" + problemId + ".txt");
    double[][] G = Utils.loadDoubleMatrixFromFile(
            "lp" + File.separator + "standardization" + File.separator + "G" + problemId + ".csv",
            ",".charAt(0));
    double[] h = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "h" + problemId + ".txt");
    ;
    double[][] A = Utils.loadDoubleMatrixFromFile(
            "lp" + File.separator + "standardization" + File.separator + "A" + problemId + ".csv",
            ",".charAt(0));
    double[] b = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "b" + problemId + ".txt");
    double[] expectedSol = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "sol" + problemId + ".txt");
    double expectedValue = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "value" + problemId + ".txt")[0];
    double expectedTolerance = MatrixUtils.createRealMatrix(A)
            .operate(MatrixUtils.createRealVector(expectedSol)).subtract(MatrixUtils.createRealVector(b))
            .getNorm();

    //standard form conversion
    double unboundedLBValue = Double.NEGATIVE_INFINITY;
    double unboundedUBValue = Double.POSITIVE_INFINITY;
    LPStandardConverter lpConverter = new LPStandardConverter(unboundedLBValue, unboundedUBValue);
    lpConverter.toStandardForm(c, G, h, A, b, null, null);

    int n = lpConverter.getStandardN();
    int s = lpConverter.getStandardS();
    c = lpConverter.getStandardC().toArray();
    A = lpConverter.getStandardA().toArray();
    b = lpConverter.getStandardB().toArray();
    double[] lb = lpConverter.getStandardLB().toArray();
    double[] ub = lpConverter.getStandardUB().toArray();
    log.debug("n : " + n);
    log.debug("s : " + s);
    log.debug("c : " + ArrayUtils.toString(c));
    log.debug("A : " + ArrayUtils.toString(A));
    log.debug("b : " + ArrayUtils.toString(b));
    log.debug("lb : " + ArrayUtils.toString(lb));
    log.debug("ub : " + ArrayUtils.toString(ub));

    //check consistency
    assertEquals(G.length, s);
    assertEquals(A[0].length, n);
    assertEquals(s + lpConverter.getOriginalN(), n);
    assertEquals(lb.length, n);
    assertEquals(ub.length, n);

    //check constraints
    RealMatrix GOrig = new Array2DRowRealMatrix(G);
    RealVector hOrig = new ArrayRealVector(h);
    RealMatrix AStandard = new Array2DRowRealMatrix(A);
    RealVector bStandard = new ArrayRealVector(b);
    RealVector expectedSolVector = new ArrayRealVector(expectedSol);
    RealVector Gxh = GOrig.operate(expectedSolVector).subtract(hOrig);//G.x - h
    RealVector slackVariables = new ArrayRealVector(s);
    for (int i = 0; i < s; i++) {
        slackVariables.setEntry(i, 0. - Gxh.getEntry(i));//the difference from 0
        assertTrue(slackVariables.getEntry(i) >= 0.);
    }
    RealVector sol = slackVariables.append(expectedSolVector);
    RealVector Axmb = AStandard.operate(sol).subtract(bStandard);
    assertEquals(0., Axmb.getNorm(), expectedTolerance);

    //      Utils.writeDoubleArrayToFile(new double[]{s}, "target" + File.separator   + "standardS"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(c, "target" + File.separator   + "standardC"+problemId+".txt");
    //      Utils.writeDoubleMatrixToFile(A, "target" + File.separator   + "standardA"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(b, "target" + File.separator   + "standardB"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(lb, "target" + File.separator   + "standardLB"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(ub, "target" + File.separator   + "standardUB"+problemId+".txt");
}

From source file:com.joptimizer.optimizers.LPStandardConverterTest.java

/**
 * Standardization of a problem on the form:
 * min(c) s.t./*from w  w  w .ja va2 s  .c o  m*/
 * G.x < h
 * A.x = b
 * lb <= x <= ub
 */
public void testCGhAbLbUb1() throws Exception {
    log.debug("testCGhAbLbUb1");

    String problemId = "1";

    double[] c = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "c" + problemId + ".txt");
    double[][] G = Utils.loadDoubleMatrixFromFile(
            "lp" + File.separator + "standardization" + File.separator + "G" + problemId + ".csv",
            ",".charAt(0));
    double[] h = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "h" + problemId + ".txt");
    ;
    double[][] A = Utils.loadDoubleMatrixFromFile(
            "lp" + File.separator + "standardization" + File.separator + "A" + problemId + ".csv",
            ",".charAt(0));
    double[] b = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "b" + problemId + ".txt");
    double[] lb = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "lb" + problemId + ".txt");
    double[] ub = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "ub" + problemId + ".txt");
    double[] expectedSol = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "sol" + problemId + ".txt");
    double expectedValue = Utils.loadDoubleArrayFromFile(
            "lp" + File.separator + "standardization" + File.separator + "value" + problemId + ".txt")[0];
    //double expectedTolerance = Utils.loadDoubleArrayFromFile("lp"+File.separator+"standardization"+File.separator+"tolerance"+problemId+".txt")[0];
    double expectedTolerance = MatrixUtils.createRealMatrix(A)
            .operate(MatrixUtils.createRealVector(expectedSol)).subtract(MatrixUtils.createRealVector(b))
            .getNorm();

    //standard form conversion
    double unboundedLBValue = Double.NEGATIVE_INFINITY;//this is because in the file the unbounded lb are -Infinity values (not the default value) 
    double unboundedUBValue = Double.POSITIVE_INFINITY;//this is because in the file the unbounded ub are +Infinity values
    LPStandardConverter lpConverter = new LPStandardConverter(unboundedLBValue, unboundedUBValue);
    lpConverter.toStandardForm(c, G, h, A, b, lb, ub);

    int n = lpConverter.getStandardN();
    int s = lpConverter.getStandardS();
    c = lpConverter.getStandardC().toArray();
    A = lpConverter.getStandardA().toArray();
    b = lpConverter.getStandardB().toArray();
    lb = lpConverter.getStandardLB().toArray();
    ub = lpConverter.getStandardUB().toArray();
    log.debug("n : " + n);
    log.debug("s : " + s);
    log.debug("c : " + ArrayUtils.toString(c));
    log.debug("A : " + ArrayUtils.toString(A));
    log.debug("b : " + ArrayUtils.toString(b));
    log.debug("lb : " + ArrayUtils.toString(lb));
    log.debug("ub : " + ArrayUtils.toString(ub));

    //check consistency
    assertEquals(G.length, s);
    assertEquals(s + lpConverter.getOriginalN(), n);
    assertEquals(lb.length, n);
    assertEquals(ub.length, n);

    //check constraints
    RealMatrix GOrig = new Array2DRowRealMatrix(G);
    RealVector hOrig = new ArrayRealVector(h);
    RealMatrix AStandard = new Array2DRowRealMatrix(A);
    RealVector bStandard = new ArrayRealVector(b);
    RealVector expectedSolVector = new ArrayRealVector(expectedSol);
    RealVector Gxh = GOrig.operate(expectedSolVector).subtract(hOrig);//G.x - h
    RealVector slackVariables = new ArrayRealVector(s);
    for (int i = 0; i < s; i++) {
        slackVariables.setEntry(i, 0. - Gxh.getEntry(i));//the difference from 0
        assertTrue(slackVariables.getEntry(i) >= 0.);
    }
    RealVector sol = slackVariables.append(expectedSolVector);
    RealVector Axmb = AStandard.operate(sol).subtract(bStandard);
    assertEquals(0., Axmb.getNorm(), expectedTolerance);

    //      Utils.writeDoubleArrayToFile(new double[]{s}, "target" + File.separator   + "standardS"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(c, "target" + File.separator   + "standardC"+problemId+".txt");
    //      Utils.writeDoubleMatrixToFile(A, "target" + File.separator   + "standardA"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(b, "target" + File.separator   + "standardB"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(lb, "target" + File.separator   + "standardLB"+problemId+".txt");
    //      Utils.writeDoubleArrayToFile(ub, "target" + File.separator   + "standardUB"+problemId+".txt");
}