/** * Converts a vector from eigen space into sample space. * * @param eigenData Eigen space data. * @return Sample space projection. */ public double[] eigenToSampleSpace(double[] eigenData) { if (eigenData.length != numComponents) throw new IllegalArgumentException("Unexpected sample length"); DenseMatrix64F s = new DenseMatrix64F(sampleSize, 1); DenseMatrix64F r = DenseMatrix64F.wrap(numComponents, 1, eigenData); CommonOps.multTransA(V_t, r, s); DenseMatrix64F mean = DenseMatrix64F.wrap(sampleSize, 1, this.mean); CommonOps.add(s, mean, s); return s.data; }
/** * Computes the dot product of each basis vector against the sample. Can be used as a measure * for membership in the training sample set. High values correspond to a better fit. * * @param sample Sample of original data. * @return Higher value indicates it is more likely to be a member of input dataset. */ public double response( double[] sample ) { if( sample.length != A.numCols ) throw new IllegalArgumentException("Expected input vector to be in sample space"); DenseMatrix64F dots = new DenseMatrix64F(numComponents,1); DenseMatrix64F s = DenseMatrix64F.wrap(A.numCols,1,sample); CommonOps.mult(V_t,s,dots); return NormOps.normF(dots); }
/** * Converts a vector from eigen space into sample space. * * @param eigenData Eigen space data. * @return Sample space projection. */ public double[] eigenToSampleSpace( double[] eigenData ) { if( eigenData.length != numComponents ) throw new IllegalArgumentException("Unexpected sample length"); DenseMatrix64F s = new DenseMatrix64F(A.getNumCols(),1); DenseMatrix64F r = DenseMatrix64F.wrap(numComponents,1,eigenData); CommonOps.multTransA(V_t,r,s); DenseMatrix64F mean = DenseMatrix64F.wrap(A.getNumCols(),1,this.mean); CommonOps.add(s,mean,s); return s.data; }
/** * Computes the dot product of each basis vector against the sample. Can be used as a measure * for membership in the training sample set. High values correspond to a better fit. * * @param sample Sample of original data. * @return Higher value indicates it is more likely to be a member of input dataset. */ public double response(double[] sample) { if (sample.length != sampleSize) throw new IllegalArgumentException("Expected input vector to be in sample space"); DenseMatrix64F dots = new DenseMatrix64F(numComponents, 1); DenseMatrix64F s = DenseMatrix64F.wrap(sampleSize, 1, sample); CommonOps.mult(V_t, s, dots); return NormOps.normF(dots); } }
/** * Randomly rotates a vector using the random rotation matrix that was created in the constructor. * * @param vector * The initial vector * @return The randomly rotated vector */ public double[] rotate(double[] vector) { DenseMatrix64F transformed = new DenseMatrix64F(1, vector.length); DenseMatrix64F original = DenseMatrix64F.wrap(1, vector.length, vector); CommonOps.mult(original, randomMatrix, transformed); return transformed.getData(); } }
/** * Converts a vector from sample space into eigen space. * * @param sampleData Sample space data. * @return Eigen space projection. */ public double[] sampleToEigenSpace(double[] sampleData) { if (sampleData.length != sampleSize) throw new IllegalArgumentException("Unexpected sample length"); DenseMatrix64F mean = DenseMatrix64F.wrap(sampleSize, 1, this.mean); DenseMatrix64F s = new DenseMatrix64F(sampleSize, 1, true, sampleData); DenseMatrix64F r = new DenseMatrix64F(numComponents, 1); CommonOps.sub(s, mean, s); CommonOps.mult(V_t, s, r); return r.data; }
/** * Converts a vector from sample space into eigen space. * * @param sampleData Sample space data. * @return Eigen space projection. */ public double[] sampleToEigenSpace( double[] sampleData ) { if( sampleData.length != A.getNumCols() ) throw new IllegalArgumentException("Unexpected sample length"); DenseMatrix64F mean = DenseMatrix64F.wrap(A.getNumCols(),1,this.mean); DenseMatrix64F s = new DenseMatrix64F(A.getNumCols(),1,true,sampleData); DenseMatrix64F r = new DenseMatrix64F(numComponents,1); CommonOps.subtract(s, mean, s); CommonOps.mult(V_t,s,r); return r.data; }
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout = 30000) public void testRemoveNullspaceComponentProblematicCase() { double[] array = new double[] { -0.025615105184150402, 0.9996675004299076, 0.0, 0.0, 0.0, 1.0, -0.014943128023036597, 0.0025766266962912077, 0.994994904861614, 0.994994904861614, 0.994994904861614, 0.0, 0.999560187938321, 0.02565637501847126, -0.09992566887155414, -0.09992566887155414, -0.09992566887155414, 0.0, 0.09097146270512581, -1.7263398865150674E-4, -0.8020248363106273, -0.42534773269796133, -0.06666465862572812, 0.0, -0.14355859699862836, 0.8437205015326914, 0.017305680726114284, 0.019518441231078962, -0.0026979930595319615, 0.06700000000000006, 1.8511050602308394E-4, -0.07800697405973986, 0.17231872793145048, 0.19435195976249223, -0.026864862431263573, 0.0 }; DenseMatrix64F matrix = DenseMatrix64F.wrap(6, 6, array); int matrixSize = matrix.getNumCols(); boolean makeLargestComponentPositive = true; SVDNullspaceCalculator nullspaceCalculator = new SVDNullspaceCalculator(matrixSize, makeLargestComponentPositive); nullspaceCalculator.setMatrix(matrix, 1); DenseMatrix64F nullspace = nullspaceCalculator.getNullspace(); double[] otherArray = new double[] {0.00246580738404988,0.10002072505447161,0.9945001472400798,0.0031310670129175676,-0.03272836951791036,0.013266977355589604,-0.0799682878842701,0.017947029012374344,0.1785478182378059,2.451030346550186E-4,1.2580020435047565,-0.125654221458273,-0.0023320638677076684,-0.22293285167952487,0.11210325702085407,-1.2227732419985802,0.0314067395046658,0.34283533772447394,5.308713273090554E-4,0.30992163367400194,0.009505290863762235,-0.05548471542070279,-5.301903531607067E-4,0.013997484370442227,0.002119726640328553,0.9169404167718533,-0.10706886430962542,1.273221672566972,-0.035158584156337144,-0.36049933068373563,1.0770237098714068,-0.015298793070857523,-0.15257197980669274,0.0015768159883589102,-1.2541201073200425,0.1318372721623865}; DenseMatrix64F otherMatrix = DenseMatrix64F.wrap(6, 6, otherArray); nullspaceCalculator.removeNullspaceComponent(otherMatrix); assertTrue(isNullspaceComponentZero(otherMatrix, nullspace)); }
this.numComponents = numComponents; DenseMatrix64F A = DenseMatrix64F.wrap(sampleCount, sampleSize, samples);
case "linear": logger.info("Using sqrt(coherence) as weights"); Qy_1 = DenseMatrix64F.wrap(numObservations, 1, coherence.toArray()); case "quadratic": logger.info("Using coherence as weights."); Qy_1 = DenseMatrix64F.wrap(numObservations, 1, coherence.toArray()); CommonOps.elementMult(Qy_1, Qy_1); final DenseMatrix64F yL_matrix = DenseMatrix64F.wrap(numObservations, 1, yOffset.toArray()); final DenseMatrix64F yP_matrix = DenseMatrix64F.wrap(numObservations, 1, xOffset.toArray());