anchor.diff:  module NeuralNetwork = 
   
       let inline create hiddenLayers output : NeuralNetwork = 
  -        let hiddens = hiddenLayers |> Array.Parallel.map(Layer)
  -        let output = Layer(output)
  -        [| hiddens; [|output|] |] |> Array.concat
  -
  -    let rec private forward (input : float Vector) (network: NeuralNetwork) i results = 
  +        [| hiddenLayers; [|output|] |] |> Array.concat
  +
  +    let rec private forwardPropagation (input : float Vector) (network: NeuralNetwork) i results = 
           if i < network.Length then
  -            match network.[i] with
  -            | Layer(layer) -> 
  -                let result = layer |> Array.Parallel.map(Neuron.forward input) |> DenseVector.ofArray
  -                forward result network (i + 1) (result::results)
  +            let layer = network.[i] 
  +            let result = layer |> Array.Parallel.map(Neuron.forward input) |> DenseVector.ofArray
  +            forwardPropagation result network (i + 1) (result::results)
           else 
  -            results.Head, results
  -
  -    let inline forwardPropagation input network = 
  -        forward input network 0 [] |> fst
  -
  -    let inline private backPropaganation errors layer+            results.Head, results |> Array.ofList
  +
  +    let mapInPlace<'T> (projection: 'T -> 'T) (array: 'T []) = 
  +        for i=0 to array.Length - 1 do
  +            array.[i] <- projection array.[i]
  +
  +    let mapiInPlace<'T> (projection: int -> 'T -> 'T) (array: 'T []) = 
  +        for i=0 to array.Length - 1 do
  +            array.[i] <- projection i array.[i]
  +
  +    let parallelMapInPlace (projection: 'T -> 'T) (array: 'T []) = 
  +        System.Threading.Tasks.Parallel.For(0, array.Length - 1, fun i -> array.[i] <- projection array.[i]) |> ignore
  +
  +    let parallelMapiInPlace (projection: int -> 'T -> 'T) (array: 'T []) = 
  +        System.Threading.Tasks.Parallel.For(0, array.Length - 1, fun i -> array.[i] <- projection i array.[i]) |> ignore
  +
  +    let inline  forward input network = 
  +        forwardPropagation input network 0 [] |> fst
  +
  +    let inline private learnLayer (alpha, epsilon) (inputs: float Vector []) (errors: float []) (layer: Layer) = 
  +        let learn i = if errors.[i] > epsilon then (Neuron.onlineLearning alpha inputs.[i] errors.[i]) else id
  +        layer |> parallelMapiInPlace (fun i neuron -> neuron |>  learn i)
  +
  +    let inline learn (alpha, epsilon) (X: float Matrix) (Y: float Vector) network = 
  +        let rec inner i prevD = 
  +            if i < network.Length then
  +                let layer = network.[i]
  +                
  +                 
  +                let d = (Yh.[i] - Y.[i]) * ()
  +                let x = Xs.[i]
  +        let Yh, Xs = 
  +            X 
  +            |> Matrix.toRowArrays 
  +            |> Array.Parallel.map(fun x -> 
  +                network 
  +                |> forwardPropagation x 0 []) 
  +            |> fun result -> result |> Array.Parallel.map fst, result |> Array.collect snd
  +        if costf Yh Y < epsilon then
  +            network
  +        else 
  +            for i=network.Length-1 to 0 do
  +                
  
positive.code:                 gdc {neuron with Weights = neuron.Weights - w'} (error::errors)
          gdc neuron []
  
      let inline onlineLearning (error: float) (x: float Vector) alpha neuron = 
          let f' = neuron.Activation'
          let max = x |> Vector.fold max (x.[0]) 
          let min = x |> Vector.fold min (x.[0])
  
negative.code:         let pName = match neuron.Func with | Lambda(var, _) -> var.Name | _ -> "x"
          {neuron with Activation = neuron.Func |> Utils.Misc.Expr.toLambda; Activation' = neuron.Func |> Utils.Math.Differential.d pName |> Utils.Misc.Expr.toLambda;}
  
  type Layer = Neuron []
      
  
  type NeuralNetwork = Layer []
  