필터 지우기
필터 지우기

Error using linspace (line 22) Inputs must be scalars.

조회 수: 29 (최근 30일)
Ryan Gallagher
Ryan Gallagher 2021년 4월 23일
댓글: Walter Roberson 2021년 4월 25일
I'm working on fitting a model to data I have collected. Within the model, I identify the optimal parameter values that best fit participant data then adjust and reduce the viewing window (range) to get more precise parameter values. I'm using linspace to generate new values to test against the participant data. Initially using a prior adaptation I had no issues. Once I edited my script to include a conditional "If" section to prevent parameters from being less than zero, I encountered the "Error using linspace (line 22) Inputs must be scalar. If I'm understanding the problem correctly its becuase I'm passing a vector into the linspace function instead of a scalar, but I don't understand why that is occuring now and was not the case with my previous adaptation. I'm assuming it has to do with the " if min_<xxx> < 0....." addition. Could someone help me to better understand where I'm making my error and how to correct this?
"Error using linspace (line 22) Inputs must be scalars."
"Error in Range_Adjustment (line 43) alphas = linspace(min_aro, max_aro,10);"
%Finds coordinates of optimal parameters for Condition 0
[x0,y0] = find(all_SSD_cond0 == min(min(all_SSD_cond0)));
%%% Identifies alpha and beta values that correspond to the coordinates for
%%% optimal parameters%%%
alphas(y0)
betas(x0)
%%%% Adjusts range for Condition 0 %%%
%Adjusts Alpha Range%
alpha_range = alpha_range.*0.7 % Decreases alpha range by 30%
min_aro = alphas(y0)-(alpha_range./(0.5)) %Creates optimized minimum of alpha range half distance away from identified optimal alpha value from previous iteration.
if min_aro < 0 % Conditional statement if minimum alpha range is less than zero min_aro = 0
min_aro = 0
end
max_aro = alphas(y0)+(alpha_range./(0.5)) %Creates optimized maximum value of alpha range half distance away from identified optimal alpha value from previous iteration.
%Adjusts Beta Range%
beta_range = beta_range.*0.7;% Decreases beta range by 30%
min_bro = betas(x0)-(beta_range./(0.5)); %Creates optimized minimum of beta range half distance away from identified optimal beta value from previous iteration.
if min_bro < 0 % Conditional statement if minimum beta range is less than zero min_bro = 0
min_bro = 0
end
max_bro = betas(x0)+(beta_range./(0.5)); %Creates optimized minimum of beta range half distance away from identified optimal beta value from previous iteration.
%%% Adjusts viewing frame and creates optimized alpha and beta parameters
%%% for fitting process%%%
alphas = linspace(min_aro, max_aro,10);
betas = linspace(min_bro, max_bro,10);
%alphas = linspace(alphas(y0)-(alpha_range./2), alphas(y0)+(alpha_range./2),10);
%betas = linspace(betas(x0)-(beta_range./2), betas(x0)+(beta_range./2),10);

채택된 답변

Walter Roberson
Walter Roberson 2021년 4월 23일
[x0,y0] = find(all_SSD_cond0 == min(min(all_SSD_cond0)));
You look for the minimum over all of all_SSD_cond0, and you return the locations of all places that exactly match the over-all minimum. For example if you had a uint8 RGB image that had block, the above would return the location of all of the pure-block pixels.
min_aro = alphas(y0)-(alpha_range./(0.5)) %Creates optimized minimum of alpha range half distance away from identified optimal alpha value from previous iteration.
y0 would be a vector, so min_aro would be a vector.
alphas = linspace(min_aro, max_aro,10);
You cannot use a vector as a parameter to linspace.
If you are certain that alphas(y0) will be the same for all locations that have the same all_SSD_cond0 then min_aro should be calculated in terms of alphas(y0(1))
  댓글 수: 2
Ryan Gallagher
Ryan Gallagher 2021년 4월 24일
편집: Ryan Gallagher 2021년 4월 24일
Each time the model loops through combinations of alpha and beta parameter values which generates a learning curve for each combination. The learning curves generated by the model are then compared that of the participant data. With each optimization loop, the new values are generated using the alpha/beta combination that was identified as the best fit. Assuming the partiicant's learning rate was close to zero, could restricting values to not less than zero cause the model to generate repeated numbers? The reason I ask is in the prior adaption, before restrciting the range to postiive integers, I didn't have this issue.
In the previous version, I was using the following to generate new alpha/beta values:
alphas = linspace(alphas(y0)-(alpha_range./2), alphas(y0)+(alpha_range./2),10);
betas = linspace(betas(x0)-(beta_range./2), betas(x0)+(beta_range./2),10);
Walter Roberson
Walter Roberson 2021년 4월 25일
could restricting values to not less than zero cause the model to generate repeated numbers?
Depending on what you implemented, potentially you might have done the equivalent of
max(0, learning_rate)
if so then that would generate 0 for all the locations in which learning_rate would have been negative, and that could easily result in there being multiple places that were 0.
It sounds to me as if your code has so-far relied on floating point round-off effects to give you slightly different numbers for what is really the same algebraically -- that you got lucky that the minimum happened to be unique.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by