1# Licensed to the Apache Software Foundation (ASF) under one 2# or more contributor license agreements. See the NOTICE file 3# distributed with this work for additional information 4# regarding copyright ownership. The ASF licenses this file 5# to you under the Apache License, Version 2.0 (the 6# "License"); you may not use this file except in compliance 7# with the License. You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, 12# software distributed under the License is distributed on an 13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14# KIND, either express or implied. See the License for the 15# specific language governing permissions and limitations 16# under the License. 17 18use strict; 19use warnings; 20use Test::More tests => 6; 21use JSON::PP; 22use AI::MXNet 'mx'; 23 24sub check_metric 25{ 26 my ($metric, @args) = @_; 27 $metric = mx->metric->create($metric, @args); 28 my $str_metric = encode_json($metric->get_config()); 29 my $metric2 = mx->metric->create($str_metric); 30 is_deeply($metric->get_config(), $metric2->get_config()); 31} 32 33 34sub test_metrics 35{ 36 check_metric('acc', axis=>0); 37 check_metric('f1'); 38 check_metric('perplexity', -1); 39 check_metric('pearsonr'); 40 check_metric('confidence', 2, [0.5, 0.9]); 41 my $composite = mx->metric->create(['acc', 'f1']); 42 check_metric($composite); 43} 44 45test_metrics(); 46