0

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!

2
  • could you please trim out the excess code and use simple dummy variables like A, B etc and post a minimal example that reproduces the problem that you have? It's hard going through such a wall of code with long variable names that mean nothing to me. Commented Apr 23, 2011 at 0:00
  • Actually right now the code only contains the way of computing 1) and 2). I'm not sure if that will be helpful towards the objective of the problem. I'll change the variable names in the question to A, B etc.. Commented Apr 23, 2011 at 0:06

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Rasman! How do I define fun to be used in fminsearch? I am saying this because my fun is being computed indirectly using x0. I have changed the variable names in the code to look like A,B,C,D and E as defined in the question. Thanks!
define a function that returns the vector I described above.. let's call it foo(A,D,E). Next: bar = @(A)foo(A,D,E). Finally foobar=fminsearch(bar, A0) (A0 is semi-random guess at the optimal outcome)
0

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:

  1. What close means. You can look at some vector norm for the B and D case, like minimizing ||B-D||^2. The standard sum of the squares of the elements of this different will probably do the trick and is computationally nice.
  2. How to optimize. This depends a lot on your functions, whether you want local or global mimina, etc.

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.