List of usage examples for org.apache.commons.math3.linear RealVector toString
public String toString()
From source file:edu.stanford.cfuller.colocalization3d.Colocalization3DMain.java
public void go(Initializer in) { //initialize parameters this.parameters = in.initializeParameters(); //load precomputed position data if needed List<ImageObject> imageObjects = this.loadExistingPositionData(); //otherwise, do the fitting: if (imageObjects == null) { imageObjects = new java.util.ArrayList<ImageObject>(); List<ImageAndMaskSet> allFilesToProcess = FileUtils.listFilesToProcess(this.parameters); for (ImageAndMaskSet iams : allFilesToProcess) { List<ImageObject> fittedObjects = this.fitObjectsInSingleImage(iams); for (ImageObject iobj : fittedObjects) { if (this.fitParametersOk(iobj)) { //java.util.logging.Logger.getLogger(LOGGER_NAME).finer("position for object " + iobj.getLabel() + " " + iobj.getPositionForChannel(0).getEntry(0) + " " + iobj.getPositionForChannel(0).getEntry(1) + " " + iobj.getPositionForChannel(0).getEntry(2)); imageObjects.add(iobj); }/*w ww . j a v a2 s .com*/ iobj.nullifyImages(); } } } java.util.logging.Logger.getLogger(LOGGER_NAME).fine(this.failures.toString()); //write the objects and their positions to disk now in case something goes wrong in subsequent steps so that we don't lose them try { FileUtils.writeFittedImageObjectsToDisk(imageObjects, this.parameters); } catch (java.io.IOException e) { java.util.logging.Logger.getLogger(LOGGER_NAME) .severe("Exception encountered while writing image objects to disk: " + e.getMessage()); } //get a correction, either by making one or reading from disk PositionCorrector pc = new PositionCorrector(this.parameters); Correction c = pc.getCorrection(imageObjects); //get or calculate the TRE double tre = 0; if (!(this.parameters.hasKeyAndTrue(DET_TRE_PARAM) && this.parameters.hasKeyAndTrue(DET_CORR_PARAM))) { tre = c.getTre(); } else { tre = pc.determineTRE(imageObjects); c.setTre(tre); } //write the correction to disk try { c.writeToDisk(FileUtils.getCorrectionFilename(this.parameters)); } catch (java.io.IOException e) { java.util.logging.Logger.getLogger(LOGGER_NAME) .severe("Exception encountered while writing correction to disk: " + e.getMessage()); } //apply the correction, removing objects that cannot be corrected RealVector diffs = pc.applyCorrection(c, imageObjects); List<ImageObject> correctedImageObjects = new java.util.ArrayList<ImageObject>(); for (ImageObject iobj : imageObjects) { if (iobj.getCorrectionSuccessful()) { correctedImageObjects.add(iobj); } } imageObjects = correctedImageObjects; //write the objects and their positions to disk again now that they've been corrected and filtered try { FileUtils.writeFittedImageObjectsToDisk(imageObjects, this.parameters); } catch (java.io.IOException e) { java.util.logging.Logger.getLogger(LOGGER_NAME) .severe("Exception encountered while writing image objects to disk: " + e.getMessage()); } //fit the distribution of separations DistributionFitter df = new P3DFitter(this.parameters); RealVector fitparams = df.fit(imageObjects, diffs); java.util.logging.Logger.getLogger(LOGGER_NAME).info("p3d fit parameters: " + fitparams.toString()); //output plots and information if (this.parameters.hasKey(POS_OUTPUT_DIR_PARAM)) { this.outputPositionData(imageObjects, c); } if (this.parameters.hasKey(IN_SITU_ABERR_NAME_PARAM) && this.parameters.hasKey(IN_SITU_ABERR_SECOND_CH_PARAM)) { RealVector slopes = pc.determineInSituAberrationCorrection(); java.util.List<RealVector> vectorDiffs = pc.applyInSituAberrationCorrection(imageObjects, slopes); RealVector scalarDiffs = this.getScalarDifferencesFromVectorDifferences(vectorDiffs); RealVector corrFitParams = df.fit(imageObjects, scalarDiffs); java.util.logging.Logger.getLogger(LOGGER_NAME) .info("p3d fit parameters after in situ correction: " + corrFitParams.toString()); } }
From source file:edu.stanford.cfuller.colocalization3d.correction.PositionCorrector.java
/** * Applies an existing correction to the positions of a set of objects, using a specified reference * and correction channel.//w w w . j a v a2 s.c om * * @param imageObjects A Vector containing all the ImageObjects to be corrected. * @param c The Correction object to be used, which could have been generated with determineCorrection, or loaded from disk. * @return A RealVector with one entry per ImageObject, containing the corrected scalar distance between the object in the reference channel and the channel being corrected. */ public RealVector applyCorrection(Correction c, java.util.List<ImageObject> imageObjects) { int referenceChannel = this.parameters.getIntValueForKey(REF_CH_PARAM); int channelToCorrect = this.parameters.getIntValueForKey(CORR_CH_PARAM); RealVector diffs = new ArrayRealVector(imageObjects.size(), 0.0); RealVector averageVectorDiffs = null; for (int i = 0; i < imageObjects.size(); i++) { diffs.setEntry(i, imageObjects.get(i).getScalarDifferenceBetweenChannels(referenceChannel, channelToCorrect, this.pixelToDistanceConversions)); if (i == 0) { averageVectorDiffs = imageObjects.get(i) .getVectorDifferenceBetweenChannels(referenceChannel, channelToCorrect).copy(); } else { averageVectorDiffs = averageVectorDiffs.add(imageObjects.get(i) .getVectorDifferenceBetweenChannels(referenceChannel, channelToCorrect).map(new Abs())); } } averageVectorDiffs.mapDivideToSelf(imageObjects.size()); averageVectorDiffs = averageVectorDiffs.ebeMultiply(this.pixelToDistanceConversions); java.util.logging.Logger.getLogger("edu.stanford.cfuller.colocalization3d") .info("mean separation uncorrected = " + diffs.getL1Norm() / diffs.getDimension()); java.util.logging.Logger.getLogger("edu.stanford.cfuller.colocalization3d") .info("mean separation components uncorrected = " + averageVectorDiffs.toString()); RealVector newDiffs = new ArrayRealVector(imageObjects.size(), 0.0); if (this.parameters.getBooleanValueForKey("correct_images")) { for (int i = 0; i < imageObjects.size(); i++) { try { newDiffs.setEntry(i, this.correctSingleObjectVectorDifference(c, imageObjects.get(i), referenceChannel, channelToCorrect).getNorm()); imageObjects.get(i).setCorrectionSuccessful(true); } catch (UnableToCorrectException e) { newDiffs.setEntry(i, -1.0 * Double.MAX_VALUE); imageObjects.get(i).setCorrectionSuccessful(false); } } java.util.logging.Logger.getLogger("edu.stanford.cfuller.colocalization3d") .info("mean separation corrected = " + newDiffs.getL1Norm() / newDiffs.getDimension()); } else { newDiffs = diffs; } return newDiffs; }
From source file:se.toxbee.sleepfighter.challenge.math.LinearEquationProblem.java
private void generateProblem() { this.A = createCoefficients(); int attempts = 0; RealVector solution; boolean foundb = false; do {// w ww .j a va 2s. co m Debug.d("try again"); // if after 40 attempts we still can't find a good constants vector, we should give up on this // coefficient matrix and try creating a new one. if (attempts == 40) { Debug.d("new coefficients matrix"); this.A = createCoefficients(); attempts = 0; } // Generate a solution. solution = this.createSolutionVector(); // Now compute Ax = b(where x is the solution) this.b = multiply(this.A, solution); // does b satisfy our requirements? if (isGoodb(b)) { foundb = true; } attempts++; } while (!foundb); Debug.d("solution: " + solution.toString()); // solve for either x1 or x2 this.variableToSolveFor = rng.nextBoolean() ? 0 : 1; this.solution = (int) solution.getEntry(this.variableToSolveFor); }
From source file:universal.Calc.java
private void Lines(int p0init, int p1init, int check) { double[] d = new double[6]; d[0] = paU[p0init].doubleValue();// w ww .java 2s. com d[1] = paV[p0init].doubleValue(); d[2] = paW[p0init].doubleValue(); d[3] = paX[p0init].doubleValue(); d[4] = paY[p0init].doubleValue(); d[5] = paZ[p0init].doubleValue(); RealVector p0 = new ArrayRealVector(d); d[0] = paU[p1init].doubleValue(); d[1] = paV[p1init].doubleValue(); d[2] = paW[p1init].doubleValue(); d[3] = paX[p1init].doubleValue(); d[4] = paY[p1init].doubleValue(); d[5] = paZ[p1init].doubleValue(); RealVector p1 = new ArrayRealVector(d); RealVector v = p0.subtract(p1); System.out.print("\n"); System.out.println(p0.toString()); System.out.println(p1.toString()); System.out.println(v.toString()); d[0] = paU[check].doubleValue(); d[1] = paV[check].doubleValue(); d[2] = paW[check].doubleValue(); d[3] = paX[check].doubleValue(); d[4] = paY[check].doubleValue(); d[5] = paZ[check].doubleValue(); RealVector p3 = new ArrayRealVector(d); RealVector v2 = p0.subtract(p3); Divisible(v, v2); }