Converts a vector from sample space into eigen space. If {@link #doWhitening} is true, then the vector
is also L2 normalized after projection.

@param sampleData
Sample space vector
@return Eigen space projected vector
@throws Exception
764484
public double[] sampleToEigenSpace(double[] sampleData) throws Exception {
		if (!isPcaInitialized) {
			// initiallize PCA correctly!
			throw new Exception("PCA is not correctly initiallized!");
		}
		if (sampleData.length != sampleSize) {
			throw new IllegalArgumentException("Unexpected vector length!");
		}
		DenseMatrix64F sample = new DenseMatrix64F(sampleSize, 1, true, sampleData);
		DenseMatrix64F projectedSample = new DenseMatrix64F(numComponents, 1);
		// mean subtraction
		CommonOps.sub(sample, means, sample);
		// projection
		CommonOps.mult(V_t, sample, projectedSample);
		// whitening
		if (doWhitening) { // always perform this normalization step when whitening is used
			return Normalization.normalizeL2(projectedSample.data);
		} else {
			return projectedSample.data;
		}
	}
265959
@Override
   public Dataset convert(Object s) {
      if (s instanceof Dataset) {
         return (Dataset) s;
      } else {
         throw new VectorPrintRuntimeException(String.format(
             "override this method to convert %s (value: %s) to a Dataset",
             (s != null) ? s.getClass().getName() : null, String.valueOf(s)
         ));
      }
   }
895442
public static function fromDataset(array $data, int $i, int $k, bool $sample = true, float $meanX = null, float $meanY = null)
    {
        if (empty($data)) {
            throw InvalidArgumentException::arrayCantBeEmpty();
        }

        $n = count($data);
        if ($sample && $n === 1) {
            throw InvalidArgumentException::arraySizeToSmall(2);
        }

        if ($i < 0 || $k < 0 || $i >= $n || $k >= $n) {
            throw new \Exception("Given indices i and k do not match with the dimensionality of data");
        }

        if ($meanX === null || $meanY === null) {
            $x = array_column($data, $i);
            $y = array_column($data, $k);

            $meanX = Mean::arithmetic($x);
            $meanY = Mean::arithmetic($y);
            $sum = 0.0;
            foreach ($x as $index => $xi) {
                $yi = $y[$index];
                $sum += ($xi - $meanX) * ($yi - $meanY);
            }
        } else {
            // In the case, whole dataset given along with dimension indices, i and k,
            // we would like to avoid getting column data with array_column and operate
            // over this extra copy of column data for memory efficiency purposes.
            //
            // Instead we traverse through the whole data and get what we actually need
            // without copying the data. This way, memory use will be reduced
            // with a slight cost of CPU utilization.
            $sum = 0.0;
            foreach ($data as $row) {
                $val = [];
                foreach ($row as $index => $col) {
                    if ($index == $i) {
                        $val[0] = $col - $meanX;
                    }
                    if ($index == $k) {
                        $val[1] = $col - $meanY;
                    }
                }
                $sum += $val[0] * $val[1];
            }
        }

        if ($sample) {
            --$n;
        }

        return $sum / $n;
    }
883841
@Override
  public <NV extends NumberVector> NV projectRenderToDataSpace(double[] v, NumberVector.Factory<NV> prototype) {
    final int dim = v.length;
    double[] vec = projectRenderToScaled(v);
    // Not calling {@link #projectScaledToDataSpace} to avoid extra copy of
    // vector.
    for(int d = 0; d < dim; d++) {
      vec[d] = scales[d].getUnscaled(vec[d]);
    }
    return prototype.newNumberVector(vec);
  }
140454
public static List<List<Writable>> sample(int count, JavaRDD<List<Writable>> data) {
        return data.takeSample(false, count);
    }
1293903
@Override
  public final List<Node<String>> getSampleDataRow(
    final Map<String, Object> pReqVars) throws Exception {
    String lang = (String) pReqVars.get("lang");
    List<Node<String>> result = new ArrayList<Node<String>>();
    Integer idx = 1;
    Node<String> nodeGoods = new Node<String>();
    result.add(nodeGoods);
    nodeGoods.setItsName(getSrvI18n().getMsg("goods", lang));
    nodeGoods.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeGoodsName = new Node<String>();
    nodeGoods.getItsNodes().add(nodeGoodsName);
    nodeGoodsName.setItsName(getSrvI18n().getMsg("itsName", lang));
    nodeGoodsName.setItsValue(idx.toString() + ";itsName");
    Node<String> nodeGoodsId = new Node<String>();
    nodeGoods.getItsNodes().add(nodeGoodsId);
    nodeGoodsId.setItsName(getSrvI18n().getMsg("itsId", lang));
    nodeGoodsId.setItsValue(idx.toString() + ";itsId");
    Node<String> nodeGoodsItsCategory = new Node<String>();
    nodeGoods.getItsNodes().add(nodeGoodsItsCategory);
    nodeGoodsItsCategory.setItsName(getSrvI18n().getMsg("itsCategory", lang));
    nodeGoodsItsCategory.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeGoodsItsCategoryName = new Node<String>();
    nodeGoodsItsCategory.getItsNodes().add(nodeGoodsItsCategoryName);
    nodeGoodsItsCategoryName.setItsName(getSrvI18n().getMsg("itsName", lang));
    nodeGoodsItsCategoryName
      .setItsValue(idx.toString() + ";itsCategory,itsName");
    Node<String> nodeGoodsItsCategoryId = new Node<String>();
    nodeGoodsItsCategory.getItsNodes().add(nodeGoodsItsCategoryId);
    nodeGoodsItsCategoryId.setItsName(getSrvI18n().getMsg("itsId", lang));
    nodeGoodsItsCategoryId.setItsValue(idx.toString() + ";itsCategory,itsId");
    Node<String> nodeGoodsDefUnitOfMeasure = new Node<String>();
    nodeGoods.getItsNodes().add(nodeGoodsDefUnitOfMeasure);
    nodeGoodsDefUnitOfMeasure.setItsName(getSrvI18n()
      .getMsg("defUnitOfMeasure", lang));
    nodeGoodsDefUnitOfMeasure.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeGoodsDefUnitOfMeasureName = new Node<String>();
    nodeGoodsDefUnitOfMeasure.getItsNodes().add(nodeGoodsDefUnitOfMeasureName);
    nodeGoodsDefUnitOfMeasureName
      .setItsName(getSrvI18n().getMsg("itsName", lang));
    nodeGoodsDefUnitOfMeasureName
      .setItsValue(idx.toString() + ";defUnitOfMeasure,itsName");
    Node<String> nodeGoodsDefUnitOfMeasureId = new Node<String>();
    nodeGoodsDefUnitOfMeasure.getItsNodes().add(nodeGoodsDefUnitOfMeasureId);
    nodeGoodsDefUnitOfMeasureId.setItsName(getSrvI18n().getMsg("itsId", lang));
    nodeGoodsDefUnitOfMeasureId
      .setItsValue(idx.toString() + ";defUnitOfMeasure,itsId");
    idx++;
    Node<String> nodePrice = new Node<String>();
    result.add(nodePrice);
    nodePrice.setItsName(getSrvI18n().getMsg("itsPrice", lang));
    nodePrice.setItsValue(idx.toString());
    idx++;
    Node<String> nodeCost = new Node<String>();
    result.add(nodeCost);
    nodeCost.setItsName(getSrvI18n().getMsg("itsCost", lang));
    nodeCost.setItsValue(idx.toString());
    idx++;
    Node<String> nodeQuantity = new Node<String>();
    result.add(nodeQuantity);
    nodeQuantity.setItsName(getSrvI18n().getMsg("itsQuantity", lang));
    nodeQuantity.setItsValue(idx.toString());
    idx++;
    Node<String> nodeIsAvailable = new Node<String>();
    result.add(nodeIsAvailable);
    nodeIsAvailable.setItsName(getSrvI18n().getMsg("isAvailable", lang));
    nodeIsAvailable.setItsValue(idx.toString());
    idx++;
    Node<String> nodeWarehouseSite = new Node<String>();
    result.add(nodeWarehouseSite);
    nodeWarehouseSite.setItsName(getSrvI18n().getMsg("WarehouseSite", lang));
    nodeWarehouseSite.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeWarehouseSiteName = new Node<String>();
    nodeWarehouseSite.getItsNodes().add(nodeWarehouseSiteName);
    nodeWarehouseSiteName.setItsName(getSrvI18n().getMsg("itsName", lang));
    nodeWarehouseSiteName.setItsValue(idx.toString() + ";itsName");
    Node<String> nodeWarehouseSiteId = new Node<String>();
    nodeWarehouseSite.getItsNodes().add(nodeWarehouseSiteId);
    nodeWarehouseSiteId.setItsName(getSrvI18n().getMsg("itsId", lang));
    nodeWarehouseSiteId.setItsValue(idx.toString() + ";itsId");
    Node<String> nodeWarehouseSiteWarehouse = new Node<String>();
    nodeWarehouseSite.getItsNodes().add(nodeWarehouseSiteWarehouse);
    nodeWarehouseSiteWarehouse
      .setItsName(getSrvI18n().getMsg("warehouse", lang));
    nodeWarehouseSiteWarehouse.setItsNodes(new ArrayList<Node<String>>());
    Node<String> nodeWarehouseSiteWarehouseName = new Node<String>();
    nodeWarehouseSiteWarehouse.getItsNodes()
      .add(nodeWarehouseSiteWarehouseName);
    nodeWarehouseSiteWarehouseName
      .setItsName(getSrvI18n().getMsg("itsName", lang));
    nodeWarehouseSiteWarehouseName
      .setItsValue(idx.toString() + ";warehouse,itsName");
    Node<String> nodeWarehouseSiteWarehouseId = new Node<String>();
    nodeWarehouseSiteWarehouse.getItsNodes().add(nodeWarehouseSiteWarehouseId);
    nodeWarehouseSiteWarehouseId.setItsName(getSrvI18n().getMsg("itsId", lang));
    nodeWarehouseSiteWarehouseId
      .setItsValue(idx.toString() + ";warehouse,itsId");
    Set<String> ndFlIdNm = new HashSet<String>();
    ndFlIdNm.add("itsId");
    ndFlIdNm.add("itsName");
    pReqVars.put("InvItemTaxCategoryneededFields", ndFlIdNm);
    pReqVars.put("TaxneededFields", ndFlIdNm);
    List<InvItemTaxCategoryLine> allTaxCatsLns = getSrvOrm()
      .retrieveList(pReqVars, InvItemTaxCategoryLine.class);
    pReqVars.remove("InvItemTaxCategoryneededFields");
    pReqVars.remove("TaxneededFields");
    List<Tax> usedTaxes = new ArrayList<Tax>();
    List<InvItemTaxCategory> usedTaxCats = new ArrayList<InvItemTaxCategory>();
    for (InvItemTaxCategoryLine tcl : allTaxCatsLns) {
      boolean txListed = false;
      for (Tax tx : usedTaxes) {
        if (tx.getItsId().equals(tcl.getTax().getItsId())) {
          txListed = true;
          break;
        }
      }
      if (!txListed) {
        usedTaxes.add(tcl.getTax());
      }
      int tci = -1;
      for (InvItemTaxCategory tc : usedTaxCats) {
        if (tc.getItsId().equals(tcl.getItsOwner().getItsId())) {
          tci = usedTaxCats.indexOf(tc);
          break;
        }
      }
      if (tci == -1) {
        usedTaxCats.add(tcl.getItsOwner());
        tcl.getItsOwner().setTaxes(new ArrayList<InvItemTaxCategoryLine>());
        tcl.getItsOwner().getTaxes().add(tcl);
      } else {
        usedTaxCats.get(tci).getTaxes().add(tcl);
      }
    }
    boolean isOnlyTax = true;
    for (InvItemTaxCategory txc : usedTaxCats) {
      if (txc.getTaxes().size() > 1) {
        isOnlyTax = false;
        break;
      }
    }
    if (isOnlyTax) {
      idx++;
      addTaxWr(result, idx.toString(),
        getSrvI18n().getMsg("OnlyTax", lang), lang);
    } else {
      idx++;
      addTaxCatWr(result, idx.toString(),
        getSrvI18n().getMsg("taxCategory", lang), lang);
      Collections.sort(usedTaxes, new CmprHasIdLong<Tax>());
      for (Tax tx : usedTaxes) {
        idx++;
        addTaxWr(result, idx.toString(), tx.getItsName(), lang);
      }
      Collections.sort(usedTaxCats, new CmprHasIdLong<InvItemTaxCategory>());
      for (InvItemTaxCategory txc : usedTaxCats) {
        idx++;
        addTaxCatWr(result, idx.toString(), txc.getItsName(), lang);
      }
    }
    return result;
  }
1126983
@Override
	public DataSet<Result<K>> runInternal(Graph<K, VV, EV> input)
			throws Exception {
		// u, v, w, bitmask
		DataSet<TriangleListing.Result<K>> triangles = input
			.run(new TriangleListing<K, VV, EV>()
				.setParallelism(parallelism));

		// u, edge count
		DataSet<Tuple2<K, LongValue>> triangleVertices = triangles
			.flatMap(new SplitTriangles<>())
				.name("Split triangle vertices");

		// u, triangle count
		DataSet<Tuple2<K, LongValue>> vertexTriangleCount = triangleVertices
			.groupBy(0)
			.reduce(new CountTriangles<>())
			.setCombineHint(CombineHint.HASH)
				.name("Count triangles")
				.setParallelism(parallelism);

		// u, deg(u)
		DataSet<Vertex<K, Degrees>> vertexDegree = input
			.run(new VertexDegrees<K, VV, EV>()
				.setIncludeZeroDegreeVertices(includeZeroDegreeVertices.get())
				.setParallelism(parallelism));

		// u, deg(u), triangle count
		return vertexDegree
			.leftOuterJoin(vertexTriangleCount)
			.where(0)
			.equalTo(0)
			.with(new JoinVertexDegreeWithTriangleCount<>())
				.setParallelism(parallelism)
				.name("Clustering coefficient");
	}
1005258
public static DMatrixRMaj convert(DMatrix2 input , DMatrixRMaj output ) {
        if( output == null)
            output = new DMatrixRMaj(2,1);

        if( output.getNumRows() != 1 && output.getNumCols() != 1 )
            throw new IllegalArgumentException("One row or column must have a length of 1 for it to be a vector");
        int length = Math.max(output.getNumRows(),output.getNumCols());
        if( length != 2 )
            throw new IllegalArgumentException("Length of input vector is not 2.  It is "+length);

        output.data[0] = input.a1;
        output.data[1] = input.a2;

        return output;
    }
1138153
@Benchmark
  @BenchmarkMode(Mode.AverageTime)
  @OutputTimeUnit(TimeUnit.NANOSECONDS)
  public Span createRootSpan(Data data) {
    Span span =
        data.tracer
            .spanBuilderWithExplicitParent("RootSpan", null)
            .setRecordEvents(data.recorded)
            .setSampler(data.sampled ? Samplers.alwaysSample() : Samplers.neverSample())
            .startSpan();
    span.end();
    return span;
  }
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;
    }
98596
@Override
  public int filter(double[] eigenValues) {
    // determine sum of eigenvalues
    double totalSum = 0;
    for(int i = 0; i < eigenValues.length; i++) {
      totalSum += eigenValues[i];
    }
    double expectedVariance = totalSum / eigenValues.length * walpha;

    // determine strong and weak eigenpairs
    double currSum = 0;
    for(int i = 0; i < eigenValues.length - 1; i++) {
      // weak Eigenvector?
      if(eigenValues[i] < expectedVariance) {
        break;
      }
      currSum += eigenValues[i];
      // calculate progressive alpha level
      double alpha = 1.0 - (1.0 - palpha) * (1.0 - (i + 1) / (double) eigenValues.length);
      if(currSum / totalSum >= alpha) {
        return i + 1;
      }
    }

    // the code using this method doesn't expect an empty strong set,
    // if we didn't find any strong ones, we make all vectors strong
    return eigenValues.length;
  }
471573
@Override
  public <NV extends NumberVector> NV projectScaledToDataSpace(double[] v, NumberVector.Factory<NV> factory) {
    final int dim = v.length;
    double[] vec = new double[dim];
    for(int d = 0; d < dim; d++) {
      vec[d] = scales[d].getUnscaled(v[d]);
    }
    return factory.newNumberVector(vec);
  }
683056
@Override
    public DataSet sample(int numSamples, org.nd4j.linalg.api.rng.Random rng) {
        return sample(numSamples, rng, false);
    }
796457
@Override
  public double[] projectDataToScaledSpace(NumberVector data) {
    final int dim = data.getDimensionality();
    double[] vec = new double[dim];
    for(int d = 0; d < dim; d++) {
      vec[d] = scales[d].getScaled(data.doubleValue(d));
    }
    return vec;
  }
1136433
public void factorize() throws Exception {
		long t0 = System.currentTimeMillis();
		this.LcolumnsValues = new double[dim][];
		
		if(this.rescaler != null){
			double[] cn_00_original = null;
			double[] cn_2_original = null;
			double[] cn_00_scaled = null;
			double[] cn_2_scaled = null;
			if(log.isDebugEnabled()){
				cn_00_original = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(ColtUtils.fillSubdiagonalSymmetricMatrix(Q).toArray()), Integer.MAX_VALUE);
				log.debug("cn_00_original Q before scaling: " + ArrayUtils.toString(cn_00_original));
				cn_2_original = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(ColtUtils.fillSubdiagonalSymmetricMatrix(Q).toArray()), 2);
				log.debug("cn_2_original Q before scaling : " + ArrayUtils.toString(cn_2_original));
			}
			//scaling the Q matrix, we have:
			//Q1 = U.Q.U[T] = U.L.L[T].U[T] = (U.L).(U.L)[T] 
			//and because U is diagonal it preserves the triangular form of U.L, so
			//Q1 = U.Q.U[T] = L1.L1[T] is the new Cholesky decomposition  
			DoubleMatrix1D Uv = rescaler.getMatrixScalingFactorsSymm(Q);
			if(log.isDebugEnabled()){
				boolean checkOK = rescaler.checkScaling(ColtUtils.fillSubdiagonalSymmetricMatrix(Q), Uv, Uv);
				if(!checkOK){
					log.warn("Scaling failed (checkScaling = false)");
				}
			}
			this.U = Uv;
			this.Q = (SparseDoubleMatrix2D)ColtUtils.diagonalMatrixMult(Uv, Q, Uv);
			if(log.isDebugEnabled()){
				cn_00_scaled = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(ColtUtils.fillSubdiagonalSymmetricMatrix(Q).toArray()), Integer.MAX_VALUE);
				log.debug("cn_00_scaled Q after scaling : " + ArrayUtils.toString(cn_00_scaled));
				cn_2_scaled = ColtUtils.getConditionNumberRange(new Array2DRowRealMatrix(ColtUtils.fillSubdiagonalSymmetricMatrix(Q).toArray()), 2);
				log.debug("cn_2_scaled Q after scaling  : " + ArrayUtils.toString(cn_2_scaled));
				
				if(cn_00_original[0] < cn_00_scaled[0] || cn_2_original[0] < cn_2_scaled[0]){
					//log.info("Q: " + ArrayUtils.toString(ColtUtils.fillSubdiagonalSymmetricMatrix(Q).toArray()));
					log.warn("Problematic scaling");
					//throw new RuntimeException("Scaling failed");
				}
			}
		}
		
		final int[] currentColumnIndexHolder = new int[] { -1 };
		
		IntIntDoubleFunction myFunct = new IntIntDoubleFunction() {
			@Override
			public double apply(int i, int s, double pis) {
				int step = currentColumnIndexHolder[0];
				//log.debug("i:" + i + ", step:" + step + ": " + pis);
				if (i >= step) {
					// at this point, step is the row index and j is the column index,
					// but we take into account only the lower left subdiagonal part of Q (that is symmetric)
					//log.debug("i:" + i + ", step:" + step + ": " + pis);
					Svalues[i - step] = pis;
				}
				return pis;
			}
		};
		
		//view Q column by column
		for (int step = 0; step < dim; step++) {
			//log.debug("column:" + step);
			
			// reset and fill initial values
			Svalues = new double[dim - step];
			DoubleMatrix2D P = Q.viewPart(0, step, dim, 1);
			currentColumnIndexHolder[0] = step;
			P.forEachNonZero(myFunct);
			doStep(step);
		}
		
		this.factorizeTime += (System.currentTimeMillis() - t0);
	}
279603
protected final PrcCsvSampleDataRow
    lazyGetPrcCsvSampleDataRow(
      final Map<String, Object> pAddParam) throws Exception {
    String beanName = PrcCsvSampleDataRow.class.getSimpleName();
    @SuppressWarnings("unchecked")
    PrcCsvSampleDataRow proc = (PrcCsvSampleDataRow)
      this.processorsMap.get(beanName);
    if (proc == null) {
      proc = new PrcCsvSampleDataRow();
      lazyInitRetrievers(pAddParam);
      proc.setRetrievers(this.retrievers);
      //assigning fully initialized object:
      this.processorsMap.put(beanName, proc);
      this.logger.info(null, FctBnTradeProcessors.class,
        beanName + " has been created.");
    }
    return proc;
  }
283352
public INDArray project(INDArray data){
        long[] tShape = targetShape(data.shape(), eps, components, autoMode);
        return data.mmul(getProjectionMatrix(tShape, this.rng));
    }