필터 지우기
필터 지우기

How to discretize statespace "logarithmicly" arround 0?

조회 수: 1 (최근 30일)
moritz thiessen
moritz thiessen 2021년 10월 14일
답변: Himanshu 2024년 4월 25일
Hello, I am trying to discretize my statespace in a way such that values arround 0 are closer together and values further away from 0 are further appart from another. I tried to do it logarithmicly but that only works for values >0 and i need them to be negative as well.
Later in the programm i have to calculate a new state, with is most likely not on my grid. Therefor i have to find the closest neighbor.
My current solution looks like this:
% States in phi
phi_spaceing=logspace(-4,pi,10)
phi_spaceing_log=log10(phi_spaceing)
states_phi=cat(2,-flip(phi_spaceing),0,phi_spaceing)
% Find neares Neighbor in phi-Direction
if abs(state_vector_calculation(3,1)) <= (10^-4)/2
calculated_state_phi_index = 11;
elseif state_vector_calculation(3,1) > 10^-4
calculated_state_phi_index = 11 + find(abs(phi_spaceing_log-log10(state_vector_calculation(3,1)))<0.2498);
elseif state_vector_calculation(3,1) < -10^-4
calculated_state_phi_index = 11 - find(abs(phi_spaceing_log-log10(-1*state_vector_calculation(3,1)))<0.2498);
end
I was Wondering if there is any better solution to this problem?
Thank you in advance for your help.

답변 (1개)

Himanshu
Himanshu 2024년 4월 25일
Hey,
Your approach to discretize the state space using a logarithmic scale is reasonable, but it seems you're encountering some challenges, particularly with negative values.
Instead of logarithmic spacing, you might consider using a different transformation that can handle both positive and negative values effectively. One such transformation is the hyperbolic tangent (tanh) function.
The following code snippet gived a rough idea of how to make these changes in the code.
% Define the range for phi values
phi_min = -pi;
phi_max = pi;
% Define the number of discrete states
num_states = 21; % Adjust as needed
% Discretize the state space using hyperbolic tangent function
phi_values = tanh(linspace(phi_min, phi_max, num_states));
% Find the nearest neighbor in the phi-direction
[~, calculated_state_phi_index] = min(abs(phi_values - state_vector_calculation(3,1)));
Hope this helps!

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by