Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
Offline anatolsen  
#1 Posted : 08 June 2021 12:15:55(UTC)
anatolsen


Rank: Member

Groups: Registered
Joined: 08/06/2021(UTC)
Posts: 15
Location: Караганда

Colleagues.
I have a problem when using it. And I'm not very good at math.
I need to with the sum of three normal distributions.
I have determined the approximating function of 9 parameters, but the iteration of the parameter values to find the minimum of the smallest sum of squares does not go. The program writes that my expression is set incorrectly.
Meaning - Sq(h1,h2, h3, µ1,µ2,µ3,σ1,σ2,σ3)
Could you tell me what I did wrong?
Solution file (01.sm) I attach - 01.sm (32kb) downloaded 9 time(s)..
P.S. I'm sorry, I don't speak English very well
Offline alyles  
#2 Posted : 08 June 2021 15:23:27(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 217
United States

Was thanked: 75 time(s) in 46 post(s)
Made some changes to your file

1.) In the function definition of Sq() I used the vectorize function on the Raz()^2. This performs element-wise operations on x, y rather than matrix operations.
2.) In your programming loop. I assigned Sq:=Sq() then changed the conditional to Sq < Sqmin. This was because later you have Sqmin:=Sq, but never defined the value Sq.
01.sm (32kb) downloaded 6 time(s).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
Offline Jean Giraud  
#3 Posted : 08 June 2021 16:19:06(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,430
Canada

Was thanked: 845 time(s) in 675 post(s)
Your data set is not normal PDF, by the look.
No matter how many different fits you will SUM, it won't cut the mustard.
It is of the Extreme Value type [Gumbel, Frechet]
We get a superb Frechet fit.
The difficulty is initializing the fitter.
The cumulative integration is Simpson native Smath.
Generally, Simpson is fine for PDF's.
Hope it will relax you pain !
Take care ... Jean. [SS 6179]

Frechet Forum.sm (74kb) downloaded 10 time(s).
Offline Jean Giraud  
#4 Posted : 09 June 2021 01:35:05(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,430
Canada

Was thanked: 845 time(s) in 675 post(s)
...Please Collab: comment on that one.
Offline anatolsen  
#5 Posted : 09 June 2021 13:46:18(UTC)
anatolsen


Rank: Member

Groups: Registered
Joined: 08/06/2021(UTC)
Posts: 15
Location: Караганда

Dear Jean Giraud
What's it?
Frechet Forum.sm?
You weren't answering my question, you were answering someone else's.
Offline overlord  
#6 Posted : 09 June 2021 13:57:55(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 365
Turkey

Was thanked: 100 time(s) in 74 post(s)
Originally Posted by: anatolsen Go to Quoted Post
Colleagues.
I have a problem when using it. And I'm not very good at math.
I need to with the sum of three normal distributions.
I have determined the approximating function of 9 parameters, but the iteration of the parameter values to find the minimum of the smallest sum of squares does not go. The program writes that my expression is set incorrectly.
Meaning - Sq(h1,h2, h3, µ1,µ2,µ3,σ1,σ2,σ3)
Could you tell me what I did wrong?
Solution file (01.sm) I attach - 01.sm (32kb) downloaded 9 time(s)..
P.S. I'm sorry, I don't speak English very well

I guess you are trying to multiply matrix elements with itselfs by squaring it.
You can't do that mathematically, unless you vectorize it.
2021-06-09_13-55.png
Here is your revised file.

Regards

01_rev.sm (31kb) downloaded 5 time(s).

2021-06-09_13-55_1.png
Offline anatolsen  
#7 Posted : 09 June 2021 14:38:18(UTC)
anatolsen


Rank: Member

Groups: Registered
Joined: 08/06/2021(UTC)
Posts: 15
Location: Караганда

Dear alles,
Thank you for correcting my mistake.
But the desired result still did not work.
There, for some reason, the search of options stopped at the value of hh1 = 0.01, respectively, and hh2 = 001, hh3 = 0.01. That is, h1, h2, and h3 were only checked when the value =1.
Whereas I expected that the iteration of options should reach hh1 = hh2 = hh3 = 1, respectively h1 = h2 = h3 = 100.
For other parameters, it also seems that the search for options has not reached the end.
That is why the resulting graph shows a complete mismatch between the original data and the approximating formula.
I don't have an error in the If statement?
There I put continue in the else field.
eng-min.sm (33kb) downloaded 7 time(s).

Offline anatolsen  
#8 Posted : 09 June 2021 14:45:19(UTC)
anatolsen


Rank: Member

Groups: Registered
Joined: 08/06/2021(UTC)
Posts: 15
Location: Караганда

Thank you, I have already been pointed out to this error.
I was trying to sum the squares of the error difference.
See the eng-min file in the last replica.

Offline overlord  
#9 Posted : 09 June 2021 16:20:52(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 365
Turkey

Was thanked: 100 time(s) in 74 post(s)
Originally Posted by: anatolsen Go to Quoted Post
Thank you, I have already been pointed out to this error.
I was trying to sum the squares of the error difference.
See the eng-min file in the last replica.

Your iterations are ill and wrong if this is not intended. Let me explain.
When sigma.3 reach 150, sigma.2 becomes 2. But sigma.3 doesn't start from 1 after it.
It has to be reseted to 1 but not on your algorithm.
Using a for loop is much more sense here.
But beware, when all ranges multiplied we reach 1.35×10¹⁹.
This means your algorithm is trying to calculate 1.35×10¹⁹ times.
Even 1×10⁶ takes 30 second on my pc. That algorithm will take very long.
I think we can't see the result of your problem in a human life time.
You can find worksheet below.

Regards.

eng-min_rev.sm (31kb) downloaded 7 time(s).

Edited by user 09 June 2021 17:26:25(UTC)  | Reason: Not specified

Offline mkraska  
#10 Posted : 09 June 2021 16:47:43(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,672
Germany

Was thanked: 922 time(s) in 581 post(s)
fit.png
fit.sm (137kb) downloaded 13 time(s).
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://en.smath.info/wi...th%20with%20Plugins.ashx
Offline Razonar  
#11 Posted : 09 June 2021 17:10:39(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 749
Uruguay

Was thanked: 400 time(s) in 256 post(s)
Hi. Some notes attached.

eng-min.sm (45kb) downloaded 11 time(s).
eng-min.pdf (383kb) downloaded 9 time(s).

Best regards.
Alvaro.

Edited by user 09 June 2021 17:12:48(UTC)  | Reason: Oh, I don't see the Martin post, it looks better than this one.

Offline Jean Giraud  
#12 Posted : 09 June 2021 19:39:03(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,430
Canada

Was thanked: 845 time(s) in 675 post(s)
Originally Posted by: anatolsen Go to Quoted Post
Dear Jean
What's it ?
Frechet Forum.sm?
You weren't answering my question, you were answering someone else's.

If you were trying to approximate your data set, that's the answer.
SSD in pink = 1.863*10^{-6} in the refreshed document.
Assuming you have 3 sets of individuals absolute residuals,
as seemingly you approximate 3 sets of functions, just sum these 3.

Frechet.PNG

Frechet Forum.sm (67kb) downloaded 7 time(s).
Offline anatolsen  
#13 Posted : 10 June 2021 09:20:29(UTC)
anatolsen


Rank: Member

Groups: Registered
Joined: 08/06/2021(UTC)
Posts: 15
Location: Караганда

Deard overlord

Thanks.
This subtlety that sigma does not reset, I did not understand, but the result began to assume something similar.
I'll look at your edits carefully.

Offline anatolsen  
#14 Posted : 10 June 2021 09:25:33(UTC)
anatolsen


Rank: Member

Groups: Registered
Joined: 08/06/2021(UTC)
Posts: 15
Location: Караганда

Thank you, Martin
Your math is too complicated for me, and I'm not very good with matrices and vectors, but I'll try to figure it out.
Offline anatolsen  
#15 Posted : 10 June 2021 09:34:10(UTC)
anatolsen


Rank: Member

Groups: Registered
Joined: 08/06/2021(UTC)
Posts: 15
Location: Караганда

Dear, Jean Giraud.
You certainly offer an approximation, but unfortunately not the one I need.
Thanks.

Offline Jean Giraud  
#16 Posted : 10 June 2021 17:03:45(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,430
Canada

Was thanked: 845 time(s) in 675 post(s)
Originally Posted by: anatolsen Go to Quoted Post
Dear, Jean.
You certainly offer an approximation, but unfortunately not the one I need.
Thanks.

Martin fits through your data, but with no statistical end use YET
If you have another data set, fit via Martin.
1. At this point, populate the two fits.
2. Next, establish qqplot between the two.
3. From these two qqplot, you will be able to determine
if the two come from closely related distribution or much different.
In other words if the two production batches are equivalent or not.
Typical of COVId-19 and the variants.
Your data set is a bit under-populated.
Cheers ... Jean

FitUnknown.PNG

Offline Jean Giraud  
#17 Posted : 10 June 2021 17:34:20(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,430
Canada

Was thanked: 845 time(s) in 675 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
2. Next, establish qqplot between the two.

... here is an example.

Stat Quantiles_qqplot Copy.sm (39kb) downloaded 7 time(s).
Offline Jean Giraud  
#18 Posted : 11 June 2021 00:12:55(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 5,430
Canada

Was thanked: 845 time(s) in 675 post(s)
At this point of the brain storm, please give more information.
What the data set represents, what you mean by approximate.
Approximate is too generic. You can simply join points.
Has it statistical meaning ?
Cheers ... Jean.

Inst_Frechet UNK.sm (89kb) downloaded 5 time(s).

Offline anatolsen  
#19 Posted : 14 June 2021 00:03:16(UTC)
anatolsen


Rank: Member

Groups: Registered
Joined: 08/06/2021(UTC)
Posts: 15
Location: Караганда

Dear overlord
I decided to take a simpler case for now, when we approximate the sum of two distributions.
With some tweaks, the time limit can be circumvented. Although I haven't tried the Fit function yet. Perhaps it will give you a gain in time.
Can you tell me how to limit the accuracy of the calculations? There Sq is calculated with an accuracy of 15 decimal places, while 9 digits are quite enough for me. This would give you a gain in time.
The approximation is quite satisfactory. The defined integral differs from the original value by only 1.5%. Given that the raw data is quite rough, there is actually a histogram, this is quite acceptable.
But I still need to calculate the Pearson correlation coefficient, and I'm faced with the fact that the reference book does not specify how to find the sum of the elements of any vector. Can you tell me what you can do in this case?

Pirson-0.sm (15kb) downloaded 3 time(s).

Regards.


Offline overlord  
#20 Posted : 14 June 2021 02:19:06(UTC)
overlord


Rank: Advanced Member

Groups: Registered
Joined: 23/07/2013(UTC)
Posts: 365
Turkey

Was thanked: 100 time(s) in 74 post(s)
Originally Posted by: anatolsen Go to Quoted Post
But I still need to calculate the Pearson correlation coefficient, and I'm faced with the fact that the reference book does not specify how to find the sum of the elements of any vector. Can you tell me what you can do in this case?

Regards.

Below you can find how to calculate Pearson correlation coefficient.
To sum all elements of a vector, you can use sum(1).
To operate piecewise you can use sum(4).

You can also use for-loop and while() to calculate something in a vector/matrix. Not demonstrated here.

Regards

pearson.sm (9kb) downloaded 5 time(s).

pearson.png

Edited by user 14 June 2021 13:38:28(UTC)  | Reason: Not specified

Users browsing this topic
Similar Topics
Approximate solution of equation system? (Questions)
by Ushwood 14/08/2018 13:43:15(UTC)
2 Pages12>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.