# parameterCost

## Syntax

## Description

returns the cost of the untuned filter specified by the
`cost`

= parameterCost(`tuner`

)`FilterInitializationFcn`

property of the `tuner`

.
The function obtains the cost based on the detection log and truth data used in the latest
call to the `tune`

object
function. You must at least use the `tune`

function once before using
this syntax.

## Examples

### Obtain Tuning Cost from `trackingFilterTuner`

Load the tuning data containing the truth and detection data.

load("filterTuningData.mat","truth","detlog");

Create a `trackingFilterTuner`

object. By default, the `FilterInitializationFcn`

property of the tuner initializes a `trackingEKF`

object.

tuner = trackingFilterTuner; filter = feval(tuner.FilterInitializationFcn,detlog{1});

Create a tunable parameter structure to evaluate the tuning cost directly.

params.ProcessNoise = filter.ProcessNoise; params.StatesCovariance = filter.StateCovariance; cost1 = parameterCost(tuner,params,detlog,truth)

cost1 = 9.2177

Alternately, you can first call the `tune`

object function and evaluate tuning cost with and without the tuned parameters.

tunedParams = tune(tuner,detlog,truth);

Iter RMSE Step Size 0 9.2177 1 9.1951 0.1509 2 9.0458 1.5276 3 9.0456 0.0176 4 9.0452 0.0706 5 9.0452 0.0142 6 9.0452 0.0012 7 9.0452 0.0119 8 9.0452 0.0015 9 9.0451 0.0500 10 9.0450 0.0743 11 9.0450 0.0312 12 9.0450 0.0122

cost2 = parameterCost(tuner)

cost2 = 9.2177

cost3 = parameterCost(tuner,tunedParams)

cost3 = 9.0450

## Input Arguments

`tuner`

— Tracking filter tuner

`trackingFilterTuner`

object

Tracking filter tuner, specified as a `trackingFilterTuner`

object.

`params`

— Tunable parameters

*N*-element array of structures

Tunable parameters, specified as an *N*-element array of
structures. The fields of each structure must have the same name, class, and size as the
output of the `tune`

object
function.

**Data Types: **`struct`

`detectionLog`

— Detection log

cell arrays of `objectDetection`

objects

Detection log, specified as cell arrays of `objectDetection`

objects.

Specify `detectionLog`

based on the number of truth targets that you specify in the `truth`

input argument.

One truth target — Specify

`detectionLog`

as a*T*-by-*N*cell array of`objectDetection`

objects.*N*is the number of Monte-Carlo runs. The number of time steps*T*does not have to be equal to the number of rows in the truth table. The timestamp of each detection does not have to match the time in the truth table.Multiple truth targets — Specify

`detectionLog`

as an*M*-element cells, where each cell contains a cell array of`objectDetection`

objects for the corresponding truth timetable.*M*is the number of truth tables. Across the*M*cells, the detection time, the number of detections, and the number of Monte-Carlo runs do not have to be the same.

`truth`

— Truth data

structure | table | timetable | cell array of structures | cell array of tables | cell array of timetables

Truth data, specified as a structure, table, timetable, cell array of structures, cell array of tables, cell array of timetables.

You can specify `truth`

for one or more truth targets.

One truth target — Specify

`truth`

as a truth structure, table, or timetable.When specified as a structure, the structure must contain a field

`Time`

and either`Position`

and`Velocity`

fields or a`State`

field.`parameterCost`

converts the structure to a timetable and uses it as defined below.When specified as a table, or timetable, the

`truth`

must have these variables as columns:`Time`

— Time of the truth information, specified as a single, double, or`duration`

in each table row.`Position`

— Position of the target at the time, specified as a 1-by-3 real-valued vector in each table row.`Velocity`

— Velocity of the target at the time, specified as a 1-by-3 real-valued vector in each table row. This variable is optional.`State`

— State of the target at the time, specified as 1-by-*S*real-valued vector in each table row, where*S*is dimension of the state.**Note**When you specify the

`State`

column, the tuner ignores the`Position`

and`Velocity`

columns if specified.The definition of the

`State`

column must be exactly the same as the state definition in the tuned filter. For example, if the filter defines its state as [*x**y**v**q*], where*x*and*y*are positions in a 2-D rectangular frame,*v*is the speed, and*q*is the heading angle, you must specify the timetable with a`State`

column in the same [*x**y**v**q*] definition.

Multiple truth targets — Specify

`truth`

as an*M*-element cell array of truth structures, tables, or timetables. Each truth structure, table, or timetable can have different initial and end times.

## Output Arguments

`cost`

— Tuning cost

real scalar | *N*-element vector

Tuning cost, returned as a real scalar when you do not specify the
`params`

input argument and returned as an
*N*-element vector when you specify the `params`

input argument. *N* is the number of tunable parameter structures
specified in the `params`

input. The definition of the cost is the
same as the `Cost`

property of the `tuner`

.

## Version History

**Introduced in R2023a**

### R2024a: Specify truth tuning data using tables or structure

When specifying the truth timetable input, you can use tables or structures. Previously, you could only use timetables.

### R2023b: Specify truth tuning data using state variable

When specifying the truth timetable input of the `tune`

function,
you can use a column called `State`

to describe the truth target state.
Previously, you had to use the `Position`

and `Velocity`

columns to describe the truth target state. Using the `State`

column
provides more flexibility on defining target state.

Note that when the truth timetable contains the `State`

column, the
tuner ignores the `Position`

and `Velocity`

columns if
specified.

## See Also

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)