本文整理了Java中water.fvec.Frame.vec()
方法的一些代码示例,展示了Frame.vec()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Frame.vec()
方法的具体详情如下:
包路径:water.fvec.Frame
类名称:Frame
方法名:vec
[英]Returns the vector by given index.
The call is direct equivalent to call vecs()[i]
and it does not do any array bounds checking.
[中]按给定索引返回向量。
该调用直接等价于调用vecs()[i]
,并且它不执行任何数组边界检查。
代码示例来源:origin: h2oai/h2o-3
public boolean isInteractionVec(int colid) {
if( null==_interactions && null==_interactionVecs ) return false;
if( _adaptedFrame!=null )
return _adaptedFrame.vec(colid) instanceof InteractionWrappedVec;
else
return Arrays.binarySearch(_interactionVecs,colid) >= 0;
}
代码示例来源:origin: h2oai/h2o-3
@Override public Frame outputFrame(Key<Frame> key, String [] names, String [][] domains){
_predFrame = new Frame(key, names, _predFrame.vecs());
if (domains!=null)
_predFrame.vec(0).setDomain(domains[0]); //only the label is ever categorical
if (_predFrame._key!=null)
DKV.put(_predFrame);
return _predFrame;
}
@Override public void map(Chunk[] chks, NewChunk[] cpreds) { }
代码示例来源:origin: h2oai/h2o-3
public static void getXChunk(Frame xVecs, int chunkIdx, Chunk[] xChunks) {
int xWidth = xChunks.length; // width of x and xold matices
for (int j = 0; j < xWidth; ++j) { // read in the relevant xVec chunks
xChunks[j] = xVecs.vec(j).chunkForChunkIdx(chunkIdx);
}
}
代码示例来源:origin: h2oai/h2o-3
double calculatePriorMean(Frame fr) {
Vec numeratorVec = fr.vec("numerator");
Vec denominatorVec = fr.vec("denominator");
return numeratorVec.mean() / denominatorVec.mean();
}
代码示例来源:origin: h2oai/h2o-3
private boolean checkAllTEColumnsExistAndAreCategorical(Frame data, String[] columnsToEncode) {
for( String columnName : columnsToEncode) {
int columnIndex = data.find(columnName);
assert columnIndex!=-1 : "Column name `" + columnName + "` was not found in the provided data frame";
if(! data.vec(columnIndex).isCategorical()) return false;
}
return true;
}
代码示例来源:origin: h2oai/h2o-3
private static Frame fullFrame(CoxPH coxPH, Frame adaptFr, Frame train) {
if (! coxPH._parms.isStratified())
return adaptFr;
Frame ff = new Frame();
for (String col : coxPH._parms._stratify_by)
if (adaptFr.vec(col) == null)
ff.add(col, train.vec(col));
ff.add(adaptFr);
return ff;
}
代码示例来源:origin: h2oai/h2o-3
Frame imputeWithMean(Frame fr, int columnIndex, double mean) {
Vec vecWithEncodings = fr.vec(columnIndex);
assert vecWithEncodings.get_type() == Vec.T_NUM : "Imputation of mean value is supported only for numerical vectors.";
long numberOfNAs = vecWithEncodings.naCnt();
if (numberOfNAs > 0) {
new FillNAWithDoubleValueTask(columnIndex, mean).doAll(fr);
Log.info(String.format("Frame with id = %s was imputed with mean = %f ( %d rows were affected)", fr._key, mean, numberOfNAs));
}
return fr;
}
代码示例来源:origin: h2oai/h2o-3
private void printOutColumnsMeta(Frame fr) {
for (String header : fr.toTwoDimTable().getColHeaders()) {
String type = fr.vec(header).get_type_str();
int cardinality = fr.vec(header).cardinality();
System.out.println(header + " - " + type + String.format("; Cardinality = %d", cardinality));
}
}
}
代码示例来源:origin: h2oai/h2o-3
Frame imputeNAsForColumn(Frame data, String teColumnName, String strToImpute) {
int columnIndex = data.find(teColumnName);
Vec currentVec = data.vec(columnIndex);
int indexForNACategory = currentVec.cardinality(); // Warn: Cardinality returns int but it could be larger than it for big datasets
new FillNAWithLongValueTask(columnIndex, indexForNACategory).doAll(data);
String[] oldDomain = currentVec.domain();
String[] newDomain = new String[indexForNACategory + 1];
System.arraycopy(oldDomain, 0, newDomain, 0, oldDomain.length);
newDomain[indexForNACategory] = strToImpute;
currentVec.setDomain(newDomain);
return data;
}
代码示例来源:origin: h2oai/h2o-3
private void printOutColumnsMeta(Frame fr) {
for (String header : fr.toTwoDimTable().getColHeaders()) {
String type = fr.vec(header).get_type_str();
int cardinality = fr.vec(header).cardinality();
System.out.println(header + " - " + type + String.format("; Cardinality = %d", cardinality));
}
}
}
代码示例来源:origin: h2oai/h2o-3
private double computeSigmaU(DataInfo dinfo, SVDModel model, int k, double[][] ivv_sum, Vec[] uvecs, double[] vresult) {
double[] ivv_vk = ArrayUtils.multArrVec(ivv_sum, model._output._v[k], vresult);
CalcSigmaU ctsk = new CalcSigmaU(_job._key, dinfo, ivv_vk).doAll(Vec.T_NUM, dinfo._adaptedFrame);
model._output._d[k] = ctsk._sval;
assert ctsk._nobs == model._output._nobs : "Processed " + ctsk._nobs + " rows but expected " + model._output._nobs; // Check same number of skipped rows as Gram
Frame tmp = ctsk.outputFrame();
uvecs[k] = tmp.vec(0); // Save output column of U
tmp.unlock(_job);
return model._output._d[k];
}
代码示例来源:origin: h2oai/h2o-3
/**
* @return frame without rows with NAs in `columnIndex` column
*/
static Frame filterOutNAsInColumn(Frame fr, int columnIndex) {
Frame noNaPredicateFrame = new IsNotNaTask().doAll(1, Vec.T_NUM, new Frame(fr.vec(columnIndex))).outputFrame();
return selectByPredicate(fr, noNaPredicateFrame);
}
代码示例来源:origin: h2oai/h2o-3
long[] getUniqueValuesOfTheFoldColumn(Frame data, int columnIndex) {
Vec uniqueValues = uniqueValuesBy(data, columnIndex).vec(0);
long numberOfUniqueValues = uniqueValues.length();
assert numberOfUniqueValues <= Integer.MAX_VALUE : "Number of unique values exceeded Integer.MAX_VALUE";
int length = (int) numberOfUniqueValues; // We assume that fold column should not has that many different values and we will fit into node's memory.
long[] uniqueValuesArr = new long[length];
for(int i = 0; i < uniqueValues.length(); i++) {
uniqueValuesArr[i] = uniqueValues.at8(i);
}
uniqueValues.remove();
return uniqueValuesArr;
}
代码示例来源:origin: h2oai/h2o-3
Frame groupByTEColumnAndAggregate(Frame data, int teColumnIndex) {
int numeratorColumnIndex = data.find("numerator");
int denominatorColumnIndex = data.find("denominator");
AstGroup.AGG[] aggs = new AstGroup.AGG[2];
AstGroup.NAHandling na = AstGroup.NAHandling.ALL;
aggs[0] = new AstGroup.AGG(AstGroup.FCN.sum, numeratorColumnIndex, na, (int) data.vec(numeratorColumnIndex).max() + 1);
aggs[1] = new AstGroup.AGG(AstGroup.FCN.sum, denominatorColumnIndex, na, (int) data.vec(denominatorColumnIndex).max() + 1);
Frame result = new AstGroup().performGroupingWithAggregations(data, new int[]{teColumnIndex}, aggs, -1).getFrame();
return register(result);
}
代码示例来源:origin: h2oai/h2o-3
private static Chunk[] chunks(DataInfo dinfo, int chunkId) {
Chunk[] cs = new Chunk[dinfo._adaptedFrame.numCols()];
for (int i = 0; i < cs.length; i++)
cs[i] = dinfo._adaptedFrame.vec(i).chunkForChunkIdx(chunkId);
return cs;
}
代码示例来源:origin: h2oai/h2o-3
@Override public void check(Frame f) {
Vec values = f.vec(0);
for (int i = 0; i < f.numRows(); i++) {
assertEquals(i, values.at8(i));
}
}
},
代码示例来源:origin: h2oai/h2o-3
@Override
protected ModelMetrics.MetricBuilder scoreMetrics(Frame adaptFrm) {
final boolean makeNative = model_info()._backend ==null;
if (makeNative) model_info().javaToNative();
final boolean computeMetrics = (!isSupervised() || (adaptFrm.vec(_output.responseName()) != null && !adaptFrm.vec(_output.responseName()).isBad()));
// Build up the names & domains.
String [] domain = !computeMetrics ? _output._domains[_output._domains.length-1] : adaptFrm.lastVec().domain();
// Score the dataset, building the class distribution & predictions
BigScore bs = new DeepWaterBigScore(domain,0,adaptFrm.means(),_output.hasWeights() && adaptFrm.find(_output.weightsName()) >= 0,computeMetrics, false /*no preds*/, null).doAll(adaptFrm);
if (makeNative) removeNativeState();
return bs._mb;
}
代码示例来源:origin: h2oai/h2o-3
private void convert2Enum(Frame f, int[] cols) {
for (int col : cols) {
f.replace(col, f.vec(col).toCategoricalVec()).remove();
}
DKV.put(f);
}
代码示例来源:origin: h2oai/h2o-3
private static double[][] frameToMatrix(Frame f) {
double[][] rows = new double[(int) f.numRows()][];
for (int r = 0; r < rows.length; r++) {
rows[r] = new double[f.numCols()];
}
for (int c = 0; c < f.numCols(); c++) {
Vec.Reader vecReader = f.vec(c).new Reader();
for (int r = 0; r < rows.length; r++)
rows[r][c] = vecReader.at(r);
}
return rows;
}
代码示例来源:origin: h2oai/h2o-3
@Test
public void isBinaryTest() {
fr = new TestFrameBuilder()
.withName("testFrame")
.withColNames("ColA", "ColB")
.withVecTypes(Vec.T_CAT, Vec.T_NUM)
.withDataForCol(0, ar("NO", "YES", "NO"))
.withDataForCol(1, ard(0, 0.5, 1))
.build();
assertTrue(fr.vec(0).isBinary());
assertFalse(fr.vec(1).isBinary());
}
内容来源于网络,如有侵权,请联系作者删除!