anchor.diff:      let post device (x: ArrayNDT<'T>) =
           if device = DevCuda then ArrayNDCuda.toDev (x :?> ArrayNDHostT<'T>) :> ArrayNDT<'T>
           else x 
  -    
  +    ///Sampling type for Model training parameters.
       type trainData ={
           Lengthscale:    ArrayNDT<single>
           Trn_X:          ArrayNDT<single>
           Trn_T:          ArrayNDT<single>
           Trn_Sigma:      ArrayNDT<single>
           }
  +
  +    ///Sampling type for Model input and prediction.
       type predOutput = {
          In_Mean:         ArrayNDT<single>
          In_Cov:          ArrayNDT<single>
          Pred_Mean:       ArrayNDT<single>
          Pred_Cov:        ArrayNDT<single>
          }
  -
  +    
  +    ///Generates a random list of singles that is sorted.
  +    let randomSortedListOfLength (rand:Random) (minValue,maxValue) length =
  +        [1..length] |> List.map (fun _ -> rand.NextDouble())
  +        |> List.map (fun x -> (single x))
  +        |> List.map (fun x -> x  * (maxValue - minValue) + minValue)
  +        |> List.sort
  +
  +    ///Generates multiple random sorted lists of singles in a 2D list
  +    let randomSortedLists (rand:Random) (minValue,maxValue) length = 
  +        List.map (fun _ -> randomSortedListOfLength rand (minValue,maxValue) length)
  +    
  +    let fsng x = single x
  +    let isng x = single x
  +
  +    //Generates a random single in the range (minValue,maxValue)
  +    let randSingleInRange (rand:Random) (minValue,maxValue) =
  +        let (imin,imax) = int minValue,int maxValue
  +        if (imin >= imax - 1) then
  +            failwith "range is too small"
  +        let rand1 = fsng (rand.NextDouble())
  +        let rand2 = isng(rand.Next(imin,imax-1))
  +        rand1+rand2
  +
  +    //Generates a random polynomial of maximal power 2
  +    let randPolynomial (rand:Random) list = 
  +
  +        let fact1 = fsng (rand.NextDouble())
  +        let fact2 = fsng (rand.NextDouble())
  +        let pow1 = isng (rand.Next(1,2))
  +        let pow2 = isng (rand.Next(1,2))
  +        list |> List.map (fun x ->   fact1 *x** pow1 - fact2 *x** pow2)
  +   
  +   ///Turns a random matrix in the form of a covariance matrix into a Psd matrix. 
  +    let fPsd c =        
  +        let cov: ExprT<single> = Expr.var "cov" [SizeSpec.broadcastable;SizeSpec.symbol "nGPs"; SizeSpec.symbol "nGPs"]
  +        let psd = cov.* cov
  +        let cmplr = DevHost.Compiler, CompileEnv.empty
  +        let funPsd = Func.make cmplr psd |> arg1 cov
  +        funPsd c
  +
  +
  +
  +    ///Tests multilayer GPs with random parameters and random inputs.
  +    ///Saves parameters and inputs in hdf5 files to compare with other implementations (especially gpsample.py).
       let testMultiGPLayer device =
   
  -        
  +        //initiating random number generator 
           let rand = Random()
  -
  +        //defining size parameters
           let ngps = 3
           let ntraining = 30
           let ntest = 2
   
  -        let cov: ExprT<single> = Expr.var "cov" [SizeSpec.broadcastable;SizeSpec.symbol "nGPs"; SizeSpec.symbol "nGPs"]
  -        let psd = cov.* cov
  -        let cmplr = DevHost.Compiler, CompileEnv.empty
  -        let fPsd = Func.make cmplr psd |> arg1 cov
  -
  -
  +
  +        //building the model
           let mb = ModelBuilder<single> "Test"
   
           let nSmpls    = mb.Size "nSmpls"
           let nGPs      = mb.Size "nGPs"
           let nTrnSmpls = mb.Size "nTrnSmpls"
           
  +
           let mgp = 
               MultiGPLayer.pars (mb.Module "MGP") {NGPs=nGPs; NTrnSmpls=nTrnSmpls}
           let inp_mean  : ExprT<single> = mb.Var "inp_mean"  [nSmpls; nGPs]
  
positive.code:         mi.ParameterStorage.[!mgp.TrnSigma] <- trn_sigma_val
  
  
          ///generates random test inputs
          let randomTest () =
              let inp_meanhost = rand.UniformArrayND (-5.0f ,5.0f) [1;ngps]
              let inp_mean_val = inp_meanhost |> post device
  
  
negative.code:             printfn "pred_mean=\n%A" pred_mean
              printfn "pred_cov=\n%A" pred_cov
  
              //return sample of inputs and predictions
              testInOut
          
          //run ntest tests and save samples in dataset
          printfn "Testing Multi GP Transfer Model"
          let testList = [1..ntest]
                         |> List.map (fun _-> randomTest () )
  