/* * This sample is a simplified version of Derek D. Monner's Distracted Sequence * Recall task, which involves 10 symbols: * * Targets: must be recognized and remembered by the network. * Distractors: never need to be remembered. * Prompts: direct the network to give an answer. * * A single trial consists of a temporal sequence of 10 input symbols. The first * 8 consist of 2 randomly chosen target symbols and 6 randomly chosen * distractor symbols in an random order. The remaining two symbols are two * prompts, which direct the network to produce the first and second target in * the sequence, in order. * * For more information, see the following paper. * * @code * @misc{Monner2012, * author = {Monner, Derek and Reggia, James A}, * title = {A generalized LSTM-like training algorithm for second-order * recurrent neural networks}, * year = {2012} * } * @endcode * * @param input The generated input sequence. * @param input The generated output sequence. */ void GenerateDistractedSequence(arma::mat& input, arma::mat& output) { input = arma::zeros<arma::mat>(10, 10); output = arma::zeros<arma::mat>(3, 10); arma::Col<size_t> index = arma::shuffle(arma::linspace<arma::Col<size_t> >( 0, 7, 8)); // Set the target in the input sequence and the corresponding targets in the // output sequence by following the correct order. for (size_t i = 0; i < 2; i++) { size_t idx = rand() % 2; input(idx, index(i)) = 1; output(idx, index(i) > index(i == 0) ? 9 : 8) = 1; } for (size_t i = 2; i < 8; i++) input(2 + rand() % 6, index(i)) = 1; // Set the prompts which direct the network to give an answer. input(8, 8) = 1; input(9, 9) = 1; input.reshape(input.n_elem, 1); output.reshape(output.n_elem, 1); }
// [[Rcpp::export]] arma::mat pMatC(arma::mat p){ arma::mat Pmat(4,4); Pmat.zeros(); arma::mat revI(4,4); revI.zeros(); //int n1=p.n_rows, n2=p.n_cols; //if(n1!=4 && n2!=4){} p.reshape(4,1); Pmat.col(0)=p; revI(0,1) = -1;revI(1,0) = 1; revI(2,3) = 1; revI(3,2) = -1; Pmat.col(1) = revI*p; revI.zeros(); revI(0,2) = -1;revI(1,3) = -1; revI(2,0) = 1; revI(3,1) = 1; Pmat.col(2) = revI*p; revI.zeros(); revI(0,3) = -1;revI(1,2) = 1; revI(2,1) = -1; revI(3,0) = 1; Pmat.col(3)=revI*p; return Pmat; }
bool subspaceIdMoor::simple_dlyap(arma::mat const &A, arma::mat const &Q, arma::mat &X){ mat kronProd = kron(A, A); mat I = eye(kronProd.n_rows, kronProd.n_cols); bool slvflg = solve(X, I - kronProd, vectorise(Q)); /*Reshape vec to matrix:*/ X.reshape(A.n_rows, A.n_rows); return slvflg; }