Menu

Unknown Auxiliary Input is categorical number

Help
Keith KK
2016-03-13
2016-03-16
  • Keith KK

    Keith KK - 2016-03-13

    Hi there,

    In my function, I input a Unknown Auxiliary Input (categorical number) which is used to extract which column of matrix dynamically. But, the adigatorGenJacFile evaluate my function with random number (continuous number) and then failed to generate derivatives. How can I resolve it?

    Example:

    x = adigatorCreateDerivInput([2,1],'x');
    theta = [1]; people = length(theta);
    Theta = adigatorCreateAuxInput([people 1]);
    resInd = adigatorCreateAuxInput([1 1]); 
    resInd.func.value = 1; 
    options = adigatorOptions('OVERWRITE',1,'AUXDATA',0);
    output = adigatorGenJacFile('myfun',{x,Theta,resInd},options);
    

    Following is my function:

    function prob = myfun(x,Theta,resInd)
    temp(:,1) = 1./(1+exp(x(1).*(Theta-x(2))));
    temp(:,2) = 1./(1+exp(-x(1).*(Theta-x(2))));
    prob = temp(:,resInd);
    end
    
     
  • Keith KK

    Keith KK - 2016-03-14

    Another question:

    How can I allow for Inf for adigatorCreateAuxInput? Like

    adigatorCreateAuxInput([Inf 1]) or even adigatorCreateAuxInput([Inf Inf])

    Thanks!

     
  • Matthew J. Weinstein

    Hi,

    For the first question:
    - Currently there is no way to turn off the random sampling mechanism - this could pose an issue for some problems where it is expected that an input will be within some bounds. I should make this an option.
    - Unfortunately, even if you were to turn off that mechanism, the tool would not be able to figure out the reference using an unknown numeric object (prob = temp(:,resInd);). -This is something which is feasible to code up, but would take some work. It would amount to having subsref/subsasgn union the derivative sparsity patterns which result from all possible values of the reference indices. This would grow in complexity as the referenced variable and/or the reference index increase in size.
    - The least klugey, most general, solution would be to write a wrapper for the adigator generated function which performs the reference on the Jacobian.
    - If you are only using a scalar reference index which can only take on a limited number of values (2 in the example), then you may consider using an if/else statement:

    if resInd == 1
      prob = temp(:,1);
    elseif resInd == 2
      prob = temp(:,2);
    else
      prob = temp(:,3);
    end
    

    Where you just want to make sure that it will run with a random number as the input.

    For your second question:
    - You can allow one dimension of an auxiliary object to be vectorized by identifying its size at Inf as you showed. Example

    cx = adigatorCreateDerivInput([Inf 1],'x');
    ca = adigatorCreateAuxInput([Inf 1]);
    adigator('myfun',{cx,ca},'myderiv',adigatorOptions('overwrite',1));
    
    N = 25;
    x.f  = randn(N,1);
    x.dx = ones(N,1);
    a = randn(N,1);
    
    y = myderiv(x,a);
    

    where

    function y = myfun(x,a)
    y = sin(x).*a;
    end
    
    • You cannot make two dimensions vectorized. The fundamental assumption of the vectorization is that an element i of a variables vectorized dimension may only be a function of an element i of another variable. There is some explaination of this in the user's manual which equates the vectorized dimension to a value of time, where we are saying that we compute quantities that are only dependent upon the current time. By creating an Inf x Inf type object, then the variable has dependencies from all past/future times.

    Matt

     

    Last edit: Matthew J. Weinstein 2016-03-16

Log in to post a comment.