All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpmml.evaluator.ProbabilityAggregator Maven / Gradle / Ivy

There is a newer version: 1.6.11
Show newest version
/*
 * Copyright (c) 2014 Villu Ruusmann
 *
 * This file is part of JPMML-Evaluator
 *
 * JPMML-Evaluator is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JPMML-Evaluator is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with JPMML-Evaluator.  If not, see .
 */
package org.jpmml.evaluator;

import java.util.Map;
import java.util.Set;

import com.google.common.base.Function;

class ProbabilityAggregator extends ClassificationAggregator {

	ProbabilityAggregator(){
		this(0);
	}

	ProbabilityAggregator(int capacity){
		super(capacity);
	}

	public void add(HasProbability hasProbability){
		add(hasProbability, 1d);
	}

	public void add(HasProbability hasProbability, double weight){
		Set categories = hasProbability.getCategoryValues();

		for(String category : categories){
			Double probability = hasProbability.getProbability(category);

			add(category, weight != 1d ? (probability * weight) : probability);
		}
	}

	public Map maxMap(){
		Function function = new Function(){

			@Override
			public Double apply(DoubleVector values){
				return values.max();
			}
		};

		return transform(function);
	}

	public Map medianMap(){
		Function function = new Function(){

			@Override
			public Double apply(DoubleVector values){
				return values.median();
			}
		};

		return transform(function);
	}

	public Map averageMap(final double denominator){
		Function function = new Function(){

			@Override
			public Double apply(DoubleVector values){
				return values.sum() / denominator;
			}
		};

		return transform(function);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy