<< Back to General Forum   Search

Posts 1 - 19 of 19   
Math: Derive function based on inputs/outputs: 1/15/2018 06:58:45

Fizzer 
Level 58

Warzone Creator
Report
OK, so I think this is an easy problem, but I'm struggling with it.

I have a function that takes four inputs: A,B,C,D, and gives result X. I'm trying to derive it. Here are the values I know:

A	B	C	D	X
0.2	100	0	1	30
0.2	50	0	1	15
0.2	0	0	1	0
0.5	100	0	1	0
0	100	0	1	50
1	100	0	1	-50
0.2	100	0	0	-20
0.2	50	0	0	-10
0.2	25	0	0	-5
0.2	0	0	0	0
0.5	100	0	0	-50
0	100	0	0	0
1	100	0	0	-100
0.2	100	0	0.5	5
0.2	50	0	0.5	2.5
0.2	0	0	0.5	0
0.5	100	0	0.5	-25
0	100	0	0.5	25
1	100	0	0.5	-75
0.2	100	0.25	0.5	17.5
0.2	50	0.25	0.5	8.8
0.2	0	0.25	0.5	0
0.2	100	1	1	80
0.2	50	1	1	40
0.2	0	1	1	0


For example, if the function were "50-B*A", it satisfies 18 of the inputs, but fails on the other 4. I think C and D need to be used as well, but I can't figure out the right algorithm.

Can anyone figure out the algorithm that satisfies all of them?

Edited 1/15/2018 11:05:06
Math: Derive function based on inputs/outputs: 1/15/2018 07:13:42


ViralGoat 
Level 59
Report
Can you only use plus minus divide and multiply?
Math: Derive function based on inputs/outputs: 1/15/2018 07:15:33


ViralGoat 
Level 59
Report
And is the order a b c d?
Math: Derive function based on inputs/outputs: 1/15/2018 07:26:46

Fizzer 
Level 58

Warzone Creator
Report
Any order. Any operators, but I suspect that those 4 are the only ones that are required.
Math: Derive function based on inputs/outputs: 1/15/2018 08:12:07


ViralGoat 
Level 59
Report
Can a b c or d be used multiple times?
Math: Derive function based on inputs/outputs: 1/15/2018 08:16:35


DanWL 
Level 62
Report
Do you have a result of:
A=0.2
B=10
C=0
D=1

And:
A=0.2
B=1
C=0
D=1
Math: Derive function based on inputs/outputs: 1/15/2018 08:21:16

Fizzer 
Level 58

Warzone Creator
Report
Can a b c or d be used multiple times?

Sure

Do you have a result of:

I'll add them to the table. Let me know if you need any more.

EDIT: When I added them, I discovered some of the rows were wrong. I corrected them.

Edited 1/15/2018 08:38:02
Math: Derive function based on inputs/outputs: 1/15/2018 09:30:04


timon92 
Level 62
Report
It seems the formula is linear with respect to every variable. Write



Plug in known values and find k_1, k_2, ..., k_16.
Math: Derive function based on inputs/outputs: 1/15/2018 09:59:31


knyte 
Level 58
Report
Take timon's method and represent the inputs as a matrix I (of the values of A, B, C, D, and any combinations thereof using the multiplication or division operators- so A, B, C, D, AB, AC, AD, BC, BD, CD, A/B, A/C, A/D, B/A, B/C, B/D, C/A, C/B, C/D, D/A, D/B, D/C- just have to keep them linearly independent; also add a column of all 1's just so you can find the constant); similarly, represent the outputs as a column-vector X where the value at each row is the value of X. Feel free to leave out input combinations that you know are unnecessary.

Then use the matrix formula for linear regression- (I' * I)^-1 * I' * X

(source: https://onlinecourses.science.psu.edu/stat501/node/382)

You should get a column-vector K where the values at each row correspond to the coefficient for the same-numbered column in I.

The following weights:

2.5000e+02
5.0000e-01
-2.0982e+01
4.5519e-15
-3.5000e+00
-2.4040e+02
5.0071e-14
5.0000e-01
-1.1744e-15
-8.7397e-13

work for all but the last 6 examples; they're off (underestimating) by -4.76552 for the last 4-6 and -19.06209 for the last 1-3.


Here's an equation that works near-perfectly (off by 3.6 * 10 ** -15 for 4 of the last 6 examples):

X = 250 * A + 0.5 * B - 45.2 * C + -3.5 * A*B - 24 * A*C + 0.5 * B*C

My current best guess:

X = 70 - 100*A -0.2*B + 0.5*B*C + 250*A*C


I'd refine this comment and figure out what I did wrong above (other than forgetting the constant term) but it's 5:28 AM

But I think using the matrix formula above is a good place to start

or you could treat this as a system of equations and solve it that way using matrices

Edited 1/15/2018 10:55:12
Math: Derive function based on inputs/outputs: 1/15/2018 10:54:15


knyte 
Level 58
Report
Double-posting so this doesn't get drowned out by my ramblings in the previous post
Congratulations Fizzer, you've successfully nerd-sniped my sleep for tonight.

Here's an equation that works perfectly for the data in your original post:
X = 70 - 100*A - 0.2*B - 100*C + 0.5*B*C + 250*A*C
Math: Derive function based on inputs/outputs: 1/15/2018 11:06:07

Fizzer 
Level 58

Warzone Creator
Report
OK I must apologize. Turns out there was a bug in my program, and the wrong values were getting inputted for column D. This messed up the result.

I have updated the table new values. I think they're right this time, but I'm going to double-check.

The solution to this SHOULD be simple. If it looks like something from the above post, there's probably a mistake somewhere.

Edited 1/15/2018 11:06:47
Math: Derive function based on inputs/outputs: 1/15/2018 14:06:41


Muli 
Level 62
Report
The following function seems to do the trick.



It calculates all lines correctly, only for the line

A	B	C	D	X
0.2	50	0.25	0.5	8.8
it returns x=8.75 instead of 8.8. Could that be a rounding error?

Edited 1/15/2018 22:05:09
Math: Derive function based on inputs/outputs: 1/15/2018 20:59:22


Hostile
Level 58
Report
(D-2A)/2 * B

0.2	100	0	1	30                           (0.6)/2 * B = 0.3 * 100
0.2	50	0	1	15                           0.3 * 50
0.2	0	0	1	0                             0 * B
0.5	100	0	1	0                             (1-1)/2 * B = 0 * B
0	100	0	1	50                           1/2 * B = 0.5B
1	100	0	1	-50                          (1-2)/2 * B = -1/2 B
0.2	100	0	0	-20                          -0.2 B
0.2	50	0	0	-10                          -0.2B
0.2	25	0	0	-5                            -0.2B
0.2	0	0	0	0                              0
0.5	100	0	0	-50                           -0.5B
0	100	0	0	0                              (0-0)/2 * B = 0B
1	100	0	0	-100                         -1 * B
0.2	100	0	0.5	5                              (0.5-0.4)/2 * B = 0.1/2 * B = 0.05 * 100 = 5
0.2	50	0	0.5	2.5                           0.1 B
0.2	0	0	0.5	0                              B is 0 so 0
0.5	100	0	0.5	-25                           (0.5-0.5*2)/2 = (0.5-1) / 2 = -0.5/2 = -0.25
0	100	0	0.5	25                            0.25
1	100	0	0.5	-75                          0.5-2 = -1.5... -0.75 * B = -75
0.2	100	0.25	0.5	17.5                           
0.2	50	0.25	0.5	8.8
0.2	0	0.25	0.5	0
0.2	100	1	1	80
0.2	50	1	1	40                          
0.2	0	1	1	0                            B is 0


Edited 1/15/2018 22:40:40
Math: Derive function based on inputs/outputs: 1/15/2018 21:16:54


Hostile
Level 58
Report
Well, it is same formula as Muli.

I think C is wrong. Maybe need more data.

The 8.8 is very very odd. Everything in table is a multiple of 5.

Edited 1/15/2018 22:15:47
Math: Derive function based on inputs/outputs: 1/15/2018 21:46:12


Kenny • apex 
Level 59
Report
If only there were a wolf in existence that enjoyed math.
Math: Derive function based on inputs/outputs: 1/15/2018 22:59:54

Fizzer 
Level 58

Warzone Creator
Report
Awesome! Nice work Muli and Hostile. This looks correct:

(D*B)/2+(C*B)/2-A*B

You're right that 8.8 is a rounding error of 8.75. Thanks so much for the help!

Edited 1/15/2018 23:24:19
Math: Derive function based on inputs/outputs: 1/16/2018 00:19:04


DanWL 
Level 62
Report
What are you going to use this for now?
Math: Derive function based on inputs/outputs: 1/16/2018 12:59:41


muddleszoom
Level 59
Report
Nerds
Math: Derive function based on inputs/outputs: 1/16/2018 13:50:37


[FCC] Aura Guardian 
Level 61
Report
Its probably for his secret project.
Posts 1 - 19 of 19