NaiveBayesModel { public void validate() { Preconditions.checkState(alphaI > 0, "alphaI has to be greater than 0!"); Preconditions.checkArgument(numFeatures > 0, "the vocab count has to be greater than 0!"); Preconditions.checkArgument(totalWeightSum > 0, "the totalWeightSum has to be greater than 0!"); Preconditions.checkNotNull(weightsPerLabel, "the number of labels has to be defined!"); Preconditions.checkArgument(weightsPerLabel.getNumNondefaultElements() > 0, "the number of labels has to be greater than 0!"); Preconditions.checkNotNull(weightsPerFeature, "the feature sums have to be defined"); Preconditions.checkArgument(weightsPerFeature.getNumNondefaultElements() > 0, "the feature sums have to be greater than 0!"); if (isComplementary){ Preconditions.checkArgument(perlabelThetaNormalizer != null, "the theta normalizers have to be defined"); Preconditions.checkArgument(perlabelThetaNormalizer.getNumNondefaultElements() > 0, "the number of theta normalizers has to be greater than 0!"); Preconditions.checkArgument(Math.signum(perlabelThetaNormalizer.minValue()) == Math.signum(perlabelThetaNormalizer.maxValue()), "Theta normalizers do not all have the same sign"); Preconditions.checkArgument(perlabelThetaNormalizer.getNumNonZeroElements() == perlabelThetaNormalizer.size(), "Theta normalizers can not have zero value."); } } NaiveBayesModel(Matrix weightMatrix, Vector weightsPerFeature, Vector weightsPerLabel, Vector thetaNormalizer,
                         float alphaI, boolean isComplementary); double labelWeight(int label); double thetaNormalizer(int label); double featureWeight(int feature); double weight(int label, int feature); float alphaI(); double numFeatures(); double totalWeightSum(); int numLabels(); Vector createScoringVector(); boolean isComplemtary(); static NaiveBayesModel materialize(Path output, Configuration conf); void serialize(Path output, Configuration conf); void validate(); final static String COMPLEMENTARY_MODEL; }
@Test public void testRandomModelGeneration() { NaiveBayesModel standardModel = getStandardModel(); standardModel.validate(); NaiveBayesModel complementaryModel = getComplementaryModel(); complementaryModel.validate(); }