Main Content

勾配とバイアスの計算

勾配バイアス スケーリングとは

勾配バイアス スケーリングでは、数値の勾配とバイアスを指定しなければなりません。勾配バイアスのスケーリングされた数値の実際値は以下で表すことができます。

real-world value=(slope×integer)+bias

slope=slope adjustment factor×2fixed exponent

勾配とバイアスの計算

目的のエンドポイント、符号属性、および語長で開始します。

lower_bound = 999;
upper_bound = 1000;
is_signed = true;
word_length = 16;

指定された語長および符号属性の fi オブジェクトの範囲を見つけるには、関数 range を使用します。

[Q_min, Q_max] = range(fi([], is_signed, word_length, 0));

勾配とバイアスを求めるには、次の方程式系を解きます。

lower_bound = slope * Q_min + bias

upper_bound = slope * Q_max + bias

これらの方程式を行列の形式で書き換えます。

[lower_boundupper_bound]=[Q_min1Q_max1]×[slopebias]

勾配とバイアスの解を求めます。

A = double ([Q_min, 1; Q_max, 1]);
b = double ([lower_bound; upper_bound]);
x = A\b;
format long g

勾配、つまり精度を求めるには、勾配バイアス ベクトル x の最初の要素を呼び出します。

slope = x(1)
slope =

      1.52590218966964e-05

バイアスを求めるには、ベクトル x の 2 番目の要素を呼び出します。

bias = x(2)
bias =

          999.500007629511

勾配バイアス スケーリングを指定して numerictype オブジェクトを作成します。

T = numerictype(is_signed, word_length, slope, bias)
T =


          DataTypeMode: Fixed-point: slope and bias scaling
            Signedness: Signed
            WordLength: 16
                 Slope: 1.5259021896696368e-5
                  Bias: 999.500007629511

numerictype T を指定して fi オブジェクトを作成します。

a = fi(999.255, T)
a = 

          999.254993514916

          DataTypeMode: Fixed-point: slope and bias scaling
            Signedness: Signed
            WordLength: 16
                 Slope: 1.5259021896696368e-5
                  Bias: 999.500007629511

a の範囲を見つけて、作成した fi オブジェクトが正しく指定されていることを確認します。

range(a)
ans = 

         999        1000

          DataTypeMode: Fixed-point: slope and bias scaling
            Signedness: Signed
            WordLength: 16
                 Slope: 1.5259021896696368e-5
                  Bias: 999.500007629511