org.ejml.simple.SimpleMatrix Java Examples
The following examples show how to use
org.ejml.simple.SimpleMatrix.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Optimization.java From okde-java with MIT License | 6 votes |
/** * Evaluate a gaussian mixture defined by the given means, covariances and component weights at a given point x. * * @param x The point where the mixture shall be evaluated. * @param means The component means. * @param covs The component covariances. * @param weights The component weights. * @return The probability at point x. */ private static double evaluate(SimpleMatrix x, List<SimpleMatrix> means, List<SimpleMatrix> covs, List<Double> weights){ ArrayList<Double> mahalanobisDistances = mahalanobis(x, means, covs); double n = x.numRows(); double a = Math.pow(Math.sqrt(2 * Math.PI), n); double prob = 0; for (int i = 0; i < means.size(); i++) { // check wether the component actually contributes to to the density at given point if(mahalanobisDistances.get(i) < MAX_MAHALANOBIS_DIST) { SimpleMatrix m = means.get(i); SimpleMatrix c = covs.get(i); double w = weights.get(i); //probability p(x,m) under component m double p = ((1 / (a * Math.sqrt(c.determinant()))) * Math.exp((-0.5d) * mahalanobisDistances.get(i))) * w; prob += p; } } return prob; }
Example #2
Source File: MatrixUtilitiesNGTest.java From constellation with Apache License 2.0 | 6 votes |
/** * Test of getAdjacencyMatrix method, of class MatrixUtilities. */ @Test public void testGetAdjacencyMatrix() { final boolean weighted = false; final double[][] expData = new double[5][5]; expData[0][1] = 1.0; expData[1][0] = 1.0; expData[1][2] = 1.0; expData[1][3] = 1.0; expData[2][1] = 1.0; expData[2][3] = 1.0; expData[3][1] = 1.0; expData[3][2] = 1.0; expData[3][4] = 1.0; expData[4][3] = 1.0; final SimpleMatrix expResult = new SimpleMatrix(expData); final SimpleMatrix result = MatrixUtilities.adjacency(graph, weighted); assertTrue(isEqual(result, expResult, 1E-3)); }
Example #3
Source File: MatrixUtilities.java From constellation with Apache License 2.0 | 6 votes |
public static SimpleMatrix incidence(final GraphReadMethods graph, final boolean weighted) { final int vertexCount = graph.getVertexCount(); final int linkCount = graph.getLinkCount(); final double[][] data = new double[vertexCount][linkCount]; for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) { final int vertexId = graph.getVertex(vertexPosition); final int adjacentLinkCount = graph.getVertexLinkCount(vertexId); for (int adjacentLinkPosition = 0; adjacentLinkPosition < adjacentLinkCount; adjacentLinkPosition++) { final int adjacentLinkId = graph.getVertexLink(vertexId, adjacentLinkPosition); final int adjacentLinkTransactionCount = graph.getLinkTransactionCount(adjacentLinkId); data[graph.getVertexPosition(vertexId)][graph.getLinkPosition(adjacentLinkId)] = weighted ? adjacentLinkTransactionCount : 1.0; } } return new SimpleMatrix(data); }
Example #4
Source File: SampleModel.java From okde-java with MIT License | 6 votes |
@Override public double evaluate(SimpleMatrix pointVector) { ArrayList<SimpleMatrix> means = new ArrayList<SimpleMatrix>(); ArrayList<SimpleMatrix> covs = new ArrayList<SimpleMatrix>(); ArrayList<Double> weights = new ArrayList<Double>(); means = this.getSubMeans(); covs = this.getSubSmoothedCovariances(); weights = this.getSubWeights(); double d = 0d; double n = means.get(0).numRows(); double a = Math.pow(Math.sqrt(2 * Math.PI), n); ArrayList<Double> mahalanobisDistances = mahalanobis(pointVector, means, covs); for (int i = 0; i < means.size(); i++) { // check wether the component actually contributes to to the density at given point if(mahalanobisDistances.get(i) < MAX_MAHALANOBIS_DIST) { SimpleMatrix m = means.get(i); SimpleMatrix c = covs.get(i); double w = weights.get(i); d += ((1 / (a * Math.sqrt(c.determinant()))) * Math.exp((-0.5d) * mahalanobisDistances.get(i))) * w; } } return d; }
Example #5
Source File: MatrixUtilities.java From constellation with Apache License 2.0 | 6 votes |
public static SimpleMatrix adjacency(final GraphReadMethods graph, final boolean weighted) { final int vertexCount = graph.getVertexCount(); final double[][] data = new double[vertexCount][vertexCount]; for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) { final int vertexId = graph.getVertex(vertexPosition); final int neighbourCount = graph.getVertexNeighbourCount(vertexId); for (int neighbourPosition = 0; neighbourPosition < neighbourCount; neighbourPosition++) { final int neighbourId = graph.getVertexNeighbour(vertexId, neighbourPosition); final int vertexNeighbourLinkId = graph.getLink(vertexId, neighbourId); final int vertexNeighbourTransactionCount = graph.getLinkTransactionCount(vertexNeighbourLinkId); data[graph.getVertexPosition(vertexId)][graph.getVertexPosition(neighbourId)] = weighted ? vertexNeighbourTransactionCount : 1.0; } } return new SimpleMatrix(data); }
Example #6
Source File: SentimentAnalyzer.java From blog-codes with Apache License 2.0 | 6 votes |
public SentimentResult getSentimentResult(String text) { SentimentClassification classification = new SentimentClassification(); SentimentResult sentimentResult = new SentimentResult(); if (text != null && text.length() > 0) { Annotation annotation = pipeline.process(text); for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); SimpleMatrix simpleMatrix = RNNCoreAnnotations.getPredictions(tree); classification.setVeryNegative((double) Math.round(simpleMatrix.get(0) * 100d)); classification.setNegative((double) Math.round(simpleMatrix.get(1) * 100d)); classification.setNeutral((double) Math.round(simpleMatrix.get(2) * 100d)); classification.setPositive((double) Math.round(simpleMatrix.get(3) * 100d)); classification.setVeryPositive((double) Math.round(simpleMatrix.get(4) * 100d)); String setimentType = sentence.get(SentimentCoreAnnotations.SentimentClass.class); sentimentResult.setSentimentType(setimentType); sentimentResult.setSentimentClass(classification); sentimentResult.setSentimentScore(RNNCoreAnnotations.getPredictedClass(tree)); } } return sentimentResult; }
Example #7
Source File: SampleModel.java From okde-java with MIT License | 6 votes |
public double evaluate(SimpleMatrix pointVector, ArrayList<SimpleMatrix> means, ArrayList<SimpleMatrix> covs, ArrayList<Double> weights) { double d = 0d; double n = means.get(0).numRows(); double a = Math.pow(Math.sqrt(2 * Math.PI), n); ArrayList<Double> mahalanobisDistances = mahalanobis(pointVector, means, covs); for (int i = 0; i < means.size(); i++) { // check wether the component actually contributes to to the density at given point if(mahalanobisDistances.get(i) < MAX_MAHALANOBIS_DIST) { SimpleMatrix m = means.get(i); SimpleMatrix c = covs.get(i); double w = weights.get(i); d += ((1 / (a * Math.sqrt(c.determinant()))) * Math.exp((-0.5d) * mahalanobisDistances.get(i))) * w; } } return d; }
Example #8
Source File: TextRankSummarization.java From cocolian-nlp with Apache License 2.0 | 6 votes |
/** * 建立相似度矩阵 * * @param sentences * @return */ protected SimpleMatrix buildSimilarityMatrix(List<Sentence> sentences) { for (Sentence sentence : sentences) { List<Term> terms = this.tokenizer.tokenize(sentence.toString()); ((SentenceWrapper) sentence).setTerms(terms); } SimpleMatrix matrix = new SimpleMatrix(sentences.size(), sentences.size()); matrix.set(0); for (int i = 0; i < sentences.size(); i++) for (int j = i + 1; j < sentences.size(); j++) { // 相似度+1,消除0值; double similarity = this.similarity(sentences.get(i), sentences.get(j)) + 1; matrix.set(i, j, similarity); matrix.set(j, i, similarity); } return matrix; }
Example #9
Source File: SentimentAnalyzer.java From hazelcast-jet-demos with Apache License 2.0 | 6 votes |
private double getScore(List<CoreMap> sentences, double overallSentiment) { int matrixIndex = overallSentiment < -0.5 ? 0 // very negative : overallSentiment < 0.0 ? 1 // negative : overallSentiment < 0.5 ? 3 // positive : 4; // very positive double sum = 0; int numberOfSentences = 0; for (CoreMap sentence : sentences) { Tree sentiments = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class); int predictedClass = RNNCoreAnnotations.getPredictedClass(sentiments); if (predictedClass == 2) { // neutral continue; } SimpleMatrix matrix = RNNCoreAnnotations.getPredictions(sentiments); sum += matrix.get(matrixIndex); numberOfSentences++; } return sum / numberOfSentences; }
Example #10
Source File: LSPI.java From burlap with Apache License 2.0 | 6 votes |
/** * Runs LSPI for either numIterations or until the change in the weight matrix is no greater than maxChange. * @param numIterations the maximum number of policy iterations. * @param maxChange when the weight change is smaller than this value, LSPI terminates. * @return a {@link burlap.behavior.policy.GreedyQPolicy} using this object as the {@link QProvider} source. */ public GreedyQPolicy runPolicyIteration(int numIterations, double maxChange){ boolean converged = false; for(int i = 0; i < numIterations && !converged; i++){ SimpleMatrix nw = this.LSTDQ(); double change = Double.POSITIVE_INFINITY; if(this.lastWeights != null){ change = this.lastWeights.minus(nw).normF(); if(change <= maxChange){ converged = true; } } this.lastWeights = nw; DPrint.cl(0, "Finished iteration: " + i + ". Weight change: " + change); } DPrint.cl(0, "Finished Policy Iteration."); return new GreedyQPolicy(this); }
Example #11
Source File: Hellinger.java From okde-java with MIT License | 6 votes |
private static ThreeComponentDistribution mergeSampleDists(OneComponentDistribution dist1, TwoComponentDistribution dist2, double w1, double w2) throws TooManyComponentsException { SimpleMatrix[] means = new SimpleMatrix[3]; means[0] = dist1.getGlobalMean(); for (int i = 1; i < dist2.getSubMeans().length + 1; i++) { means[i] = dist2.getSubMeans()[i - 1]; } SimpleMatrix[] covs = new SimpleMatrix[3]; covs[0] = dist1.getGlobalCovariance(); for (int i = 1; i < dist2.getSubCovariances().length + 1; i++) { covs[i] = dist2.getSubCovariances()[i - 1]; } double[] weights = new double[3]; weights[0] = w1; for (int i = 1; i < dist2.getSubWeights().length + 1; i++) { weights[i] = dist2.getSubWeights()[i - 1] * w2; } ThreeComponentDistribution dist = null; dist = new ThreeComponentDistribution(weights, means, covs, dist1.getBandwidthMatrix()); return dist; }
Example #12
Source File: Hellinger.java From okde-java with MIT License | 6 votes |
/** * Returns 2n+k sigma points starting with mean as the first point * * @param mean * @param cov * @param no * @param k * @return */ private static List<SimpleMatrix> getSigmaPoints(SimpleMatrix mean, SimpleMatrix cov, int no, int k) { List<SimpleMatrix> resultVectors = new ArrayList<SimpleMatrix>(); int n = cov.numRows(); SimpleSVD<?> svd = cov.svd(true); SimpleMatrix U = svd.getU(); SimpleMatrix S = svd.getW(); S = U.mult(MatrixOps.elemSqrt(S)).scale(Math.sqrt(n + k)); for (int i = 0; i < S.numCols(); i++) { SimpleMatrix columnVector = S.extractVector(false, i); SimpleMatrix negColumnVector = S.extractVector(false, i).scale(-1); resultVectors.add(columnVector.plus(mean)); resultVectors.add(negColumnVector.plus(mean)); } if (k != 0) resultVectors.add(mean); return resultVectors; }
Example #13
Source File: MultipleComponentDistribution.java From okde-java with MIT License | 6 votes |
@Override public double evaluate(SimpleMatrix pointVector) { SimpleMatrix[] means = this.getSubMeans(); SimpleMatrix[] covs = this.getSubCovariances(); Double[] weights = this.getSubWeights(); double d = 0d; double n = means[0].numRows(); double a = Math.pow(Math.sqrt(2 * Math.PI), n); for (int i = 0; i < means.length; i++) { SimpleMatrix m = means[i]; SimpleMatrix c = covs[i].plus(this.mBandwidthMatrix); double w = weights[i]; double tmp = (-0.5d) * pointVector.minus(m).transpose().mult(c.invert()).mult(pointVector.minus(m)).trace(); d += ((1 / (a * Math.sqrt(c.determinant()))) * Math.exp(tmp)) * w; } return d; }
Example #14
Source File: MatrixOps.java From okde-java with MIT License | 5 votes |
public static SimpleMatrix ones(int rows, int cols) { SimpleMatrix matrix = new SimpleMatrix(rows, cols); for (int i = 0; i < rows; i++) { for (int j = 0; j < rows; j++) { matrix.set(i, j, 1); } } return matrix; }
Example #15
Source File: MultipleComponentDistribution.java From okde-java with MIT License | 5 votes |
/** * Evaluates the distribution at the given n-dimensional points and returns * the results in a List of double-values. * * @param points * @return array of double values */ @Override public ArrayList<Double> evaluate(ArrayList<SimpleMatrix> points) { ArrayList<Double> resultPoints = new ArrayList<Double>(); for (SimpleMatrix point : points) { resultPoints.add(evaluate(point)); } return resultPoints; }
Example #16
Source File: HashableSimpleMatrix.java From okde-java with MIT License | 5 votes |
@Override public boolean equals(Object obj) { SimpleMatrix m = (SimpleMatrix) obj; if(m.isIdentical(this, 1E-30)) return true; else return false; }
Example #17
Source File: SampleModel.java From okde-java with MIT License | 5 votes |
@Override public void setBandwidthMatrix(SimpleMatrix mBandwidthMatrix) { this.mBandwidthMatrix = mBandwidthMatrix; for (BaseSampleDistribution d : mSubDistributions) { d.setBandwidthMatrix(mBandwidthMatrix); } }
Example #18
Source File: Optimization.java From okde-java with MIT License | 5 votes |
/** * Calculcates Mahalanobis distance between given point x and all given components defined by their means and covariances. * * @param x The reference point. * @param means The component means. * @param covs The component covariances. * @return A list with Mahalanobis distances between x and the given components. */ private static ArrayList<Double> mahalanobis(SimpleMatrix x, List<SimpleMatrix> means, List<SimpleMatrix> covs) { ArrayList<Double> mahalanobisDistances = new java.util.ArrayList<Double>(); for (int i = 0; i < means.size(); i++) { SimpleMatrix m = means.get(i); SimpleMatrix c = covs.get(i); // calculate Mahalanobis distance double distance = x.minus(m).transpose().mult(c.invert()).mult(x.minus(m)).trace(); mahalanobisDistances.add(distance); } return mahalanobisDistances; }
Example #19
Source File: TextRankSummarization.java From cocolian-nlp with Apache License 2.0 | 5 votes |
/** * 将matrix归一化处理。 * * @param matrix */ protected void normalize(SimpleMatrix matrix) { SimpleMatrix one = new SimpleMatrix(matrix.numCols(), matrix.numRows()); one.set(1); SimpleMatrix sum = matrix.mult(one); //CommonOps.elementDiv(matrix.getMatrix(), sum.getMatrix()); matrix.set(matrix.elementDiv(sum)); //CommonOps.transpose(matrix.getMatrix()); matrix.set(matrix.transpose()); }
Example #20
Source File: CoreNLPSentimentAnnotator.java From Heracles with GNU General Public License v3.0 | 5 votes |
private static void assignSentiment(DataEntity a, SimpleMatrix sm, String sentimentLabel){ ArrayList<Double> sentimentScores = new ArrayList<>(); for (int i = 0; i < 5; i++){ sentimentScores.add(sm.get(i, 0)); } a.putAnnotation(sentimentLabel, sentimentScores); }
Example #21
Source File: FactorGraphTrueSkillCalculator.java From ACManager with GNU General Public License v3.0 | 5 votes |
@Override public double calculateMatchQuality(GameInfo gameInfo, Collection<ITeam> teams) { // We need to create the A matrix which is the player team assignments. List<ITeam> teamAssignmentsList = new ArrayList<>(teams); SimpleMatrix skillsMatrix = GetPlayerCovarianceMatrix(teamAssignmentsList); SimpleMatrix meanVector = GetPlayerMeansVector(teamAssignmentsList); SimpleMatrix meanVectorTranspose = meanVector.transpose(); SimpleMatrix playerTeamAssignmentsMatrix = CreatePlayerTeamAssignmentMatrix(teamAssignmentsList, meanVector.numRows()); SimpleMatrix playerTeamAssignmentsMatrixTranspose = playerTeamAssignmentsMatrix.transpose(); double betaSquared = square(gameInfo.getBeta()); SimpleMatrix start = meanVectorTranspose.mult(playerTeamAssignmentsMatrix); SimpleMatrix aTa = playerTeamAssignmentsMatrixTranspose.mult(playerTeamAssignmentsMatrix).scale(betaSquared); SimpleMatrix aTSA = playerTeamAssignmentsMatrixTranspose.mult(skillsMatrix).mult(playerTeamAssignmentsMatrix); SimpleMatrix middle = aTa.plus(aTSA); SimpleMatrix middleInverse = middle.invert(); SimpleMatrix end = playerTeamAssignmentsMatrixTranspose.mult(meanVector); SimpleMatrix expPartMatrix = start.mult(middleInverse).mult(end).scale(-0.5); double expPart = expPartMatrix.determinant(); double sqrtPartNumerator = aTa.determinant(); double sqrtPartDenominator = middle.determinant(); double sqrtPart = sqrtPartNumerator / sqrtPartDenominator; return Math.exp(expPart) * Math.sqrt(sqrtPart); }
Example #22
Source File: FactorGraphTrueSkillCalculator.java From ACManager with GNU General Public License v3.0 | 5 votes |
/** * This is a square matrix whose diagonal values represent the variance (square of standard deviation) of all players. */ private static SimpleMatrix GetPlayerCovarianceMatrix(Collection<ITeam> teamAssignmentsList) { List<Double> temp = GetPlayerVarianceRatingValues(teamAssignmentsList); double[] tempa = new double[temp.size()]; for (int i = 0; i < tempa.length; i++) tempa[i] = temp.get(i); return SimpleMatrix.diag(tempa).transpose(); }
Example #23
Source File: FactorGraphTrueSkillCalculator.java From ACManager with GNU General Public License v3.0 | 5 votes |
/** * The team assignment matrix is often referred to as the "A" matrix. * It's a matrix whose rows represent the players and the columns * represent teams. At Matrix[row, column] represents that player[row] * is on team[col] Positive values represent an assignment and a * negative value means that we subtract the value of the next team * since we're dealing with pairs. This means that this matrix always * has teams - 1 columns. The only other tricky thing is that values * represent the play percentage. * <p> * For example, consider a 3 team game where team1 is just player1, team * 2 is player 2 and player 3, and team3 is just player 4. Furthermore, * player 2 and player 3 on team 2 played 25% and 75% of the time (e.g. * partial play), the A matrix would be: * <p><pre> * A = this 4x2 matrix: * | 1.00 0.00 | * | -0.25 0.25 | * | -0.75 0.75 | * | 0.00 -1.00 | * </pre> */ private static SimpleMatrix CreatePlayerTeamAssignmentMatrix(List<ITeam> teamAssignmentsList, int totalPlayers) { List<List<Double>> playerAssignments = new ArrayList<List<Double>>(); int totalPreviousPlayers = 0; for (int i = 0; i < teamAssignmentsList.size() - 1; i++) { ITeam currentTeam = teamAssignmentsList.get(i); // Need to add in 0's for all the previous players, since they're not // on this team List<Double> currentRowValues = new ArrayList<Double>(); for(int j = 0; j < totalPreviousPlayers; j++) currentRowValues.add(0.); playerAssignments.add(currentRowValues); for(IPlayer player: currentTeam.keySet()) { currentRowValues.add(PartialPlay.getPartialPlayPercentage(player)); // indicates the player is on the team totalPreviousPlayers++; } ITeam nextTeam = teamAssignmentsList.get(i + 1); for(IPlayer nextTeamPlayer : nextTeam.keySet()) { // Add a -1 * playing time to represent the difference currentRowValues.add(-1 * PartialPlay.getPartialPlayPercentage(nextTeamPlayer)); } } SimpleMatrix playerTeamAssignmentsMatrix = new SimpleMatrix(totalPlayers, teamAssignmentsList.size() - 1); for(int i=0; i < playerAssignments.size(); i++) for(int j=0; j < playerAssignments.get(i).size(); j++) playerTeamAssignmentsMatrix.set(j, i, playerAssignments.get(i).get(j)); return playerTeamAssignmentsMatrix; }
Example #24
Source File: SampleModel.java From okde-java with MIT License | 5 votes |
private void checkInputParams(SimpleMatrix[] means, SimpleMatrix[] covariances, double[] weights) throws EmptyDistributionException { if (weights == null || weights.length == 0) throw new EmptyDistributionException(); if (means == null || means.length == 0) throw new EmptyDistributionException(); if (covariances == null || covariances.length == 0) throw new EmptyDistributionException(); }
Example #25
Source File: MultipleComponentDistribution.java From okde-java with MIT License | 5 votes |
public MultipleComponentDistribution(double[] weights, SimpleMatrix[] means, SimpleMatrix[] covariances, SimpleMatrix bandwidth) { if(bandwidth == null) bandwidth = covariances[0].scale(0); mBandwidthMatrix = bandwidth; // add components to distribution mSubDistributions = new OneComponentDistribution[weights.length]; for(int i=0; i<mSubDistributions.length; i++){ mSubDistributions[i] = new OneComponentDistribution(weights[i], means[i], covariances[i], bandwidth); } mGlobalWeight = 0; for (double w : weights) { mGlobalWeight += w; } mForgettingFactor = 1; }
Example #26
Source File: SimpleMatrixUnitTest.java From tutorials with MIT License | 5 votes |
@Test void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { SimpleMatrix firstMatrix = new SimpleMatrix( new double[][] { new double[] {1d, 5d}, new double[] {2d, 3d}, new double[] {1d ,7d} } ); SimpleMatrix secondMatrix = new SimpleMatrix( new double[][] { new double[] {1d, 2d, 3d, 7d}, new double[] {5d, 2d, 8d, 1d} } ); SimpleMatrix expected = new SimpleMatrix( new double[][] { new double[] {26d, 12d, 43d, 12d}, new double[] {17d, 10d, 30d, 17d}, new double[] {36d, 16d, 59d, 14d} } ); SimpleMatrix actual = firstMatrix.mult(secondMatrix); assertThat(actual).matches(m -> m.isIdentical(expected, 0d)); }
Example #27
Source File: MatrixMultiplicationBenchmarking.java From tutorials with MIT License | 5 votes |
@Benchmark public Object ejmlMatrixMultiplication(MatrixProvider matrixProvider) { SimpleMatrix firstMatrix = new SimpleMatrix(matrixProvider.getFirstMatrix()); SimpleMatrix secondMatrix = new SimpleMatrix(matrixProvider.getSecondMatrix()); return firstMatrix.mult(secondMatrix); }
Example #28
Source File: BigMatrixMultiplicationBenchmarking.java From tutorials with MIT License | 5 votes |
@Benchmark public Object ejmlMatrixMultiplication(BigMatrixProvider matrixProvider) { SimpleMatrix firstMatrix = new SimpleMatrix(matrixProvider.getFirstMatrix()); SimpleMatrix secondMatrix = new SimpleMatrix(matrixProvider.getSecondMatrix()); return firstMatrix.mult(secondMatrix); }
Example #29
Source File: BetaBinomAltLikelihood.java From systemsgenetics with GNU General Public License v3.0 | 5 votes |
@Override public double[] value(SimpleMatrix xx) { int n = xx.numRows(); double [] retval = new double[n]; for (int i = 0; i < n; i++){ retval[i] = value(xx.extractVector(true, i).getMatrix().getData()); } return retval; }
Example #30
Source File: EphemerisSystemGps.java From GNSS_Compare with Apache License 2.0 | 5 votes |
/** * @param traveltime */ protected SimpleMatrix computeEarthRotationCorrection(long unixTime, double receiverClockError, double transmissionTime) { // Computation of signal travel time // SimpleMatrix diff = satellitePosition.minusXYZ(approxPos);//this.coord.minusXYZ(approxPos); // double rho2 = Math.pow(diff.get(0), 2) + Math.pow(diff.get(1), 2) // + Math.pow(diff.get(2), 2); // double traveltime = Math.sqrt(rho2) / Constants.SPEED_OF_LIGHT; double receptionTime = (new Time(unixTime)).getGpsTime(); double traveltime = receptionTime + receiverClockError - transmissionTime; // Compute rotation angle double omegatau = Constants.EARTH_ANGULAR_VELOCITY * traveltime; // Rotation matrix double[][] data = new double[3][3]; data[0][0] = Math.cos(omegatau); data[0][1] = Math.sin(omegatau); data[0][2] = 0; data[1][0] = -Math.sin(omegatau); data[1][1] = Math.cos(omegatau); data[1][2] = 0; data[2][0] = 0; data[2][1] = 0; data[2][2] = 1; SimpleMatrix R = new SimpleMatrix(data); return R; // Apply rotation //this.coord.ecef = R.mult(this.coord.ecef); //this.coord.setSMMultXYZ(R);// = R.mult(this.coord.ecef); //satellitePosition.setSMMultXYZ(R);// = R.mult(this.coord.ecef); }