Python Forum
Fitting data to a curve - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Fitting data to a curve (/thread-40257.html)



Fitting data to a curve - daaegp - Jun-30-2023

Coding newbie here!

I'm trying to fit data to a 2d6 probability, with a couple of caveats.

data
input = { “Blue”: 10.46, “Orange”: 0.57, “Red”: 15.27, “Yellow”: 49.87, “Green”: 3.13:, “Purple”: 20.77 }

2d6 curve
curve = { 2: 2.77, 3: 5.55: , 4: 8.33, 5: 11.11, 6: 13.88, 7: 16.66, 8: 13.88, 9: 11.11, 10: 8.33, 11: 5.55, 12: 2.77 }

Since the input values don't already match the curve values, I need to divide them up. For example, Yellow (49.87) should probably be fitted to 7, 8, 9 and 10 (16.66+13.88+11.11+8.33 = 49.98).

Sometimes there will be more or fewer values in input, but they will always add up to (about) 100. Each point on the curve can only be used once.

The expected output looks something like:

2: Orange
3: Red
4: Yellow
5: Blue
6: Yellow
7: Yellow
8: Purple
9: Red
10: Yellow
11: Purple
12: Green

How would you go about this?


RE: Fitting data to a curve - Gribouillis - Jun-30-2023

>>> import more_itertools as mit
>>> 
>>> sum(mit.ilen(mit.set_partitions(range(2, 13), k)) for k in range(1, 7))
601492
There are 601_492 ways to partition a 11 elements set into at most 6 subsets. For each of these partitions, you could compute the 2d6 score of each subset, which gives you at most 6 numbers. You could then choose a color for each of these numbers and try to minimize a global score such as a least square difference in doing so.