001/* 002 * Copyright (c) 2015-2020, Oracle and/or its affiliates. All rights reserved. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.tribuo.evaluation.metrics; 018 019import org.tribuo.Model; 020import org.tribuo.Output; 021import org.tribuo.Prediction; 022import org.tribuo.sequence.SequenceModel; 023 024import java.util.Collections; 025import java.util.List; 026 027/** 028 * The context for a metric or set of metrics. At minimum the model used to generate 029 * the predictions, and the predictions themselves. 030 */ 031public abstract class MetricContext<T extends Output<T>> { 032 033 private final Model<T> model; 034 private final SequenceModel<T> seqModel; 035 private final List<Prediction<T>> predictions; 036 037 protected MetricContext(Model<T> model, List<Prediction<T>> predictions) { 038 this.model = model; 039 this.seqModel = null; 040 this.predictions = Collections.unmodifiableList(predictions); 041 } 042 043 protected MetricContext(SequenceModel<T> model, List<Prediction<T>> predictions) { 044 this.model = null; 045 this.seqModel = model; 046 this.predictions = Collections.unmodifiableList(predictions); 047 } 048 049 /** 050 * Gets the Model used by this context. 051 * @return The model, or null if this MetricContext operates on a SequenceModel. 052 */ 053 public Model<T> getModel() { 054 return model; 055 } 056 057 /** 058 * Gets the SequenceModel used by this context. 059 * @return The model, or null if this MetricContext operates on a Model. 060 */ 061 public SequenceModel<T> getSequenceModel() { 062 return seqModel; 063 } 064 065 /** 066 * Gets the predictions used by this context. 067 * @return The predictions. 068 */ 069 public List<Prediction<T>> getPredictions() { 070 return predictions; 071 } 072}