/** * Convenience method to create a new {@code WeightedValue}. * * @param <ValueType> * The type of the value. * @param value * The value. * @param weight * The weight. * @return * A new weighted value with the given value and weight. */ public static <ValueType> DefaultWeightedValue<ValueType> create( final ValueType value, final double weight) { return new DefaultWeightedValue<ValueType>(value, weight); }
/** * Convenience method to create a new {@code WeightedValue}. * * @param <ValueType> * The type of the value. * @param value * The value. * @param weight * The weight. * @return * A new weighted value with the given value and weight. */ public static <ValueType> DefaultWeightedValue<ValueType> create( final ValueType value, final double weight) { return new DefaultWeightedValue<ValueType>(value, weight); }
/** * Convenience method to create a new {@code WeightedValue}. * * @param <ValueType> * The type of the value. * @param value * The value. * @param weight * The weight. * @return * A new weighted value with the given value and weight. */ public static <ValueType> DefaultWeightedValue<ValueType> create( final ValueType value, final double weight) { return new DefaultWeightedValue<ValueType>(value, weight); }
/** * Gets the prior probability weight and conditional distribution for * the given category. * @param category * Category to consider * @return * Prior probability weight and conditional distribution for * the given category. */ public WeightedValue<ProbabilityFunction<ObservationType>> getCategory( final CategoryType category ) { ProbabilityFunction<ObservationType> conditional = this.categoryConditionals.get(category); double prior = this.categoryPriors.evaluate(category); return new DefaultWeightedValue<ProbabilityFunction<ObservationType>>( conditional, prior ); }
/** * Adds the given regression function with a given weight. * * @param member * The regression function to add. * @param weight * The weight for the new member. */ public void add( final MemberType member, final double weight) { ArgumentChecker.assertIsNotNull("categorizer", member); final WeightedValue<MemberType> weighted = new DefaultWeightedValue<MemberType>(member, weight); this.getMembers().add(weighted); }
/** * Adds the given regression function with a given weight. * * @param member * The regression function to add. * @param weight * The weight for the new member. */ public void add( final MemberType member, final double weight) { ArgumentChecker.assertIsNotNull("categorizer", member); final WeightedValue<MemberType> weighted = new DefaultWeightedValue<MemberType>(member, weight); this.getMembers().add(weighted); }
/** * Adds the given regression function with a given weight. * * @param member * The regression function to add. * @param weight * The weight for the new member. */ public void add( final MemberType member, final double weight) { ArgumentChecker.assertIsNotNull("categorizer", member); final WeightedValue<MemberType> weighted = new DefaultWeightedValue<MemberType>(member, weight); this.getMembers().add(weighted); }
public <SampleType> UnivariateGaussian.PDF integrate( List<? extends WeightedValue<? extends SampleType>> samples, Evaluator<? super SampleType, ? extends Double> expectationFunction) { ArrayList<DefaultWeightedValue<Double>> outputs = new ArrayList<DefaultWeightedValue<Double>>( samples.size() ); for( WeightedValue<? extends SampleType> sample : samples ) { Double output = expectationFunction.evaluate(sample.getValue()); outputs.add( new DefaultWeightedValue<Double>(output, sample.getWeight()) ); } return this.getMean(outputs); }
public <SampleType> UnivariateGaussian.PDF integrate( List<? extends WeightedValue<? extends SampleType>> samples, Evaluator<? super SampleType, ? extends Double> expectationFunction) { ArrayList<DefaultWeightedValue<Double>> outputs = new ArrayList<DefaultWeightedValue<Double>>( samples.size() ); for( WeightedValue<? extends SampleType> sample : samples ) { Double output = expectationFunction.evaluate(sample.getValue()); outputs.add( new DefaultWeightedValue<Double>(output, sample.getWeight()) ); } return this.getMean(outputs); }
public <SampleType> UnivariateGaussian.PDF integrate( List<? extends WeightedValue<? extends SampleType>> samples, Evaluator<? super SampleType, ? extends Double> expectationFunction) { ArrayList<DefaultWeightedValue<Double>> outputs = new ArrayList<DefaultWeightedValue<Double>>( samples.size() ); for( WeightedValue<? extends SampleType> sample : samples ) { Double output = expectationFunction.evaluate(sample.getValue()); outputs.add( new DefaultWeightedValue<Double>(output, sample.getWeight()) ); } return this.getMean(outputs); }
protected void cleanupAlgorithm() { if (this.getSupportsMap() != null) { // Make the result object have a more efficient backing collection // at the end. ArrayList<DefaultWeightedValue<InputType>> supports = new ArrayList<DefaultWeightedValue<InputType>>( this.supportsMap.size()); for (Entry entry : this.supportsMap.values()) { supports.add(new DefaultWeightedValue<InputType>(entry)); } this.getResult().setExamples(supports); this.setSupportsMap(null); } }
protected void cleanupAlgorithm() { if (this.getSupportsMap() != null) { // Make the result object have a more efficient backing collection // at the end. ArrayList<DefaultWeightedValue<InputType>> supports = new ArrayList<DefaultWeightedValue<InputType>>( this.supportsMap.size()); for (Entry entry : this.supportsMap.values()) { supports.add(new DefaultWeightedValue<InputType>(entry)); } this.getResult().setExamples(supports); this.setSupportsMap(null); } }
protected void cleanupAlgorithm() { if (this.getSupportsMap() != null) { // Make the result object have a more efficient backing collection // at the end. ArrayList<DefaultWeightedValue<InputType>> supports = new ArrayList<DefaultWeightedValue<InputType>>( this.supportsMap.size()); for (Entry entry : this.supportsMap.values()) { supports.add(new DefaultWeightedValue<InputType>(entry)); } this.getResult().setExamples(supports); this.setSupportsMap(null); } }
public ArrayList<DefaultWeightedValue<DataType>> sample( Evaluator<? super DataType,Double> targetFunction, Random random, int numSamples) { ArrayList<? extends DataType> importanceSamples = this.importanceDistribution.sample(random, numSamples); ArrayList<DefaultWeightedValue<DataType>> weightedSamples = new ArrayList<DefaultWeightedValue<DataType>>( numSamples ); for( DataType importanceSample : importanceSamples ) { double weight = targetFunction.evaluate(importanceSample) / this.importanceDistribution.evaluate(importanceSample); weightedSamples.add( new DefaultWeightedValue<DataType>( importanceSample, weight ) ); } return weightedSamples; }
public ArrayList<DefaultWeightedValue<DataType>> sample( Evaluator<? super DataType,Double> targetFunction, Random random, int numSamples) { ArrayList<? extends DataType> importanceSamples = this.importanceDistribution.sample(random, numSamples); ArrayList<DefaultWeightedValue<DataType>> weightedSamples = new ArrayList<DefaultWeightedValue<DataType>>( numSamples ); for( DataType importanceSample : importanceSamples ) { double weight = targetFunction.evaluate(importanceSample) / this.importanceDistribution.evaluate(importanceSample); weightedSamples.add( new DefaultWeightedValue<DataType>( importanceSample, weight ) ); } return weightedSamples; }
public <SampleType> MultivariateGaussian.PDF integrate( List<? extends WeightedValue<? extends SampleType>> samples, Evaluator<? super SampleType, ? extends Vector> expectationFunction) { ArrayList<DefaultWeightedValue<Vector>> outputs = new ArrayList<DefaultWeightedValue<Vector>>( samples.size() ); for( WeightedValue<? extends SampleType> sample : samples ) { Vector output = expectationFunction.evaluate(sample.getValue()).convertToVector(); outputs.add( new DefaultWeightedValue<Vector>(output, sample.getWeight()) ); } return MultivariateGaussian.WeightedMaximumLikelihoodEstimator.learn( outputs, DEFAULT_VARIANCE); }
/** * Adds the given categorizer with a given weight. * * @param member * The categorizer to add. * @param weight * The weight for the new member. Cannot be negative. */ public void add( final MemberType member, final double weight) { ArgumentChecker.assertIsNotNull("member", member); ArgumentChecker.assertIsNonNegative("weight", weight); final WeightedValue<MemberType> weighted = new DefaultWeightedValue<MemberType>(member, weight); this.getMembers().add(weighted); }
public <SampleType> MultivariateGaussian.PDF integrate( List<? extends WeightedValue<? extends SampleType>> samples, Evaluator<? super SampleType, ? extends Vector> expectationFunction) { ArrayList<DefaultWeightedValue<Vector>> outputs = new ArrayList<DefaultWeightedValue<Vector>>( samples.size() ); for( WeightedValue<? extends SampleType> sample : samples ) { Vector output = expectationFunction.evaluate(sample.getValue()).convertToVector(); outputs.add( new DefaultWeightedValue<Vector>(output, sample.getWeight()) ); } return MultivariateGaussian.WeightedMaximumLikelihoodEstimator.learn( outputs, DEFAULT_VARIANCE); }
/** * Adds the given categorizer with a given weight. * * @param member * The categorizer to add. * @param weight * The weight for the new member. Cannot be negative. */ public void add( final MemberType member, final double weight) { ArgumentChecker.assertIsNotNull("member", member); ArgumentChecker.assertIsNonNegative("weight", weight); final WeightedValue<MemberType> weighted = new DefaultWeightedValue<MemberType>(member, weight); this.getMembers().add(weighted); }
public <SampleType> MultivariateGaussian.PDF integrate( List<? extends WeightedValue<? extends SampleType>> samples, Evaluator<? super SampleType, ? extends Vector> expectationFunction) { ArrayList<DefaultWeightedValue<Vector>> outputs = new ArrayList<DefaultWeightedValue<Vector>>( samples.size() ); for( WeightedValue<? extends SampleType> sample : samples ) { Vector output = expectationFunction.evaluate(sample.getValue()).convertToVector(); outputs.add( new DefaultWeightedValue<Vector>(output, sample.getWeight()) ); } return MultivariateGaussian.WeightedMaximumLikelihoodEstimator.learn( outputs, DEFAULT_VARIANCE); }