Difference between revisions of "ComputedBy"

 
Line 1: Line 1:
 +
[[Category:Special Functions]]
 +
 
= ComputedBy(X) =
 
= ComputedBy(X) =
  
Line 7: Line 9:
  
 
Then the definition of X must contain an assignment statement, ''A := value'', that sets the value of A.
 
Then the definition of X must contain an assignment statement, ''A := value'', that sets the value of A.
 +
 +
ComputedBy can only appear at the top level of a Variable's definition.
  
 
= Referential Transparency =
 
= Referential Transparency =

Revision as of 03:49, 18 October 2007


ComputedBy(X)

Used to indicate that the value of a variable is computed as a side-effect of a different variable X.

When a variable, A, has the definition

ComputedBy(X)

Then the definition of X must contain an assignment statement, A := value, that sets the value of A.

ComputedBy can only appear at the top level of a Variable's definition.

Referential Transparency

Analytica's modeling language is referentially transparent, so that side-effects in general are not allowed. However, in some cases it is natural to set another variable as a side-effect of a computation. ComputedBy makes this possible without a loss of referential transparency.

When to Use

ComputedBy can be particularly convenient within an Iterate function, when multiple quantities need to be updated at each iteration. Prior to the introduction of ComputedBy, it was necessary to bundle all quantites together, using references, and then unbundle them. With computed by, this can be accomplished as follows:

Variable A := ComputedBy(The_iteration)
Variable B := ComputedBy(The_iteration)
Variable The_iteration := Iterate(  initial:(A:=A0;B:=B0), 
                                    expr:(A:=F(A,B);B:=G(A,B)), 
                                    until: H(A,B), 
                                    maxIter:100 )

In other cases, there are times in which a useful quantity is computed in the course of computing a primary quantity. The secondary quantity can be stored in a variable defined as ComputedBy. The following is an example:

Variable Component_Variance := ComputedBy( Principle_Components )
Variable Principle_Components := 
     Var eig := EigenDecompose(X,I,J);
     Component_Variance := eig[.item='value'];
     #eig[.item='vector']

Use in Dynamic

When A := ComputedBy(X), and X is within a Dynamic loop, then the assignment within X sets the value of A for the current Time. Thus, A will also be indexed by Time when the computation completes.

Evaluation Mode

When A := ComputedBy(X), if the assignment to A inside of X's definition occurs from within a Sample evaluation context, then the Sample value of A is set. Likewise, if the assignment occurs from a Mid context, then the Mid value of A is set.

Availability

ComputedBy is not officially supported as of release 4.0.0, although it is present in the build. It is currently considered an experimental feature, and is not documented in the User's Guide.

See Also

Comments


You are not allowed to post comments.