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.sequence;
018
019import com.oracle.labs.mlrg.olcut.provenance.Provenancable;
020import org.tribuo.Output;
021import org.tribuo.evaluation.metrics.MetricID;
022import org.tribuo.provenance.EvaluationProvenance;
023
024import java.util.Map;
025
026/**
027 * An immutable evaluation of a specific sequence model and dataset.
028 * @param <T> The output type.
029 */
030public interface SequenceEvaluation<T extends Output<T>> extends Provenancable<EvaluationProvenance> {
031
032    /**
033     * Get a map of all the metrics stored in this evaluation. The keys are metric id's and the values are their
034     * corresponding computed results.
035     *
036     * @return a map of all stored results
037     */
038    public Map<MetricID<T>, Double> asMap();
039
040    /**
041     * Gets the value associated with the specific metric. Throws {@link IllegalArgumentException} if
042     * the metric is unknown.
043     * @param key The metric to lookup.
044     * @return The value for that metric.
045     */
046    public default double get(MetricID<T> key) {
047        Double value = asMap().get(key);
048        if (value == null) {
049            throw new IllegalArgumentException("Metric value not found: " + key.toString());
050        }
051        return value;
052    }
053}