How to discretize statespace "logarithmicly" arround 0?

1 visualización (últimos 30 días)
moritz thiessen
moritz thiessen el 14 de Oct. de 2021
Respondida: Himanshu el 25 de Abr. de 2024
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.

Respuestas (1)

Himanshu
Himanshu el 25 de Abr. de 2024
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!

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by