# Shape Error during inference

**URL:** <https://uqworld.org/t/shape-error-during-inference/1351>\
**Category:** Community Q&A and How To\
**Tags:** input, inversion\
**Created:** [October 19, 2021, 2:01pm UTC](https://uqworld.org/t/shape-error-during-inference/1351 "2021-10-19T14:01:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BlueMan66](https://uqworld.org/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@BlueMan66](https://uqworld.org/u/BlueMan66)\
**Post date:** [October 19, 2021, 2:01pm UTC](https://uqworld.org/t/shape-error-during-inference/1351/1 "2021-10-19T14:01:17Z")

</div>

Hi! I’m trying to implement Bayesian linear regression. Since the example given was kinda strange in terms of implementation I played around with the function handle in order to perform the inversion.  
What I came up with is the following:

```matlab
nsamples = 10;
N_cycles = log(linspace(1000, 1e7));
size_ = size(N_cycles);
a = -10;
b = 1000;

big_Array = ones(size_(2),2);
big_Array(:,1) = N_cycles;

modelOpts.mHandle = @(x) big_Array * transpose(x);
modelOpts.isVectorized=true;
foward_model = uq_createModel(modelOpts);

```

I’m trying to set up linear regression for the Baskin relationship for the fatigue analysis of a mechanical component.  
The idea behind it is that I observe `\sigma = [\sigma_1,...,\sigma_n]^t` observations linearly related to `N` the amount of cycles to failure. Then I try to get the distributions for `a,b` the parameters of the model.  
When trying to perform the inference, the sampling algorithm starts and after a certain amount of samples throws the following error:  
 ![imagen](https://uqworld.org/uploads/default/original/1X/8db49e69b61ffe6ceeb74050abfbec41cb59054b.png)  
Which is strange since it’s a shape error when the sampler already started. I believe the cause of this error to be in the settings I gave the sampler but I’m at a lost of what could it be.  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![BlueMan66](https://uqworld.org/letter_avatar_proxy/v4/letter/b/b38774/32.png) [@BlueMan66](https://uqworld.org/u/BlueMan66)\
**Post date:** [October 19, 2021, 2:38pm UTC](https://uqworld.org/t/shape-error-during-inference/1351/2 "2021-10-19T14:38:36Z")

</div>

Update:  
The script raising the error has the following assignments (I’ve added the `disp` statements for debugging):

```matlab
for ii = 1:Internal.nForwardModels
    %retreive relevant model params
    modelParamsCurr = modelParams(:,Internal.ForwardModel_WithoutConst(ii).PMap);
    
    %forwardModel(ii).evaluation =
    %uq_evalModel(Internal.ForwardModel_WithoutConst(ii).Model,modelParamsCurr,'hpc');
    
    eval_model = uq_evalModel(Internal.ForwardModel_WithoutConst(ii).Model,modelParamsCurr);
    disp('Eval_model size...')
    disp(size(eval_model))
    
    forwardModel(ii).evaluation = eval_model;    
    disp('foward_model size...')
    disp(size(forwardModel(ii).evaluation))
    
end

```

As I run the code the following happens:  
 ![imagen](https://uqworld.org/uploads/default/original/1X/90334e7dc21225d682c53ec88a8717ffd048f10c.png)  
Suddenly shape changes and then the shape error gets raised. This is quite mind-boggling but I believe it should make sense for someone more in touch with the algorithm.

---

<div class="post-metadata">

**Author:** ![paulremo](https://uqworld.org/user_avatar/uqworld.org/paulremo/32/192_2.png) [@paulremo](https://uqworld.org/u/paulremo)\
**Post date:** [October 21, 2021, 11:48am UTC](https://uqworld.org/t/shape-error-during-inference/1351/3 "2021-10-21T11:48:04Z")

</div>

Hi @BlueMan66

Can you share a minimal working example? This way I’ll be able to easily reproduce your problem.
