List of usage examples for org.apache.commons.math3.linear ArrayRealVector ArrayRealVector
public ArrayRealVector(ArrayRealVector v) throws NullArgumentException
From source file:lirmm.inria.fr.math.BigSparseRealMatrixTest.java
/** * test operate/* w ww . j av a 2 s . c o m*/ */ @Test public void testOperate() { RealMatrix m = new BigSparseRealMatrix(id); TestUtils.assertEquals("identity operate", testVector, m.operate(testVector), entryTolerance); TestUtils.assertEquals("identity operate", testVector, m.operate(new ArrayRealVector(testVector)).toArray(), entryTolerance); m = new BigSparseRealMatrix(bigSingular); try { m.operate(testVector); Assert.fail("Expecting illegalArgumentException"); } catch (MathIllegalArgumentException ex) { // ignored } }
From source file:monitor.processing.OLD.Drawing3D.java
public void drawTree(MonitorPerception p, PGraphics g) { g.beginDraw();/* ww w . jav a 2 s.c o m*/ g.background(0); g.noStroke(); g.camera(0, 0, eyeZ, atX, atY, atZ, upX, upY, 0); g.translate(posX, posY); synchronized (p) { drawTree(p.getSceneGraph(), new ArrayRealVector(new double[] { 0, 0, 0, 1 }), g); } g.endDraw(); }
From source file:com.joptimizer.optimizers.LPStandardConverterTest.java
/** * Standardization of a problem on the form: * min(c) s.t.//from w w w .j a v a 2 s .co m * 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:GeMSE.GS.Analysis.Stats.OneSamplePCAPanel.java
private void computePrincipalComponents() { RealMatrix realMatrix = MatrixUtils.createRealMatrix(_data); Covariance covariance = new Covariance(realMatrix); _covariance = covariance.getCovarianceMatrix(); EigenDecomposition ed = new EigenDecomposition(_covariance); double[] realEigenvalues = ed.getRealEigenvalues(); int pcaCols = numPCAIndices(realEigenvalues, _level); int eigenCount = realEigenvalues.length; _principalComponents = new Array2DRowRealMatrix(eigenCount, pcaCols); _variance = new ArrayRealVector(pcaCols); for (int i = 0; i < pcaCols; i++) { RealVector eigenVec = ed.getEigenvector(i); for (int j = 0; j < eigenCount; j++) _principalComponents.setEntry(j, i, eigenVec.getEntry(j)); _variance.setEntry(i, realEigenvalues[i]); }//from w w w . ja v a 2 s .c om }
From source file:hits.HitTools.java
private static PointWithPropertiesIfc rotateAndClonePointWithProperties(PointWithPropertiesIfc inputPoint, ResultsFromEvaluateCost result) { RealVector coordsVector = new ArrayRealVector( MathTools.convertToDoubleArray(inputPoint.getCoords().getCoords())); RealVector newPointCoords = PairingTools.alignPointFromShape2toShape1(result, coordsVector); PointWithPropertiesIfc newPoint = new PointWithProperties(); newPoint.setCoords(new Point(MathTools.convertToFloatArray(newPointCoords.toArray()))); newPoint.setStrikingProperties(inputPoint.getStrikingProperties()); return newPoint; }
From source file:gamlss.distributions.TF.java
/** Second cross derivative of likelihood function in * respect to mu and sigma (d2ldmdd = d2l/dmu*dsigma). * @param y - vector of values of response variable * @return a vector of Second cross derivative */// w w w . j a v a2 s.c om private ArrayRealVector d2ldmds(final ArrayRealVector y) { //d2ldmdd = function(y) rep(0,length(y) return new ArrayRealVector(y.getDimension()); }
From source file:lirmm.inria.fr.math.BigSparseRealMatrixTest.java
/** * test preMultiply by vector/*from w w w. j a va 2 s . com*/ */ @Test public void testPremultiplyVector() { RealMatrix m = new BigSparseRealMatrix(testData); TestUtils.assertEquals("premultiply", m.preMultiply(testVector), preMultTest, normTolerance); TestUtils.assertEquals("premultiply", m.preMultiply(new ArrayRealVector(testVector).toArray()), preMultTest, normTolerance); m = new BigSparseRealMatrix(bigSingular); try { m.preMultiply(testVector); Assert.fail("expecting MathIllegalArgumentException"); } catch (MathIllegalArgumentException ex) { // ignored } }
From source file:gamlss.distributions.PE.java
/** Second cross derivative of likelihood function in * respect to mu and sigma (d2ldmdd = d2l/dmu*dsigma). * @param y - vector of values of response variable * @return a vector of Second cross derivative */// w w w. jav a 2s .c o m private ArrayRealVector d2ldmds(final ArrayRealVector y) { // d2ldmdd = function(y) rep(0,length(y)) return new ArrayRealVector(y.getDimension()); }
From source file:gamlss.distributions.PE.java
/** Second cross derivative of likelihood function * in respect to mu and nu (d2ldmdd = d2l/dmu*dnu). * @param y - vector of values of response variable * @return a vector of Second cross derivative *//*w w w .j a v a 2 s . c om*/ private ArrayRealVector d2ldmdn(final ArrayRealVector y) { //d2ldmdv = function(y) rep(0,length(y)), return new ArrayRealVector(y.getDimension()); }
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. *///from w w w . j ava 2 s .c o 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; }