//-------------------------------------------------------------------------------------------------- /// Project the given point onto the plane //-------------------------------------------------------------------------------------------------- Vec3d Plane::projectPoint(const Vec3d& point) const { Vec3d pip = pointInPlane(); // Create vector from point in plane to node Vec3d vector = point - pip; // Project vector to find node in plane Vec3d projectedPoint; if (projectVector(vector, &projectedPoint)) { projectedPoint += pip; } else { // The <point - pip> vector is parallel with the normal vector, use the point in plane as the projected projectedPoint = pip; } return projectedPoint; }
/** * Gradient (projected) * * @param x argument * @param g gradient */ void grad(const double* x, double* g) { projectPoint(x, mAux); gradBase(mAux, g); projectVector(x, g); }
AlphaList projectList( AlphaList list, int a, int z ) { /* Compute the back projection of the list sent in for a particular action and observation. It also takes the discounting into account. and part of the immediate reward. It distributes the immediate reward (which is independent of the observation) evenly among all the projection sets, so that the addition of the vectors will incorporate the proper immediate reward. */ AlphaList projection, temp; double *alpha; int cur_state; projection = newAlphaList(); /* We put the action and observation in the list header so we can easily identify which projection a particular list is. */ projection->action = a; projection->obs = z; if ( list == NULL ) return ( projection ); /* It is possible that a particular observation is impossible to observe for this given action and the possible resulting states. If this happens we will get a vector of all zeroes. This vector of all zeroes is a bit different than what we want. We want to say that there is no value function, not that the value is zero everywhere. When an observation is impossible, we represent this with a single vector of 1/|Z| weighted immediate rewards with prev_source pointer set to NULL. */ if ( ! gObservationPossible[a][z] ) { alpha = newAlpha(); for ( cur_state = 0; cur_state < gNumStates; cur_state++) alpha[cur_state] = getAdjustedReward( a, cur_state ) / ((double) gNumObservations); /* Make sure the projections will be added in the proper order. */ temp = appendAlphaList( projection, alpha, a ); temp->prev_source = NULL; temp->action = a; temp->obs = z; return ( projection ); } /* if impossible observation */ list = list->head; while ( list != NULL ) { temp = projectVector( list, a, z ); appendNodeToAlphaList( projection, temp ); list = list->next; } /* while list */ return ( projection ); } /* projectList */