List of usage examples for org.apache.commons.math3.linear ArrayRealVector ArrayRealVector
public ArrayRealVector(ArrayRealVector v) throws NullArgumentException
From source file:com.github.thorbenlindhauer.test.util.LinearAlgebraUtil.java
public static RealVector asVector(double value) { return new ArrayRealVector(new double[] { value }); }
From source file:EndmemberExtraction.java
public static ArrayList<Integer> ORASIS(double[][] data, int nData, int nDim, double threshold, int[] exemplarLabel) { ArrayRealVector vec;//from ww w. ja va 2 s .c o m ArrayList<ArrayRealVector> X = new ArrayList<>(); ArrayList<ArrayRealVector> E = new ArrayList<>(); ArrayList<Integer> exemplarIndex = new ArrayList<>(); for (int i = 0; i < nData; i++) { vec = new ArrayRealVector(data[i]); vec.unitize(); X.add(vec); } E.add(X.get(0)); exemplarIndex.add(0); double t = Math.sqrt(2 * (1 - threshold)); //Add first element of test spectra to set of exemplar spectra exemplarLabel[0] = 0; boolean flag; double maxCos, sigmaMin, sigmaMax, dotXR, dotER, cosTheta; double[] vecR = new double[nDim]; for (int i = 0; i < nDim; i++) { vecR[i] = 1 / Math.sqrt(nDim); } ArrayRealVector R = new ArrayRealVector(vecR); ArrayRealVector exemplarSpec, testSpec; for (int i = 0; i < X.size(); i++) { if (i == 0 || exemplarLabel[i] == -1) { continue; } flag = false; maxCos = 0; testSpec = X.get(i); dotXR = testSpec.dotProduct(R); sigmaMin = dotXR - t; sigmaMax = dotXR + t; for (int j = 0; j < E.size(); j++) { exemplarSpec = E.get(j); dotER = exemplarSpec.dotProduct(R); if (dotER < sigmaMax && dotER > sigmaMin) { cosTheta = testSpec.dotProduct(exemplarSpec); if (cosTheta > threshold) { //Test spectra is similar to one of the exemplar spectra if (cosTheta > maxCos) { maxCos = cosTheta; exemplarLabel[i] = j; //System.out.println("Count: "+i+"\texemplarLabel: "+exemplarLabel[i]); flag = true; } } } } if (!flag) { //Test spectra is unique, add it to set of exemplars E.add(testSpec); exemplarIndex.add(i); exemplarLabel[i] = E.size() - 1; //System.out.println("Count: "+i+"\texemplarLabel: "+exemplarLabel[i]); } } return exemplarIndex; }
From source file:com.cloudera.oryx.common.math.Vectors.java
/** * Constructs a dense {@link RealVector} of the given dimension. * * @param dimension The size of the dense vector to create *//*from w w w. j a v a2 s . com*/ public static RealVector dense(int dimension) { return new ArrayRealVector(dimension); }
From source file:edu.oregonstate.eecs.mcplan.ml.WekaGlue.java
public static RealVector toRealVector(final Instance inst) { final RealVector v = new ArrayRealVector(inst.numAttributes()); for (int i = 0; i < inst.numAttributes(); ++i) { v.setEntry(i, inst.value(i));//from w w w .ja v a 2 s . c o m } return v; }
From source file:com.cloudera.oryx.kmeans.computation.covariance.CovarianceDataBuilder.java
CovarianceDataBuilder(int n) { this.means = new ArrayRealVector(n); this.rawCoMoment = new Array2DRowRealMatrix(n, n); }
From source file:edu.byu.nlp.stats.VectorCategoricalDistributionTest.java
/** * Test method for {@link edu.byu.nlp.stats.VectorCategoricalDistribution#entropy()}. */// w ww. java 2 s .c o m @Test public void testEntropy() { double[] logProbs = new double[] { log(0.7), log(0.0), log(0.3) }; VectorCategoricalDistribution dist = new VectorCategoricalDistribution(new ArrayRealVector(logProbs)); assertThat(dist.entropy()).isEqualTo(-0.7 * log(0.7) - 0.3 * log(0.3), Delta.delta(1e-10)); }
From source file:com.datumbox.opensource.examples.DPMMExample.java
/** * Demo of Dirichlet Process Mixture Model with Multinomial *//* w w w.j av a 2 s. co m*/ public static void MDPMM() { System.out.println("Multinomial DPMM"); //Data points to cluster List<Point> pointList = new ArrayList<>(); //cluster 1 pointList.add(new Point(0, new ArrayRealVector(new double[] { 10.0, 13.0, 5.0, 6.0, 5.0, 4.0, 0.0, 0.0, 0.0, 0.0 }))); pointList.add(new Point(1, new ArrayRealVector(new double[] { 11.0, 11.0, 6.0, 7.0, 7.0, 3.0, 0.0, 0.0, 1.0, 0.0 }))); pointList.add(new Point(2, new ArrayRealVector(new double[] { 12.0, 12.0, 10.0, 16.0, 4.0, 6.0, 0.0, 0.0, 0.0, 2.0 }))); //cluster 2 pointList.add(new Point(3, new ArrayRealVector(new double[] { 10.0, 13.0, 0.0, 0.0, 0.0, 0.0, 5.0, 6.0, 5.0, 4.0 }))); pointList.add(new Point(4, new ArrayRealVector(new double[] { 11.0, 11.0, 0.0, 0.0, 1.0, 0.0, 6.0, 7.0, 7.0, 3.0 }))); pointList.add(new Point(5, new ArrayRealVector(new double[] { 12.0, 12.0, 0.0, 0.0, 0.0, 2.0, 10.0, 16.0, 4.0, 6.0 }))); //cluster 3 pointList.add(new Point(6, new ArrayRealVector(new double[] { 10.0, 13.0, 5.0, 6.0, 5.0, 4.0, 5.0, 6.0, 5.0, 4.0 }))); pointList.add(new Point(7, new ArrayRealVector(new double[] { 11.0, 11.0, 6.0, 7.0, 7.0, 3.0, 6.0, 7.0, 7.0, 3.0 }))); pointList.add(new Point(8, new ArrayRealVector(new double[] { 12.0, 12.0, 10.0, 16.0, 4.0, 6.0, 10.0, 16.0, 4.0, 6.0 }))); //Dirichlet Process parameter Integer dimensionality = 10; double alpha = 1.0; //Hyper parameters of Base Function double alphaWords = 1.0; //Create a DPMM object DPMM dpmm = new MultinomialDPMM(dimensionality, alpha, alphaWords); int maxIterations = 100; int performedIterations = dpmm.cluster(pointList, maxIterations); if (performedIterations < maxIterations) { System.out.println("Converged in " + String.valueOf(performedIterations)); } else { System.out.println("Max iterations of " + String.valueOf(performedIterations) + " reached. Possibly did not converge."); } //get a list with the point ids and their assignments Map<Integer, Integer> zi = dpmm.getPointAssignments(); System.out.println(zi.toString()); }
From source file:game.plugins.valuetemplates.VectorTemplate.java
@Override public RealVector loadValue(List<String> description) { RealVector ret = new ArrayRealVector(dimension); int i = 0;//ww w . ja v a2 s. c o m try { for (String s : description) ret.setEntry(i++, Double.parseDouble(s)); } catch (Exception e) { System.out.println("oh"); } return ret; }
From source file:game.plugins.weka.classifiers.WekaClassifier.java
@Override public Data classify(Data input) { Data ret = new Data(); for (Element e : input) { Instance i = new Instance(1.0, e.get(RealVector.class).toArray()); i.setDataset(dataset);//from w w w .ja va 2 s .c o m try { ret.add(new Element(new ArrayRealVector(internal.distributionForInstance(i)))); } catch (Exception ex) { ex.printStackTrace(); } } return ret; }
From source file:gamlss.algorithm.GlimFitCG.java
public GlimFitCG(boolean copyOriginal, int size) { wls = new WLSMultipleLinearRegression(copyOriginal); adj = new ArrayRealVector(size); }