Reputation:
I have a 101x82
size matrix called A
. Using this variable matrix, I compute two other variables called:
1) B
, a 1x1
scalar, and
2) C
, a 50x6
matrix.
I compare 1)
and 2)
with their analogues variables 3)
and 4)
, whose values are fixed:
3) D
, a 1x1
scalar, and
4) E
, a 50x6
matrix.
Now, I want to perturb/change the values of A
matrix, such that:
1)
~ 3)
, i.e. B
is nearly equal to D
, and
2)
~ 4)
, i.e. C
is nearly equal to E
Note that on perturbing A
, B
and C
will change, but not D
and E
.
Any ideas how to do this? Thanks!
Upvotes: 0
Views: 943
Reputation: 6887
From my understanding you have a few functions.
fb(A) = B
fc(A) = C
Do you know the functions listed above, that is do you know the mappings from A to each of these? If you want to try to optimize, so that B is close to D, you need to pick:
So basically, now we've boiled the problem down to minimizing:
Cost = ||fb(A) - fd(A)||^2
One thing you can certainly do is to compute the gradient of this cost function with respect to the individual elements of A, and then perform minimization steps with forward Euler method with a suitable "time step". This might not be fast, but with small enough time step and well-behaved enough functions it will at least get you to a local minima.
Computing the gradient of this
grad_A(cost) = 2*||fb(A)-fd(A)||*(grad_A(fb)(A)-grad_A(fd)(A))
Where grad_A means gradient with respect to A, and grad_A(fb)(A) means gradient with respect to A of the function fb evaluated at A, etc.
Computing the grad_A(fb)(A) depends on the form of fb, but here are some pages have "Matrix calculus" identities and explanations.
Matrix calculus identities Matrix calculus explanation
Then you simply perform gradient descent on A by doing forward Euler updates:
A_next = A_prev - timestep * grad_A(cost)
Upvotes: 0
Reputation: 5359
I can't run your code as it's demanding to load data (which I don't have) and it's not immediatly obvious how to calculate B or C.
Fortunately I may be able to answer your problem. You're describing an optimization problem, and the solution would be to use fminsearch (or something of that variety).
What you do is define a function that returns a vector with two elements:
y1 = (B - D)^weight1;
y2 = norm((C - E), weight2);
with weight being how strong you allow for variability (weight = 2 is usually sufficient).
Your function variable would be A.
Upvotes: 1