Converts a vector from sample space into eigen space.

@param sampleData Sample space data.
@return Eigen space projection.
177847
public double[] sampleToEigenSpace( double[] sampleData ) {
        if( sampleData.length != A.getNumCols() )
            throw new IllegalArgumentException("Unexpected sample length");
        DMatrixRMaj mean = DMatrixRMaj.wrap(A.getNumCols(),1,this.mean);

        DMatrixRMaj s = new DMatrixRMaj(A.getNumCols(),1,true,sampleData);
        DMatrixRMaj r = new DMatrixRMaj(numComponents,1);

        CommonOps_DDRM.subtract(s, mean, s);

        CommonOps_DDRM.mult(V_t,s,r);

        return r.data;
    }
82123
@Override
    public INDArray rand(int[] shape, Distribution r) {
        INDArray ret = r.sample(shape);
        return ret;
    }
1060324
public static List<Example<String, String>> exampleArrayToList(String[][] data) {
    List<Example<String, String>> pairs = Lists.newArrayList();
    for (int i = 0; i < data.length; i++) {
      pairs.add(new Example<String, String>(data[i][0], data[i][1]));
    }
    return pairs;
  }
296299
def _sample_aAt(self,n):
        """"""
        #Sample frequency along largest eigenvalue using ARS
        dO1s=\
            bovy_ars.bovy_ars([0.,0.],[True,False],
                              [self._meandO-numpy.sqrt(self._sortedSigOEig[2]),
                               self._meandO+numpy.sqrt(self._sortedSigOEig[2])],
                              _h_ars,_hp_ars,nsamples=n,
                              hxparams=(self._meandO,self._sortedSigOEig[2]),
                              maxn=100)
        dO1s= numpy.array(dO1s)*self._sigMeanSign
        dO2s= numpy.random.normal(size=n)*numpy.sqrt(self._sortedSigOEig[1])
        dO3s= numpy.random.normal(size=n)*numpy.sqrt(self._sortedSigOEig[0])
        #Rotate into dOs in R,phi,z coordinates
        dO= numpy.vstack((dO3s,dO2s,dO1s))
        dO= numpy.dot(self._sigomatrixEig[1][:,self._sigomatrixEigsortIndx],
                      dO)
        Om= dO+numpy.tile(self._progenitor_Omega.T,(n,1)).T
        #Also generate angles
        da= numpy.random.normal(size=(3,n))*self._sigangle
        #And a random time
        dt= self.sample_t(n)
        #Integrate the orbits relative to the progenitor
        da+= dO*numpy.tile(dt,(3,1))
        angle= da+numpy.tile(self._progenitor_angle.T,(n,1)).T
        return (Om,angle,dt)
294024
@Override
	public Iterator<T> sample(final Iterator<T> input) {
		if (fraction == 0) {
			return emptyIterable;
		}

		return new SampledIterator<T>() {
			T currentElement;
			int currentCount = 0;

			@Override
			public boolean hasNext() {
				if (currentCount > 0) {
					return true;
				} else {
					samplingProcess();
					if (currentCount > 0) {
						return true;
					} else {
						return false;
					}
				}
			}

			@Override
			public T next() {
				if (currentCount <= 0) {
					samplingProcess();
				}
				currentCount--;
				return currentElement;
			}

			public int poisson_ge1(double p) {
				// sample 'k' from Poisson(p), conditioned to k >= 1.
				double q = Math.pow(Math.E, -p);
				// simulate a poisson trial such that k >= 1.
				double t = q + (1 - q) * random.nextDouble();
				int k = 1;
				// continue standard poisson generation trials.
				t = t * random.nextDouble();
				while (t > q) {
					k++;
					t = t * random.nextDouble();
				}
				return k;
			}

			private void skipGapElements(int num) {
				// skip the elements that occurrence number is zero.
				int elementCount = 0;
				while (input.hasNext() && elementCount < num) {
					currentElement = input.next();
					elementCount++;
				}
			}

			private void samplingProcess() {
				if (fraction <= THRESHOLD) {
					double u = Math.max(random.nextDouble(), EPSILON);
					int gap = (int) (Math.log(u) / -fraction);
					skipGapElements(gap);
					if (input.hasNext()) {
						currentElement = input.next();
						currentCount = poisson_ge1(fraction);
					}
				} else {
					while (input.hasNext()) {
						currentElement = input.next();
						currentCount = poissonDistribution.sample();
						if (currentCount > 0) {
							break;
						}
					}
				}
			}
		};
	}
1096549
@Override
	public Iterator<T> sample(final Iterator<T> input) {
		if (fraction == 0) {
			return emptyIterable;
		}

		return new SampledIterator<T>() {
			T current = null;

			@Override
			public boolean hasNext() {
				if (current == null) {
					current = getNextSampledElement();
				}

				return current != null;
			}

			@Override
			public T next() {
				if (current == null) {
					return getNextSampledElement();
				} else {
					T result = current;
					current = null;

					return result;
				}
			}

			private T getNextSampledElement() {
				if (fraction <= THRESHOLD) {
					double rand = random.nextDouble();
					double u = Math.max(rand, EPSILON);
					int gap = (int) (Math.log(u) / Math.log(1 - fraction));
					int elementCount = 0;
					if (input.hasNext()) {
						T element = input.next();
						while (input.hasNext() && elementCount < gap) {
							element = input.next();
							elementCount++;
						}
						if (elementCount < gap) {
							return null;
						} else {
							return element;
						}
					} else {
						return null;
					}
				} else {
					while (input.hasNext()) {
						T element = input.next();

						if (random.nextDouble() <= fraction) {
							return element;
						}
					}
					return null;
				}
			}
		};
	}
250223
public Instance sample(Random random) {
		// Create sample in hypersphere coordinates
		//get the center through getCenter so subclass have a chance
		double[] center = getCenter();

		final int dimensions = center.length;

		final double sin[] = new double[dimensions - 1];
		final double cos[] = new double[dimensions - 1];
		final double length = random.nextDouble() * getRadius();

		double lastValue = 1.0;
		for (int i = 0; i < dimensions-1; i++) {
			double angle = random.nextDouble() * 2 * Math.PI;
			sin[i] = lastValue * Math.sin( angle ); // Store cumulative values
			cos[i] = Math.cos( angle );
			lastValue = sin[i];
		}

		// Calculate cartesian coordinates
		double res[] = new double[dimensions];

		// First value uses only cosines
		res[0] = center[0] + length*cos[0];

		// Loop through 'middle' coordinates which use cosines and sines
		for (int i = 1; i < dimensions-1; i++) {
			res[i] = center[i] + length*sin[i-1]*cos[i];
		}

		// Last value uses only sines
		res[dimensions-1] = center[dimensions-1] + length*sin[dimensions-2];

		return new DenseInstance(1.0, res);
	}
479852
public ExampleSet copy() {
        ExampleSet copy = new VectorSet();
        for (int i = 0; i < size(); i++)
            copy.add(x(i), y(i), id(i));

        return copy;
    }
1280436
public AutoEncoderModelPrediction predictAutoEncoder(RowData data) throws PredictException {
    validateModelCategory(ModelCategory.AutoEncoder);

    int size = m.getPredsSize(ModelCategory.AutoEncoder);
    double[] output = new double[size];
    double[] rawData = nanArray(m.nfeatures());
    rawData = fillRawData(data, rawData);
    output = m.score0(rawData, output);

    AutoEncoderModelPrediction p = new AutoEncoderModelPrediction();
    p.original = expandRawData(rawData, output.length);
    p.reconstructed = output;
    p.reconstructedRowData = reconstructedToRowData(output);
    if (m instanceof DeeplearningMojoModel){
      DeeplearningMojoModel mojoModel = ((DeeplearningMojoModel)m);
      p.mse =  mojoModel.calculateReconstructionErrorPerRowData(p.original, p.reconstructed);
    }
    return p;
  }
49979
public static PlotCanvas screeplot(PCA pca) {
        int n = pca.getVarianceProportion().length;

        double[] lowerBound = {0, 0.0};
        double[] upperBound = {n + 1, 1.0};

        PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound, false);
        canvas.setAxisLabels("Principal Component", "Proportion of Variance");

        String[] labels = new String[n];
        double[] x = new double[n];
        double[][] data = new double[n][2];
        double[][] data2 = new double[n][2];
        for (int i = 0; i < n; i++) {
            labels[i] = "PC" + (i + 1);
            x[i] = i + 1;
            data[i][0] = x[i];
            data[i][1] = pca.getVarianceProportion()[i];
            data2[i][0] = x[i];
            data2[i][1] = pca.getCumulativeVarianceProportion()[i];
        }

        LinePlot plot = new LinePlot(data);
        plot.setID("Variance");
        plot.setColor(Color.RED);
        plot.setLegend('@');
        canvas.add(plot);
        canvas.getAxis(0).addLabel(labels, x);

        LinePlot plot2 = new LinePlot(data2);
        plot2.setID("Cumulative Variance");
        plot2.setColor(Color.BLUE);
        plot2.setLegend('@');
        canvas.add(plot2);

        return canvas;
    }
1210402
public INDArray project(INDArray data, INDArray result){
        long[] tShape = targetShape(data.shape(), eps, components, autoMode);
        return data.mmuli(getProjectionMatrix(tShape, this.rng), result);
    }
512662
@Benchmark
  @BenchmarkMode(Mode.SampleTime)
  @OutputTimeUnit(TimeUnit.NANOSECONDS)
  public Map<String, String> inject(Data data) {
    Map<String, String> carrier = new HashMap<String, String>();
    data.textFormatBase.inject(data.spanContext, carrier);
    return carrier;
  }
690954
@Override
  public double[] projectRelativeDataToScaledSpace(NumberVector data) {
    final int dim = data.getDimensionality();
    double[] vec = new double[dim];
    for(int d = 0; d < dim; d++) {
      vec[d] = scales[d].getRelativeScaled(data.doubleValue(d));
    }
    return vec;
  }
716510
public static String[] replaceDataReferencesInArray(final String[] args, final Map<String, Map<String, String>> data) {
        return replaceDataReferencesInArray(args, data, null, false);
    }
1185820
public static TransposeDataCollection randomSampling(TransposeDataList clusterIdList, int sampleM) {
        TransposeDataCollection sampledIds = new TransposeDataCollection(); 
        
        Object[] selectedClusters = clusterIdList.keySet().toArray();
        PHPMethods.<Object>shuffle(selectedClusters);
        
        for(int i = 0; i<sampleM; ++i) {
            Object cluster = selectedClusters[i];
            sampledIds.put(cluster, clusterIdList.get(cluster).toFlatDataCollection());
        }
        
        
        return sampledIds;
    }
835100
@Nullable
    public static String sampledToString(@Nullable Boolean sampled) {
        return sampled == null ? null : (sampled ? DO_SAMPLE_VALUE : DO_NOT_SAMPLE_VALUE);
    }
829762
public Word2VecPrediction predictWord2Vec(RowData data) throws PredictException {
    validateModelCategory(ModelCategory.WordEmbedding);

    if (! (m instanceof WordEmbeddingModel))
      throw new PredictException("Model is not of the expected type, class = " + m.getClass().getSimpleName());
    final WordEmbeddingModel weModel = (WordEmbeddingModel) m;
    final int vecSize = weModel.getVecSize();

    HashMap<String, float[]> embeddings = new HashMap<>(data.size());
    for (String wordKey : data.keySet()) {
      Object value = data.get(wordKey);
      if (value instanceof String) {
        String word = (String) value;
        embeddings.put(wordKey, weModel.transform0(word, new float[vecSize]));
      }
    }

    Word2VecPrediction p = new Word2VecPrediction();
    p.wordEmbeddings = embeddings;

    return p;

  }